Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementKunz committed Jan 17, 2025
1 parent aee49d5 commit f7018d8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ void TestSnapshot::setUp() {
ParametersCache::instance(true);

_rootNodeId = SyncDb::driveRootNode().nodeIdLocal().value();
const DbNode dummyRootNode(0, std::nullopt, SyncName(), SyncName(), "1", "1", std::nullopt, std::nullopt, std::nullopt,
NodeType::Directory, 0, std::nullopt);
_snapshot = std::make_unique<Snapshot>(ReplicaSide::Local, dummyRootNode);
_dummyRootNode = DbNode(0, std::nullopt, SyncName(), SyncName(), "1", "1", std::nullopt, std::nullopt, std::nullopt,
NodeType::Directory, 0, std::nullopt);
_snapshot = std::make_unique<Snapshot>(ReplicaSide::Local, _dummyRootNode);

// Insert node A
const SnapshotItem itemA("a", _rootNodeId, Str("A"), testhelpers::defaultTime, testhelpers::defaultTime, NodeType::Directory,
Expand Down Expand Up @@ -241,6 +241,42 @@ void TestSnapshot::testPath() {
CPPUNIT_ASSERT(_snapshot->path(childId, path, ignore));
CPPUNIT_ASSERT_EQUAL(SyncPath("A") / name / childName, path);
CPPUNIT_ASSERT(!ignore);
#endif
}
// Same test but on the snapshot copy (meaning using paths stored in cache)
std::vector<SyncName> names = {Str("E:S"), Str("E:/S")};
for (const auto &name: names) {
Snapshot snapshotCopy(ReplicaSide::Local, _dummyRootNode);
snapshotCopy = *_snapshot;
const auto id = CommonUtility::generateRandomStringAlphaNum();
const SnapshotItem item(id, "a", name, testhelpers::defaultTime, testhelpers::defaultTime, NodeType::Directory,
testhelpers::defaultFileSize, false, true, true);
snapshotCopy.updateItem(item);
SyncPath path;
bool ignore = false;
// On Windows, if the file name starts with "X:" pattern, the previous element of the path are overrode
// (https://en.cppreference.com/w/cpp/filesystem/path/append)
#ifdef _WIN32
CPPUNIT_ASSERT(!snapshotCopy.path(id, path, ignore));
CPPUNIT_ASSERT(ignore);
#else
CPPUNIT_ASSERT(snapshotCopy.path(id, path, ignore));
CPPUNIT_ASSERT_EQUAL(SyncPath("A") / name, path);
CPPUNIT_ASSERT(!ignore);
#endif

const auto childId = CommonUtility::generateRandomStringAlphaNum();
const auto childName = Str("test");
const SnapshotItem childItem(childId, id, childName, testhelpers::defaultTime, testhelpers::defaultTime,
NodeType::Directory, testhelpers::defaultFileSize, false, true, true);
snapshotCopy.updateItem(childItem);
#ifdef _WIN32
CPPUNIT_ASSERT(!snapshotCopy.path(childId, path, ignore));
CPPUNIT_ASSERT(ignore);
#else
CPPUNIT_ASSERT(snapshotCopy.path(childId, path, ignore));
CPPUNIT_ASSERT_EQUAL(SyncPath("A") / name / childName, path);
CPPUNIT_ASSERT(!ignore);
#endif
}
// Item name starting by pattern "X:", should be ignored on Windows only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class TestSnapshot : public CppUnit::TestFixture {

std::unique_ptr<Snapshot> _snapshot;
NodeId _rootNodeId;
DbNode _dummyRootNode;
};

} // namespace KDC

0 comments on commit f7018d8

Please sign in to comment.