| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Copyright (C) 2017 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 "mockmutex.h"
 | 
					
						
							|  |  |  | #include "mocksqlitedatabase.h"
 | 
					
						
							|  |  |  | #include "mocksqlitereadstatement.h"
 | 
					
						
							|  |  |  | #include "mocksqlitewritestatement.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <filepathstorage.h>
 | 
					
						
							|  |  |  | #include <filepathstoragesqlitestatementfactory.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-20 12:43:05 +01:00
										 |  |  | using StatementFactory = ClangBackEnd::FilePathStorageSqliteStatementFactory<NiceMock<MockSqliteDatabase>>; | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | using Storage = ClangBackEnd::FilePathStorage<StatementFactory>; | 
					
						
							|  |  |  | using ClangBackEnd::Sources::Directory; | 
					
						
							|  |  |  | using ClangBackEnd::Sources::Source; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FilePathStorage : public testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     void SetUp() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         ON_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, | 
					
						
							| 
									
										
										
										
											2019-06-06 10:57:55 +02:00
										 |  |  |                 valueReturnInt32(A<Utils::SmallStringView>())) | 
					
						
							|  |  |  |             .WillByDefault(Return(Utils::optional<int>())); | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |         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)); | 
					
						
							| 
									
										
										
										
											2019-08-06 13:12:03 +02:00
										 |  |  |         ON_CALL(selectAllDirectories, valuesReturnStdVectorDirectory(_)) | 
					
						
							|  |  |  |             .WillByDefault(Return(std::vector<Directory>{{"/path/to", 1}, {"/other/path", 2}})); | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |         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))); | 
					
						
							| 
									
										
										
										
											2019-08-06 13:12:03 +02:00
										 |  |  |         ON_CALL(selectAllSources, valuesReturnStdVectorSource(_)) | 
					
						
							|  |  |  |             .WillByDefault(Return(std::vector<Source>{{"file.h", 1, 1}, {"file.cpp", 2, 4}})); | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |         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}))); | 
					
						
							| 
									
										
										
										
											2019-06-06 10:57:55 +02:00
										 |  |  |         ON_CALL(selectDirectoryIdFromSourcesBySourceId, valueReturnInt32(TypedEq<int>(42))) | 
					
						
							|  |  |  |             .WillByDefault(Return(Utils::optional<int>(5))); | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-06 10:57:55 +02:00
										 |  |  |         EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, | 
					
						
							|  |  |  |                     valueReturnInt32(A<Utils::SmallStringView>())) | 
					
						
							|  |  |  |             .Times(AnyNumber()); | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |         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()); | 
					
						
							| 
									
										
										
										
											2018-12-04 19:03:48 +01:00
										 |  |  |         EXPECT_CALL(selectDirectoryPathFromDirectoriesByDirectoryId, valueReturnPathString(An<int>())) | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |                 .Times(AnyNumber()); | 
					
						
							|  |  |  |         EXPECT_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId, valueReturnSourceNameAndDirectoryId(_)) | 
					
						
							|  |  |  |                 .Times(AnyNumber()); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     NiceMock<MockSqliteDatabase> mockDatabase; | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |     StatementFactory factory{mockDatabase}; | 
					
						
							|  |  |  |     MockSqliteReadStatement &selectDirectoryIdFromDirectoriesByDirectoryPath = factory.selectDirectoryIdFromDirectoriesByDirectoryPath; | 
					
						
							|  |  |  |     MockSqliteReadStatement &selectSourceIdFromSourcesByDirectoryIdAndSourceName = factory.selectSourceIdFromSourcesByDirectoryIdAndSourceName; | 
					
						
							|  |  |  |     MockSqliteReadStatement &selectDirectoryPathFromDirectoriesByDirectoryId = factory.selectDirectoryPathFromDirectoriesByDirectoryId; | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     MockSqliteReadStatement &selectSourceNameAndDirectoryIdFromSourcesBySourceId = factory.selectSourceNameAndDirectoryIdFromSourcesBySourceId; | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |     MockSqliteReadStatement &selectAllDirectories = factory.selectAllDirectories; | 
					
						
							|  |  |  |     MockSqliteWriteStatement &insertIntoDirectories = factory.insertIntoDirectories; | 
					
						
							|  |  |  |     MockSqliteWriteStatement &insertIntoSources = factory.insertIntoSources; | 
					
						
							|  |  |  |     MockSqliteReadStatement &selectAllSources = factory.selectAllSources; | 
					
						
							| 
									
										
										
										
											2019-06-06 10:57:55 +02:00
										 |  |  |     MockSqliteReadStatement &selectDirectoryIdFromSourcesBySourceId = factory.selectDirectoryIdFromSourcesBySourceId; | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |     Storage storage{factory}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, ReadDirectoryIdForNotContainedPath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto directoryId = storage.readDirectoryId("/some/not/known/path"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(directoryId); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, ReadSourceIdForNotContainedPathAndDirectoryId) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto sourceId = storage.readSourceId(23, "/some/not/known/path"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_FALSE(sourceId); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, ReadDirectoryIdForEmptyPath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto directoryId = storage.readDirectoryId(""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(directoryId.value(), 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, ReadSourceIdForEmptyNameAndZeroDirectoryId) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto sourceId = storage.readSourceId(0, ""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(sourceId.value(), 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, ReadDirectoryIdForPath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto directoryId = storage.readDirectoryId("/path/to"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(directoryId.value(), 5); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, ReadSourceIdForPathAndDirectoryId) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto sourceId = storage.readSourceId(5, "file.h"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(sourceId.value(), 42); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, FetchDirectoryIdForEmptyPath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto directoryId = storage.fetchDirectoryId(""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(directoryId, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, FetchSourceIdForEmptyNameAndZeroDirectoryId) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto sourceId = storage.fetchSourceId(0, ""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(sourceId, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, FetchDirectoryIdForPath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto directoryId = storage.fetchDirectoryId("/path/to"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(directoryId, 5); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, FetchSourceIdForPathAndDirectoryId) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto sourceId = storage.fetchSourceId(5, "file.h"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(sourceId, 42); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallWriteForWriteDirectory) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(insertIntoDirectories, write(TypedEq<Utils::SmallStringView>("/some/not/known/path"))); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     storage.writeDirectoryId("/some/not/known/path"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallWriteForWriteSource) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-02-25 19:07:19 +01:00
										 |  |  |     EXPECT_CALL(insertIntoSources, | 
					
						
							|  |  |  |                 write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("unknownfile.h"))); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     storage.writeSourceId(5, "unknownfile.h"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, GetTheDirectoryIdBackAfterWritingANewEntryInDirectories) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto directoryId = storage.writeDirectoryId("/some/not/known/path"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(directoryId, 12); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, GetTheSourceIdBackAfterWritingANewEntryInSources) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto sourceId = storage.writeSourceId(5, "unknownfile.h"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(sourceId, 12); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, GetTheDirectoryIdBackAfterFetchingANewEntryFromDirectories) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto directoryId = storage.fetchDirectoryId("/some/not/known/path"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(directoryId, 12); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, GetTheSourceIdBackAfterFetchingANewEntryFromSources) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto sourceId = storage.fetchSourceId(5, "unknownfile.h"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(sourceId, 12); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallSelectForFetchingDirectoryIdForKnownPath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |     EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, | 
					
						
							| 
									
										
										
										
											2019-06-06 10:57:55 +02:00
										 |  |  |                 valueReturnInt32(TypedEq<Utils::SmallStringView>("/path/to"))); | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchDirectoryId("/path/to"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallSelectForFetchingSourceIdForKnownPath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |     EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, | 
					
						
							|  |  |  |                 valueReturnInt32(5, Eq("file.h"))); | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchSourceId(5, "file.h"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallNotWriteForFetchingDirectoryIdForKnownPath) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(insertIntoDirectories, write(An<Utils::SmallStringView>())).Times(0); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchDirectoryId("/path/to"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallNotWriteForFetchingSoureIdForKnownEntry) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(insertIntoSources, write(An<uint>(), An<Utils::SmallStringView>())).Times(0); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchSourceId(5, "file.h"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallSelectAndWriteForFetchingDirectoryIdForUnknownPath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |     EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, | 
					
						
							| 
									
										
										
										
											2019-06-06 10:57:55 +02:00
										 |  |  |                 valueReturnInt32(TypedEq<Utils::SmallStringView>("/some/not/known/path"))); | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(insertIntoDirectories, write(TypedEq<Utils::SmallStringView>("/some/not/known/path"))); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchDirectoryId("/some/not/known/path"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallSelectAndWriteForFetchingSourceIdForUnknownEntry) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 18:25:16 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |     EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, | 
					
						
							|  |  |  |                 valueReturnInt32(5, Eq("unknownfile.h"))); | 
					
						
							| 
									
										
										
										
											2019-02-25 19:07:19 +01:00
										 |  |  |     EXPECT_CALL(insertIntoSources, | 
					
						
							|  |  |  |                 write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("unknownfile.h"))); | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchSourceId(5, "unknownfile.h"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  | TEST_F(FilePathStorage, RestartFetchDirectoryIDIfTheStatementIsBusyInBeginBecauseTheTableAlreadyChanged) | 
					
						
							| 
									
										
										
										
											2018-03-29 18:25:16 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, rollback()).Times(0); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, | 
					
						
							| 
									
										
										
										
											2019-06-06 10:57:55 +02:00
										 |  |  |                 valueReturnInt32(TypedEq<Utils::SmallStringView>("/other/unknow/path"))); | 
					
						
							| 
									
										
										
										
											2018-03-29 18:25:16 +02:00
										 |  |  |     EXPECT_CALL(insertIntoDirectories, write(TypedEq<Utils::SmallStringView>("/other/unknow/path"))); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchDirectoryId("/other/unknow/path"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  | TEST_F(FilePathStorage, | 
					
						
							|  |  |  |        CallSelectAndWriteForFetchingDirectoryIdTwoTimesIfTheStatementIsBusyInWriteBecauseTheTableAlreadyChanged) | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 18:25:16 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |     EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, | 
					
						
							| 
									
										
										
										
											2019-06-06 10:57:55 +02:00
										 |  |  |                 valueReturnInt32(TypedEq<Utils::SmallStringView>("/other/unknow/path"))); | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(insertIntoDirectories, write(TypedEq<Utils::SmallStringView>("/other/unknow/path"))) | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |             .WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(mockDatabase, rollback()); | 
					
						
							| 
									
										
										
										
											2018-03-29 18:25:16 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |     EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, | 
					
						
							| 
									
										
										
										
											2019-06-06 10:57:55 +02:00
										 |  |  |                 valueReturnInt32(TypedEq<Utils::SmallStringView>("/other/unknow/path"))); | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(insertIntoDirectories, write(TypedEq<Utils::SmallStringView>("/other/unknow/path"))); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchDirectoryId("/other/unknow/path"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  | TEST_F(FilePathStorage, CallSelectAndWriteForFetchingDirectoryIdTwoTimesIfTheIndexIsConstraintBecauseTheEntryExistsAlready) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase,deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, | 
					
						
							| 
									
										
										
										
											2019-06-06 10:57:55 +02:00
										 |  |  |                 valueReturnInt32(TypedEq<Utils::SmallStringView>("/other/unknow/path"))); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  |     EXPECT_CALL(insertIntoDirectories, write(TypedEq<Utils::SmallStringView>("/other/unknow/path"))) | 
					
						
							|  |  |  |             .WillOnce(Throw(Sqlite::ConstraintPreventsModification("busy"))); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, rollback()); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase,deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, | 
					
						
							| 
									
										
										
										
											2019-06-06 10:57:55 +02:00
										 |  |  |                 valueReturnInt32(TypedEq<Utils::SmallStringView>("/other/unknow/path"))); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchDirectoryId("/other/unknow/path"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  | TEST_F(FilePathStorage, RestartFetchSourceIdIfTheStatementIsBusyInBeginBecauseTheTableAlreadyChanged) | 
					
						
							| 
									
										
										
										
											2018-03-29 18:25:16 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, rollback()).Times(0); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, | 
					
						
							|  |  |  |                 valueReturnInt32(5, Eq("otherunknownfile.h"))); | 
					
						
							| 
									
										
										
										
											2019-02-25 19:07:19 +01:00
										 |  |  |     EXPECT_CALL(insertIntoSources, | 
					
						
							|  |  |  |                 write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("otherunknownfile.h"))); | 
					
						
							| 
									
										
										
										
											2018-03-29 18:25:16 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchSourceId(5, "otherunknownfile.h"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  | TEST_F(FilePathStorage, | 
					
						
							|  |  |  |        CallSelectAndWriteForFetchingSourceTwoTimesIfTheStatementIsBusyInWriteBecauseTheTableAlreadyChanged) | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-29 18:25:16 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |     EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, | 
					
						
							|  |  |  |                 valueReturnInt32(5, Eq("otherunknownfile.h"))); | 
					
						
							| 
									
										
										
										
											2019-02-25 19:07:19 +01:00
										 |  |  |     EXPECT_CALL(insertIntoSources, | 
					
						
							|  |  |  |                 write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("otherunknownfile.h"))) | 
					
						
							|  |  |  |         .WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(mockDatabase, rollback()); | 
					
						
							| 
									
										
										
										
											2018-03-29 18:25:16 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |     EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, | 
					
						
							|  |  |  |                 valueReturnInt32(5, Eq("otherunknownfile.h"))); | 
					
						
							| 
									
										
										
										
											2019-02-25 19:07:19 +01:00
										 |  |  |     EXPECT_CALL(insertIntoSources, | 
					
						
							|  |  |  |                 write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("otherunknownfile.h"))); | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchSourceId(5, "otherunknownfile.h"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  | TEST_F(FilePathStorage, CallSelectAndWriteForFetchingSourceTwoTimesIfTheIndexIsConstraintBecauseTheEntryExistsAlready) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase,deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, | 
					
						
							|  |  |  |                 valueReturnInt32(5, Eq("otherunknownfile.h"))); | 
					
						
							| 
									
										
										
										
											2019-02-25 19:07:19 +01:00
										 |  |  |     EXPECT_CALL(insertIntoSources, | 
					
						
							|  |  |  |                 write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("otherunknownfile.h"))) | 
					
						
							|  |  |  |         .WillOnce(Throw(Sqlite::ConstraintPreventsModification("busy"))); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, rollback()); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase,deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, | 
					
						
							| 
									
										
										
										
											2019-02-25 19:07:19 +01:00
										 |  |  |                 valueReturnInt32(5, Eq("otherunknownfile.h"))) | 
					
						
							|  |  |  |         .WillOnce(Return(Utils::optional<int>(42))); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchSourceId(5, "otherunknownfile.h"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | TEST_F(FilePathStorage, SelectAllDirectories) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto directories = storage.fetchAllDirectories(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-06 13:12:03 +02:00
										 |  |  |     ASSERT_THAT(directories, ElementsAre(Directory{"/path/to", 1}, Directory{"/other/path", 2})); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, SelectAllSources) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto sources = storage.fetchAllSources(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-06 13:12:03 +02:00
										 |  |  |     ASSERT_THAT(sources, ElementsAre(Source{"file.h", 1, 1}, Source{"file.cpp", 2, 4})); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallSelectAllDirectories) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-03-29 18:25:16 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |     EXPECT_CALL(selectAllDirectories, valuesReturnStdVectorDirectory(256)); | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchAllDirectories(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallSelectAllSources) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-03-29 18:25:16 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |     EXPECT_CALL(selectAllSources, valuesReturnStdVectorSource(8192)); | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchAllSources(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallValueForFetchDirectoryPathForId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-03-29 18:25:16 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  |     EXPECT_CALL(selectDirectoryPathFromDirectoriesByDirectoryId, valueReturnPathString(5)); | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchDirectoryPath(5); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, FetchDirectoryPathForId) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto path = storage.fetchDirectoryPath(5); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(path, Eq("/path/to")); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, ThrowAsFetchingDirectoryPathForNonExistingId) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ASSERT_THROW(storage.fetchDirectoryPath(12), ClangBackEnd::DirectoryPathIdDoesNotExists); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallValueForFetchSoureNameForId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-03-29 18:25:16 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     EXPECT_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId, valueReturnSourceNameAndDirectoryId(42)); | 
					
						
							| 
									
										
										
										
											2018-01-22 14:21:01 +01:00
										 |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     storage.fetchSourceNameAndDirectoryId(42); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, FetchSoureNameForId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     auto entry = storage.fetchSourceNameAndDirectoryId(42); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     ASSERT_THAT(entry.sourceName, Eq("file.cpp")); | 
					
						
							|  |  |  |     ASSERT_THAT(entry.directoryId, 5); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, ThrowAsFetchingSourceNameForNonExistingId) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     ASSERT_THROW(storage.fetchSourceNameAndDirectoryId(12), ClangBackEnd::SourceNameIdDoesNotExists); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  | TEST_F(FilePathStorage, RestartFetchSourceNameIfTheStatementIsBusyInBegin) | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 10:38:04 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, lock()); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, rollback()).Times(0); | 
					
						
							| 
									
										
										
										
											2018-04-04 10:38:04 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, unlock()); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, lock()); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     EXPECT_CALL(selectSourceNameAndDirectoryIdFromSourcesBySourceId, valueReturnSourceNameAndDirectoryId(42)); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							| 
									
										
										
										
											2018-04-04 10:38:04 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, unlock()); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-06 19:02:00 +01:00
										 |  |  |     storage.fetchSourceNameAndDirectoryId(42); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 15:09:30 +01:00
										 |  |  | TEST_F(FilePathStorage, RestartFetchDirectoryPathIfTheStatementIsBusyInBegin) | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 10:38:04 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, lock()); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, rollback()).Times(0); | 
					
						
							| 
									
										
										
										
											2018-04-04 10:38:04 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, unlock()); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, lock()); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							| 
									
										
										
										
											2018-04-04 10:38:04 +02:00
										 |  |  |     EXPECT_CALL(selectDirectoryPathFromDirectoriesByDirectoryId, valueReturnPathString(5)); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, unlock()); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchDirectoryPath(5); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, RestartFetchAllDirectoriesIfBeginIsBusy) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 10:38:04 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, lock()); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, rollback()).Times(0); | 
					
						
							| 
									
										
										
										
											2018-04-04 10:38:04 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, unlock()); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, lock()); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectAllDirectories, valuesReturnStdVectorDirectory(256)); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							| 
									
										
										
										
											2018-04-04 10:38:04 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, unlock()); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchAllDirectories(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, RestartFetchAllSourcesIfBeginIsBusy) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-04 10:38:04 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, lock()); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, rollback()).Times(0); | 
					
						
							| 
									
										
										
										
											2018-04-04 10:38:04 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, unlock()); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, lock()); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectAllSources, valuesReturnStdVectorSource(8192)); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							| 
									
										
										
										
											2018-04-04 10:38:04 +02:00
										 |  |  |     EXPECT_CALL(mockDatabase, unlock()); | 
					
						
							| 
									
										
										
										
											2018-04-03 14:34:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchAllSources(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-06 10:57:55 +02:00
										 |  |  | TEST_F(FilePathStorage, FetchDirectoryIdForUnknownFileID) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ASSERT_THROW(storage.fetchDirectoryId(1111), ClangBackEnd::SourceNameIdDoesNotExists); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, FetchDirectoryId) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto directoryId = storage.fetchDirectoryId(42); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(directoryId, 5); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, FetchDirectoryIdCalls) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, lock()); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectDirectoryIdFromSourcesBySourceId, valueReturnInt32(TypedEq<int>(42))); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, unlock()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchDirectoryId(42); | 
					
						
							| 
									
										
										
										
											2017-09-21 11:43:59 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-06-06 10:57:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, FetchDirectoryIdCallsDatabaseIsBusy) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, lock()); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()).WillOnce(Throw(Sqlite::StatementIsBusy("busy"))); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, rollback()).Times(0); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, unlock()); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, lock()); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectDirectoryIdFromSourcesBySourceId, valueReturnInt32(TypedEq<int>(42))); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, commit()); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, unlock()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchDirectoryId(42); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, FetchDirectoryIdCallsThrows) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, lock()); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, deferredBegin()); | 
					
						
							|  |  |  |     EXPECT_CALL(selectDirectoryIdFromSourcesBySourceId, valueReturnInt32(TypedEq<int>(41))); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, rollback()); | 
					
						
							|  |  |  |     EXPECT_CALL(mockDatabase, unlock()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_ANY_THROW(storage.fetchDirectoryId(41)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-07 18:45:55 +02:00
										 |  |  | TEST_F(FilePathStorage, GetTheDirectoryIdBackAfterFetchingANewEntryFromDirectoriesUnguarded) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto directoryId = storage.fetchDirectoryIdUnguarded("/some/not/known/path"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(directoryId, 12); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, GetTheSourceIdBackAfterFetchingANewEntryFromSourcesUnguarded) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto sourceId = storage.fetchSourceIdUnguarded(5, "unknownfile.h"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(sourceId, 12); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallSelectForFetchingDirectoryIdForKnownPathUnguarded) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, | 
					
						
							|  |  |  |                 valueReturnInt32(TypedEq<Utils::SmallStringView>("/path/to"))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchDirectoryIdUnguarded("/path/to"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallSelectForFetchingSourceIdForKnownPathUnguarded) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, | 
					
						
							|  |  |  |                 valueReturnInt32(5, Eq("file.h"))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchSourceIdUnguarded(5, "file.h"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallNotWriteForFetchingDirectoryIdForKnownPathUnguarded) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     EXPECT_CALL(insertIntoDirectories, write(An<Utils::SmallStringView>())).Times(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchDirectoryIdUnguarded("/path/to"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallNotWriteForFetchingSoureIdForKnownEntryUnguarded) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     EXPECT_CALL(insertIntoSources, write(An<uint>(), An<Utils::SmallStringView>())).Times(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchSourceIdUnguarded(5, "file.h"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallSelectAndWriteForFetchingDirectoryIdForUnknownPathUnguarded) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(selectDirectoryIdFromDirectoriesByDirectoryPath, | 
					
						
							|  |  |  |                 valueReturnInt32(TypedEq<Utils::SmallStringView>("/some/not/known/path"))); | 
					
						
							|  |  |  |     EXPECT_CALL(insertIntoDirectories, write(TypedEq<Utils::SmallStringView>("/some/not/known/path"))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchDirectoryIdUnguarded("/some/not/known/path"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(FilePathStorage, CallSelectAndWriteForFetchingSourceIdForUnknownEntryUnguarded) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     InSequence s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EXPECT_CALL(selectSourceIdFromSourcesByDirectoryIdAndSourceName, | 
					
						
							|  |  |  |                 valueReturnInt32(5, Eq("unknownfile.h"))); | 
					
						
							|  |  |  |     EXPECT_CALL(insertIntoSources, | 
					
						
							|  |  |  |                 write(TypedEq<int>(5), TypedEq<Utils::SmallStringView>("unknownfile.h"))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     storage.fetchSourceIdUnguarded(5, "unknownfile.h"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-06 10:57:55 +02:00
										 |  |  | } // namespace
 |