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
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-09-15 17:41:41 +02:00
|
|
|
#include "googletest.h"
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
#include <clangcodecompleteresults.h>
|
2016-09-07 10:42:12 +02:00
|
|
|
#include <clangdocument.h>
|
2016-07-01 15:07:32 +02:00
|
|
|
#include <clangfilepath.h>
|
2016-06-05 19:59:23 +02:00
|
|
|
#include <clangtranslationunitupdater.h>
|
2016-09-07 14:50:58 +02:00
|
|
|
#include <clangtranslationunit.h>
|
2016-09-07 10:42:12 +02:00
|
|
|
#include <clangdocuments.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>
|
|
|
|
|
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;
|
2016-09-07 10:42:12 +02:00
|
|
|
using ClangBackEnd::Document;
|
2015-06-16 11:56:00 +02:00
|
|
|
using ClangBackEnd::UnsavedFiles;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-06-05 19:59:23 +02:00
|
|
|
static unsigned completionOptions()
|
2016-07-05 13:52:43 +02:00
|
|
|
{
|
2016-06-05 19:59:23 +02:00
|
|
|
return ClangBackEnd::TranslationUnitUpdater::defaultParseOptions()
|
|
|
|
& CXTranslationUnit_IncludeBriefCommentsInCodeCompletion
|
|
|
|
? CXCodeComplete_IncludeBriefComments
|
|
|
|
: 0;
|
2016-07-05 13:52:43 +02:00
|
|
|
}
|
|
|
|
|
2017-01-04 11:39:17 +01:00
|
|
|
TEST(ClangCodeCompleteResultsSlowTest, GetData)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 12:40:14 +02:00
|
|
|
ClangBackEnd::UnsavedFiles unsavedFiles;
|
2018-09-25 09:41:32 +02:00
|
|
|
ClangBackEnd::Documents documents{unsavedFiles};
|
2016-09-07 10:42:12 +02:00
|
|
|
Document document(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"),
|
2018-10-19 10:20:27 +02:00
|
|
|
{},
|
|
|
|
{},
|
2016-09-07 10:42:12 +02:00
|
|
|
documents);
|
|
|
|
Utf8String nativeFilePath = FilePath::toNativeSeparators(document.filePath());
|
|
|
|
document.parse();
|
2016-07-05 13:52:43 +02:00
|
|
|
CXCodeCompleteResults *cxCodeCompleteResults =
|
2016-09-07 14:50:58 +02:00
|
|
|
clang_codeCompleteAt(document.translationUnit().cxTranslationUnit(),
|
2016-07-05 13:52:43 +02:00
|
|
|
nativeFilePath.constData(),
|
|
|
|
49, 1, 0, 0,
|
2016-06-05 19:59:23 +02:00
|
|
|
completionOptions());
|
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);
|
|
|
|
}
|
|
|
|
|
2017-01-04 11:39:17 +01:00
|
|
|
TEST(ClangCodeCompleteResultsSlowTest, MoveClangCodeCompleteResults)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-08-31 12:40:14 +02:00
|
|
|
ClangBackEnd::UnsavedFiles unsavedFiles;
|
2018-09-25 09:41:32 +02:00
|
|
|
ClangBackEnd::Documents documents{unsavedFiles};
|
2016-09-07 10:42:12 +02:00
|
|
|
Document document(Utf8StringLiteral(TESTDATA_DIR"/complete_testfile_1.cpp"),
|
2018-10-19 10:20:27 +02:00
|
|
|
{},
|
|
|
|
{},
|
2016-09-07 10:42:12 +02:00
|
|
|
documents);
|
|
|
|
Utf8String nativeFilePath = FilePath::toNativeSeparators(document.filePath());
|
|
|
|
document.parse();
|
2016-07-05 13:52:43 +02:00
|
|
|
CXCodeCompleteResults *cxCodeCompleteResults =
|
2016-09-07 14:50:58 +02:00
|
|
|
clang_codeCompleteAt(document.translationUnit().cxTranslationUnit(),
|
2016-07-05 13:52:43 +02:00
|
|
|
nativeFilePath.constData(),
|
|
|
|
49, 1, 0, 0,
|
2016-06-05 19:59:23 +02:00
|
|
|
completionOptions());
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|