summaryrefslogtreecommitdiff
path: root/tests/unit/unittest/filepathstorage-test.cpp
diff options
context:
space:
mode:
authorMarco Bubke <marco.bubke@qt.io>2018-11-06 19:02:00 +0100
committerMarco Bubke <marco.bubke@qt.io>2018-11-08 12:51:15 +0000
commit6eb620238b31af81bb097260afb53bcac1054221 (patch)
tree7c4842e2e8a3d0630a72da993d45344f677b1288 /tests/unit/unittest/filepathstorage-test.cpp
parentd37ec2c1e511df19f48b4a621270df3e7135a731 (diff)
downloadqt-creator-6eb620238b31af81bb097260afb53bcac1054221.tar.gz
Clang: Refactor FilePathId
We don't need the directory id any more. It's not used widely any way. Task-number: QTCREATORBUG-21443 Change-Id: Ia95ea4c72fe9530ac56262f61f17faca04d313ba Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Diffstat (limited to 'tests/unit/unittest/filepathstorage-test.cpp')
-rw-r--r--tests/unit/unittest/filepathstorage-test.cpp122
1 files changed, 61 insertions, 61 deletions
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());
-}
}