diff options
author | Eike Ziller <eike.ziller@qt.io> | 2018-11-09 13:30:40 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2018-11-09 13:30:40 +0100 |
commit | 3666e3aaeb26f91097a473491ea4cf58219029ca (patch) | |
tree | 2d1387557e243eacfe78698371c7726aa9a19350 /tests | |
parent | 951eb885af8692c2c4aac67d18e3cbf033b7e912 (diff) | |
parent | dc82e49b62d6b851900689321828aee95f8eab54 (diff) |
Merge remote-tracking branch 'origin/4.8'
Conflicts:
tests/unit/unittest/unittest.pro
Change-Id: I4f0ab05f96ee60900a3a35fad4c7331238367593
Diffstat (limited to 'tests')
37 files changed, 887 insertions, 462 deletions
diff --git a/tests/auto/debugger/tst_dumpers.cpp b/tests/auto/debugger/tst_dumpers.cpp index 3084db31b5..b3754c90e5 100644 --- a/tests/auto/debugger/tst_dumpers.cpp +++ b/tests/auto/debugger/tst_dumpers.cpp @@ -5520,7 +5520,9 @@ void tst_Dumpers::dumper_data() "enum E { V1, V2 };" "struct S\n" "{\n" - " S() : x(2), y(3), z(39), e(V2), c(1), b(0), f(5), d(6), i(7) {}\n" + " S() : front(13), x(2), y(3), z(39), e(V2), c(1), b(0), f(5)," + " d(6), i(7) {}\n" + " unsigned int front;\n" " unsigned int x : 3;\n" " unsigned int y : 4;\n" " unsigned int z : 18;\n" @@ -5547,6 +5549,7 @@ void tst_Dumpers::dumper_data() + Check("s.x", "2", "unsigned int") % CdbEngine + Check("s.y", "3", "unsigned int") % CdbEngine + Check("s.z", "39", "unsigned int") % CdbEngine + + Check("s.front", "13", "unsigned int") + Check("s.e", "V2 (1)", TypePattern("main::[a-zA-Z0-9_]*::E")) % CdbEngine; @@ -5757,7 +5760,11 @@ void tst_Dumpers::dumper_data() "const Foo &b4 = a4;\n" "typedef Foo &Ref4;\n" "const Ref4 d4 = const_cast<Ref4>(a4);\n" - "unused(&a4, &b4, &d4);\n") + "unused(&a4, &b4, &d4);\n" + + "int *q = 0;\n" + "int &qq = *q;\n" + "unused(&qq, &q);\n") + CoreProfile() + NoCdbEngine // The Cdb has no information about references @@ -5781,7 +5788,9 @@ void tst_Dumpers::dumper_data() + Check("b4", "", "Foo &") + Check("b4.a", "12", "int") //+ Check("d4", "\"hello\"", "Ref4"); FIXME: We get "Foo &" instead - + Check("d4.a", "12", "int"); + + Check("d4.a", "12", "int") + + + Check("qq", "<null reference>", "int &"); QTest::newRow("DynamicReference") << Data("struct BaseClass { virtual ~BaseClass() {} };\n" diff --git a/tests/system/suite_editors/tst_memberoperator/test.py b/tests/system/suite_editors/tst_memberoperator/test.py index d7b20f8b3d..910e4b35c5 100644 --- a/tests/system/suite_editors/tst_memberoperator/test.py +++ b/tests/system/suite_editors/tst_memberoperator/test.py @@ -25,12 +25,29 @@ source("../../shared/qtcreator.py") +WhatsThisRole = 5 # Qt::WhatsThisRole + +def __getGenericProposalListView__(timeout): + try: + waitForObject(':popupFrame_TextEditor::GenericProposalWidget', timeout) + return findObject(':popupFrame_Proposal_QListView') + except LookupError: + return None + + +def __verifyLineUnderCursor__(cppwindow, record): + found = str(lineUnderCursor(cppwindow)).strip() + exp = testData.field(record, "expected") + test.compare(found, exp) + + def main(): for useClang in [False, True]: with TestSection(getCodeModelString(useClang)): if not startCreatorVerifyingClang(useClang): continue createProject_Qt_Console(tempDir(), "SquishProject") + selectBuildConfig(Targets.DESKTOP_5_6_1_DEFAULT, "Debug") # do not use the default Qt4 checkCodeModelSettings(useClang) selectFromLocator("main.cpp") cppwindow = waitForObject(":Qt Creator_CppEditor::Internal::CPPEditorWidget") @@ -45,10 +62,36 @@ def main(): type(cppwindow, testData.field(record, "usage")) snooze(1) # maybe find something better type(cppwindow, testData.field(record, "operator")) - waitFor("object.exists(':popupFrame_TextEditor::GenericProposalWidget')", 1500) - found = str(lineUnderCursor(cppwindow)).strip() - exp = testData.field(record, "expected") - test.compare(found, exp) + genericProposalWidget = __getGenericProposalListView__(1500) + # the clang code model does not change the . to -> before applying a proposal + # so, verify list of proposals roughly + if useClang: + expectProposal = testData.field(record, "clangProposal") == 'True' + test.compare(genericProposalWidget is not None, expectProposal, + 'Verifying whether proposal widget is displayed as expected.') + + if genericProposalWidget is not None: + model = genericProposalWidget.model() + proposalToolTips = dumpItems(model, role=WhatsThisRole) + needCorrection = filter(lambda x: 'Requires changing "." to "->"' in x, + proposalToolTips) + correction = testData.field(record, "correction") + if correction == 'all': + test.compare(len(needCorrection), len(proposalToolTips), + "Verifying whether all proposal need correction.") + elif correction == 'mixed': + test.verify(len(proposalToolTips) > len(needCorrection) > 0, + "Verifying whether some of the proposals need correction.") + elif correction == 'none': + test.verify(len(needCorrection) == 0, + "Verifying whether no proposal needs a correction.") + else: + test.warning("Used tsv file seems to be broken - found '%s' in " + "correction column." % correction) + elif not expectProposal: + __verifyLineUnderCursor__(cppwindow, record) + else: + __verifyLineUnderCursor__(cppwindow, record) invokeMenuItem("File", 'Revert "main.cpp" to Saved') clickButton(waitForObject(":Revert to Saved.Proceed_QPushButton")) snooze(1) diff --git a/tests/system/suite_editors/tst_memberoperator/testdata/usages.tsv b/tests/system/suite_editors/tst_memberoperator/testdata/usages.tsv index 9d44b0431f..daecc37c7a 100644 --- a/tests/system/suite_editors/tst_memberoperator/testdata/usages.tsv +++ b/tests/system/suite_editors/tst_memberoperator/testdata/usages.tsv @@ -1,30 +1,32 @@ -"include" "declaration" "usage" "operator" "expected" -"" "" "syntaxError" "." "syntaxError." -"" "" "argc" "." "argc." -"" "" "argv[0]" "." "argv[0]." -"" "" "2" "." "2." -"" "" "float fl = 2" "." "float fl = 2." -"" "QCoreApplication qa;" "qa" "." "qa." -"" "QCoreApplication *p;" "p" "." "p->" -"" "QCoreApplication &ref = a;" "ref" "." "ref." -"<QPointer>" "QPointer<QCoreApplication> p;" "p" "." "p." -"<QPointer>" "QPointer<QCoreApplication> *poi;" "poi" "." "poi->" -"<QPointer>" "QPointer<QCoreApplication> &poi;" "poi" "." "poi." -"<QPointer>" "QPointer<QCoreApplication> poi[5];" "poi[2]" "." "poi[2]." -"<QPointer>" "QPointer<QCoreApplication> *poi[5];" "poi[2]" "." "poi[2]->" -"<memory>" "std::auto_ptr<QCoreApplication> sap;" "sap" "." "sap." -"<memory>" "std::auto_ptr<QCoreApplication> *sap;" "sap" "." "sap->" -"<memory>" "std::auto_ptr<QCoreApplication> &sap;" "sap" "." "sap." -"<memory>" "std::auto_ptr<QCoreApplication> sap[10];" "sap[2]" "." "sap[2]." -"<memory>" "std::auto_ptr<QCoreApplication> *sap[10];" "sap[2]" "." "sap[2]->" -"<QVector>" "QVector<QCoreApplication> vec;" "vec" "." "vec." -"<QVector>" "QVector<QCoreApplication *> vec;" "vec" "." "vec." -"<QVector>" "QVector<QCoreApplication> *vec;" "vec" "." "vec->" -"<QVector>" "QVector<QCoreApplication *> *vec;" "vec" "." "vec->" -"<QVector>" "QVector<QCoreApplication> vec;" "vec[0]" "." "vec[0]." -"<QVector>" "QVector<QCoreApplication *> vec;" "vec[0]" "." "vec[0]->" -"" "struct Foo { int foo; }; Foo *baz;" "baz" "." "baz->" -"<QString>" "auto s = QString();" "s" "." "s." -"<QString>" "auto *s = QString();" "s" "." "s." -"<QString>" "auto s = new QString();" "s" "." "s->" -"<QString>" "auto *s = new QString();" "s" "." "s->" +"include" "declaration" "usage" "operator" "expected" "clangProposal" "correction" +"" "" "syntaxError" "." "syntaxError." "False" "" +"" "" "argc" "." "argc." "False" "" +"" "" "argv[0]" "." "argv[0]." "False" "" +"" "" "2" "." "2." "False" "" +"" "" "float fl = 2" "." "float fl = 2." "False" "" +"" "QCoreApplication qa;" "qa" "." "qa." "False" "" +"" "QCoreApplication *p;" "p" "." "p->" "True" "all" +"" "QCoreApplication &ref = a;" "ref" "." "ref." "True" "none" +"<QPointer>" "QPointer<QCoreApplication> p;" "p" "." "p." "True" "mixed" +"<QPointer>" "QPointer<QCoreApplication> *poi;" "poi" "." "poi->" "True" "all" +"<QPointer>" "QPointer<QCoreApplication> &poi;" "poi" "." "poi." "False" "" +"<QPointer>" "QPointer<QCoreApplication> pa; QPointer<QCoreApplication> &poi = pa;" "poi" "." "poi." "True" "mixed" +"<QPointer>" "QPointer<QCoreApplication> poi[5];" "poi[2]" "." "poi[2]." "True" "mixed" +"<QPointer>" "QPointer<QCoreApplication> *poi[5];" "poi[2]" "." "poi[2]->" "True" "all" +"<memory>" "std::auto_ptr<QCoreApplication> sap;" "sap" "." "sap." "True" "mixed" +"<memory>" "std::auto_ptr<QCoreApplication> *sap;" "sap" "." "sap->" "True" "all" +"<memory>" "std::auto_ptr<QCoreApplication> &sap;" "sap" "." "sap." "False" "" +"<memory>" "std::auto_ptr<QCoreApplication> sapqa; std::auto_ptr<QCoreApplication> &sap = sapqa;" "sap" "." "sap." "True" "mixed" +"<memory>" "std::auto_ptr<QCoreApplication> sap[10];" "sap[2]" "." "sap[2]." "True" "mixed" +"<memory>" "std::auto_ptr<QCoreApplication> *sap[10];" "sap[2]" "." "sap[2]->" "True" "all" +"<QVector>" "QVector<QCoreApplication> vec;" "vec" "." "vec." "True" "none" +"<QVector>" "QVector<QCoreApplication *> vec;" "vec" "." "vec." "True" "none" +"<QVector>" "QVector<QCoreApplication> *vec;" "vec" "." "vec->" "True" "all" +"<QVector>" "QVector<QCoreApplication *> *vec;" "vec" "." "vec->" "True" "all" +"<QVector>" "QVector<QCoreApplication> vec;" "vec[0]" "." "vec[0]." "True" "none" +"<QVector>" "QVector<QCoreApplication *> vec;" "vec[0]" "." "vec[0]->" "True" "all" +"" "struct Foo { int foo; }; Foo *baz;" "baz" "." "baz->" "True" "all" +"<QString>" "auto s = QString();" "s" "." "s." "True" "none" +"<QString>" "auto *s = QString();" "s" "." "s." "False" "" +"<QString>" "auto s = new QString();" "s" "." "s->" "True" "all" +"<QString>" "auto *s = new QString();" "s" "." "s->" "True" "all" diff --git a/tests/unit/unittest/builddependenciesprovider-test.cpp b/tests/unit/unittest/builddependenciesprovider-test.cpp new file mode 100644 index 0000000000..24d4b10465 --- /dev/null +++ b/tests/unit/unittest/builddependenciesprovider-test.cpp @@ -0,0 +1,152 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 +** 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. +** +** 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. +** +****************************************************************************/ + +#include "googletest.h" + +#include "mockbuilddependenciesstorage.h" +#include "mockmodifiedtimechecker.h" +#include "mockbuilddependenciesgenerator.h" + +#include <builddependenciesprovider.h> + +namespace { + +using ClangBackEnd::BuildDependency; +using ClangBackEnd::BuildDependencies; +using ClangBackEnd::FilePathId; +using ClangBackEnd::FilePathIds; +using ClangBackEnd::SourceEntry; +using ClangBackEnd::SourceEntries; +using ClangBackEnd::SourceType; +using ClangBackEnd::UsedMacro; +using ClangBackEnd::UsedMacros; + +MATCHER_P(HasSourceId, sourceId, std::string(negation ? "hasn't" : "has") + + " sourceId " + PrintToString(sourceId)) +{ + const SourceEntry & sourceEntry = arg; + + return sourceEntry.sourceId.filePathId == sourceId; +} + +class BuildDependenciesProvider : public testing::Test +{ +protected: + NiceMock<MockBuildDependenciesStorage> mockBuildDependenciesStorage; + NiceMock<MockModifiedTimeChecker> mockModifiedTimeChecker; + NiceMock<MockBuildDependenciesGenerator> mockBuildDependenciesGenerator; + ClangBackEnd::BuildDependenciesProvider provider{mockBuildDependenciesStorage, mockModifiedTimeChecker, mockBuildDependenciesGenerator}; + ClangBackEnd::V2::ProjectPartContainer projectPart1{"ProjectPart1", + {"--yi"}, + {{"YI","1"}}, + {"/yi"}, + {1}, + {2}}; + ClangBackEnd::V2::ProjectPartContainer projectPart2{"ProjectPart2", + {"--er"}, + {{"ER","2"}}, + {"/er"}, + {1}, + {2, 3, 4}}; + SourceEntries firstSources{{1, SourceType::Any, 1}, {2, SourceType::Any, 1}, {10, SourceType::Any, 1}}; + SourceEntries secondSources{{1, SourceType::Any, 1}, {3, SourceType::Any, 1}, {8, SourceType::Any, 1}}; + SourceEntries thirdSources{{4, SourceType::Any, 1}, {8, SourceType::Any, 1}, {10, SourceType::Any, 1}}; + UsedMacros firstUsedMacros{{"YI", 1}}; + UsedMacros secondUsedMacros{{"LIANG", 2}, {"ER", 2}}; + UsedMacros thirdUsedMacros{{"SAN", 10}}; + BuildDependency buildDependency{secondSources, {}, {}, {}}; +}; + +TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromStorageIfTimeStampsAreUpToDate) +{ + InSequence s; + + EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))).WillRepeatedly(Return(firstSources)); + EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(true)); + EXPECT_CALL(mockBuildDependenciesGenerator, create(projectPart1)).Times(0); + + provider.create(projectPart1); +} + +TEST_F(BuildDependenciesProvider, FetchDependSourcesFromStorage) +{ + ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart2"))).WillByDefault(Return(firstSources)); + ON_CALL(mockBuildDependenciesStorage, fetchDependSources({3}, TypedEq<Utils::SmallStringView>("ProjectPart2"))).WillByDefault(Return(secondSources)); + ON_CALL(mockBuildDependenciesStorage, fetchDependSources({4}, TypedEq<Utils::SmallStringView>("ProjectPart2"))).WillByDefault(Return(thirdSources)); + ON_CALL(mockModifiedTimeChecker, isUpToDate(_)).WillByDefault(Return(true)); + + auto buildDependency = provider.create(projectPart2); + + ASSERT_THAT(buildDependency.includes, ElementsAre(HasSourceId(1), HasSourceId(2), HasSourceId(3), HasSourceId(4), HasSourceId(8), HasSourceId(10))); +} + +TEST_F(BuildDependenciesProvider, CreateCallsFetchDependSourcesFromGeneratorIfTimeStampsAreNotUpToDate) +{ + InSequence s; + + EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))).WillRepeatedly(Return(firstSources)); + EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(false)); + EXPECT_CALL(mockBuildDependenciesGenerator, create(projectPart1)); + + provider.create(projectPart1); +} + +TEST_F(BuildDependenciesProvider, FetchDependSourcesFromGenerator) +{ + ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))).WillByDefault(Return(firstSources)); + ON_CALL(mockModifiedTimeChecker, isUpToDate(_)).WillByDefault(Return(false)); + ON_CALL(mockBuildDependenciesGenerator, create(projectPart1)).WillByDefault(Return(buildDependency)); + + auto buildDependency = provider.create(projectPart1); + + ASSERT_THAT(buildDependency.includes, ElementsAre(HasSourceId(1), HasSourceId(3), HasSourceId(8))); +} + +TEST_F(BuildDependenciesProvider, CreateCallsFetchUsedMacrosFromStorageIfTimeStampsAreUpToDate) +{ + InSequence s; + + EXPECT_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))).WillRepeatedly(Return(firstSources)); + EXPECT_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillRepeatedly(Return(true)); + EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros({1})); + EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros({2})); + EXPECT_CALL(mockBuildDependenciesStorage, fetchUsedMacros({10})); + + provider.create(projectPart1); +} + +TEST_F(BuildDependenciesProvider, FetchUsedMacrosFromStorageIfDependSourcesAreUpToDate) +{ + ON_CALL(mockBuildDependenciesStorage, fetchDependSources({2}, TypedEq<Utils::SmallStringView>("ProjectPart1"))).WillByDefault(Return(firstSources)); + ON_CALL(mockModifiedTimeChecker, isUpToDate(firstSources)).WillByDefault(Return(true)); + ON_CALL(mockBuildDependenciesStorage, fetchUsedMacros({1})).WillByDefault(Return(firstUsedMacros)); + ON_CALL(mockBuildDependenciesStorage, fetchUsedMacros({2})).WillByDefault(Return(secondUsedMacros)); + ON_CALL(mockBuildDependenciesStorage, fetchUsedMacros({10})).WillByDefault(Return(thirdUsedMacros)); + + auto buildDependency = provider.create(projectPart1); + + ASSERT_THAT(buildDependency.usedMacros, ElementsAre(UsedMacro{"YI", 1}, UsedMacro{"ER", 2}, UsedMacro{"LIANG", 2}, UsedMacro{"SAN", 10})); +} +} diff --git a/tests/unit/unittest/usedmacroandsourcestorage-test.cpp b/tests/unit/unittest/builddependenciesstorage-test.cpp index d9acc7f123..05d3d70887 100644 --- a/tests/unit/unittest/usedmacroandsourcestorage-test.cpp +++ b/tests/unit/unittest/builddependenciesstorage-test.cpp @@ -29,7 +29,7 @@ #include "mocksqlitedatabase.h" #include <sqlitedatabase.h> -#include <usedmacroandsourcestorage.h> +#include <builddependenciesstorage.h> #include <utils/optional.h> @@ -38,12 +38,15 @@ namespace { using Utils::PathString; using ClangBackEnd::FilePathId; using ClangBackEnd::FilePathCachingInterface; +using ClangBackEnd::SourceEntries; +using ClangBackEnd::SourceType; +using ClangBackEnd::UsedMacro; using Sqlite::Database; using Sqlite::Table; -using Storage = ClangBackEnd::UsedMacroAndSourceStorage<MockSqliteDatabase>; +using Storage = ClangBackEnd::BuildDependenciesStorage<MockSqliteDatabase>; -class UsedMacroAndSourceStorage : public testing::Test +class BuildDependenciesStorage : public testing::Test { protected: NiceMock<MockSqliteDatabase> mockDatabase; @@ -52,15 +55,20 @@ protected: MockSqliteWriteStatement &syncNewUsedMacrosStatement =storage.m_syncNewUsedMacrosStatement; MockSqliteWriteStatement &deleteOutdatedUsedMacrosStatement = storage.m_deleteOutdatedUsedMacrosStatement; MockSqliteWriteStatement &deleteNewUsedMacrosTableStatement = storage.m_deleteNewUsedMacrosTableStatement; - MockSqliteWriteStatement &insertFileStatuses = storage.m_insertFileStatuses; + MockSqliteWriteStatement &insertFileStatuses = storage.m_insertFileStatusesStatement; MockSqliteWriteStatement &insertIntoNewSourceDependenciesStatement = storage.m_insertIntoNewSourceDependenciesStatement; MockSqliteWriteStatement &syncNewSourceDependenciesStatement = storage.m_syncNewSourceDependenciesStatement; MockSqliteWriteStatement &deleteOutdatedSourceDependenciesStatement = storage.m_deleteOutdatedSourceDependenciesStatement; MockSqliteWriteStatement &deleteNewSourceDependenciesStatement = storage.m_deleteNewSourceDependenciesStatement; MockSqliteReadStatement &getLowestLastModifiedTimeOfDependencies = storage.m_getLowestLastModifiedTimeOfDependencies; + MockSqliteWriteStatement &updateBuildDependencyTimeStampStatement = storage.m_updateBuildDependencyTimeStampStatement; + MockSqliteWriteStatement &updateSourceTypeStatement = storage.m_updateSourceTypeStatement; + MockSqliteReadStatement &fetchSourceDependenciesStatement = storage.m_fetchSourceDependenciesStatement; + MockSqliteReadStatement &fetchProjectPartIdStatement = storage.m_fetchProjectPartIdStatement; + MockSqliteReadStatement &fetchUsedMacrosStatement = storage.m_fetchUsedMacrosStatement; }; -TEST_F(UsedMacroAndSourceStorage, ConvertStringsToJson) +TEST_F(BuildDependenciesStorage, ConvertStringsToJson) { Utils::SmallStringVector strings{"foo", "bar", "foo"}; @@ -69,7 +77,7 @@ TEST_F(UsedMacroAndSourceStorage, ConvertStringsToJson) ASSERT_THAT(jsonText, Eq("[\"foo\",\"bar\",\"foo\"]")); } -TEST_F(UsedMacroAndSourceStorage, InsertOrUpdateUsedMacros) +TEST_F(BuildDependenciesStorage, InsertOrUpdateUsedMacros) { InSequence sequence; @@ -79,18 +87,18 @@ TEST_F(UsedMacroAndSourceStorage, InsertOrUpdateUsedMacros) EXPECT_CALL(deleteOutdatedUsedMacrosStatement, execute()); EXPECT_CALL(deleteNewUsedMacrosTableStatement, execute()); - storage.insertOrUpdateUsedMacros({{"FOO", {1, 42}}, {"BAR", {1, 43}}}); + storage.insertOrUpdateUsedMacros({{"FOO", 42}, {"BAR", 43}}); } -TEST_F(UsedMacroAndSourceStorage, InsertFileStatuses) +TEST_F(BuildDependenciesStorage, InsertFileStatuses) { EXPECT_CALL(insertFileStatuses, write(TypedEq<int>(42), TypedEq<off_t>(1), TypedEq<time_t>(2), TypedEq<bool>(false))); EXPECT_CALL(insertFileStatuses, write(TypedEq<int>(43), TypedEq<off_t>(4), TypedEq<time_t>(5), TypedEq<bool>(true))); - storage.insertFileStatuses({{{1, 42}, 1, 2, false}, {{1, 43}, 4, 5, true}}); + storage.insertFileStatuses({{42, 1, 2, false}, {43, 4, 5, true}}); } -TEST_F(UsedMacroAndSourceStorage, InsertOrUpdateSourceDependencies) +TEST_F(BuildDependenciesStorage, InsertOrUpdateSourceDependencies) { InSequence sequence; @@ -100,10 +108,10 @@ TEST_F(UsedMacroAndSourceStorage, InsertOrUpdateSourceDependencies) EXPECT_CALL(deleteOutdatedSourceDependenciesStatement, execute()); EXPECT_CALL(deleteNewSourceDependenciesStatement, execute()); - storage.insertOrUpdateSourceDependencies({{{1, 42}, {1, 1}}, {{1, 42}, {1, 2}}}); + storage.insertOrUpdateSourceDependencies({{42, 1}, {42, 2}}); } -TEST_F(UsedMacroAndSourceStorage, AddTablesInConstructor) +TEST_F(BuildDependenciesStorage, AddTablesInConstructor) { InSequence s; @@ -118,26 +126,26 @@ TEST_F(UsedMacroAndSourceStorage, AddTablesInConstructor) } -TEST_F(UsedMacroAndSourceStorage, FetchLowestLastModifiedTimeIfNoModificationTimeExists) +TEST_F(BuildDependenciesStorage, FetchLowestLastModifiedTimeIfNoModificationTimeExists) { EXPECT_CALL(getLowestLastModifiedTimeOfDependencies, valueReturnInt64(Eq(1))); - auto lowestLastModified = storage.fetchLowestLastModifiedTime({1, 1}); + auto lowestLastModified = storage.fetchLowestLastModifiedTime(1); ASSERT_THAT(lowestLastModified, Eq(0)); } -TEST_F(UsedMacroAndSourceStorage, FetchLowestLastModifiedTime) +TEST_F(BuildDependenciesStorage, FetchLowestLastModifiedTime) { EXPECT_CALL(getLowestLastModifiedTimeOfDependencies, valueReturnInt64(Eq(21))) .WillRepeatedly(Return(12)); - auto lowestLastModified = storage.fetchLowestLastModifiedTime({1, 21}); + auto lowestLastModified = storage.fetchLowestLastModifiedTime(21); ASSERT_THAT(lowestLastModified, Eq(12)); } -TEST_F(UsedMacroAndSourceStorage, AddNewUsedMacroTable) +TEST_F(BuildDependenciesStorage, AddNewUsedMacroTable) { InSequence s; @@ -147,7 +155,7 @@ TEST_F(UsedMacroAndSourceStorage, AddNewUsedMacroTable) storage.createNewUsedMacrosTable(); } -TEST_F(UsedMacroAndSourceStorage, AddNewSourceDependenciesTable) +TEST_F(BuildDependenciesStorage, AddNewSourceDependenciesTable) { InSequence s; @@ -157,5 +165,71 @@ TEST_F(UsedMacroAndSourceStorage, AddNewSourceDependenciesTable) storage.createNewSourceDependenciesTable(); } +TEST_F(BuildDependenciesStorage, UpdateSources) +{ + InSequence s; + SourceEntries entries{{1, SourceType::TopInclude, 10}, {2, SourceType::TopSystemInclude, 20}}; + + EXPECT_CALL(updateBuildDependencyTimeStampStatement, write(TypedEq<long long>(10), TypedEq<int>(1))); + EXPECT_CALL(updateSourceTypeStatement, write(TypedEq<uchar>(1), TypedEq<int>(1))); + EXPECT_CALL(updateBuildDependencyTimeStampStatement, write(TypedEq<long long>(20), TypedEq<int>(2))); + EXPECT_CALL(updateSourceTypeStatement, write(TypedEq<uchar>(2), TypedEq<int>(2))); + + storage.updateSources(entries); +} + +TEST_F(BuildDependenciesStorage, CallsFetchDependSourcesWithNonExistingProjectPartDontFetchesSourceDependencies) +{ + EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq<Utils::SmallStringView>("test"))).WillOnce(Return(Utils::optional<int>{})); + EXPECT_CALL(fetchSourceDependenciesStatement, valuesReturnSourceEntries(_, _, _)).Times(0); + + storage.fetchDependSources(22, "test"); +} + +TEST_F(BuildDependenciesStorage, CallsFetchDependSourcesWithExistingProjectPartFetchesSourceDependencies) +{ + EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq<Utils::SmallStringView>("test"))).WillOnce(Return(Utils::optional<int>{20})); + EXPECT_CALL(fetchSourceDependenciesStatement, valuesReturnSourceEntries(_, 22, 20)); + + storage.fetchDependSources(22, "test"); +} + +TEST_F(BuildDependenciesStorage, FetchDependSourcesWithNonExistingProjectPartReturnsEmptySourceEntries) +{ + EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq<Utils::SmallStringView>("test"))).WillOnce(Return(Utils::optional<int>{})); + + auto entries = storage.fetchDependSources(22, "test"); + + ASSERT_THAT(entries, IsEmpty()); +} + +TEST_F(BuildDependenciesStorage, FetchDependSourcesWithExistingProjectPartReturnsSourceEntries) +{ + SourceEntries sourceEntries{{1, SourceType::TopInclude, 10}, {2, SourceType::TopSystemInclude, 20}}; + EXPECT_CALL(fetchProjectPartIdStatement, valueReturnInt32(TypedEq<Utils::SmallStringView>("test"))).WillOnce(Return(Utils::optional<int>{20})); + EXPECT_CALL(fetchSourceDependenciesStatement, valuesReturnSourceEntries(_, 22, 20)).WillOnce(Return(sourceEntries)); + + auto entries = storage.fetchDependSources(22, "test"); + + ASSERT_THAT(entries, sourceEntries); +} + +TEST_F(BuildDependenciesStorage, CallsFetchUsedMacros) +{ + EXPECT_CALL(fetchUsedMacrosStatement, valuesReturnUsedMacros(_, 22)); + + storage.fetchUsedMacros(22); +} + +TEST_F(BuildDependenciesStorage, FetchUsedMacros) +{ + ClangBackEnd::UsedMacros result{UsedMacro{"YI", 1}, UsedMacro{"ER", 2}}; + EXPECT_CALL(fetchUsedMacrosStatement, valuesReturnUsedMacros(_, 22)).WillOnce(Return(result)); + + auto usedMacros = storage.fetchUsedMacros(22); + + ASSERT_THAT(usedMacros, result); +} + } diff --git a/tests/unit/unittest/clangpathwatcher-test.cpp b/tests/unit/unittest/clangpathwatcher-test.cpp index bdc20348bc..058ae8e96a 100644 --- a/tests/unit/unittest/clangpathwatcher-test.cpp +++ b/tests/unit/unittest/clangpathwatcher-test.cpp @@ -73,7 +73,7 @@ protected: FilePathView path2{"/path/path2"}; QString path1QString = QString(path1.toStringView()); QString path2QString = QString(path2.toStringView()); - FilePathIds pathIds = {{1, 1}, {1, 2}}; + FilePathIds pathIds = {1, 2}; std::vector<int> ids{watcher.idCache().stringIds({id1, id2, id3})}; WatcherEntry watcherEntry1{ids[0], pathIds[0]}; WatcherEntry watcherEntry2{ids[1], pathIds[0]}; diff --git a/tests/unit/unittest/clangqueryexamplehighlightmarker-test.cpp b/tests/unit/unittest/clangqueryexamplehighlightmarker-test.cpp index 7d65e40025..8af631774f 100644 --- a/tests/unit/unittest/clangqueryexamplehighlightmarker-test.cpp +++ b/tests/unit/unittest/clangqueryexamplehighlightmarker-test.cpp @@ -66,7 +66,7 @@ TEST_F(ClangQueryExampleHighlightMarker, NoCallForNotSourceRanges) TEST_F(ClangQueryExampleHighlightMarker, SingleLineSourceRange) { - SourceRanges sourceRanges{{{1, 1}, 1, 3, 3, 1, 10, 10, "function"}}; + SourceRanges sourceRanges{{1, 1, 3, 3, 1, 10, 10, "function"}}; Marker marker(std::move(sourceRanges), highlighter, textFormats); EXPECT_CALL(highlighter, setFormat(2, 7, textFormats[0])); @@ -76,7 +76,7 @@ TEST_F(ClangQueryExampleHighlightMarker, SingleLineSourceRange) TEST_F(ClangQueryExampleHighlightMarker, OtherSingleLineSourceRange) { - SourceRanges sourceRanges{{{1, 1}, 2, 5, 5, 2, 11, 11, "function"}}; + SourceRanges sourceRanges{{1, 2, 5, 5, 2, 11, 11, "function"}}; Marker marker(std::move(sourceRanges), highlighter, textFormats); marker.highlightBlock(1, "foo"); @@ -88,9 +88,9 @@ TEST_F(ClangQueryExampleHighlightMarker, OtherSingleLineSourceRange) TEST_F(ClangQueryExampleHighlightMarker, CascadedSingleLineSourceRanges) { InSequence sequence; - SourceRanges sourceRanges{{{1, 1}, 1, 2, 2, 1, 15, 15, "void function"}, - {{1, 1}, 1, 2, 2, 1, 6, 6, "void"}, - {{1, 1}, 1, 7, 7, 1, 15, 15, "function"}}; + SourceRanges sourceRanges{{1, 1, 2, 2, 1, 15, 15, "void function"}, + {1, 1, 2, 2, 1, 6, 6, "void"}, + {1, 1, 7, 7, 1, 15, 15, "function"}}; Marker marker(std::move(sourceRanges), highlighter, textFormats); EXPECT_CALL(highlighter, setFormat(1, 13, textFormats[0])); @@ -103,7 +103,7 @@ TEST_F(ClangQueryExampleHighlightMarker, CascadedSingleLineSourceRanges) TEST_F(ClangQueryExampleHighlightMarker, DualLineSourceRanges) { InSequence sequence; - SourceRanges sourceRanges{{{1, 1}, 1, 2, 2, 2, 4, 20, "void f()\n {}"}}; + SourceRanges sourceRanges{{1, 1, 2, 2, 2, 4, 20, "void f()\n {}"}}; Marker marker(std::move(sourceRanges), highlighter, textFormats); EXPECT_CALL(highlighter, setFormat(1, 7, textFormats[0])); @@ -116,7 +116,7 @@ TEST_F(ClangQueryExampleHighlightMarker, DualLineSourceRanges) TEST_F(ClangQueryExampleHighlightMarker, MultipleLineSourceRanges) { InSequence sequence; - SourceRanges sourceRanges{{{1, 1}, 1, 2, 2, 3, 3, 20, "void f()\n {\n }"}}; + SourceRanges sourceRanges{{1, 1, 2, 2, 3, 3, 20, "void f()\n {\n }"}}; Marker marker(std::move(sourceRanges), highlighter, textFormats); EXPECT_CALL(highlighter, setFormat(1, 7, textFormats[0])); @@ -131,9 +131,9 @@ TEST_F(ClangQueryExampleHighlightMarker, MultipleLineSourceRanges) TEST_F(ClangQueryExampleHighlightMarker, MoreMultipleLineSourceRanges) { InSequence sequence; - SourceRanges sourceRanges{{{1, 1}, 1, 1, 0, 4, 2, 0, ""}, - {{1, 1}, 2, 2, 0, 2, 7, 0, ""}, - {{1, 1}, 3, 2, 0, 3, 7, 0, ""}}; + SourceRanges sourceRanges{{1, 1, 1, 0, 4, 2, 0, ""}, + {1, 2, 2, 0, 2, 7, 0, ""}, + {1, 3, 2, 0, 3, 7, 0, ""}}; Marker marker(std::move(sourceRanges), highlighter, textFormats); EXPECT_CALL(highlighter, setFormat(0, 10, textFormats[0])); @@ -152,9 +152,9 @@ TEST_F(ClangQueryExampleHighlightMarker, MoreMultipleLineSourceRanges) TEST_F(ClangQueryExampleHighlightMarker, CascadedMultipleLineSourceRanges) { InSequence sequence; - SourceRanges sourceRanges{{{1, 1}, 1, 1, 0, 4, 2, 0, ""}, - {{1, 1}, 2, 2, 0, 3, 4, 0, ""}, - {{1, 1}, 2, 11, 0, 2, 16, 0, ""}}; + SourceRanges sourceRanges{{1, 1, 1, 0, 4, 2, 0, ""}, + {1, 2, 2, 0, 3, 4, 0, ""}, + {1, 2, 11, 0, 2, 16, 0, ""}}; Marker marker(std::move(sourceRanges), highlighter, textFormats); EXPECT_CALL(highlighter, setFormat(0, 9, textFormats[0])); @@ -173,7 +173,7 @@ TEST_F(ClangQueryExampleHighlightMarker, CascadedMultipleLineSourceRanges) TEST_F(ClangQueryExampleHighlightMarker, FormatSingle) { - SourceRange sourceRange{{1, 1}, 1, 3, 3, 1, 10, 10}; + SourceRange sourceRange{1, 1, 3, 3, 1, 10, 10}; EXPECT_CALL(highlighter, setFormat(2, 7, textFormats[0])); @@ -182,7 +182,7 @@ TEST_F(ClangQueryExampleHighlightMarker, FormatSingle) TEST_F(ClangQueryExampleHighlightMarker, FormatMultipleStart) { - SourceRange sourceRange{{1, 1}, 1, 3, 3, 2, 9, 20}; + SourceRange sourceRange{1, 1, 3, 3, 2, 9, 20}; EXPECT_CALL(highlighter, setFormat(2, 8, textFormats[0])); @@ -191,7 +191,7 @@ TEST_F(ClangQueryExampleHighlightMarker, FormatMultipleStart) TEST_F(ClangQueryExampleHighlightMarker, FormatMultipleEnd) { - SourceRange sourceRange{{1, 1}, 1, 3, 3, 2, 8, 20}; + SourceRange sourceRange{1, 1, 3, 3, 2, 8, 20}; EXPECT_CALL(highlighter, setFormat(0, 7, textFormats[1])); @@ -200,7 +200,7 @@ TEST_F(ClangQueryExampleHighlightMarker, FormatMultipleEnd) TEST_F(ClangQueryExampleHighlightMarker, FormatMultipleMiddle) { - SourceRange sourceRange{{1, 1}, 1, 3, 3, 3, 8, 20}; + SourceRange sourceRange{1, 1, 3, 3, 3, 8, 20}; EXPECT_CALL(highlighter, setFormat(0, 10, textFormats[2])); diff --git a/tests/unit/unittest/clangqueryhighlightmarker-test.cpp b/tests/unit/unittest/clangqueryhighlightmarker-test.cpp index 11efd1d519..05e657b9ea 100644 --- a/tests/unit/unittest/clangqueryhighlightmarker-test.cpp +++ b/tests/unit/unittest/clangqueryhighlightmarker-test.cpp @@ -74,10 +74,10 @@ TEST_F(ClangQueryHighlightMarker, NoCallForNoMessagesAndContexts) TEST_F(ClangQueryHighlightMarker, CallForMessagesAndContextsForASingleLine) { InSequence sequence; - Messages messages{{{{0, 1}, 1, 5, 0, 1, 10, 0}, ErrorType::RegistryMatcherNotFound, {}}, - {{{0, 1}, 1, 30, 0, 1, 40, 0}, ErrorType::RegistryMatcherNotFound, {}}}; - Contexts contexts{{{{0, 1}, 1, 2, 0, 1, 15, 0}, ContextType::MatcherArg, {}}, - {{{0, 1}, 1, 20, 0, 1, 50, 0}, ContextType::MatcherArg, {}}}; + Messages messages{{{1, 1, 5, 0, 1, 10, 0}, ErrorType::RegistryMatcherNotFound, {}}, + {{1, 1, 30, 0, 1, 40, 0}, ErrorType::RegistryMatcherNotFound, {}}}; + Contexts contexts{{{1, 1, 2, 0, 1, 15, 0}, ContextType::MatcherArg, {}}, + {{1, 1, 20, 0, 1, 50, 0}, ContextType::MatcherArg, {}}}; marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); EXPECT_CALL(highlighter, setFormat(1, 13, contextTextFormat)); @@ -91,7 +91,7 @@ TEST_F(ClangQueryHighlightMarker, CallForMessagesAndContextsForASingleLine) TEST_F(ClangQueryHighlightMarker, CallForMessagesForAMultiLine) { InSequence sequence; - Messages messages{{{{0, 1}, 1, 5, 0, 3, 3, 0}, ErrorType::RegistryMatcherNotFound, {}}}; + Messages messages{{{1, 1, 5, 0, 3, 3, 0}, ErrorType::RegistryMatcherNotFound, {}}}; Contexts contexts; marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); @@ -107,8 +107,8 @@ TEST_F(ClangQueryHighlightMarker, CallForMessagesForAMultiLine) TEST_F(ClangQueryHighlightMarker, CallForMessagesAndContextForAMultiLine) { InSequence sequence; - Messages messages{{{{1, 1}, 1, 5, 0, 3, 3, 0}, ErrorType::RegistryMatcherNotFound, {}}}; - Contexts contexts{{{{1, 1}, 1, 2, 0, 3, 4, 0}, ContextType::MatcherArg, {}}}; + Messages messages{{{1, 1, 5, 0, 3, 3, 0}, ErrorType::RegistryMatcherNotFound, {}}}; + Contexts contexts{{{1, 1, 2, 0, 3, 4, 0}, ContextType::MatcherArg, {}}}; marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); EXPECT_CALL(highlighter, setFormat(1, 11, contextTextFormat)); @@ -136,7 +136,7 @@ TEST_F(ClangQueryHighlightMarker, NoMessagesIfEmpty) TEST_F(ClangQueryHighlightMarker, NoMessagesForBeforePosition) { - Messages messages{{{{0, 1}, 1, 5, 0, 3, 3, 0}, + Messages messages{{{1, 1, 5, 0, 3, 3, 0}, ErrorType::RegistryMatcherNotFound, {"foo"}}}; Contexts contexts; @@ -149,7 +149,7 @@ TEST_F(ClangQueryHighlightMarker, NoMessagesForBeforePosition) TEST_F(ClangQueryHighlightMarker, NoMessagesForAfterPosition) { - Messages messages{{{{0, 1}, 1, 5, 0, 3, 3, 0}, + Messages messages{{{1, 1, 5, 0, 3, 3, 0}, ErrorType::RegistryMatcherNotFound, {"foo"}}}; Contexts contexts; @@ -162,7 +162,7 @@ TEST_F(ClangQueryHighlightMarker, NoMessagesForAfterPosition) TEST_F(ClangQueryHighlightMarker, OneMessagesForInsidePosition) { - Message message{{{0, 1}, 1, 5, 0, 3, 3, 0}, + Message message{{1, 1, 5, 0, 3, 3, 0}, ErrorType::RegistryMatcherNotFound, {"foo"}}; Messages messages{message.clone()}; @@ -176,7 +176,7 @@ TEST_F(ClangQueryHighlightMarker, OneMessagesForInsidePosition) TEST_F(ClangQueryHighlightMarker, NoMessagesForOutsidePosition) { - Message message{{{0, 1}, 1, 5, 0, 3, 3, 0}, + Message message{{1, 1, 5, 0, 3, 3, 0}, ErrorType::RegistryMatcherNotFound, {"foo"}}; Messages messages{message.clone()}; @@ -190,7 +190,7 @@ TEST_F(ClangQueryHighlightMarker, NoMessagesForOutsidePosition) TEST_F(ClangQueryHighlightMarker, AfterStartColumnBeforeLine) { - SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0}; + SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; bool isAfterStartColumn = marker.isInsideRange(sourceRange, 1, 6); @@ -199,7 +199,7 @@ TEST_F(ClangQueryHighlightMarker, AfterStartColumnBeforeLine) TEST_F(ClangQueryHighlightMarker, AfterStartColumnBeforeColumn) { - SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0}; + SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; bool isAfterStartColumn = marker.isInsideRange(sourceRange, 2, 4); @@ -208,7 +208,7 @@ TEST_F(ClangQueryHighlightMarker, AfterStartColumnBeforeColumn) TEST_F(ClangQueryHighlightMarker, AfterStartColumnAtColumn) { - SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0}; + SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; bool isAfterStartColumn = marker.isInsideRange(sourceRange, 2, 5); @@ -217,7 +217,7 @@ TEST_F(ClangQueryHighlightMarker, AfterStartColumnAtColumn) TEST_F(ClangQueryHighlightMarker, AfterStartColumnAfterColumn) { - SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0}; + SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; bool isAfterStartColumn = marker.isInsideRange(sourceRange, 2, 6); @@ -226,7 +226,7 @@ TEST_F(ClangQueryHighlightMarker, AfterStartColumnAfterColumn) TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAfterLine) { - SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0}; + SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; bool isBeforeEndColumn = marker.isInsideRange(sourceRange, 4, 1); @@ -235,7 +235,7 @@ TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAfterLine) TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAfterColumn) { - SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0}; + SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; bool isBeforeEndColumn = marker.isInsideRange(sourceRange, 3, 4); @@ -244,7 +244,7 @@ TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAfterColumn) TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAtColumn) { - SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0}; + SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; bool isBeforeEndColumn = marker.isInsideRange(sourceRange, 3, 3); @@ -253,7 +253,7 @@ TEST_F(ClangQueryHighlightMarker, BeforeEndColumnAtColumn) TEST_F(ClangQueryHighlightMarker, BeforeEndColumnBeforeColumn) { - SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0}; + SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; bool isBeforeEndColumn = marker.isInsideRange(sourceRange, 3, 2); @@ -262,7 +262,7 @@ TEST_F(ClangQueryHighlightMarker, BeforeEndColumnBeforeColumn) TEST_F(ClangQueryHighlightMarker, InBetweenLineBeforeLine) { - SourceRange sourceRange{{0, 1}, 2, 5, 0, 3, 3, 0}; + SourceRange sourceRange{1, 2, 5, 0, 3, 3, 0}; bool isInBetween = marker.isInsideRange(sourceRange, 1, 6); @@ -271,7 +271,7 @@ TEST_F(ClangQueryHighlightMarker, InBetweenLineBeforeLine) TEST_F(ClangQueryHighlightMarker, InBetweenLineAfterLine) { - SourceRange sourceRange{{0, 1}, 2, 5, 0, 4, 3, 0}; + SourceRange sourceRange{1, 2, 5, 0, 4, 3, 0}; bool isInBetween = marker.isInsideRange(sourceRange, 5, 1); @@ -280,7 +280,7 @@ TEST_F(ClangQueryHighlightMarker, InBetweenLineAfterLine) TEST_F(ClangQueryHighlightMarker, InBetweenLine) { - SourceRange sourceRange{{0, 1}, 2, 5, 0, 4, 3, 0}; + SourceRange sourceRange{1, 2, 5, 0, 4, 3, 0}; bool isInBetween = marker.isInsideRange(sourceRange, 3, 1); @@ -289,7 +289,7 @@ TEST_F(ClangQueryHighlightMarker, InBetweenLine) TEST_F(ClangQueryHighlightMarker, SingleLineBefore) { - SourceRange sourceRange{{0, 1}, 2, 5, 0, 2, 10, 0}; + SourceRange sourceRange{1, 2, 5, 0, 2, 10, 0}; bool isInRange = marker.isInsideRange(sourceRange, 2, 4); @@ -298,7 +298,7 @@ TEST_F(ClangQueryHighlightMarker, SingleLineBefore) TEST_F(ClangQueryHighlightMarker, SingleLineAfter) { - SourceRange sourceRange{{0, 1}, 2, 5, 0, 2, 10, 0}; + SourceRange sourceRange{1, 2, 5, 0, 2, 10, 0}; bool isInRange = marker.isInsideRange(sourceRange, 2, 11); @@ -307,7 +307,7 @@ TEST_F(ClangQueryHighlightMarker, SingleLineAfter) TEST_F(ClangQueryHighlightMarker, SingleLineInRange) { - SourceRange sourceRange{{0, 1}, 2, 5, 0, 2, 10, 0}; + SourceRange sourceRange{1, 2, 5, 0, 2, 10, 0}; bool isInRange = marker.isInsideRange(sourceRange, 2, 6); @@ -328,7 +328,7 @@ TEST_F(ClangQueryHighlightMarker, NoContextsIfEmpty) TEST_F(ClangQueryHighlightMarker, NoContextsForBeforePosition) { Messages messages; - Contexts contexts{{{{0, 1}, 1, 5, 0, 3, 3, 0}, + Contexts contexts{{{1, 1, 5, 0, 3, 3, 0}, ContextType::MatcherArg, {"foo"}}}; marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); @@ -341,7 +341,7 @@ TEST_F(ClangQueryHighlightMarker, NoContextsForBeforePosition) TEST_F(ClangQueryHighlightMarker, NoContextsForAfterPosition) { Messages messages; - Contexts contexts{{{{0, 1}, 1, 5, 0, 3, 3, 0}, + Contexts contexts{{{1, 1, 5, 0, 3, 3, 0}, ContextType::MatcherArg, {"foo"}}}; marker.setMessagesAndContexts(std::move(messages), std::move(contexts)); @@ -353,7 +353,7 @@ TEST_F(ClangQueryHighlightMarker, NoContextsForAfterPosition) TEST_F(ClangQueryHighlightMarker, OneContextsForInsidePosition) { - Context context{{{0, 1}, 1, 5, 0, 3, 3, 0}, + Context context{{1, 1, 5, 0, 3, 3, 0}, ContextType::MatcherArg, {"foo"}}; Messages messages; @@ -367,7 +367,7 @@ TEST_F(ClangQueryHighlightMarker, OneContextsForInsidePosition) TEST_F(ClangQueryHighlightMarker, NoContextsForOutsidePosition) { - Context context{{{0, 1}, 1, 5, 0, 3, 3, 0}, + Context context{{1, 1, 5, 0, 3, 3, 0}, ContextType::MatcherArg, {"foo"}}; Messages messages; diff --git a/tests/unit/unittest/compilationdatabaseutils-test.cpp b/tests/unit/unittest/compilationdatabaseutils-test.cpp index 2d528b9793..252ab2ffd6 100644 --- a/tests/unit/unittest/compilationdatabaseutils-test.cpp +++ b/tests/unit/unittest/compilationdatabaseutils-test.cpp @@ -53,11 +53,18 @@ TEST_F(CompilationDatabaseUtils, FilterEmptyFlags) ASSERT_THAT(flags.isEmpty(), true); } +TEST_F(CompilationDatabaseUtils, FilterFromFilename) +{ + flags = filterFromFileName(QStringList{"-o", "foo.o"}, "foo"); + + ASSERT_THAT(flags, QStringList{"-o"}); +} + TEST_F(CompilationDatabaseUtils, FilterArguments) { fileName = "compileroptionsbuilder.cpp"; workingDir = "C:/build-qtcreator-MinGW_32bit-Debug"; - flags = QStringList { + flags = filterFromFileName(QStringList { "clang++", "-c", "-m32", @@ -77,7 +84,7 @@ TEST_F(CompilationDatabaseUtils, FilterArguments) "-x", "c++", "C:\\qt-creator\\src\\plugins\\cpptools\\compileroptionsbuilder.cpp" - }; + }, "compileroptionsbuilder"); filteredFlags(fileName, workingDir, flags, headerPaths, macros, fileKind); @@ -146,7 +153,7 @@ TEST_F(CompilationDatabaseUtils, FilterCommand) { fileName = "SemaCodeComplete.cpp"; workingDir = "C:/build-qt_llvm-msvc2017_64bit-Debug"; - flags = splitCommandLine(kCmakeCommand); + flags = filterFromFileName(splitCommandLine(kCmakeCommand), "SemaCodeComplete"); filteredFlags(fileName, workingDir, flags, headerPaths, macros, fileKind); @@ -188,8 +195,7 @@ TEST_F(CompilationDatabaseUtils, FileKindDifferentFromExtension2) TEST_F(CompilationDatabaseUtils, SkipOutputFiles) { - fileName = "foo.cpp"; - flags = QStringList{"-o", "foo.o"}; + flags = filterFromFileName(QStringList{"-o", "foo.o"}, "foo"); filteredFlags(fileName, workingDir, flags, headerPaths, macros, fileKind); diff --git a/tests/unit/unittest/filepathcache-test.cpp b/tests/unit/unittest/filepathcache-test.cpp index 282654ad7b..43b5b026bb 100644 --- a/tests/unit/unittest/filepathcache-test.cpp +++ b/tests/unit/unittest/filepathcache-test.cpp @@ -36,11 +36,28 @@ using Cache = ClangBackEnd::FilePathCache<NiceMock<MockFilePathStorage>>; using ClangBackEnd::FilePathId; using NFP = ClangBackEnd::FilePath; using ClangBackEnd::FilePathView; +using ClangBackEnd::Sources::SourceNameAndDirectoryId; class FilePathCache : public testing::Test { protected: - void SetUp(); + void SetUp() + { + ON_CALL(mockStorage, fetchDirectoryId(Eq("/path/to"))) + .WillByDefault(Return(5)); + ON_CALL(mockStorage, fetchDirectoryId(Eq("/path2/to"))) + .WillByDefault(Return(6)); + ON_CALL(mockStorage, fetchSourceId(5, Eq("file.cpp"))) + .WillByDefault(Return(42)); + ON_CALL(mockStorage, fetchSourceId(5, Eq("file2.cpp"))) + .WillByDefault(Return(63)); + ON_CALL(mockStorage, fetchSourceId(6, Eq("file.cpp"))) + .WillByDefault(Return(72)); + ON_CALL(mockStorage, fetchDirectoryPath(5)) + .WillByDefault(Return(Utils::PathString("/path/to"))); + ON_CALL(mockStorage, fetchSourceNameAndDirectoryId(42)) + .WillByDefault(Return(SourceNameAndDirectoryId("file.cpp", 5))); + } protected: NiceMock<MockFilePathStorage> mockStorage; @@ -61,13 +78,6 @@ TEST_F(FilePathCache, FilePathIdWithOutAnyEntryCalls) cache.filePathId(FilePathView("/path/to/file.cpp")); } -TEST_F(FilePathCache, DirectoryIdOfFilePathIdWithOutAnyEntry) -{ - auto filePathId = cache.filePathId(FilePathView("/path/to/file.cpp")); - - ASSERT_THAT(filePathId.directoryId, 5); -} - TEST_F(FilePathCache, FilePathIdOfFilePathIdWithOutAnyEntry) { auto filePathId = cache.filePathId(FilePathView("/path/to/file.cpp")); @@ -113,24 +123,6 @@ TEST_F(FilePathCache, GetFilePathIdWithDirectoryIdCached) ASSERT_THAT(filePathId.filePathId, 63); } -TEST_F(FilePathCache, GetDirectyIdWithCachedValue) -{ - cache.filePathId(FilePathView("/path/to/file.cpp")); - - auto filePathId = cache.filePathId(FilePathView("/path/to/file2.cpp")); - - ASSERT_THAT(filePathId.directoryId, 5); -} - -TEST_F(FilePathCache, GetDirectyIdWithDirectoryIdCached) -{ - cache.filePathId(FilePathView("/path/to/file.cpp")); - - auto filePathId = cache.filePathId(FilePathView("/path/to/file2.cpp")); - - ASSERT_THAT(filePathId.directoryId, 5); -} - TEST_F(FilePathCache, ThrowForGettingAFilePathWithAnInvalidId) { FilePathId filePathId; @@ -149,7 +141,7 @@ TEST_F(FilePathCache, GetAFilePath) TEST_F(FilePathCache, GetAFilePathWithCachedFilePathId) { - FilePathId filePathId{5, 42}; + FilePathId filePathId{42}; auto filePath = cache.filePath(filePathId); @@ -174,22 +166,4 @@ TEST_F(FilePathCache, DuplicateFilePathsAreEqual) ASSERT_THAT(filePath2Id, Eq(filePath1Id)); } -void FilePathCache::SetUp() -{ - ON_CALL(mockStorage, fetchDirectoryId(Eq("/path/to"))) - .WillByDefault(Return(5)); - ON_CALL(mockStorage, fetchDirectoryId(Eq("/path2/to"))) - .WillByDefault(Return(6)); - ON_CALL(mockStorage, fetchSourceId(5, Eq("file.cpp"))) - .WillByDefault(Return(42)); - ON_CALL(mockStorage, fetchSourceId(5, Eq("file2.cpp"))) - .WillByDefault(Return(63)); - ON_CALL(mockStorage, fetchSourceId(6, Eq("file.cpp"))) - .WillByDefault(Return(72)); - ON_CALL(mockStorage, fetchDirectoryPath(5)) - .WillByDefault(Return(Utils::PathString("/path/to"))); - ON_CALL(mockStorage, fetchSourceName(42)) - .WillByDefault(Return(Utils::SmallString("file.cpp"))); -} - } diff --git a/tests/unit/unittest/filepathstorage-test.cpp b/tests/unit/unittest/filepathstorage-test.cpp index 2692f9f79d..f94f3dfad2 100644 --- a/tests/unit/unittest/filepathstorage-test.cpp +++ b/tests/unit/unittest/filepathstorage-test.cpp @@ -43,7 +43,58 @@ using ClangBackEnd::Sources::Source; class FilePathStorage : public testing::Test { protected: - void SetUp(); + void SetUp() + { + ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, + valueReturnInt32(_)) + .WillByDefault(Return(Utils::optional<int>())); + ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, + valueReturnInt32(Utils::SmallStringView(""))) + .WillByDefault(Return(Utils::optional<int>(0))); + ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, + valueReturnInt32(Utils::SmallStringView("/path/to"))) + .WillByDefault(Return(Utils::optional<int>(5))); + ON_CALL(mockDatabase, lastInsertedRowId()) + .WillByDefault(Return(12)); + ON_CALL(selectAllDirectories, + valuesReturnStdVectorDirectory(_)) + .WillByDefault(Return(std::vector<Directory>{{1, "/path/to"}, {2, "/other/path"}})); + ON_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, + valueReturnInt32(_, _)) + .WillByDefault(Return(Utils::optional<int>())); + ON_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, + valueReturnInt32(0, Utils::SmallStringView(""))) + .WillByDefault(Return(Utils::optional<int>(0))); + ON_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, + valueReturnInt32(5, Utils::SmallStringView("file.h"))) + .WillByDefault(Return(Utils::optional<int>(42))); + ON_CALL(selectAllSources, + valuesReturnStdVectorSource(_)) + .WillByDefault(Return(std::vector<Source>{{1, "file.h"}, {4, "file.cpp"}})); + ON_CALL(selectDirectoryPathFromDirectoriesByDirectoryId, + valueReturnPathString(5)) + .WillByDefault(Return(Utils::optional<Utils::PathString>("/path/to"))); + ON_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId, + valueReturnSourceNameAndDirectoryId(42)) + .WillByDefault(Return(Utils::optional<ClangBackEnd::Sources::SourceNameAndDirectoryId>({"file.cpp", 5}))); + + EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, valueReturnInt32(_)) + .Times(AnyNumber()); + EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, valueReturnInt32(_, _)) + .Times(AnyNumber()); + EXPECT_CALL(insertIntoDirectories, write(An<Utils::SmallStringView>())) + .Times(AnyNumber()); + EXPECT_CALL(insertIntoSources, write(An<uint>(), A<Utils::SmallStringView>())) + .Times(AnyNumber()); + EXPECT_CALL(selectAllDirectories, valuesReturnStdVectorDirectory(_)) + .Times(AnyNumber()); + EXPECT_CALL(selectAllSources, valuesReturnStdVectorSource(_)) + .Times(AnyNumber()); + EXPECT_CALL(selectDirectoryPathFromDirectoriesByDirectoryId, valueReturnPathString(_)) + .Times(AnyNumber()); + EXPECT_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId, valueReturnSourceNameAndDirectoryId(_)) + .Times(AnyNumber()); + } protected: NiceMock<MockSqliteDatabase> mockDatabase; @@ -51,7 +102,7 @@ protected: MockSqliteReadStatement &selectDirectoryIdFromDirectoriesByDirectoryPath = factory.selectDirectoryIdFromDirectoriesByDirectoryPath; MockSqliteReadStatement &selectSourceIdFromSourcesByDirectoryIdAndSourceName = factory.selectSourceIdFromSourcesByDirectoryIdAndSourceName; MockSqliteReadStatement &selectDirectoryPathFromDirectoriesByDirectoryId = factory.selectDirectoryPathFromDirectoriesByDirectoryId; - MockSqliteReadStatement &selectSourceNameFromSourcesBySourceId = factory.selectSourceNameFromSourcesBySourceId; + MockSqliteReadStatement &selectSourceNameAndDirectoryIdFromSourcesBySourceId = factory.selectSourceNameAndDirectoryIdFromSourcesBySourceId; MockSqliteReadStatement &selectAllDirectories = factory.selectAllDirectories; MockSqliteWriteStatement &insertIntoDirectories = factory.insertIntoDirectories; MockSqliteWriteStatement &insertIntoSources = factory.insertIntoSources; @@ -397,22 +448,23 @@ TEST_F(FilePathStorage, ThrowAsFetchingDirectoryPathForNonExistingId) TEST_F(FilePathStorage, CallValueForFetchSoureNameForId) { EXPECT_CALL(mockDatabase, deferredBegin()); - EXPECT_CALL(selectSourceNameFromSourcesBySourceId, valueReturnSmallString(42)); + EXPECT_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId, valueReturnSourceNameAndDirectoryId(42)); EXPECT_CALL(mockDatabase, commit()); - storage.fetchSourceName(42); + storage.fetchSourceNameAndDirectoryId(42); } TEST_F(FilePathStorage, FetchSoureNameForId) { - auto path = storage.fetchSourceName(42); + auto entry = storage.fetchSourceNameAndDirectoryId(42); - ASSERT_THAT(path, Eq("file.cpp")); + ASSERT_THAT(entry.sourceName, Eq("file.cpp")); + ASSERT_THAT(entry.directoryId, 5); } TEST_F(FilePathStorage, ThrowAsFetchingSourceNameForNonExistingId) { - ASSERT_THROW(storage.fetchSourceName(12), ClangBackEnd::SourceNameIdDoesNotExists); + ASSERT_THROW(storage.fetchSourceNameAndDirectoryId(12), ClangBackEnd::SourceNameIdDoesNotExists); } TEST_F(FilePathStorage, RestartFetchSourceNameIfTheDatabaseIsBusyInBegin) @@ -425,11 +477,11 @@ TEST_F(FilePathStorage, RestartFetchSourceNameIfTheDatabaseIsBusyInBegin) EXPECT_CALL(mockDatabase, unlock()); EXPECT_CALL(mockDatabase, lock()); EXPECT_CALL(mockDatabase, deferredBegin()); - EXPECT_CALL(selectSourceNameFromSourcesBySourceId, valueReturnSmallString(42)); + EXPECT_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId, valueReturnSourceNameAndDirectoryId(42)); EXPECT_CALL(mockDatabase, commit()); EXPECT_CALL(mockDatabase, unlock()); - storage.fetchSourceName(42); + storage.fetchSourceNameAndDirectoryId(42); } TEST_F(FilePathStorage, RestartFetchDirectoryPathIfTheDatabaseIsBusyInBegin) @@ -483,56 +535,4 @@ TEST_F(FilePathStorage, RestartFetchAllSourcesIfBeginIsBusy) storage.fetchAllSources(); } -void FilePathStorage::SetUp() -{ - ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, - valueReturnInt32(_)) - .WillByDefault(Return(Utils::optional<int>())); - ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, - valueReturnInt32(Utils::SmallStringView(""))) - .WillByDefault(Return(Utils::optional<int>(0))); - ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, - valueReturnInt32(Utils::SmallStringView("/path/to"))) - .WillByDefault(Return(Utils::optional<int>(5))); - ON_CALL(mockDatabase, lastInsertedRowId()) - .WillByDefault(Return(12)); - ON_CALL(selectAllDirectories, - valuesReturnStdVectorDirectory(_)) - .WillByDefault(Return(std::vector<Directory>{{1, "/path/to"}, {2, "/other/path"}})); - ON_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, - valueReturnInt32(_, _)) - .WillByDefault(Return(Utils::optional<int>())); - ON_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, - valueReturnInt32(0, Utils::SmallStringView(""))) - .WillByDefault(Return(Utils::optional<int>(0))); - ON_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, - valueReturnInt32(5, Utils::SmallStringView("file.h"))) - .WillByDefault(Return(Utils::optional<int>(42))); - ON_CALL(selectAllSources, - valuesReturnStdVectorSource(_)) - .WillByDefault(Return(std::vector<Source>{{1, "file.h"}, {4, "file.cpp"}})); - ON_CALL(selectDirectoryPathFromDirectoriesByDirectoryId, - valueReturnPathString(5)) - .WillByDefault(Return(Utils::optional<Utils::PathString>("/path/to"))); - ON_CALL(selectSourceNameFromSourcesBySourceId, - valueReturnSmallString(42)) - .WillByDefault(Return(Utils::optional<Utils::SmallString>("file.cpp"))); - - EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, valueReturnInt32(_)) - .Times(AnyNumber()); - EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, valueReturnInt32(_, _)) - .Times(AnyNumber()); - EXPECT_CALL(insertIntoDirectories, write(An<Utils::SmallStringView>())) - .Times(AnyNumber()); - EXPECT_CALL(insertIntoSources, write(An<uint>(), A<Utils::SmallStringView>())) - .Times(AnyNumber()); - EXPECT_CALL(selectAllDirectories, valuesReturnStdVectorDirectory(_)) - .Times(AnyNumber()); - EXPECT_CALL(selectAllSources, valuesReturnStdVectorSource(_)) - .Times(AnyNumber()); - EXPECT_CALL(selectDirectoryPathFromDirectoriesByDirectoryId, valueReturnPathString(_)) - .Times(AnyNumber()); - EXPECT_CALL(selectSourceNameFromSourcesBySourceId, valueReturnSmallString(_)) - .Times(AnyNumber()); -} } diff --git a/tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp b/tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp index 92ddc10a4a..ac902fa700 100644 --- a/tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp +++ b/tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp @@ -63,8 +63,8 @@ TEST_F(FilePathStorageSqliteStatementFactory, SelectSourceIdFromSourcesByDirecto TEST_F(FilePathStorageSqliteStatementFactory, SelectSourceNameFromSourcesByDirectoryIdAndSourceId) { - ASSERT_THAT(factory.selectSourceNameFromSourcesBySourceId.sqlStatement, - Eq("SELECT sourceName FROM sources WHERE sourceId = ?")); + ASSERT_THAT(factory.selectSourceNameAndDirectoryIdFromSourcesBySourceId.sqlStatement, + Eq("SELECT sourceName, directoryId FROM sources WHERE sourceId = ?")); } TEST_F(FilePathStorageSqliteStatementFactory, SelectAllDirectories) diff --git a/tests/unit/unittest/gtest-creator-printing.cpp b/tests/unit/unittest/gtest-creator-printing.cpp index 2af5894d63..08433ff393 100644 --- a/tests/unit/unittest/gtest-creator-printing.cpp +++ b/tests/unit/unittest/gtest-creator-printing.cpp @@ -32,7 +32,7 @@ #include <sourcelocations.h> -#include <builddependencies.h> +#include <builddependency.h> #include <clangcodemodelclientmessages.h> #include <clangcodemodelservermessages.h> #include <clangdocumentsuspenderresumer.h> @@ -171,7 +171,7 @@ namespace ClangBackEnd { std::ostream &operator<<(std::ostream &out, const FilePathId &id) { - return out << "(" << id.directoryId << ", " << id.filePathId << ")"; + return out << "(" << id.filePathId << ")"; } std::ostream &operator<<(std::ostream &out, const FilePathView &filePathView) @@ -1033,11 +1033,29 @@ std::ostream &operator<<(std::ostream &out, const PchTask &task) std::ostream &operator<<(std::ostream &out, const BuildDependency &dependency) { return out << "(" - << dependency.includeIds << ", " + << dependency.includes << ", " << dependency.topsSystemIncludeIds << ", " << dependency.topIncludeIds << ")"; } +const char *sourceTypeString(SourceType sourceType) +{ + using ClangBackEnd::SymbolTag; + + switch (sourceType) { + case SourceType::Any: return "Any"; + case SourceType::TopInclude: return "TopInclude"; + case SourceType::TopSystemInclude: return "TopSystemInclude"; + } + + return ""; +} + +std::ostream &operator<<(std::ostream &out, const SourceEntry &entry) +{ + return out << "(" << entry.sourceId << ", " << sourceTypeString(entry.sourceType) << ")"; +} + void PrintTo(const FilePath &filePath, ::std::ostream *os) { *os << filePath; @@ -1086,8 +1104,8 @@ std::ostream &operator<<(std::ostream &out, const ProjectPartContainer &containe std::ostream &operator<<(std::ostream &os, const SourceLocationContainer &container) { - os << "((" - << container.filePathId.directoryId << ", " << container.filePathId.filePathId << "), " + os << "(" + << container.filePathId.filePathId << ", " << container.line << ", " << container.column << ", " << container.offset diff --git a/tests/unit/unittest/gtest-creator-printing.h b/tests/unit/unittest/gtest-creator-printing.h index 51692acea7..09331e7ef2 100644 --- a/tests/unit/unittest/gtest-creator-printing.h +++ b/tests/unit/unittest/gtest-creator-printing.h @@ -173,6 +173,7 @@ class ProgressMessage; class PchCreatorIncludes; class PchTask; class BuildDependency; +class SourceEntry; std::ostream &operator<<(std::ostream &out, const SourceLocationEntry &entry); std::ostream &operator<<(std::ostream &out, const IdPaths &idPaths); @@ -256,6 +257,7 @@ std::ostream &operator<<(std::ostream &out, const ProgressMessage &message); std::ostream &operator<<(std::ostream &out, const PchCreatorIncludes &includes); std::ostream &operator<<(std::ostream &out, const PchTask &task); std::ostream &operator<<(std::ostream &out, const BuildDependency &dependency); +std::ostream &operator<<(std::ostream &out, const SourceEntry &entry); void PrintTo(const FilePath &filePath, ::std::ostream *os); void PrintTo(const FilePathView &filePathView, ::std::ostream *os); diff --git a/tests/unit/unittest/locatorfilter-test.cpp b/tests/unit/unittest/locatorfilter-test.cpp index 00bdbbd1ae..1cc15b281c 100644 --- a/tests/unit/unittest/locatorfilter-test.cpp +++ b/tests/unit/unittest/locatorfilter-test.cpp @@ -69,7 +69,7 @@ protected: int length = 0; QString newText; Utils::LineColumn lineColumn{4, 3}; - ClangBackEnd::FilePathId filePathId{42, 64}; + ClangBackEnd::FilePathId filePathId{64}; ClangRefactoring::SourceLocation sourceLocation{filePathId, lineColumn}; }; diff --git a/tests/unit/unittest/mockusedmacroandsourcestorage.h b/tests/unit/unittest/mockbuilddependenciesgenerator.h index 6fba12c26c..832c37f0bf 100644 --- a/tests/unit/unittest/mockusedmacroandsourcestorage.h +++ b/tests/unit/unittest/mockbuilddependenciesgenerator.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2018 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of Qt Creator. @@ -27,19 +27,12 @@ #include "googletest.h" -#include "mocksqlitedatabase.h" +#include <builddependenciesgeneratorinterface.h> -#include <usedmacroandsourcestorageinterface.h> - -class MockUsedMacroAndSourceStorage : public ClangBackEnd::UsedMacroAndSourceStorageInterface +class MockBuildDependenciesGenerator : public ClangBackEnd::BuildDependenciesGeneratorInterface { public: - MOCK_METHOD1(insertOrUpdateUsedMacros, - void (const ClangBackEnd::UsedMacros &usedMacros)); - MOCK_METHOD1(insertFileStatuses, - void (const ClangBackEnd::FileStatuses &fileStatuses)); - MOCK_METHOD1(insertOrUpdateSourceDependencies, - void (const ClangBackEnd::SourceDependencies &sourceDependencies)); - MOCK_CONST_METHOD1(fetchLowestLastModifiedTime, - long long (ClangBackEnd::FilePathId sourceId)); + MOCK_METHOD1(create, + ClangBackEnd::BuildDependency (const ClangBackEnd::V2::ProjectPartContainer &projectPart)); }; + diff --git a/tests/unit/unittest/mockbuilddependenciesprovider.h b/tests/unit/unittest/mockbuilddependenciesprovider.h index 9bd8175a5f..8bb048bd24 100644 --- a/tests/unit/unittest/mockbuilddependenciesprovider.h +++ b/tests/unit/unittest/mockbuilddependenciesprovider.h @@ -32,6 +32,6 @@ class MockBuildDependenciesProvider : public ClangBackEnd::BuildDependenciesProviderInterface { public: - MOCK_METHOD1(create, - ClangBackEnd::BuildDependency (const ClangBackEnd::V2::ProjectPartContainer &projectPart)); + MOCK_CONST_METHOD1(create, + ClangBackEnd::BuildDependency (const ClangBackEnd::V2::ProjectPartContainer &projectPart)); }; diff --git a/tests/unit/unittest/mockbuilddependenciesstorage.h b/tests/unit/unittest/mockbuilddependenciesstorage.h new file mode 100644 index 0000000000..a654579a83 --- /dev/null +++ b/tests/unit/unittest/mockbuilddependenciesstorage.h @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 +** 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. +** +** 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. +** +****************************************************************************/ + +#pragma once + +#include "googletest.h" + +#include <builddependenciesstorageinterface.h> + +class MockBuildDependenciesStorage : public ClangBackEnd::BuildDependenciesStorageInterface +{ +public: + MOCK_METHOD1(updateSources, + void (const ClangBackEnd::SourceEntries &sources)); + MOCK_METHOD1(insertOrUpdateUsedMacros, + void (const ClangBackEnd::UsedMacros &usedMacros)); + MOCK_METHOD1(insertFileStatuses, + void (const ClangBackEnd::FileStatuses &fileStatuses)); + MOCK_METHOD1(insertOrUpdateSourceDependencies, + void (const ClangBackEnd::SourceDependencies &sourceDependencies)); + MOCK_CONST_METHOD1(fetchLowestLastModifiedTime, + long long (ClangBackEnd::FilePathId sourceId)); + MOCK_CONST_METHOD2(fetchDependSources, + ClangBackEnd::SourceEntries (ClangBackEnd::FilePathId sourceId, Utils::SmallStringView)); + MOCK_CONST_METHOD1(fetchUsedMacros, + ClangBackEnd::UsedMacros (ClangBackEnd::FilePathId sourceId)); +}; + diff --git a/tests/unit/unittest/mockfilepathstorage.h b/tests/unit/unittest/mockfilepathstorage.h index b1114747b1..7056ee2480 100644 --- a/tests/unit/unittest/mockfilepathstorage.h +++ b/tests/unit/unittest/mockfilepathstorage.h @@ -27,6 +27,8 @@ #include "googletest.h" +#include <filepathstoragesources.h> + class MockFilePathStorage { public: @@ -36,7 +38,7 @@ public: int (int directoryId, Utils::SmallStringView sourceName)); MOCK_METHOD1(fetchDirectoryPath, Utils::PathString (int directoryId)); - MOCK_METHOD1(fetchSourceName, - Utils::SmallString (int sourceId)); + MOCK_METHOD1(fetchSourceNameAndDirectoryId, + ClangBackEnd::Sources::SourceNameAndDirectoryId (int sourceId)); }; diff --git a/tests/unit/unittest/mockmodifiedtimechecker.h b/tests/unit/unittest/mockmodifiedtimechecker.h new file mode 100644 index 0000000000..5f0559f682 --- /dev/null +++ b/tests/unit/unittest/mockmodifiedtimechecker.h @@ -0,0 +1,37 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 +** 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. +** +** 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. +** +****************************************************************************/ + +#pragma once + +#include "googletest.h" + +#include <modifiedtimecheckerinterface.h> + +class MockModifiedTimeChecker : public ClangBackEnd::ModifiedTimeCheckerInterface +{ +public: + MOCK_CONST_METHOD1(isUpToDate, + bool (const ClangBackEnd::SourceEntries &sourceEntries)); +}; diff --git a/tests/unit/unittest/mocksqlitereadstatement.cpp b/tests/unit/unittest/mocksqlitereadstatement.cpp index eb114e3a47..66406f09fa 100644 --- a/tests/unit/unittest/mocksqlitereadstatement.cpp +++ b/tests/unit/unittest/mocksqlitereadstatement.cpp @@ -27,7 +27,7 @@ template <> SourceLocations -MockSqliteReadStatement::values<SourceLocation, 4>(std::size_t reserveSize, +MockSqliteReadStatement::values<SourceLocation, 3>(std::size_t reserveSize, const int &sourceId, const int &line, const int &column) @@ -82,6 +82,15 @@ MockSqliteReadStatement::values<Symbol, 3>( } template <> +UsedMacros +MockSqliteReadStatement::values<ClangBackEnd::UsedMacro, 2>( + std::size_t reserveSize, + const int &sourceId) +{ + return valuesReturnUsedMacros(reserveSize, sourceId); +} + +template <> std::vector<Sources::Directory> MockSqliteReadStatement::values<Sources::Directory, 2>(std::size_t reserveSize) { return valuesReturnStdVectorDirectory(reserveSize); @@ -158,7 +167,21 @@ MockSqliteReadStatement::value<Utils::SmallString>(const int &sourceId) template <> Utils::optional<SourceLocation> -MockSqliteReadStatement::value<SourceLocation, 4>(const long long &symbolId, const int &locationKind) +MockSqliteReadStatement::value<SourceLocation, 3>(const long long &symbolId, const int &locationKind) { return valueReturnSourceLocation(symbolId, locationKind); } + +template <> +SourceEntries +MockSqliteReadStatement::values<SourceEntry, 3>(std::size_t reserveSize, const int &filePathId, const int &projectPartId) +{ + return valuesReturnSourceEntries(reserveSize, filePathId, projectPartId); +} + +template <> +Utils::optional<Sources::SourceNameAndDirectoryId> +MockSqliteReadStatement::value<Sources::SourceNameAndDirectoryId, 2>(const int &id) +{ + return valueReturnSourceNameAndDirectoryId(id); +} diff --git a/tests/unit/unittest/mocksqlitereadstatement.h b/tests/unit/unittest/mocksqlitereadstatement.h index 2ad17ee07f..e5926d2d17 100644 --- a/tests/unit/unittest/mocksqlitereadstatement.h +++ b/tests/unit/unittest/mocksqlitereadstatement.h @@ -33,6 +33,8 @@ #include <stringcachefwd.h> #include <projectpartartefact.h> #include <projectpartpch.h> +#include <sourceentry.h> +#include <usedmacro.h> #include <symbol.h> #include <cpptools/usages.h> @@ -45,11 +47,14 @@ #include <vector> using std::int64_t; +using ClangBackEnd::SourceEntry; +using ClangBackEnd::SourceEntries; using ClangRefactoring::SourceLocation; using ClangRefactoring::SourceLocations; namespace Sources = ClangBackEnd::Sources; using ClangRefactoring::Symbol; using ClangRefactoring::Symbols; +using ClangBackEnd::UsedMacros; class MockSqliteDatabase; @@ -73,6 +78,12 @@ public: MOCK_METHOD1(valuesReturnStdVectorSource, std::vector<Sources::Source>(std::size_t)); + MOCK_METHOD3(valuesReturnSourceEntries, + SourceEntries(std::size_t, int, int)); + + MOCK_METHOD2(valuesReturnUsedMacros, + UsedMacros (std::size_t, int)); + MOCK_METHOD1(valueReturnInt32, Utils::optional<int>(Utils::SmallStringView)); @@ -88,6 +99,9 @@ public: MOCK_METHOD1(valueReturnSmallString, Utils::optional<Utils::SmallString>(int)); + MOCK_METHOD1(valueReturnSourceNameAndDirectoryId, + Utils::optional<Sources::SourceNameAndDirectoryId>(int)); + MOCK_METHOD1(valueReturnProjectPartArtefact, Utils::optional<ClangBackEnd::ProjectPartArtefact>(int)); @@ -137,7 +151,7 @@ public: template <> SourceLocations -MockSqliteReadStatement::values<SourceLocation, 4>( +MockSqliteReadStatement::values<SourceLocation, 3>( std::size_t reserveSize, const int &sourceId, const int &line, @@ -176,6 +190,12 @@ MockSqliteReadStatement::values<Symbol, 3>( const Utils::SmallStringView&); template <> +UsedMacros +MockSqliteReadStatement::values<ClangBackEnd::UsedMacro, 2>( + std::size_t reserveSize, + const int &sourceId); + +template <> std::vector<Sources::Directory> MockSqliteReadStatement::values<Sources::Directory, 2>(std::size_t reserveSize); template <> @@ -219,4 +239,12 @@ MockSqliteReadStatement::value<Utils::SmallString>(const int&); template <> Utils::optional<SourceLocation> -MockSqliteReadStatement::value<SourceLocation, 4>(const long long &symbolId, const int &locationKind); +MockSqliteReadStatement::value<SourceLocation, 3>(const long long &symbolId, const int &locationKind); + +template <> +SourceEntries +MockSqliteReadStatement::values<SourceEntry, 3>(std::size_t reserveSize, const int&, const int&); + +template <> +Utils::optional<Sources::SourceNameAndDirectoryId> +MockSqliteReadStatement::value<Sources::SourceNameAndDirectoryId, 2>(const int&); diff --git a/tests/unit/unittest/mocksqlitewritestatement.h b/tests/unit/unittest/mocksqlitewritestatement.h index 05d2404d91..8da4db8ef5 100644 --- a/tests/unit/unittest/mocksqlitewritestatement.h +++ b/tests/unit/unittest/mocksqlitewritestatement.h @@ -99,5 +99,11 @@ public: MOCK_METHOD2(write, void (uint, uint)); + MOCK_METHOD2(write, + void (uchar, int)); + + MOCK_METHOD2(write, + void (long long, int)); + Utils::SmallString sqlStatement; }; diff --git a/tests/unit/unittest/pchmanagerserver-test.cpp b/tests/unit/unittest/pchmanagerserver-test.cpp index 6732fd74c4..336af38159 100644 --- a/tests/unit/unittest/pchmanagerserver-test.cpp +++ b/tests/unit/unittest/pchmanagerserver-test.cpp @@ -79,7 +79,7 @@ protected: PathString main2Path = TESTDATA_DIR "/includecollector_main2.cpp"; PathString header1Path = TESTDATA_DIR "/includecollector_header1.h"; PathString header2Path = TESTDATA_DIR "/includecollector_header2.h"; - ClangBackEnd::IdPaths idPath{projectPartId1, {{1, 1}, {1, 2}}}; + ClangBackEnd::IdPaths idPath{projectPartId1, {1, 2}}; ProjectPartContainer projectPart1{projectPartId1.clone(), {"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"}, {{"DEFINE", "1"}}, diff --git a/tests/unit/unittest/pchtaskgenerator-test.cpp b/tests/unit/unittest/pchtaskgenerator-test.cpp index cfb34f4c5d..248803cc4b 100644 --- a/tests/unit/unittest/pchtaskgenerator-test.cpp +++ b/tests/unit/unittest/pchtaskgenerator-test.cpp @@ -35,6 +35,8 @@ using ClangBackEnd::BuildDependency; using ClangBackEnd::BuildDependencies; using ClangBackEnd::FilePathId; using ClangBackEnd::PchTask; +using ClangBackEnd::SourceEntries; +using ClangBackEnd::SourceType; class PchTaskGenerator : public testing::Test { @@ -47,7 +49,8 @@ protected: {"/yi"}, {{1, 1}}, {{1, 2}}}; - BuildDependency buildDependency{{{1, 1}}, {}, {}}; + SourceEntries firstSources{{1, SourceType::Any, 1}, {2, SourceType::Any, 1}, {10, SourceType::Any, 1}}; + BuildDependency buildDependency{firstSources, {}, {}, {}}; }; TEST_F(PchTaskGenerator, Create) @@ -60,7 +63,7 @@ TEST_F(PchTaskGenerator, Create) ElementsAre( AllOf(Field(&PchTask::ids, ElementsAre("ProjectPart1")), Field(&PchTask::buildDependency, - Field(&BuildDependency::includeIds, ElementsAre(FilePathId{1, 1})))))); + Field(&BuildDependency::includes, firstSources))))); } } diff --git a/tests/unit/unittest/projectpartqueue-test.cpp b/tests/unit/unittest/projectpartqueue-test.cpp index bf7748cd50..03561728fd 100644 --- a/tests/unit/unittest/projectpartqueue-test.cpp +++ b/tests/unit/unittest/projectpartqueue-test.cpp @@ -48,26 +48,26 @@ protected: {"--yi"}, {{"YI","1"}}, {"/yi"}, - {{1, 1}}, - {{1, 2}}}; + {1}, + {2}}; ClangBackEnd::V2::ProjectPartContainer projectPart2{"ProjectPart2", {"--er"}, {{"ER","2"}}, {"/bar"}, - {{2, 1}}, - {{2, 2}}}; + {1}, + {2}}; ClangBackEnd::V2::ProjectPartContainer projectPart2b{"ProjectPart2", {"--liang"}, {{"LIANG","3"}}, {"/liang"}, - {{2, 3}}, - {{2, 2}, {2, 4}}}; + {3}, + {2, 4}}; ClangBackEnd::V2::ProjectPartContainer projectPart3{"ProjectPart3", {"--san"}, {{"SAN","2"}}, {"/SAN"}, - {{3, 1}}, - {{3, 2}}}; + {1}, + {2}}; }; TEST_F(ProjectPartQueue, AddProjectPart) diff --git a/tests/unit/unittest/projectparts-test.cpp b/tests/unit/unittest/projectparts-test.cpp index 74d1c86338..405b955fed 100644 --- a/tests/unit/unittest/projectparts-test.cpp +++ b/tests/unit/unittest/projectparts-test.cpp @@ -42,11 +42,11 @@ class ProjectParts : public testing::Test { protected: ClangBackEnd::ProjectParts projectParts; - FilePathId firstHeader{1, 1}; - FilePathId secondHeader{1, 2}; - FilePathId firstSource{1, 11}; - FilePathId secondSource{1, 12}; - FilePathId thirdSource{1, 13}; + FilePathId firstHeader{1}; + FilePathId secondHeader{2}; + FilePathId firstSource{11}; + FilePathId secondSource{12}; + FilePathId thirdSource{13}; ProjectPartContainer projectPartContainer1{"id", {"-DUNIX", "-O2"}, {{"DEFINE", "1"}}, diff --git a/tests/unit/unittest/refactoringclient-test.cpp b/tests/unit/unittest/refactoringclient-test.cpp index c3b290815e..37b6e2a744 100644 --- a/tests/unit/unittest/refactoringclient-test.cpp +++ b/tests/unit/unittest/refactoringclient-test.cpp @@ -87,10 +87,10 @@ protected: CppTools::ProjectPart::Ptr projectPart; CppTools::ProjectFile projectFile{qStringFilePath, CppTools::ProjectFile::CXXSource}; SourceLocationsForRenamingMessage renameMessage{"symbol", - {{{{1, 42}, 1, 1, 0}, {{1, 42}, 2, 5, 10}}}, + {{{42, 1, 1, 0}, {42, 2, 5, 10}}}, 1}; - SourceRangesForQueryMessage queryResultMessage{{{{{1, 42}, 1, 1, 0, 1, 5, 4, ""}, - {{1, 42}, 2, 1, 5, 2, 5, 10, ""}}}}; + SourceRangesForQueryMessage queryResultMessage{{{{42, 1, 1, 0, 1, 5, 4, ""}, + {42, 2, 1, 5, 2, 5, 10, ""}}}}; SourceRangesForQueryMessage emptyQueryResultMessage; }; @@ -214,7 +214,7 @@ TEST_F(RefactoringClient, ResultCounterIsZeroAfterSettingExpectedResultCount) TEST_F(RefactoringClient, XXX) { const Core::Search::TextRange textRange{{1,0,1},{1,0,1}}; - const ClangBackEnd::SourceRangeWithTextContainer sourceRange{{1, 1}, 1, 1, 1, 1, 1, 1, "function"}; + const ClangBackEnd::SourceRangeWithTextContainer sourceRange{1, 1, 1, 1, 1, 1, 1, "function"}; EXPECT_CALL(mockSearchHandle, addResult(QString("/path/to/file"), QString("function"), textRange)) .Times(1); @@ -243,9 +243,9 @@ void RefactoringClient::SetUp() client.setSearchHandle(&mockSearchHandle); client.setExpectedResultCount(1); - ON_CALL(mockFilePathCaching, filePath(Eq(FilePathId{1, 1}))) + ON_CALL(mockFilePathCaching, filePath(Eq(FilePathId{1}))) .WillByDefault(Return(FilePath(PathString("/path/to/file")))); - ON_CALL(mockFilePathCaching, filePath(Eq(FilePathId{1, 42}))) + ON_CALL(mockFilePathCaching, filePath(Eq(FilePathId{42}))) .WillByDefault(Return(clangBackEndFilePath)); } diff --git a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp index 347802f350..ba7d62ddb9 100644 --- a/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp +++ b/tests/unit/unittest/refactoringdatabaseinitializer-test.cpp @@ -68,7 +68,7 @@ TEST_F(RefactoringDatabaseInitializer, AddSourcesTable) { InSequence s; - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, directoryId INTEGER, sourceName TEXT, sourceType INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, directoryId INTEGER, sourceName TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_sources_directoryId_sourceName ON sources(directoryId, sourceName)"))); initializer.createSourcesTable(); @@ -98,7 +98,7 @@ TEST_F(RefactoringDatabaseInitializer, AddProjectPartsSourcesTable) { InSequence s; - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, sourceId INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, sourceId INTEGER, sourceType INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsSources_sourceId_projectPartId ON projectPartsSources(sourceId, projectPartId)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsSources_projectPartId ON projectPartsSources(projectPartId)"))); @@ -120,7 +120,7 @@ TEST_F(RefactoringDatabaseInitializer, AddFileStatusesTable) { InSequence s; - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER, isInPrecompiledHeader INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER, buildDependencyTimeStamp INTEGER, isInPrecompiledHeader INTEGER)"))); initializer.createFileStatusesTable(); } @@ -156,19 +156,19 @@ TEST_F(RefactoringDatabaseInitializer, CreateInTheContructor) EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS locations(symbolId INTEGER, line INTEGER, column INTEGER, sourceId INTEGER, locationKind INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_locations_sourceId_line_column ON locations(sourceId, line, column)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_locations_sourceId_locationKind ON locations(sourceId, locationKind)"))); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, directoryId INTEGER, sourceName TEXT, sourceType INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sources(sourceId INTEGER PRIMARY KEY, directoryId INTEGER, sourceName TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_sources_directoryId_sourceName ON sources(directoryId, sourceName)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS directories(directoryId INTEGER PRIMARY KEY, directoryPath TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_directories_directoryPath ON directories(directoryPath)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectParts(projectPartId INTEGER PRIMARY KEY, projectPartName TEXT, compilerArguments TEXT, compilerMacros TEXT, includeSearchPaths TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectParts_projectPartName ON projectParts(projectPartName)"))); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, sourceId INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS projectPartsSources(projectPartId INTEGER, sourceId INTEGER, sourceType INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE UNIQUE INDEX IF NOT EXISTS index_projectPartsSources_sourceId_projectPartId ON projectPartsSources(sourceId, projectPartId)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_projectPartsSources_projectPartId ON projectPartsSources(projectPartId)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS usedMacros(usedMacroId INTEGER PRIMARY KEY, sourceId INTEGER, macroName TEXT)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_sourceId_macroName ON usedMacros(sourceId, macroName)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_usedMacros_macroName ON usedMacros(macroName)"))); - EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER, isInPrecompiledHeader INTEGER)"))); + EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS fileStatuses(sourceId INTEGER PRIMARY KEY, size INTEGER, lastModified INTEGER, buildDependencyTimeStamp INTEGER, isInPrecompiledHeader INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS sourceDependencies(sourceId INTEGER, dependencySourceId INTEGER)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE INDEX IF NOT EXISTS index_sourceDependencies_sourceId_dependencySourceId ON sourceDependencies(sourceId, dependencySourceId)"))); EXPECT_CALL(mockDatabase, execute(Eq("CREATE TABLE IF NOT EXISTS precompiledHeaders(projectPartId INTEGER PRIMARY KEY, pchPath TEXT, pchBuildTime INTEGER)"))); diff --git a/tests/unit/unittest/sourcerangeextractor-test.cpp b/tests/unit/unittest/sourcerangeextractor-test.cpp index 5e4da1e31b..ae9d670bf4 100644 --- a/tests/unit/unittest/sourcerangeextractor-test.cpp +++ b/tests/unit/unittest/sourcerangeextractor-test.cpp @@ -74,7 +74,7 @@ using SourceRangeExtractorSlowTest = SourceRangeExtractor; TEST_F(SourceRangeExtractorSlowTest, ExtractSourceRangeContainer) { - SourceRangeWithTextContainer sourceRangeContainer{{1, 1}, 1, 1, 0, 1, 10, 9, Utils::SmallString("int value;")}; + SourceRangeWithTextContainer sourceRangeContainer{1, 1, 1, 0, 1, 10, 9, Utils::SmallString("int value;")}; extractor.addSourceRange(sourceRange); diff --git a/tests/unit/unittest/sourcerangefilter-test.cpp b/tests/unit/unittest/sourcerangefilter-test.cpp index d59bd033e1..4b84f4b5f8 100644 --- a/tests/unit/unittest/sourcerangefilter-test.cpp +++ b/tests/unit/unittest/sourcerangefilter-test.cpp @@ -42,19 +42,19 @@ protected: protected: - SourceRangeWithTextContainers sourceRanges1{{{1, 1}, 1, 1, 1, 2, 1, 4, "foo"}, - {{1, 1}, 1, 1, 1, 2, 2, 5, "foo"}, - {{1, 2}, 1, 1, 1, 2, 1, 4, "foo"}}; - SourceRangeWithTextContainers sourceRanges2{{{1, 3}, 1, 1, 1, 2, 1, 4, "foo"}, - {{1, 1}, 1, 1, 1, 2, 1, 4, "foo"}, - {{1, 1}, 1, 1, 1, 2, 3, 6, "foo"}}; - SourceRangeWithTextContainers sourceRanges3{{{1, 1}, 1, 1, 1, 2, 3, 6, "foo"}, - {{1, 3}, 1, 1, 1, 2, 1, 4, "foo"}}; - SourceRangeWithTextContainers sourceRanges4{{{1, 1}, 1, 1, 1, 2, 3, 6, "foo"}, - {{1, 3}, 1, 1, 1, 2, 1, 4, "foo"}, - {{1, 3}, 1, 1, 1, 2, 1, 4, "foo"}}; - SourceRangeWithTextContainers sourceRanges5{{{1, 3}, 1, 1, 1, 2, 1, 4, "foo"}, - {{1, 1}, 1, 1, 1, 2, 3, 6, "foo"}}; + SourceRangeWithTextContainers sourceRanges1{{1, 1, 1, 1, 2, 1, 4, "foo"}, + {1, 1, 1, 1, 2, 2, 5, "foo"}, + {2, 1, 1, 1, 2, 1, 4, "foo"}}; + SourceRangeWithTextContainers sourceRanges2{{3, 1, 1, 1, 2, 1, 4, "foo"}, + {1, 1, 1, 1, 2, 1, 4, "foo"}, + {1, 1, 1, 1, 2, 3, 6, "foo"}}; + SourceRangeWithTextContainers sourceRanges3{{1, 1, 1, 1, 2, 3, 6, "foo"}, + {3, 1, 1, 1, 2, 1, 4, "foo"}}; + SourceRangeWithTextContainers sourceRanges4{{1, 1, 1, 1, 2, 3, 6, "foo"}, + {3, 1, 1, 1, 2, 1, 4, "foo"}, + {3, 1, 1, 1, 2, 1, 4, "foo"}}; + SourceRangeWithTextContainers sourceRanges5{{3, 1, 1, 1, 2, 1, 4, "foo"}, + {1, 1, 1, 1, 2, 3, 6, "foo"}}; SourceRangesForQueryMessage message1{{Utils::clone(sourceRanges1)}}; SourceRangesForQueryMessage message2{{Utils::clone(sourceRanges2)}}; ClangBackEnd::SourceRangeFilter filter{3}; diff --git a/tests/unit/unittest/sourcesmanager-test.cpp b/tests/unit/unittest/sourcesmanager-test.cpp index 9c149dac6e..290139e7cf 100644 --- a/tests/unit/unittest/sourcesmanager-test.cpp +++ b/tests/unit/unittest/sourcesmanager-test.cpp @@ -37,103 +37,103 @@ protected: TEST_F(SourcesManager, TouchFilePathIdFirstTime) { - ASSERT_FALSE(sources.alreadyParsed({1, 1}, 56)); + ASSERT_FALSE(sources.alreadyParsed(1, 56)); } TEST_F(SourcesManager, TouchFilePathIdTwoTimesWithSameTime) { - sources.alreadyParsed({1, 1}, 56); + sources.alreadyParsed(1, 56); - ASSERT_FALSE(sources.alreadyParsed({1, 1}, 56)); + ASSERT_FALSE(sources.alreadyParsed(1, 56)); } TEST_F(SourcesManager, TouchFilePathIdSecondTimeWithSameTime) { - sources.alreadyParsed({1, 1}, 56); + sources.alreadyParsed(1, 56); sources.updateModifiedTimeStamps(); - ASSERT_TRUE(sources.alreadyParsed({1, 1}, 56)); + ASSERT_TRUE(sources.alreadyParsed(1, 56)); } TEST_F(SourcesManager, TouchFilePathIdSecondTimeWithOlderTime) { - sources.alreadyParsed({1, 1}, 56); + sources.alreadyParsed(1, 56); sources.updateModifiedTimeStamps(); - ASSERT_TRUE(sources.alreadyParsed({1, 1}, 55)); + ASSERT_TRUE(sources.alreadyParsed(1, 55)); } TEST_F(SourcesManager, TouchFilePathIdSecondTimeWithNewerTime) { - sources.alreadyParsed({1, 1}, 56); + sources.alreadyParsed(1, 56); sources.updateModifiedTimeStamps(); - ASSERT_FALSE(sources.alreadyParsed({1, 1}, 57)); + ASSERT_FALSE(sources.alreadyParsed(1, 57)); } TEST_F(SourcesManager, MultipleFileIds) { - sources.alreadyParsed({1, 1}, 455); - sources.alreadyParsed({1, 4}, 56); - sources.alreadyParsed({1, 3}, 85); - sources.alreadyParsed({1, 6}, 56); - sources.alreadyParsed({1, 2}, 45); + sources.alreadyParsed(1, 455); + sources.alreadyParsed(4, 56); + sources.alreadyParsed(3, 85); + sources.alreadyParsed(6, 56); + sources.alreadyParsed(2, 45); sources.updateModifiedTimeStamps(); - ASSERT_TRUE(sources.alreadyParsed({1, 3}, 85)); + ASSERT_TRUE(sources.alreadyParsed(3, 85)); } TEST_F(SourcesManager, UpdateModifiedTimeStampsWithNewerTimeStamp) { - sources.alreadyParsed({1, 1}, 455); - sources.alreadyParsed({1, 4}, 56); - sources.alreadyParsed({1, 3}, 85); - sources.alreadyParsed({1, 6}, 56); - sources.alreadyParsed({1, 2}, 45); + sources.alreadyParsed(1, 455); + sources.alreadyParsed(4, 56); + sources.alreadyParsed(3, 85); + sources.alreadyParsed(6, 56); + sources.alreadyParsed(2, 45); sources.updateModifiedTimeStamps(); - sources.alreadyParsed({1, 3}, 86); + sources.alreadyParsed(3, 86); sources.updateModifiedTimeStamps(); - ASSERT_TRUE(sources.alreadyParsed({1, 3}, 86)); + ASSERT_TRUE(sources.alreadyParsed(3, 86)); } TEST_F(SourcesManager, DontUpdateModifiedTimeStampsWithOlderTimeStamp) { - sources.alreadyParsed({1, 1}, 455); - sources.alreadyParsed({1, 4}, 56); - sources.alreadyParsed({1, 3}, 85); - sources.alreadyParsed({1, 6}, 56); - sources.alreadyParsed({1, 2}, 45); + sources.alreadyParsed(1, 455); + sources.alreadyParsed(4, 56); + sources.alreadyParsed(3, 85); + sources.alreadyParsed(6, 56); + sources.alreadyParsed(2, 45); sources.updateModifiedTimeStamps(); - sources.alreadyParsed({1, 3}, 84); + sources.alreadyParsed(3, 84); sources.updateModifiedTimeStamps(); - ASSERT_TRUE(sources.alreadyParsed({1, 3}, 85)); + ASSERT_TRUE(sources.alreadyParsed(3, 85)); } TEST_F(SourcesManager, ZeroTime) { - sources.alreadyParsed({1, 1}, 0); + sources.alreadyParsed(1, 0); sources.updateModifiedTimeStamps(); - ASSERT_TRUE(sources.alreadyParsed({1, 1}, 0)); + ASSERT_TRUE(sources.alreadyParsed(1, 0)); } TEST_F(SourcesManager, TimeIsUpdated) { - sources.alreadyParsed({1, 1}, 56); - sources.alreadyParsed({1, 1}, 57); + sources.alreadyParsed(1, 56); + sources.alreadyParsed(1, 57); sources.updateModifiedTimeStamps(); - ASSERT_TRUE(sources.alreadyParsed({1, 1}, 57)); + ASSERT_TRUE(sources.alreadyParsed(1, 57)); } TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterInitialization) @@ -143,22 +143,22 @@ TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterInitialization) TEST_F(SourcesManager, AnyDependFileIsModified) { - sources.alreadyParsed({1, 1}, 56); + sources.alreadyParsed(1, 56); ASSERT_TRUE(sources.dependentFilesModified()); } TEST_F(SourcesManager, AnyDependFileIsModifiedAfterParsingTwoTimesSameTimeStamp) { - sources.alreadyParsed({1, 1}, 56); - sources.alreadyParsed({1, 1}, 56); + sources.alreadyParsed(1, 56); + sources.alreadyParsed(1, 56); ASSERT_TRUE(sources.dependentFilesModified()); } TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterUpdate) { - sources.alreadyParsed({1, 1}, 56); + sources.alreadyParsed(1, 56); sources.updateModifiedTimeStamps(); ASSERT_FALSE(sources.dependentFilesModified()); @@ -166,68 +166,68 @@ TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterUpdate) TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterNotAlreadyPared) { - sources.alreadyParsed({1, 1}, 56); + sources.alreadyParsed(1, 56); sources.updateModifiedTimeStamps(); - sources.alreadyParsed({1, 1}, 56); + sources.alreadyParsed(1, 56); ASSERT_FALSE(sources.dependentFilesModified()); } TEST_F(SourcesManager, AnyDependFileIsNotModifiedAfterAlreadyPared) { - sources.alreadyParsed({1, 1}, 56); + sources.alreadyParsed(1, 56); sources.updateModifiedTimeStamps(); - sources.alreadyParsed({1, 1}, 57); + sources.alreadyParsed(1, 57); ASSERT_TRUE(sources.dependentFilesModified()); } TEST_F(SourcesManager, AnyDependFileIsModifiedAfterUpdateNewTimeStamp) { - sources.alreadyParsed({1, 1}, 56); - sources.alreadyParsed({1, 2}, 56); + sources.alreadyParsed(1, 56); + sources.alreadyParsed(2, 56); sources.updateModifiedTimeStamps(); - sources.alreadyParsed({1, 1}, 57); + sources.alreadyParsed(1, 57); - sources.alreadyParsed({1, 2}, 56); + sources.alreadyParsed(2, 56); ASSERT_TRUE(sources.dependentFilesModified()); } TEST_F(SourcesManager, AlreadyParsedWithDependencyAfterUpdateNewTimeStamp) { - sources.alreadyParsedAllDependentFiles({1, 1}, 56); - sources.alreadyParsedAllDependentFiles({1, 2}, 56); + sources.alreadyParsedAllDependentFiles(1, 56); + sources.alreadyParsedAllDependentFiles(2, 56); sources.updateModifiedTimeStamps(); - sources.alreadyParsedAllDependentFiles({1, 1}, 57); + sources.alreadyParsedAllDependentFiles(1, 57); - bool alreadyParsed = sources.alreadyParsedAllDependentFiles({1, 2}, 56); + bool alreadyParsed = sources.alreadyParsedAllDependentFiles(2, 56); ASSERT_FALSE(alreadyParsed); } TEST_F(SourcesManager, AlreadyParsedWithDependencyAfterUpdateNewSecondTimeStamp) { - sources.alreadyParsedAllDependentFiles({1, 1}, 56); - sources.alreadyParsedAllDependentFiles({1, 2}, 56); + sources.alreadyParsedAllDependentFiles(1, 56); + sources.alreadyParsedAllDependentFiles(2, 56); sources.updateModifiedTimeStamps(); - sources.alreadyParsedAllDependentFiles({1, 1}, 56); + sources.alreadyParsedAllDependentFiles(1, 56); - bool alreadyParsed = sources.alreadyParsedAllDependentFiles({1, 2}, 57); + bool alreadyParsed = sources.alreadyParsedAllDependentFiles(2, 57); ASSERT_FALSE(alreadyParsed); } TEST_F(SourcesManager, AlreadyParsedWithDependencyAfterUpdateSameTimeStamps) { - sources.alreadyParsedAllDependentFiles({1, 1}, 56); - sources.alreadyParsedAllDependentFiles({1, 2}, 56); + sources.alreadyParsedAllDependentFiles(1, 56); + sources.alreadyParsedAllDependentFiles(2, 56); sources.updateModifiedTimeStamps(); - sources.alreadyParsedAllDependentFiles({1, 1}, 56); + sources.alreadyParsedAllDependentFiles(1, 56); - bool alreadyParsed = sources.alreadyParsedAllDependentFiles({1, 2}, 56); + bool alreadyParsed = sources.alreadyParsedAllDependentFiles(2, 56); ASSERT_TRUE(alreadyParsed); } diff --git a/tests/unit/unittest/symbolindexer-test.cpp b/tests/unit/unittest/symbolindexer-test.cpp index 28d30713a7..c33bceb399 100644 --- a/tests/unit/unittest/symbolindexer-test.cpp +++ b/tests/unit/unittest/symbolindexer-test.cpp @@ -29,7 +29,7 @@ #include "mocksymbolstorage.h" #include "mockfilepathcaching.h" #include "mocksqlitetransactionbackend.h" -#include "mockusedmacroandsourcestorage.h" +#include "mockbuilddependenciesstorage.h" #include <filepathcaching.h> #include <filestatuscache.h> @@ -71,11 +71,11 @@ using ClangBackEnd::SourceLocationKind; using ClangBackEnd::UsedMacros; using OptionalProjectPartArtefact = Utils::optional<ClangBackEnd::ProjectPartArtefact>; -MATCHER_P2(IsFileId, directoryId, fileNameId, +MATCHER_P(IsFileId, fileNameId, std::string(negation ? "isn't " : "is ") - + PrintToString(ClangBackEnd::FilePathId(directoryId, fileNameId))) + + PrintToString(ClangBackEnd::FilePathId(fileNameId))) { - return arg == ClangBackEnd::FilePathId(directoryId, fileNameId); + return arg == ClangBackEnd::FilePathId(fileNameId); } struct Data @@ -112,7 +112,7 @@ protected: ON_CALL(mockCollector, fileStatuses()).WillByDefault(ReturnRef(fileStatus)); ON_CALL(mockCollector, sourceDependencies()).WillByDefault(ReturnRef(sourceDependencies)); ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(A<FilePathId>())).WillByDefault(Return(artefact)); - ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(-1)); + ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(-1)); mockCollector.setIsUsed(false); @@ -163,7 +163,7 @@ protected: ClangBackEnd::FilePathId header2PathId{filePathId(TESTDATA_DIR "/symbolindexer_header1.h")}; ClangBackEnd::FilePathId header1PathId{filePathId(TESTDATA_DIR "/symbolindexer_header2.h")}; PathString generatedFileName = "includecollector_generated_file.h"; - ClangBackEnd::FilePathId generatedFilePathId{1, 21}; + ClangBackEnd::FilePathId generatedFilePathId21; ProjectPartContainer projectPart1{"project1", {"-I", TESTDATA_DIR, "-Wno-pragma-once-outside-header"}, {{"BAR", "1"}, {"FOO", "1"}}, @@ -186,18 +186,18 @@ protected: "void f();", {}}}; SymbolEntries symbolEntries{{1, {"function", "function", SymbolKind::Function}}}; - SourceLocationEntries sourceLocations{{1, {1, 1}, {42, 23}, SourceLocationKind::Declaration}}; - FilePathIds sourceFileIds{{1, 1}, {42, 23}}; - UsedMacros usedMacros{{"Foo", {1, 1}}}; - FileStatuses fileStatus{{{1, 2}, 3, 4, false}}; - SourceDependencies sourceDependencies{{{1, 1}, {1, 2}}, {{1, 1}, {1, 3}}}; + SourceLocationEntries sourceLocations{{1, 1, {42, 23}, SourceLocationKind::Declaration}}; + FilePathIds sourceFileIds{1, 23}; + UsedMacros usedMacros{{"Foo", 1}}; + FileStatuses fileStatus{{2, 3, 4, false}}; + SourceDependencies sourceDependencies{{1, 2}, {1, 3}}; ClangBackEnd::ProjectPartArtefact artefact{"[\"-DFOO\"]", "{\"FOO\":\"1\",\"BAR\":\"1\"}", "[\"/includes\"]", 74}; ClangBackEnd::ProjectPartArtefact emptyArtefact{"", "", "", 74}; Utils::optional<ClangBackEnd::ProjectPartArtefact > nullArtefact; ClangBackEnd::ProjectPartPch projectPartPch{"/path/to/pch", 4}; NiceMock<MockSqliteTransactionBackend> mockSqliteTransactionBackend; NiceMock<MockSymbolStorage> mockSymbolStorage; - NiceMock<MockUsedMacroAndSourceStorage> mockUsedMacroAndSourceStorage; + NiceMock<MockBuildDependenciesStorage> mockBuildDependenciesStorage; NiceMock<MockClangPathWatcher> mockPathWatcher; ClangBackEnd::FileStatusCache fileStatusCache{filePathCache}; ClangBackEnd::GeneratedFiles generatedFiles; @@ -208,7 +208,7 @@ protected: SymbolIndexerTaskQueue indexerQueue{indexerScheduler, progressCounter}; ClangBackEnd::SymbolIndexer indexer{indexerQueue, mockSymbolStorage, - mockUsedMacroAndSourceStorage, + mockBuildDependenciesStorage, mockPathWatcher, filePathCache, fileStatusCache, @@ -340,14 +340,14 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsUpdateProjectPartSourcesWithoutArti ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>("project2"))).WillByDefault(Return(nullArtefact)); ON_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq("project2"), _, _, _)).WillByDefault(Return(3)); - EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(3, ElementsAre(IsFileId(1, 1), IsFileId(42, 23)))); + EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(3, ElementsAre(IsFileId(1), IsFileId(23)))); indexer.updateProjectParts({projectPart2}); } TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertOrUpdateUsedMacros) { - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(Eq(usedMacros))) + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros))) .Times(2); indexer.updateProjectParts({projectPart1, projectPart2}); @@ -355,7 +355,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertOrUpdateUsedMacros) TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertFileStatuses) { - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(Eq(fileStatus))) + EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus))) .Times(2); indexer.updateProjectParts({projectPart1, projectPart2}); @@ -363,7 +363,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertFileStatuses) TEST_F(SymbolIndexer, UpdateProjectPartsCallsInsertOrUpdateSourceDependencies) { - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))) + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))) .Times(2); indexer.updateProjectParts({projectPart1, projectPart2}); @@ -385,16 +385,16 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithoutProjectPartArtifact) EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillOnce(Return(nullArtefact)); EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId), Eq(projectPart1.arguments), Eq(projectPart1.compilerMacros), Eq(projectPart1.includeSearchPaths))).WillOnce(Return(12)); EXPECT_CALL(mockSymbolStorage, fetchPrecompiledHeader(Eq(12))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(Eq(main1PathId))).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(Eq(main1PathId))).Times(0); EXPECT_CALL(mockSqliteTransactionBackend, commit()); EXPECT_CALL(mockCollector, setFile(main1PathId, projectPart1.arguments)); EXPECT_CALL(mockCollector, collectSymbols()); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)); EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(TypedEq<int>(12), Eq(sourceFileIds))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(Eq(usedMacros))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(Eq(fileStatus))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros))); + EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); EXPECT_CALL(mockSqliteTransactionBackend, commit()); indexer.updateProjectParts({projectPart1}); @@ -408,16 +408,16 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithProjectPartArtifact) EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillRepeatedly(Return(artefact)); EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId), Eq(projectPart1.arguments), Eq(projectPart1.compilerMacros), Eq(projectPart1.includeSearchPaths))).WillOnce(Return(-1)); EXPECT_CALL(mockSymbolStorage, fetchPrecompiledHeader(Eq(artefact.projectPartId))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(Eq(main1PathId))).WillOnce(Return(-1)); + EXPECT_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(Eq(main1PathId))).WillOnce(Return(-1)); EXPECT_CALL(mockSqliteTransactionBackend, commit()); EXPECT_CALL(mockCollector, setFile(Eq(main1PathId), Eq(projectPart1.arguments))); EXPECT_CALL(mockCollector, collectSymbols()); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)); EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(TypedEq<int>(artefact.projectPartId), Eq(sourceFileIds))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(Eq(usedMacros))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(Eq(fileStatus))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros))); + EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); EXPECT_CALL(mockSqliteTransactionBackend, commit()); indexer.updateProjectParts({projectPart1}); @@ -427,7 +427,7 @@ TEST_F(SymbolIndexer, CallSetNotifier) { EXPECT_CALL(mockPathWatcher, setNotifier(_)); - ClangBackEnd::SymbolIndexer indexer{indexerQueue, mockSymbolStorage, mockUsedMacroAndSourceStorage, mockPathWatcher, filePathCache, fileStatusCache, mockSqliteTransactionBackend}; + ClangBackEnd::SymbolIndexer indexer{indexerQueue, mockSymbolStorage, mockBuildDependenciesStorage, mockPathWatcher, filePathCache, fileStatusCache, mockSqliteTransactionBackend}; } TEST_F(SymbolIndexer, PathChangedCallsFetchProjectPartArtefactInStorage) @@ -451,9 +451,9 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrder) EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(symbolEntries, sourceLocations)); EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(artefact.projectPartId, Eq(sourceFileIds))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(Eq(usedMacros))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(Eq(fileStatus))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(Eq(usedMacros))); + EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(Eq(fileStatus))); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(Eq(sourceDependencies))); EXPECT_CALL(mockSqliteTransactionBackend, commit()); indexer.pathsChanged({sourceFileIds[0]}); @@ -472,9 +472,9 @@ TEST_F(SymbolIndexer, HandleEmptyOptionalArtifactInUpdateChangedPath) EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)).Times(0); EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(An<int>(), _)).Times(0); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(_)).Times(0); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(_)).Times(0); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(_)).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(_)).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(_)).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(_)).Times(0); EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0); indexer.pathsChanged({sourceFileIds[0]}); @@ -550,21 +550,21 @@ TEST_F(SymbolIndexer, IncludeSearchPathsAreDifferent) TEST_F(SymbolIndexer, DontReparseInUpdateProjectPartsIfDefinesAreTheSame) { InSequence s; - ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(QDateTime::currentSecsSinceEpoch())); + ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(QDateTime::currentSecsSinceEpoch())); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()); EXPECT_CALL(mockSymbolStorage, fetchProjectPartArtefact(TypedEq<Utils::SmallStringView>(projectPart1.projectPartId))).WillRepeatedly(Return(artefact)); EXPECT_CALL(mockSymbolStorage, insertOrUpdateProjectPart(Eq(projectPart1.projectPartId), Eq(projectPart1.arguments), Eq(projectPart1.compilerMacros), Eq(projectPart1.includeSearchPaths))); - EXPECT_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillRepeatedly(Return(QDateTime::currentSecsSinceEpoch())); + EXPECT_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillRepeatedly(Return(QDateTime::currentSecsSinceEpoch())); EXPECT_CALL(mockSqliteTransactionBackend, commit()); EXPECT_CALL(mockCollector, setFile(_, _)).Times(0); EXPECT_CALL(mockCollector, collectSymbols()).Times(0); EXPECT_CALL(mockSqliteTransactionBackend, immediateBegin()).Times(0); EXPECT_CALL(mockSymbolStorage, addSymbolsAndSourceLocations(_, _)).Times(0); EXPECT_CALL(mockSymbolStorage, updateProjectPartSources(An<int>(), _)).Times(0); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateUsedMacros(_)).Times(0); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertFileStatuses(_)).Times(0); - EXPECT_CALL(mockUsedMacroAndSourceStorage, insertOrUpdateSourceDependencies(_)).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateUsedMacros(_)).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, insertFileStatuses(_)).Times(0); + EXPECT_CALL(mockBuildDependenciesStorage, insertOrUpdateSourceDependencies(_)).Times(0); EXPECT_CALL(mockSqliteTransactionBackend, commit()).Times(0); indexer.updateProjectPart(std::move(projectPart1)); @@ -602,7 +602,7 @@ TEST_F(SymbolIndexer, GetUpdatableFilePathIdsIfIncludeSearchPathsAreDifferent) TEST_F(SymbolIndexer, GetNoUpdatableFilePathIdsIfArtefactsAreTheSame) { ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact)); - ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(QDateTime::currentSecsSinceEpoch())); + ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A<FilePathId>())).WillByDefault(Return(QDateTime::currentSecsSinceEpoch())); auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact); @@ -613,7 +613,7 @@ TEST_F(SymbolIndexer, OutdatedFilesPassUpdatableFilePathIds) { indexer.pathsChanged({main1PathId}); ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact)); - ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())) + ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A<FilePathId>())) .WillByDefault(Return(0)); auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact); @@ -625,7 +625,7 @@ TEST_F(SymbolIndexer, UpToDateFilesDontPassFilteredUpdatableFilePathIds) { indexer.pathsChanged({main1PathId}); ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact)); - ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())) + ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A<FilePathId>())) .WillByDefault(Return(QDateTime::currentSecsSinceEpoch())); auto filePathIds = indexer.updatableFilePathIds(projectPart1, artefact); @@ -638,7 +638,7 @@ TEST_F(SymbolIndexer, OutdatedFilesAreParsedInUpdateProjectParts) indexer.pathsChanged({main1PathId}); indexerScheduler.syncTasks(); ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact)); - ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())) + ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A<FilePathId>())) .WillByDefault(Return(0)); EXPECT_CALL(mockCollector, setFile(Eq(main1PathId), _)); @@ -651,7 +651,7 @@ TEST_F(SymbolIndexer, UpToDateFilesAreNotParsedInUpdateProjectParts) indexer.pathsChanged({main1PathId}); indexerScheduler.syncTasks(); ON_CALL(mockSymbolStorage, fetchProjectPartArtefact(An<Utils::SmallStringView>())).WillByDefault(Return(artefact)); - ON_CALL(mockUsedMacroAndSourceStorage, fetchLowestLastModifiedTime(A<FilePathId>())) + ON_CALL(mockBuildDependenciesStorage, fetchLowestLastModifiedTime(A<FilePathId>())) .WillByDefault(Return(QDateTime::currentSecsSinceEpoch())); EXPECT_CALL(mockCollector, setFile(_, _)).Times(0); diff --git a/tests/unit/unittest/symbolindexertaskqueue-test.cpp b/tests/unit/unittest/symbolindexertaskqueue-test.cpp index 431aedc911..a46f99972c 100644 --- a/tests/unit/unittest/symbolindexertaskqueue-test.cpp +++ b/tests/unit/unittest/symbolindexertaskqueue-test.cpp @@ -58,19 +58,19 @@ protected: TEST_F(SymbolIndexerTaskQueue, AddTasks) { - queue.addOrUpdateTasks({{{1, 2}, 1, Callable{}}, - {{1, 4}, 1, Callable{}}}); + queue.addOrUpdateTasks({{2, 1, Callable{}}, + {4, 1, Callable{}}}); - queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}}, - {{1, 3}, 1, Callable{}}, - {{1, 5}, 1, Callable{}}}); + queue.addOrUpdateTasks({{1, 1, Callable{}}, + {3, 1, Callable{}}, + {5, 1, Callable{}}}); ASSERT_THAT(queue.tasks(), - ElementsAre(IsTask(FilePathId{1, 1}, 1), - IsTask(FilePathId{1, 2}, 1), - IsTask(FilePathId{1, 3}, 1), - IsTask(FilePathId{1, 4}, 1), - IsTask(FilePathId{1, 5}, 1))); + ElementsAre(IsTask(1, 1), + IsTask(2, 1), + IsTask(3, 1), + IsTask(4, 1), + IsTask(5, 1))); } TEST_F(SymbolIndexerTaskQueue, AddTasksCallsProgressCounter) @@ -89,57 +89,57 @@ TEST_F(SymbolIndexerTaskQueue, AddTasksCallsProgressCounter) TEST_F(SymbolIndexerTaskQueue, ReplaceTask) { - queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}}, - {{1, 3}, 1, Callable{}}, - {{1, 5}, 1, Callable{}}}); + queue.addOrUpdateTasks({{1, 1, Callable{}}, + {3, 1, Callable{}}, + {5, 1, Callable{}}}); - queue.addOrUpdateTasks({{{1, 2}, 1, Callable{}}, - {{1, 3}, 1, Callable{}}}); + queue.addOrUpdateTasks({{2, 1, Callable{}}, + {3, 1, Callable{}}}); ASSERT_THAT(queue.tasks(), - ElementsAre(IsTask(FilePathId{1, 1}, 1), - IsTask(FilePathId{1, 2}, 1), - IsTask(FilePathId{1, 3}, 1), - IsTask(FilePathId{1, 5}, 1))); + ElementsAre(IsTask(1, 1), + IsTask(2, 1), + IsTask(3, 1), + IsTask(5, 1))); } TEST_F(SymbolIndexerTaskQueue, AddTaskWithDifferentProjectId) { - queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}}, - {{1, 3}, 1, Callable{}}, - {{1, 5}, 1, Callable{}}}); + queue.addOrUpdateTasks({{1, 1, Callable{}}, + {3, 1, Callable{}}, + {5, 1, Callable{}}}); - queue.addOrUpdateTasks({{{1, 2}, 2, Callable{}}, - {{1, 3}, 2, Callable{}}}); + queue.addOrUpdateTasks({{2, 2, Callable{}}, + {3, 2, Callable{}}}); ASSERT_THAT(queue.tasks(), - ElementsAre(IsTask(FilePathId{1, 1}, 1), - IsTask(FilePathId{1, 2}, 2), - IsTask(FilePathId{1, 3}, 1), - IsTask(FilePathId{1, 3}, 2), - IsTask(FilePathId{1, 5}, 1))); + ElementsAre(IsTask(1, 1), + IsTask(2, 2), + IsTask(3, 1), + IsTask(3, 2), + IsTask(5, 1))); } TEST_F(SymbolIndexerTaskQueue, RemoveTaskByProjectParts) { - queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}}, - {{1, 3}, 1, Callable{}}, - {{1, 5}, 1, Callable{}}}); - queue.addOrUpdateTasks({{{1, 2}, 2, Callable{}}, - {{1, 3}, 2, Callable{}}}); - queue.addOrUpdateTasks({{{1, 2}, 3, Callable{}}, - {{1, 3}, 3, Callable{}}}); - queue.addOrUpdateTasks({{{1, 2}, 4, Callable{}}, - {{1, 3}, 4, Callable{}}}); + queue.addOrUpdateTasks({{1, 1, Callable{}}, + {3, 1, Callable{}}, + {5, 1, Callable{}}}); + queue.addOrUpdateTasks({{2, 2, Callable{}}, + {3, 2, Callable{}}}); + queue.addOrUpdateTasks({{2, 3, Callable{}}, + {3, 3, Callable{}}}); + queue.addOrUpdateTasks({{2, 4, Callable{}}, + {3, 4, Callable{}}}); queue.removeTasks({2, 3}); ASSERT_THAT(queue.tasks(), - ElementsAre(IsTask(FilePathId{1, 1}, 1), - IsTask(FilePathId{1, 2}, 4), - IsTask(FilePathId{1, 3}, 1), - IsTask(FilePathId{1, 3}, 4), - IsTask(FilePathId{1, 5}, 1))); + ElementsAre(IsTask(1, 1), + IsTask(2, 4), + IsTask(3, 1), + IsTask(3, 4), + IsTask(5, 1))); } TEST_F(SymbolIndexerTaskQueue, RemoveTasksCallsProgressCounter) @@ -163,9 +163,9 @@ TEST_F(SymbolIndexerTaskQueue, RemoveTasksCallsProgressCounter) TEST_F(SymbolIndexerTaskQueue, ProcessTasksCallsFreeSlotsAndAddTasksInScheduler) { InSequence s; - queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}}, - {{1, 3}, 1, Callable{}}, - {{1, 5}, 1, Callable{}}}); + queue.addOrUpdateTasks({{1, 1, Callable{}}, + {3, 1, Callable{}}, + {5, 1, Callable{}}}); EXPECT_CALL(mockTaskScheduler, freeSlots()).WillRepeatedly(Return(2)); EXPECT_CALL(mockTaskScheduler, addTasks(SizeIs(2))); @@ -186,9 +186,9 @@ TEST_F(SymbolIndexerTaskQueue, ProcessTasksCallsFreeSlotsAndAddTasksWithNoTaskIn TEST_F(SymbolIndexerTaskQueue, ProcessTasksCallsFreeSlotsAndMoveAllTasksInSchedulerIfMoreSlotsAreFree) { InSequence s; - queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}}, - {{1, 3}, 1, Callable{}}, - {{1, 5}, 1, Callable{}}}); + queue.addOrUpdateTasks({{1, 1, Callable{}}, + {3, 1, Callable{}}, + {5, 1, Callable{}}}); EXPECT_CALL(mockTaskScheduler, freeSlots()).WillRepeatedly(Return(4)); EXPECT_CALL(mockTaskScheduler, addTasks(SizeIs(3))); @@ -198,9 +198,9 @@ TEST_F(SymbolIndexerTaskQueue, ProcessTasksCallsFreeSlotsAndMoveAllTasksInSchedu TEST_F(SymbolIndexerTaskQueue, ProcessTasksRemovesProcessedTasks) { - queue.addOrUpdateTasks({{{1, 1}, 1, Callable{}}, - {{1, 3}, 1, Callable{}}, - {{1, 5}, 1, Callable{}}}); + queue.addOrUpdateTasks({{1, 1, Callable{}}, + {3, 1, Callable{}}, + {5, 1, Callable{}}}); ON_CALL(mockTaskScheduler, freeSlots()).WillByDefault(Return(2)); queue.processEntries(); diff --git a/tests/unit/unittest/symbolquery-test.cpp b/tests/unit/unittest/symbolquery-test.cpp index 53eb9d1c68..a2aeb41d08 100644 --- a/tests/unit/unittest/symbolquery-test.cpp +++ b/tests/unit/unittest/symbolquery-test.cpp @@ -61,12 +61,12 @@ protected: MockSqliteReadStatement &selectSymbolsForKindAndStartsWith2 = mockStatementFactory.selectSymbolsForKindAndStartsWith2; MockSqliteReadStatement &selectSymbolsForKindAndStartsWith3 = mockStatementFactory.selectSymbolsForKindAndStartsWith3; MockSqliteReadStatement &selectLocationOfSymbol = mockStatementFactory.selectLocationOfSymbol; - SourceLocations locations{{{1, 1}, 1, 1}, - {{1, 1}, 2, 3}, - {{1, 2}, 1, 1}, - {{1, 2}, 3, 1}, - {{1, 4}, 1, 1}, - {{1, 4}, 1, 3}}; + SourceLocations locations{{1, 1, 1}, + {1, 2, 3}, + {2, 1, 1}, + {2, 3, 1}, + {4, 1, 1}, + {4, 1, 3}}; MockQuery query{mockStatementFactory}; }; @@ -75,8 +75,8 @@ class SymbolQuerySlowTest : public testing::Test protected: void SetUp() override { - database.execute("INSERT INTO sources VALUES (1, 1, \"filename.h\", 1)"); - database.execute("INSERT INTO sources VALUES (2, 1, \"filename.cpp\", 1)"); + database.execute("INSERT INTO sources VALUES (1, 1, \"filename.h\")"); + database.execute("INSERT INTO sources VALUES (2, 1, \"filename.cpp\")"); database.execute("INSERT INTO directories VALUES (1, \"/path/to\")"); database.execute("INSERT INTO locations VALUES (1, 2, 3, 1, 1)"); database.execute("INSERT INTO locations VALUES (1, 4, 6, 2, 3)"); @@ -96,28 +96,28 @@ TEST_F(SymbolQuery, LocationsAtCallsValues) { EXPECT_CALL(selectLocationsForSymbolLocation, valuesReturnSourceLocations(_, 42, 14, 7)); - query.locationsAt({1, 42}, 14, 7); + query.locationsAt(42, 14, 7); } TEST_F(SymbolQuerySlowTest, LocationsAt) { - auto locations = query.locationsAt({1, 2}, 4, 6); + auto locations = query.locationsAt(2, 4, 6); ASSERT_THAT(locations, - UnorderedElementsAre(SourceLocation({1, 1}, 2, 3), - SourceLocation({1, 2}, 4, 6))); + UnorderedElementsAre(SourceLocation(1, 2, 3), + SourceLocation(2, 4, 6))); } TEST_F(SymbolQuery, SourceUsagesAtCallsValues) { EXPECT_CALL(selectSourceUsagesForSymbolLocation, valuesReturnSourceUsages(_, 42, 14, 7)); - query.sourceUsagesAt({1, 42}, 14, 7); + query.sourceUsagesAt(42, 14, 7); } TEST_F(SymbolQuerySlowTest, SourceUsagesAt) { - auto usages = query.sourceUsagesAt({1, 2}, 4, 6); + auto usages = query.sourceUsagesAt(2, 4, 6); ASSERT_THAT(usages, UnorderedElementsAre(CppTools::Usage("/path/to/filename.h", 2, 3), @@ -190,7 +190,7 @@ TEST_F(SymbolQuerySlowTest, LocationForSymbolId) { auto location = query.locationForSymbolId(1, SourceLocationKind::Definition); - ASSERT_THAT(location.value(), Eq(SourceLocation({1, 2}, {4, 6}))); + ASSERT_THAT(location.value(), Eq(SourceLocation(2, {4, 6}))); } } diff --git a/tests/unit/unittest/symbolstorage-test.cpp b/tests/unit/unittest/symbolstorage-test.cpp index 1b7e7383a6..9949f464f9 100644 --- a/tests/unit/unittest/symbolstorage-test.cpp +++ b/tests/unit/unittest/symbolstorage-test.cpp @@ -76,8 +76,8 @@ protected: SymbolEntries symbolEntries{{1, {"functionUSR", "function", SymbolKind::Function}}, {2, {"function2USR", "function2", SymbolKind::Function}}}; - SourceLocationEntries sourceLocations{{1, {1, 3}, {42, 23}, SourceLocationKind::Declaration}, - {2, {1, 4}, {7, 11}, SourceLocationKind::Definition}}; + SourceLocationEntries sourceLocations{{1, 3, {42, 23}, SourceLocationKind::Declaration}, + {2, 4, {7, 11}, SourceLocationKind::Definition}}; ClangBackEnd::ProjectPartArtefact artefact{"[\"-DFOO\"]", "{\"FOO\":\"1\"}", "[\"/includes\"]", 74}; }; @@ -213,7 +213,7 @@ TEST_F(SymbolStorage, UpdateProjectPartSources) EXPECT_CALL(insertProjectPartSourcesStatement, write(TypedEq<int>(42), TypedEq<int>(1))); EXPECT_CALL(insertProjectPartSourcesStatement, write(TypedEq<int>(42), TypedEq<int>(2))); - storage.updateProjectPartSources(42, {{1, 1}, {1, 2}}); + storage.updateProjectPartSources(42, {1, 2}); } TEST_F(SymbolStorage, FetchProjectPartArtefactBySourceIdCallsValueInStatement) @@ -221,7 +221,7 @@ TEST_F(SymbolStorage, FetchProjectPartArtefactBySourceIdCallsValueInStatement) EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1)) .WillRepeatedly(Return(artefact)); - storage.fetchProjectPartArtefact({2, 1}); + storage.fetchProjectPartArtefact(1); } TEST_F(SymbolStorage, FetchProjectPartArtefactBySourceIdReturnArtefact) @@ -229,7 +229,7 @@ TEST_F(SymbolStorage, FetchProjectPartArtefactBySourceIdReturnArtefact) EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1)) .WillRepeatedly(Return(artefact)); - auto result = storage.fetchProjectPartArtefact({2, 1}); + auto result = storage.fetchProjectPartArtefact(1); ASSERT_THAT(result, Eq(artefact)); } @@ -239,7 +239,7 @@ TEST_F(SymbolStorage, FetchProjectPartArtefactByProjectNameCallsValueInStatement EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1)) .WillRepeatedly(Return(artefact)); - storage.fetchProjectPartArtefact({2, 1}); + storage.fetchProjectPartArtefact(1); } TEST_F(SymbolStorage, FetchProjectPartArtefactByProjectNameReturnArtefact) @@ -247,7 +247,7 @@ TEST_F(SymbolStorage, FetchProjectPartArtefactByProjectNameReturnArtefact) EXPECT_CALL(getProjectPartArtefactsBySourceId, valueReturnProjectPartArtefact(1)) .WillRepeatedly(Return(artefact)); - auto result = storage.fetchProjectPartArtefact({2, 1}); + auto result = storage.fetchProjectPartArtefact(1); ASSERT_THAT(result, Eq(artefact)); } diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro index 64e80654d9..2dc4389f08 100644 --- a/tests/unit/unittest/unittest.pro +++ b/tests/unit/unittest/unittest.pro @@ -104,9 +104,10 @@ SOURCES += \ taskscheduler-test.cpp \ compileroptionsbuilder-test.cpp \ progresscounter-test.cpp \ - usedmacroandsourcestorage-test.cpp \ pchtaskgenerator-test.cpp \ - compilationdatabaseutils-test.cpp + compilationdatabaseutils-test.cpp \ + builddependenciesprovider-test.cpp \ + builddependenciesstorage-test.cpp !isEmpty(LIBCLANG_LIBS) { SOURCES += \ @@ -252,8 +253,10 @@ HEADERS += \ mocktaskscheduler.h \ mockprogressmanager.h \ mockfutureinterface.h \ - mockusedmacroandsourcestorage.h \ - mockbuilddependenciesprovider.h + mockbuilddependenciesprovider.h \ + mockmodifiedtimechecker.h \ + mockbuilddependenciesgenerator.h \ + mockbuilddependenciesstorage.h !isEmpty(LIBCLANG_LIBS) { HEADERS += \ |