2015-06-01 18:51:55 +02:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 14:55:33 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
**
|
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:55:33 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
2016-01-15 14:55:33 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <clangcodecompleteresults.h>
|
2016-07-01 15:07:32 +02:00
|
|
|
#include <clangfilepath.h>
|
2015-06-01 18:51:55 +02:00
|
|
|
#include <projectpart.h>
|
2015-08-31 12:40:14 +02:00
|
|
|
#include <projects.h>
|
2015-11-24 11:17:18 +01:00
|
|
|
#include <clangtranslationunit.h>
|
2015-08-31 12:40:14 +02:00
|
|
|
#include <translationunits.h>
|
2015-06-01 18:51:55 +02:00
|
|
|
#include <unsavedfiles.h>
|
|
|
|
#include <utf8string.h>
|
|
|
|
|
2015-06-16 12:38:04 +02:00
|
|
|
#include <clang-c/Index.h>
|
|
|
|
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <gmock/gmock-matchers.h>
|
|
|
|
#include <gtest/gtest.h>
|
2015-07-01 14:50:35 +02:00
|
|
|
#include "gtest-qt-printing.h"
|
2015-06-16 12:38:04 +02:00
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
namespace {
|
|
|
|
|
2015-06-16 11:56:00 +02:00
|
|
|
using ClangBackEnd::ClangCodeCompleteResults;
|
2016-07-01 15:07:32 +02:00
|
|
|
using ClangBackEnd::FilePath;
|
2015-06-16 11:56:00 +02:00
|
|
|
using ClangBackEnd::TranslationUnit;
|
|
|
|
using ClangBackEnd::UnsavedFiles;
|
|
|
|
using ClangBackEnd::ProjectPart;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-07-05 13:52:43 +02:00
|
|
|
static unsigned completionOptions(const TranslationUnit &translationUnit)
|
|
|
|
{
|
|
|
|
return translationUnit.defaultOptions() & CXTranslationUnit_IncludeBriefCommentsInCodeCompletion
|
|
|
|
? CXCodeComplete_IncludeBriefComments : 0;
|
|
|
|
}
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
TEST(ClangCodeCompleteResults, GetData)
|
|
|
|
{
|
|
|
|
ProjectPart projectPart(Utf8StringLiteral("projectPartId"));
|
2015-08-31 12:40:14 +02:00
|
|
|
ClangBackEnd::ProjectParts projects;
|
|
|
|
ClangBackEnd::UnsavedFiles unsavedFiles;
|
|
|
|
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
|
|
|
|
TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"),
|
|
|
|
projectPart,
|
2015-11-05 13:57:57 +01:00
|
|
|
Utf8StringVector(),
|
2015-08-31 12:40:14 +02:00
|
|
|
translationUnits);
|
2016-07-01 15:07:32 +02:00
|
|
|
Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnit.filePath());
|
2016-07-05 13:52:43 +02:00
|
|
|
CXCodeCompleteResults *cxCodeCompleteResults =
|
|
|
|
clang_codeCompleteAt(translationUnit.cxTranslationUnit(),
|
|
|
|
nativeFilePath.constData(),
|
|
|
|
49, 1, 0, 0,
|
|
|
|
completionOptions(translationUnit));
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults);
|
|
|
|
|
|
|
|
ASSERT_THAT(codeCompleteResults.data(), cxCodeCompleteResults);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ClangCodeCompleteResults, GetInvalidData)
|
|
|
|
{
|
|
|
|
CXCodeCompleteResults *cxCodeCompleteResults = clang_codeCompleteAt(nullptr, "file.cpp", 49, 1, 0, 0, 0);
|
|
|
|
|
|
|
|
ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults);
|
|
|
|
|
|
|
|
ASSERT_THAT(codeCompleteResults.data(), cxCodeCompleteResults);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ClangCodeCompleteResults, MoveClangCodeCompleteResults)
|
|
|
|
{
|
|
|
|
ProjectPart projectPart(Utf8StringLiteral("projectPartId"));
|
2015-08-31 12:40:14 +02:00
|
|
|
ClangBackEnd::ProjectParts projects;
|
|
|
|
ClangBackEnd::UnsavedFiles unsavedFiles;
|
|
|
|
ClangBackEnd::TranslationUnits translationUnits{projects, unsavedFiles};
|
|
|
|
TranslationUnit translationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"),
|
|
|
|
projectPart,
|
2015-11-05 13:57:57 +01:00
|
|
|
Utf8StringVector(),
|
2015-08-31 12:40:14 +02:00
|
|
|
translationUnits);
|
2016-07-01 15:07:32 +02:00
|
|
|
Utf8String nativeFilePath = FilePath::toNativeSeparators(translationUnit.filePath());
|
2016-07-05 13:52:43 +02:00
|
|
|
CXCodeCompleteResults *cxCodeCompleteResults =
|
|
|
|
clang_codeCompleteAt(translationUnit.cxTranslationUnit(),
|
|
|
|
nativeFilePath.constData(),
|
|
|
|
49, 1, 0, 0,
|
|
|
|
completionOptions(translationUnit));
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
ClangCodeCompleteResults codeCompleteResults(cxCodeCompleteResults);
|
|
|
|
|
|
|
|
const ClangCodeCompleteResults codeCompleteResults2 = std::move(codeCompleteResults);
|
|
|
|
|
|
|
|
ASSERT_TRUE(codeCompleteResults.isNull());
|
|
|
|
ASSERT_FALSE(codeCompleteResults2.isNull());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|