diff options
author | Marco Bubke <marco.bubke@qt.io> | 2019-08-08 14:47:33 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2019-08-27 11:52:09 +0000 |
commit | 199746143a4f4d87af2d87b7be3ac1228589edbe (patch) | |
tree | f3b05a8e91a8d453cbbb0b6733fed74da3862a92 /tests/unit | |
parent | 947cb9ed4ee6e87404fa66be667b30667fef9ef5 (diff) | |
download | qt-creator-199746143a4f4d87af2d87b7be3ac1228589edbe.tar.gz |
Clang: Bulk add project file paths to database
This project part container generation because there is not anymore one
single access to the database for every file path.
Change-Id: I5f82022262fe89a976729d48ee4f098b74a1e1d1
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/unittest/filepathcache-test.cpp | 42 | ||||
-rw-r--r-- | tests/unit/unittest/mockfilepathcaching.h | 2 | ||||
-rw-r--r-- | tests/unit/unittest/mockfilepathstorage.h | 13 | ||||
-rw-r--r-- | tests/unit/unittest/projectupdater-test.cpp | 17 | ||||
-rw-r--r-- | tests/unit/unittest/stringcache-test.cpp | 6 |
5 files changed, 70 insertions, 10 deletions
diff --git a/tests/unit/unittest/filepathcache-test.cpp b/tests/unit/unittest/filepathcache-test.cpp index c46bb0ce88..789eb66451 100644 --- a/tests/unit/unittest/filepathcache-test.cpp +++ b/tests/unit/unittest/filepathcache-test.cpp @@ -26,6 +26,7 @@ #include "googletest.h" #include "mockfilepathstorage.h" +#include "mocksqlitedatabase.h" #include <filepathcache.h> @@ -37,6 +38,7 @@ using Cache = ClangBackEnd::FilePathCache<NiceMock<MockFilePathStorage>>; using ClangBackEnd::FilePathId; using NFP = ClangBackEnd::FilePath; using ClangBackEnd::FilePathView; +using ClangBackEnd::FilePathViews; using ClangBackEnd::Sources::SourceNameAndDirectoryId; class FilePathCache : public testing::Test @@ -73,9 +75,10 @@ protected: } protected: - NiceMock<MockFilePathStorage> mockStorage; + NiceMock<MockSqliteDatabase> mockDatabase; + NiceMock<MockFilePathStorage> mockStorage{mockDatabase}; Cache cache{mockStorage}; - NiceMock<MockFilePathStorage> mockStorageFilled; + NiceMock<MockFilePathStorage> mockStorageFilled{mockDatabase}; }; TEST_F(FilePathCache, FilePathIdWithOutAnyEntryCallDirectoryId) @@ -379,7 +382,7 @@ TEST_F(FilePathCache, GetFileIdAfterAddFilePaths) Cache cacheFilled{mockStorageFilled}; cacheFilled.addFilePaths( - {"/path3/to/file.h", "/path/to/file.h", "/path2/to/file2.h", "/path/to/file.cpp"}); + FilePathViews{"/path3/to/file.h", "/path/to/file.h", "/path2/to/file2.h", "/path/to/file.cpp"}); ASSERT_THAT(cacheFilled.filePath(101), Eq("/path3/to/file.h")); } @@ -388,7 +391,7 @@ TEST_F(FilePathCache, GetFileIdAfterAddFilePathsWhichWasAlreadyAdded) { Cache cacheFilled{mockStorageFilled}; - cacheFilled.addFilePaths({"/path3/to/file.h", "/path/to/file.h", "/path2/to/file2.h"}); + cacheFilled.addFilePaths(FilePathViews{"/path3/to/file.h", "/path/to/file.h", "/path2/to/file2.h"}); ASSERT_THAT(cacheFilled.filePath(42), Eq("/path/to/file.cpp")); } @@ -398,13 +401,42 @@ TEST_F(FilePathCache, AddFilePathsCalls) Cache cacheFilled{mockStorageFilled}; InSequence s; + EXPECT_CALL(mockDatabase, deferredBegin()); EXPECT_CALL(mockStorageFilled, fetchDirectoryIdUnguarded(Eq("/path3/to"))).WillOnce(Return(7)); + EXPECT_CALL(mockStorageFilled, fetchDirectoryIdUnguarded(Eq("/path/to"))).Times(0); EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(5, Eq("file.h"))).WillOnce(Return(99)); EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(6, Eq("file2.h"))).WillOnce(Return(106)); EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(7, Eq("file.h"))).WillOnce(Return(101)); + EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(5, Eq("file.cpp"))).Times(0); + EXPECT_CALL(mockDatabase, commit()); cacheFilled.addFilePaths( - {"/path3/to/file.h", "/path/to/file.h", "/path2/to/file2.h", "/path/to/file.cpp"}); + FilePathViews{"/path3/to/file.h", "/path/to/file.h", "/path2/to/file2.h", "/path/to/file.cpp"}); } +TEST_F(FilePathCache, DontUseTransactionIfNotAddingFilesInAddFilePathsCalls) +{ + Cache cacheFilled{mockStorageFilled}; + InSequence s; + + EXPECT_CALL(mockDatabase, deferredBegin()).Times(0); + EXPECT_CALL(mockStorageFilled, fetchDirectoryIdUnguarded(Eq("/path/to"))).Times(0); + EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(5, Eq("file.cpp"))).Times(0); + EXPECT_CALL(mockDatabase, commit()).Times(0); + + cacheFilled.addFilePaths(FilePathViews{"/path/to/file.cpp"}); +} + +TEST_F(FilePathCache, UseTransactionIfAddingFilesOnlyInAddFilePathsCalls) +{ + Cache cacheFilled{mockStorageFilled}; + InSequence s; + + EXPECT_CALL(mockDatabase, deferredBegin()); + EXPECT_CALL(mockStorageFilled, fetchDirectoryIdUnguarded(Eq("/path/to"))).Times(0); + EXPECT_CALL(mockStorageFilled, fetchSourceIdUnguarded(5, Eq("file.h"))); + EXPECT_CALL(mockDatabase, commit()); + + cacheFilled.addFilePaths(FilePathViews{"/path/to/file.h"}); +} } // namespace diff --git a/tests/unit/unittest/mockfilepathcaching.h b/tests/unit/unittest/mockfilepathcaching.h index ca7960513e..bec249a5a5 100644 --- a/tests/unit/unittest/mockfilepathcaching.h +++ b/tests/unit/unittest/mockfilepathcaching.h @@ -42,5 +42,5 @@ public: Utils::PathString(ClangBackEnd::DirectoryPathId directoryPathId)); MOCK_CONST_METHOD1(directoryPathId, ClangBackEnd::DirectoryPathId(ClangBackEnd::FilePathId filePathId)); + MOCK_METHOD1(addFilePaths, void(const ClangBackEnd::FilePaths &filePaths)); }; - diff --git a/tests/unit/unittest/mockfilepathstorage.h b/tests/unit/unittest/mockfilepathstorage.h index c6701228e7..cc6cfa07c7 100644 --- a/tests/unit/unittest/mockfilepathstorage.h +++ b/tests/unit/unittest/mockfilepathstorage.h @@ -27,13 +27,18 @@ #include "googletest.h" +#include "mocksqlitedatabase.h" + #include <filepathstoragesources.h> class MockFilePathStorage { public: - MOCK_METHOD1(fetchDirectoryId, - int (Utils::SmallStringView directoryPath)); + MockFilePathStorage(MockSqliteDatabase &mockDatabase) + : mockDatabase{mockDatabase} + {} + + MOCK_METHOD1(fetchDirectoryId, int(Utils::SmallStringView directoryPath)); MOCK_METHOD2(fetchSourceId, int (int directoryId, Utils::SmallStringView sourceName)); MOCK_METHOD1(fetchDirectoryIdUnguarded, int(Utils::SmallStringView directoryPath)); @@ -44,5 +49,9 @@ public: ClangBackEnd::Sources::SourceNameAndDirectoryId (int sourceId)); MOCK_METHOD0(fetchAllDirectories, std::vector<ClangBackEnd::Sources::Directory>()); MOCK_METHOD0(fetchAllSources, std::vector<ClangBackEnd::Sources::Source>()); + + MockSqliteDatabase &database() { return mockDatabase; } + + MockSqliteDatabase &mockDatabase; }; diff --git a/tests/unit/unittest/projectupdater-test.cpp b/tests/unit/unittest/projectupdater-test.cpp index 88ba30dd8f..73f5359df0 100644 --- a/tests/unit/unittest/projectupdater-test.cpp +++ b/tests/unit/unittest/projectupdater-test.cpp @@ -25,6 +25,7 @@ #include "googletest.h" +#include "mockfilepathcaching.h" #include "mockpchmanagerclient.h" #include "mockpchmanagernotifier.h" #include "mockpchmanagerserver.h" @@ -470,6 +471,22 @@ TEST_F(ProjectUpdater, FetchProjectPartName) ASSERT_THAT(projectPartName, Eq(QString{" projectb"})); } +TEST_F(ProjectUpdater, AddProjectFilesToFilePathCache) +{ + NiceMock<MockFilePathCaching> mockFilePathCaching; + ClangPchManager::ProjectUpdater updater{mockPchManagerServer, + mockFilePathCaching, + projectPartsStorage}; + + EXPECT_CALL(mockFilePathCaching, + addFilePaths(UnorderedElementsAre(Eq(headerPaths[0]), + Eq(headerPaths[1]), + Eq(sourcePaths[0]), + Eq(sourcePaths[1])))); + + updater.updateProjectParts({&projectPart}, {}); +} + // test for update many time and get the same id } // namespace diff --git a/tests/unit/unittest/stringcache-test.cpp b/tests/unit/unittest/stringcache-test.cpp index 027adb2ac6..10dbb69aac 100644 --- a/tests/unit/unittest/stringcache-test.cpp +++ b/tests/unit/unittest/stringcache-test.cpp @@ -25,8 +25,9 @@ #include "googletest.h" -#include "mockmutex.h" #include "mockfilepathstorage.h" +#include "mockmutex.h" +#include "mocksqlitedatabase.h" #include <stringcache.h> @@ -72,7 +73,8 @@ protected: } protected: - NiceMock<MockFilePathStorage> mockStorage; + NiceMock<MockSqliteDatabase> mockDatabase; + NiceMock<MockFilePathStorage> mockStorage{mockDatabase}; StorageIdFunction mockStorageFetchDirectyId = [&] (Utils::SmallStringView string) { return mockStorage.fetchDirectoryId(string); }; |