2021-05-04 16:36:06 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2021 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 "projectstoragemock.h"
|
|
|
|
|
#include "sqlitedatabasemock.h"
|
|
|
|
|
|
|
|
|
|
#include <projectstorage/sourcepathcache.h>
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
using QmlDesigner::SourceContextId;
|
|
|
|
|
using QmlDesigner::SourceId;
|
|
|
|
|
using QmlDesigner::SourceIds;
|
|
|
|
|
using Cache = QmlDesigner::SourcePathCache<NiceMock<ProjectStorageMock>>;
|
|
|
|
|
using NFP = QmlDesigner::SourcePath;
|
|
|
|
|
using QmlDesigner::SourcePathView;
|
|
|
|
|
using QmlDesigner::SourcePathViews;
|
2021-05-06 12:26:39 +02:00
|
|
|
using QmlDesigner::Cache::SourceNameAndSourceContextId;
|
2021-05-04 16:36:06 +02:00
|
|
|
|
|
|
|
|
class SourcePathCache : public testing::Test
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
SourcePathCache()
|
|
|
|
|
{
|
|
|
|
|
ON_CALL(storageMock, fetchSourceContextId(Eq("/path/to")))
|
2022-07-19 14:33:00 +02:00
|
|
|
.WillByDefault(Return(SourceContextId::create(5)));
|
2021-05-04 16:36:06 +02:00
|
|
|
ON_CALL(storageMock, fetchSourceContextId(Eq("/path2/to")))
|
2022-07-19 14:33:00 +02:00
|
|
|
.WillByDefault(Return(SourceContextId::create(6)));
|
|
|
|
|
ON_CALL(storageMock, fetchSourceId(SourceContextId::create(5), Eq("file.cpp")))
|
|
|
|
|
.WillByDefault(Return(SourceId::create(42)));
|
|
|
|
|
ON_CALL(storageMock, fetchSourceId(SourceContextId::create(5), Eq("file2.cpp")))
|
|
|
|
|
.WillByDefault(Return(SourceId::create(63)));
|
|
|
|
|
ON_CALL(storageMock, fetchSourceId(SourceContextId::create(6), Eq("file.cpp")))
|
|
|
|
|
.WillByDefault(Return(SourceId::create(72)));
|
|
|
|
|
ON_CALL(storageMock, fetchSourceContextPath(SourceContextId::create(5)))
|
2021-05-04 16:36:06 +02:00
|
|
|
.WillByDefault(Return(Utils::PathString("/path/to")));
|
2022-07-19 14:33:00 +02:00
|
|
|
ON_CALL(storageMock, fetchSourceNameAndSourceContextId(SourceId::create(42)))
|
|
|
|
|
.WillByDefault(
|
|
|
|
|
Return(SourceNameAndSourceContextId("file.cpp", SourceContextId::create(5))));
|
2021-05-04 16:36:06 +02:00
|
|
|
ON_CALL(storageMockFilled, fetchAllSources())
|
2021-05-06 12:26:39 +02:00
|
|
|
.WillByDefault(Return(std::vector<QmlDesigner::Cache::Source>({
|
2022-07-19 14:33:00 +02:00
|
|
|
{"file.cpp", SourceContextId::create(6), SourceId::create(72)},
|
|
|
|
|
{"file2.cpp", SourceContextId::create(5), SourceId::create(63)},
|
|
|
|
|
{"file.cpp", SourceContextId::create(5), SourceId::create(42)},
|
2021-05-04 16:36:06 +02:00
|
|
|
})));
|
|
|
|
|
ON_CALL(storageMockFilled, fetchAllSourceContexts())
|
2021-05-06 12:26:39 +02:00
|
|
|
.WillByDefault(Return(std::vector<QmlDesigner::Cache::SourceContext>(
|
2022-07-19 14:33:00 +02:00
|
|
|
{{"/path2/to", SourceContextId::create(6)}, {"/path/to", SourceContextId::create(5)}})));
|
2021-05-04 16:36:06 +02:00
|
|
|
ON_CALL(storageMockFilled, fetchSourceContextId(Eq("/path/to")))
|
2022-07-19 14:33:00 +02:00
|
|
|
.WillByDefault(Return(SourceContextId::create(5)));
|
|
|
|
|
ON_CALL(storageMockFilled, fetchSourceId(SourceContextId::create(5), Eq("file.cpp")))
|
|
|
|
|
.WillByDefault(Return(SourceId::create(42)));
|
2021-05-04 16:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2021-09-16 17:19:56 +02:00
|
|
|
NiceMock<ProjectStorageMock> storageMock;
|
2021-05-04 16:36:06 +02:00
|
|
|
Cache cache{storageMock};
|
2021-09-16 17:19:56 +02:00
|
|
|
NiceMock<ProjectStorageMock> storageMockFilled;
|
2021-05-04 16:36:06 +02:00
|
|
|
Cache cacheNotFilled{storageMockFilled};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, SourceIdWithOutAnyEntryCallSourceContextId)
|
|
|
|
|
{
|
|
|
|
|
EXPECT_CALL(storageMock, fetchSourceContextId(Eq("/path/to")));
|
|
|
|
|
|
|
|
|
|
cache.sourceId(SourcePathView("/path/to/file.cpp"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, SourceIdWithOutAnyEntryCalls)
|
|
|
|
|
{
|
2022-07-19 14:33:00 +02:00
|
|
|
EXPECT_CALL(storageMock, fetchSourceId(SourceContextId::create(5), Eq("file.cpp")));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
|
|
|
|
cache.sourceId(SourcePathView("/path/to/file.cpp"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, SourceIdOfSourceIdWithOutAnyEntry)
|
|
|
|
|
{
|
|
|
|
|
auto sourceId = cache.sourceId(SourcePathView("/path/to/file.cpp"));
|
|
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
ASSERT_THAT(sourceId, SourceId::create(42));
|
2021-05-04 16:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-16 17:19:56 +02:00
|
|
|
TEST_F(SourcePathCache, SourceIdWithSourceContextIdAndSourceName)
|
|
|
|
|
{
|
|
|
|
|
auto sourceContextId = cache.sourceContextId("/path/to"_sv);
|
|
|
|
|
|
|
|
|
|
auto sourceId = cache.sourceId(sourceContextId, "file.cpp"_sv);
|
|
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
ASSERT_THAT(sourceId, SourceId::create(42));
|
2021-09-16 17:19:56 +02:00
|
|
|
}
|
|
|
|
|
|
2021-05-04 16:36:06 +02:00
|
|
|
TEST_F(SourcePathCache, IfEntryExistsDontCallInStrorage)
|
|
|
|
|
{
|
|
|
|
|
cache.sourceId(SourcePathView("/path/to/file.cpp"));
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(storageMock, fetchSourceContextId(Eq("/path/to"))).Times(0);
|
2022-07-19 14:33:00 +02:00
|
|
|
EXPECT_CALL(storageMock, fetchSourceId(SourceContextId::create(5), Eq("file.cpp"))).Times(0);
|
2021-05-04 16:36:06 +02:00
|
|
|
|
|
|
|
|
cache.sourceId(SourcePathView("/path/to/file.cpp"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, IfDirectoryEntryExistsDontCallFetchSourceContextIdButStillCallFetchSourceId)
|
|
|
|
|
{
|
|
|
|
|
cache.sourceId(SourcePathView("/path/to/file2.cpp"));
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(storageMock, fetchSourceContextId(Eq("/path/to"))).Times(0);
|
2022-07-19 14:33:00 +02:00
|
|
|
EXPECT_CALL(storageMock, fetchSourceId(SourceContextId::create(5), Eq("file.cpp")));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
|
|
|
|
cache.sourceId(SourcePathView("/path/to/file.cpp"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, GetSourceIdWithCachedValue)
|
|
|
|
|
{
|
|
|
|
|
cache.sourceId(SourcePathView("/path/to/file.cpp"));
|
|
|
|
|
|
|
|
|
|
auto sourceId = cache.sourceId(SourcePathView("/path/to/file.cpp"));
|
|
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
ASSERT_THAT(sourceId, SourceId::create(42));
|
2021-05-04 16:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, GetSourceIdWithSourceContextIdCached)
|
|
|
|
|
{
|
|
|
|
|
cache.sourceId(SourcePathView("/path/to/file.cpp"));
|
|
|
|
|
|
|
|
|
|
auto sourceId = cache.sourceId(SourcePathView("/path/to/file2.cpp"));
|
|
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
ASSERT_THAT(sourceId, SourceId::create(63));
|
2021-05-04 16:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, ThrowForGettingAFilePathWithAnInvalidId)
|
|
|
|
|
{
|
|
|
|
|
SourceId sourceId;
|
|
|
|
|
|
|
|
|
|
ASSERT_THROW(cache.sourcePath(sourceId), QmlDesigner::NoSourcePathForInvalidSourceId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, GetAFilePath)
|
|
|
|
|
{
|
|
|
|
|
SourceId sourceId = cache.sourceId(SourcePathView("/path/to/file.cpp"));
|
|
|
|
|
|
|
|
|
|
auto sourcePath = cache.sourcePath(sourceId);
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(sourcePath, Eq(SourcePathView{"/path/to/file.cpp"}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, GetAFilePathWithCachedSourceId)
|
|
|
|
|
{
|
2022-07-19 14:33:00 +02:00
|
|
|
SourceId sourceId{SourceId::create(42)};
|
2021-05-04 16:36:06 +02:00
|
|
|
|
|
|
|
|
auto sourcePath = cache.sourcePath(sourceId);
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(sourcePath, Eq(SourcePathView{"/path/to/file.cpp"}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, FileNamesAreUniqueForEveryDirectory)
|
|
|
|
|
{
|
|
|
|
|
SourceId sourceId = cache.sourceId(SourcePathView("/path/to/file.cpp"));
|
|
|
|
|
|
|
|
|
|
SourceId sourcePath2Id = cache.sourceId(SourcePathView("/path2/to/file.cpp"));
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(sourcePath2Id, Ne(sourceId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, DuplicateFilePathsAreEqual)
|
|
|
|
|
{
|
|
|
|
|
SourceId sourcePath1Id = cache.sourceId(SourcePathView("/path/to/file.cpp"));
|
|
|
|
|
|
|
|
|
|
SourceId sourcePath2Id = cache.sourceId(SourcePathView("/path/to/file.cpp"));
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(sourcePath2Id, Eq(sourcePath1Id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, SourceContextIdCallsFetchSourceContextId)
|
|
|
|
|
{
|
|
|
|
|
EXPECT_CALL(storageMock, fetchSourceContextId(Eq("/path/to")));
|
|
|
|
|
|
|
|
|
|
cache.sourceContextId(Utils::SmallString("/path/to"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, SecondSourceContextIdCallsNotFetchSourceContextId)
|
|
|
|
|
{
|
|
|
|
|
cache.sourceContextId(Utils::SmallString("/path/to"));
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(storageMock, fetchSourceContextId(Eq("/path/to"))).Times(0);
|
|
|
|
|
|
|
|
|
|
cache.sourceContextId(Utils::SmallString("/path/to"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, SourceContextIdWithTrailingSlash)
|
|
|
|
|
{
|
|
|
|
|
EXPECT_CALL(storageMock, fetchSourceContextId(Eq("/path/to")));
|
|
|
|
|
|
|
|
|
|
cache.sourceContextId(Utils::SmallString("/path/to/"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, SourceContextId)
|
|
|
|
|
{
|
|
|
|
|
auto id = cache.sourceContextId(Utils::SmallString("/path/to"));
|
|
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
ASSERT_THAT(id, Eq(SourceContextId::create(5)));
|
2021-05-04 16:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, SourceContextIdIsAlreadyInCache)
|
|
|
|
|
{
|
|
|
|
|
auto firstId = cache.sourceContextId(Utils::SmallString("/path/to"));
|
|
|
|
|
|
|
|
|
|
auto secondId = cache.sourceContextId(Utils::SmallString("/path/to"));
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(secondId, firstId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, SourceContextIdIsAlreadyInCacheWithTrailingSlash)
|
|
|
|
|
{
|
|
|
|
|
auto firstId = cache.sourceContextId(Utils::SmallString("/path/to/"));
|
|
|
|
|
|
|
|
|
|
auto secondId = cache.sourceContextId(Utils::SmallString("/path/to/"));
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(secondId, firstId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, SourceContextIdIsAlreadyInCacheWithAndWithoutTrailingSlash)
|
|
|
|
|
{
|
|
|
|
|
auto firstId = cache.sourceContextId(Utils::SmallString("/path/to/"));
|
|
|
|
|
|
|
|
|
|
auto secondId = cache.sourceContextId(Utils::SmallString("/path/to"));
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(secondId, firstId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, SourceContextIdIsAlreadyInCacheWithoutAndWithTrailingSlash)
|
|
|
|
|
{
|
|
|
|
|
auto firstId = cache.sourceContextId(Utils::SmallString("/path/to"));
|
|
|
|
|
|
|
|
|
|
auto secondId = cache.sourceContextId(Utils::SmallString("/path/to/"));
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(secondId, firstId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, ThrowForGettingADirectoryPathWithAnInvalidId)
|
|
|
|
|
{
|
|
|
|
|
SourceContextId sourceContextId;
|
|
|
|
|
|
|
|
|
|
ASSERT_THROW(cache.sourceContextPath(sourceContextId),
|
|
|
|
|
QmlDesigner::NoSourceContextPathForInvalidSourceContextId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, GetADirectoryPath)
|
|
|
|
|
{
|
2022-07-19 14:33:00 +02:00
|
|
|
SourceContextId sourceContextId{SourceContextId::create(5)};
|
2021-05-04 16:36:06 +02:00
|
|
|
|
|
|
|
|
auto sourceContextPath = cache.sourceContextPath(sourceContextId);
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(sourceContextPath, Eq(Utils::SmallStringView{"/path/to"}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, GetADirectoryPathWithCachedSourceContextId)
|
|
|
|
|
{
|
2022-07-19 14:33:00 +02:00
|
|
|
SourceContextId sourceContextId{SourceContextId::create(5)};
|
2021-05-04 16:36:06 +02:00
|
|
|
cache.sourceContextPath(sourceContextId);
|
|
|
|
|
|
|
|
|
|
auto sourceContextPath = cache.sourceContextPath(sourceContextId);
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(sourceContextPath, Eq(Utils::SmallStringView{"/path/to"}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, DirectoryPathCallsFetchDirectoryPath)
|
|
|
|
|
{
|
2022-07-19 14:33:00 +02:00
|
|
|
EXPECT_CALL(storageMock, fetchSourceContextPath(Eq(SourceContextId::create(5))));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
cache.sourceContextPath(SourceContextId::create(5));
|
2021-05-04 16:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, SecondDirectoryPathCallsNotFetchDirectoryPath)
|
|
|
|
|
{
|
2022-07-19 14:33:00 +02:00
|
|
|
cache.sourceContextPath(SourceContextId::create(5));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
|
|
|
|
EXPECT_CALL(storageMock, fetchSourceContextPath(_)).Times(0);
|
|
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
cache.sourceContextPath(SourceContextId::create(5));
|
2021-05-04 16:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, ThrowForGettingASourceContextIdWithAnInvalidSourceId)
|
|
|
|
|
{
|
|
|
|
|
SourceId sourceId;
|
|
|
|
|
|
|
|
|
|
ASSERT_THROW(cache.sourceContextId(sourceId), QmlDesigner::NoSourcePathForInvalidSourceId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, FetchSourceContextIdBySourceId)
|
|
|
|
|
{
|
2022-07-19 14:33:00 +02:00
|
|
|
auto sourceContextId = cache.sourceContextId(SourceId::create(42));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
ASSERT_THAT(sourceContextId, Eq(SourceContextId::create(5)));
|
2021-05-04 16:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, FetchSourceContextIdBySourceIdCached)
|
|
|
|
|
{
|
2022-07-19 14:33:00 +02:00
|
|
|
cache.sourceContextId(SourceId::create(42));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
auto sourceContextId = cache.sourceContextId(SourceId::create(42));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
ASSERT_THAT(sourceContextId, Eq(SourceContextId::create(5)));
|
2021-05-04 16:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, FetchFilePathAfterFetchingSourceContextIdBySourceId)
|
|
|
|
|
{
|
2022-07-19 14:33:00 +02:00
|
|
|
cache.sourceContextId(SourceId::create(42));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
auto sourcePath = cache.sourcePath(SourceId::create(42));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
|
|
|
|
ASSERT_THAT(sourcePath, Eq("/path/to/file.cpp"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, FetchSourceContextIdAfterFetchingFilePathBySourceId)
|
|
|
|
|
{
|
2022-07-19 14:33:00 +02:00
|
|
|
cache.sourcePath(SourceId::create(42));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
auto sourceContextId = cache.sourceContextId(SourceId::create(42));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
ASSERT_THAT(sourceContextId, Eq(SourceContextId::create(5)));
|
2021-05-04 16:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, FetchAllSourceContextsAndSourcesAtCreation)
|
|
|
|
|
{
|
|
|
|
|
EXPECT_CALL(storageMock, fetchAllSourceContexts());
|
|
|
|
|
EXPECT_CALL(storageMock, fetchAllSources());
|
|
|
|
|
|
|
|
|
|
Cache cache{storageMock};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, GetFileIdInFilledCache)
|
|
|
|
|
{
|
|
|
|
|
Cache cacheFilled{storageMockFilled};
|
|
|
|
|
|
|
|
|
|
auto id = cacheFilled.sourceId("/path2/to/file.cpp");
|
|
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
ASSERT_THAT(id, Eq(SourceId::create(72)));
|
2021-05-04 16:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, GetSourceContextIdInFilledCache)
|
|
|
|
|
{
|
|
|
|
|
Cache cacheFilled{storageMockFilled};
|
|
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
auto id = cacheFilled.sourceContextId(SourceId::create(42));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
ASSERT_THAT(id, Eq(SourceContextId::create(5)));
|
2021-05-04 16:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, GetDirectoryPathInFilledCache)
|
|
|
|
|
{
|
|
|
|
|
Cache cacheFilled{storageMockFilled};
|
|
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
auto path = cacheFilled.sourceContextPath(SourceContextId::create(5));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
|
|
|
|
ASSERT_THAT(path, Eq("/path/to"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, GetFilePathInFilledCache)
|
|
|
|
|
{
|
|
|
|
|
Cache cacheFilled{storageMockFilled};
|
|
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
auto path = cacheFilled.sourcePath(SourceId::create(42));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
|
|
|
|
ASSERT_THAT(path, Eq("/path/to/file.cpp"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, GetFileIdInAfterPopulateIfEmpty)
|
|
|
|
|
{
|
|
|
|
|
cacheNotFilled.populateIfEmpty();
|
|
|
|
|
|
|
|
|
|
auto id = cacheNotFilled.sourceId("/path2/to/file.cpp");
|
|
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
ASSERT_THAT(id, Eq(SourceId::create(72)));
|
2021-05-04 16:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, DontPopulateIfNotEmpty)
|
|
|
|
|
{
|
|
|
|
|
cacheNotFilled.sourceId("/path/to/file.cpp");
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(storageMockFilled, fetchAllSourceContexts()).Times(0);
|
|
|
|
|
EXPECT_CALL(storageMockFilled, fetchAllSources()).Times(0);
|
|
|
|
|
|
|
|
|
|
cacheNotFilled.populateIfEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, GetSourceContextIdAfterPopulateIfEmpty)
|
|
|
|
|
{
|
|
|
|
|
cacheNotFilled.populateIfEmpty();
|
|
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
auto id = cacheNotFilled.sourceContextId(SourceId::create(42));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
ASSERT_THAT(id, Eq(SourceContextId::create(5)));
|
2021-05-04 16:36:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, GetDirectoryPathAfterPopulateIfEmpty)
|
|
|
|
|
{
|
|
|
|
|
cacheNotFilled.populateIfEmpty();
|
|
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
auto path = cacheNotFilled.sourceContextPath(SourceContextId::create(5));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
|
|
|
|
ASSERT_THAT(path, Eq("/path/to"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(SourcePathCache, GetFilePathAfterPopulateIfEmptye)
|
|
|
|
|
{
|
|
|
|
|
cacheNotFilled.populateIfEmpty();
|
|
|
|
|
|
2022-07-19 14:33:00 +02:00
|
|
|
auto path = cacheNotFilled.sourcePath(SourceId::create(42));
|
2021-05-04 16:36:06 +02:00
|
|
|
|
|
|
|
|
ASSERT_THAT(path, Eq("/path/to/file.cpp"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|