summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2019-08-06 13:12:03 +0200
committerMarco Bubke <marco.bubke@qt.io>2019-08-27 11:51:28 +0000
commitf9fb4508d4b73b59b7a7a3c74c009cdccb24d21c (patch)
treee4ebcfda4cd6a0021ff7730187310a460057db8e /tests/unit
parent912b4763e00437d32759ba948e9bc678ff53b6be (diff)
downloadqt-creator-f9fb4508d4b73b59b7a7a3c74c009cdccb24d21c.tar.gz
Clang: Optimize file path cache
We now fetch all directories and sources from the database at file path cache creation. Change-Id: I92510b49a234128f4c82b840611db82ead3f1a54 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/unittest/filepathcache-test.cpp56
-rw-r--r--tests/unit/unittest/filepathstorage-test.cpp16
-rw-r--r--tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp12
-rw-r--r--tests/unit/unittest/mockfilepathstorage.h2
-rw-r--r--tests/unit/unittest/mocksqlitereadstatement.cpp4
-rw-r--r--tests/unit/unittest/mocksqlitereadstatement.h4
-rw-r--r--tests/unit/unittest/pchcreator-test.cpp3
-rw-r--r--tests/unit/unittest/stringcache-test.cpp18
-rw-r--r--tests/unit/unittest/symbolscollector-test.cpp2
9 files changed, 74 insertions, 43 deletions
diff --git a/tests/unit/unittest/filepathcache-test.cpp b/tests/unit/unittest/filepathcache-test.cpp
index 478e5f0215..8ec44064e4 100644
--- a/tests/unit/unittest/filepathcache-test.cpp
+++ b/tests/unit/unittest/filepathcache-test.cpp
@@ -57,12 +57,22 @@ protected:
ON_CALL(mockStorage, fetchDirectoryPath(5))
.WillByDefault(Return(Utils::PathString("/path/to")));
ON_CALL(mockStorage, fetchSourceNameAndDirectoryId(42))
- .WillByDefault(Return(SourceNameAndDirectoryId("file.cpp", 5)));
+ .WillByDefault(Return(SourceNameAndDirectoryId("file.cpp", 5)));
+ ON_CALL(mockStorageFilled, fetchAllSources())
+ .WillByDefault(Return(std::vector<ClangBackEnd::Sources::Source>({
+ {"file.cpp", 6, 72},
+ {"file2.cpp", 5, 63},
+ {"file.cpp", 5, 42},
+ })));
+ ON_CALL(mockStorageFilled, fetchAllDirectories())
+ .WillByDefault(Return(
+ std::vector<ClangBackEnd::Sources::Directory>({{"/path2/to", 6}, {"/path/to", 5}})));
}
protected:
NiceMock<MockFilePathStorage> mockStorage;
Cache cache{mockStorage};
+ NiceMock<MockFilePathStorage> mockStorageFilled;
};
TEST_F(FilePathCache, FilePathIdWithOutAnyEntryCallDirectoryId)
@@ -316,4 +326,48 @@ TEST_F(FilePathCache, FetchDirectoryPathIdAfterFetchingFilePathByFilePathId)
ASSERT_THAT(directoryId, Eq(5));
}
+
+TEST_F(FilePathCache, FetchAllDirectoriesAndSourcesAtCreation)
+{
+ EXPECT_CALL(mockStorage, fetchAllDirectories());
+ EXPECT_CALL(mockStorage, fetchAllSources());
+
+ Cache cache{mockStorage};
+}
+
+TEST_F(FilePathCache, GetFileIdInFilledCache)
+{
+ Cache cacheFilled{mockStorageFilled};
+
+ auto id = cacheFilled.filePathId("/path2/to/file.cpp");
+
+ ASSERT_THAT(id, Eq(72));
+}
+
+TEST_F(FilePathCache, GetDirectoryIdInFilledCache)
+{
+ Cache cacheFilled{mockStorageFilled};
+
+ auto id = cacheFilled.directoryPathId(42);
+
+ ASSERT_THAT(id, Eq(5));
+}
+
+TEST_F(FilePathCache, GetDirectoryPathInFilledCache)
+{
+ Cache cacheFilled{mockStorageFilled};
+
+ auto path = cacheFilled.directoryPath(5);
+
+ ASSERT_THAT(path, Eq("/path/to"));
+}
+
+TEST_F(FilePathCache, GetFilePathInFilledCache)
+{
+ Cache cacheFilled{mockStorageFilled};
+
+ auto path = cacheFilled.filePath(42);
+
+ ASSERT_THAT(path, Eq("/path/to/file.cpp"));
+}
} // namespace
diff --git a/tests/unit/unittest/filepathstorage-test.cpp b/tests/unit/unittest/filepathstorage-test.cpp
index fb60e32512..309b5d0c70 100644
--- a/tests/unit/unittest/filepathstorage-test.cpp
+++ b/tests/unit/unittest/filepathstorage-test.cpp
@@ -56,9 +56,8 @@ protected:
.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(selectAllDirectories, valuesReturnStdVectorDirectory(_))
+ .WillByDefault(Return(std::vector<Directory>{{"/path/to", 1}, {"/other/path", 2}}));
ON_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName,
valueReturnInt32(_, _))
.WillByDefault(Return(Utils::optional<int>()));
@@ -68,9 +67,8 @@ protected:
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(selectAllSources, valuesReturnStdVectorSource(_))
+ .WillByDefault(Return(std::vector<Source>{{"file.h", 1, 1}, {"file.cpp", 2, 4}}));
ON_CALL(selectDirectoryPathFromDirectoriesByDirectoryId,
valueReturnPathString(5))
.WillByDefault(Return(Utils::optional<Utils::PathString>("/path/to")));
@@ -407,16 +405,14 @@ TEST_F(FilePathStorage, SelectAllDirectories)
{
auto directories = storage.fetchAllDirectories();
- ASSERT_THAT(directories,
- ElementsAre(Directory{1, "/path/to"}, Directory{2, "/other/path"}));
+ ASSERT_THAT(directories, ElementsAre(Directory{"/path/to", 1}, Directory{"/other/path", 2}));
}
TEST_F(FilePathStorage, SelectAllSources)
{
auto sources = storage.fetchAllSources();
- ASSERT_THAT(sources,
- ElementsAre(Source{1, "file.h"}, Source{4, "file.cpp"}));
+ ASSERT_THAT(sources, ElementsAre(Source{"file.h", 1, 1}, Source{"file.cpp", 2, 4}));
}
TEST_F(FilePathStorage, CallSelectAllDirectories)
diff --git a/tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp b/tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp
index 40af2d99c3..42c1d0541a 100644
--- a/tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp
+++ b/tests/unit/unittest/filepathstoragesqlitestatementfactory-test.cpp
@@ -73,12 +73,6 @@ TEST_F(FilePathStorageSqliteStatementFactory, SelectSourceNameAndDirectoryIdBySo
Eq("SELECT sourceName, directoryId FROM sources WHERE sourceId = ?"));
}
-TEST_F(FilePathStorageSqliteStatementFactory, SelectAllDirectories)
-{
- ASSERT_THAT(factory.selectAllDirectories.sqlStatement,
- Eq("SELECT directoryId, directoryPath FROM directories"));
-}
-
TEST_F(FilePathStorageSqliteStatementFactory, InsertIntoDirectories)
{
ASSERT_THAT(factory.insertIntoDirectories.sqlStatement,
@@ -91,10 +85,4 @@ TEST_F(FilePathStorageSqliteStatementFactory, InsertIntoSources)
Eq("INSERT INTO sources(directoryId, sourceName) VALUES (?,?)"));
}
-TEST_F(FilePathStorageSqliteStatementFactory, SelectAllSources)
-{
- ASSERT_THAT(factory.selectAllSources.sqlStatement,
- Eq("SELECT sourceId, sourceName FROM sources"));
-}
-
}
diff --git a/tests/unit/unittest/mockfilepathstorage.h b/tests/unit/unittest/mockfilepathstorage.h
index 7056ee2480..4adb965e86 100644
--- a/tests/unit/unittest/mockfilepathstorage.h
+++ b/tests/unit/unittest/mockfilepathstorage.h
@@ -40,5 +40,7 @@ public:
Utils::PathString (int directoryId));
MOCK_METHOD1(fetchSourceNameAndDirectoryId,
ClangBackEnd::Sources::SourceNameAndDirectoryId (int sourceId));
+ MOCK_METHOD0(fetchAllDirectories, std::vector<ClangBackEnd::Sources::Directory>());
+ MOCK_METHOD0(fetchAllSources, std::vector<ClangBackEnd::Sources::Source>());
};
diff --git a/tests/unit/unittest/mocksqlitereadstatement.cpp b/tests/unit/unittest/mocksqlitereadstatement.cpp
index eb68dcc9c9..9a949e4b0a 100644
--- a/tests/unit/unittest/mocksqlitereadstatement.cpp
+++ b/tests/unit/unittest/mocksqlitereadstatement.cpp
@@ -103,8 +103,8 @@ std::vector<Sources::Directory> MockSqliteReadStatement::values<Sources::Directo
return valuesReturnStdVectorDirectory(reserveSize);
}
-template <>
-std::vector<Sources::Source> MockSqliteReadStatement::values<Sources::Source, 2>(std::size_t reserveSize)
+template<>
+std::vector<Sources::Source> MockSqliteReadStatement::values<Sources::Source, 3>(std::size_t reserveSize)
{
return valuesReturnStdVectorSource(reserveSize);
}
diff --git a/tests/unit/unittest/mocksqlitereadstatement.h b/tests/unit/unittest/mocksqlitereadstatement.h
index 5386c13907..8ebcb6e13b 100644
--- a/tests/unit/unittest/mocksqlitereadstatement.h
+++ b/tests/unit/unittest/mocksqlitereadstatement.h
@@ -223,8 +223,8 @@ FilePathIds MockSqliteReadStatement::values<ClangBackEnd::FilePathId>(std::size_
template <>
std::vector<Sources::Directory> MockSqliteReadStatement::values<Sources::Directory, 2>(std::size_t reserveSize);
-template <>
-std::vector<Sources::Source> MockSqliteReadStatement::values<Sources::Source, 2>(std::size_t reserveSize);
+template<>
+std::vector<Sources::Source> MockSqliteReadStatement::values<Sources::Source, 3>(std::size_t reserveSize);
template <>
Utils::optional<int>
diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp
index c5f7f7394d..e97f60b9f5 100644
--- a/tests/unit/unittest/pchcreator-test.cpp
+++ b/tests/unit/unittest/pchcreator-test.cpp
@@ -114,8 +114,9 @@ protected:
NiceMock<MockPchManagerClient> mockPchManagerClient;
NiceMock<MockClangPathWatcher> mockClangPathWatcher;
NiceMock<MockBuildDependenciesStorage> mockBuildDependenciesStorage;
+ ClangBackEnd::FilePathCaching filePathCache{database};
ClangBackEnd::PchCreator creator{environment,
- database,
+ filePathCache,
mockPchManagerClient,
mockClangPathWatcher,
mockBuildDependenciesStorage};
diff --git a/tests/unit/unittest/stringcache-test.cpp b/tests/unit/unittest/stringcache-test.cpp
index 102d851042..f8c7114e5e 100644
--- a/tests/unit/unittest/stringcache-test.cpp
+++ b/tests/unit/unittest/stringcache-test.cpp
@@ -194,9 +194,9 @@ TEST_F(StringCache, PopulateWithEmptyVector)
TEST_F(StringCache, IsNotEmptyAfterPopulateWithSomeEntries)
{
CacheEntries entries{{filePath1.clone(), 0},
- {filePath2.clone(), 1},
+ {filePath2.clone(), 3},
{filePath3.clone(), 2},
- {filePath4.clone(), 3}};
+ {filePath4.clone(), 5}};
cache.uncheckedPopulate(std::move(entries));
@@ -207,11 +207,11 @@ TEST_F(StringCache, GetEntryAfterPopulateWithSomeEntries)
{
CacheEntries entries{{filePath1.clone(), 0},
{filePath2.clone(), 1},
- {filePath3.clone(), 2},
+ {filePath3.clone(), 7},
{filePath4.clone(), 3}};
cache.uncheckedPopulate(std::move(entries));
- auto string = cache.string(2);
+ auto string = cache.string(7);
ASSERT_THAT(string, filePath3);
}
@@ -226,16 +226,6 @@ TEST_F(StringCache, EntriesHaveUniqueIds)
ASSERT_THROW(cache.populate(std::move(entries)), StringCacheException);
}
-TEST_F(StringCache, IdsAreHigherLowerEntriesSize)
-{
- CacheEntries entries{{filePath1.clone(), 0},
- {filePath2.clone(), 1},
- {filePath3.clone(), 4},
- {filePath4.clone(), 3}};
-
- ASSERT_THROW(cache.populate(std::move(entries)), std::out_of_range);
-}
-
TEST_F(StringCache, MultipleEntries)
{
CacheEntries entries{{filePath1.clone(), 0},
diff --git a/tests/unit/unittest/symbolscollector-test.cpp b/tests/unit/unittest/symbolscollector-test.cpp
index fca9ec88d0..cdefde2a31 100644
--- a/tests/unit/unittest/symbolscollector-test.cpp
+++ b/tests/unit/unittest/symbolscollector-test.cpp
@@ -177,7 +177,7 @@ protected:
Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory};
ClangBackEnd::RefactoringDatabaseInitializer<Sqlite::Database> initializer{database};
FilePathCaching filePathCache{database};
- ClangBackEnd::SymbolsCollector collector{database};
+ ClangBackEnd::SymbolsCollector collector{filePathCache};
};
TEST_F(SymbolsCollector, CollectSymbolName)