worldforge/libs/squall/tests/IteratorTest.cpp

98 lines
2.9 KiB
C++
Raw Permalink Normal View History

2022-08-28 22:17:31 +02:00
/*
Copyright (C) 2022 Erik Ogenvik
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
2023-02-08 22:23:32 +01:00
#include "squall/core/Iterator.h"
#include "squall/core/Repository.h"
2022-08-28 22:17:31 +02:00
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_vector.hpp>
#include <utility>
#include <algorithm>
#include <iostream>
using namespace Squall;
2024-01-04 17:48:55 +01:00
TEST_CASE("Iterator allows iteration", "[Iterator]") {
setupEncodings();
2022-08-28 22:17:31 +02:00
std::filesystem::path repoPath = TESTDATADIR "/repo";
Repository repository(repoPath);
2023-03-24 23:54:59 +01:00
SECTION("iterate over working manifest should work") {
2022-08-28 22:17:31 +02:00
auto fetchManifestResult = repository.fetchManifest("e34c28f74227a7213ede2d254a8e98b3379add41e69a5538525b8ba8dde538");
2022-08-28 22:17:31 +02:00
2023-03-24 23:54:59 +01:00
REQUIRE(fetchManifestResult.fetchResult.status == FetchStatus::SUCCESS);
2022-08-28 22:17:31 +02:00
std::vector<std::filesystem::path> paths;
2024-01-04 17:48:55 +01:00
Iterator it(repository, *fetchManifestResult.manifest);
for (; it != Iterator(); ++it) {
2022-08-28 22:17:31 +02:00
paths.emplace_back((*it).path);
REQUIRE(it);
}
std::vector<std::filesystem::path> expected{
"bar/",
"bar/baz.txt",
"empty_directory/",
"empty_file",
"file with spaces in name",
"filè with nön äscií chårs",
"foo.txt"
2022-08-28 22:17:31 +02:00
};
REQUIRE_THAT(paths, Catch::Matchers::Equals(expected));
}
2023-03-24 23:54:59 +01:00
SECTION("iterate over working manifest without recurse should work") {
auto fetchManifestResult = repository.fetchManifest("e34c28f74227a7213ede2d254a8e98b3379add41e69a5538525b8ba8dde538");
2023-03-24 23:54:59 +01:00
REQUIRE(fetchManifestResult.fetchResult.status == FetchStatus::SUCCESS);
std::vector<std::filesystem::path> paths;
2024-01-04 17:48:55 +01:00
Iterator it(repository, *fetchManifestResult.manifest, false);
for (; it != Iterator(); ++it) {
2023-03-24 23:54:59 +01:00
paths.emplace_back((*it).path);
REQUIRE(it);
}
std::vector<std::filesystem::path> expected{
"bar/",
"empty_directory/",
"empty_file",
"file with spaces in name",
"filè with nön äscií chårs",
"foo.txt"
};
REQUIRE_THAT(paths, Catch::Matchers::Equals(expected));
}
2022-08-28 22:17:31 +02:00
SECTION("missing entry should be marked") {
2023-02-08 22:27:44 +01:00
Manifest digest;
2022-08-28 22:17:31 +02:00
digest.entries.emplace_back(FileEntry{
.fileName= "missing",
.signature="1111111111111111111111111111111111111111111111111111111111111111",
.type=Squall::FileEntryType::FILE,
.size=10});
digest.version = "1";
2024-01-04 17:48:55 +01:00
Iterator it(repository, (digest));
2022-08-28 22:17:31 +02:00
REQUIRE(it == false);
}
}