Compare commits

..

13 Commits

Author SHA1 Message Date
10d570f3ea Update cmake.yml
Fix Asan crash
2024-03-18 23:17:58 +01:00
e996e93431 switch to c++20 2024-03-18 22:39:10 +01:00
8e9ed2b715 ASSERT_EQ instead of EXPECT_EQ in tests
because that's what we actually want, to crash right now, no point in continuing
2024-03-15 22:37:26 +01:00
0095f9ff69 Small ThreadPool improvements 2024-03-15 22:37:02 +01:00
a14eb1c501 fix for act runner
Some checks failed
CMake / build (push) Failing after 31m10s
i guess its ctest is too old and doesn't have the option?
2024-01-06 09:59:56 +01:00
5ea76e566e add discovery timeout to gtests
All checks were successful
CMake / build (push) Successful in 24m18s
2024-01-05 22:53:18 +01:00
275f1208c5 it was actually because sys ptrace wasn't allowed for gitea runner 2024-01-05 22:32:33 +01:00
d424adc389 fix diff
Some checks failed
CMake / build (push) Failing after 29m54s
2023-12-24 14:14:54 +01:00
1f72814b99 Update cmake.yml
Some checks failed
CMake / build (push) Failing after 26m7s
2023-11-26 14:13:51 +01:00
8f63891aee set cmake min for 3.18
Some checks failed
CMake / build (push) Has been cancelled
for gitea actions runner
2023-11-26 13:49:34 +01:00
b3123bb70d Update cmake.yml
Some checks failed
CMake / build (push) Failing after 1m17s
2023-11-26 13:47:54 +01:00
77cb49a32c Update cmake.yml
Some checks failed
CMake / build (push) Failing after 1m23s
2023-11-26 13:44:37 +01:00
e0ea1c1ce9 Update cmake.yml 2023-11-26 13:42:37 +01:00
35 changed files with 199 additions and 186 deletions

View File

@@ -17,13 +17,22 @@ jobs:
# You can convert this to a matrix build if you need cross-platform coverage. # You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest runs-on: ubuntu-latest
container: gcc
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- run: apt-get update && apt-get install -y sudo
if: env.ACT=='true'
- name: Fix kernel mmap rnd bits
# Asan in llvm 14 provided in ubuntu 22.04 is incompatible with
# high-entropy ASLR in much newer kernels that GitHub runners are
# using leading to random crashes: https://reviews.llvm.org/D148280
run: sudo sysctl vm.mmap_rnd_bits=28
if: env.ACT!='true'
- name: install everything - name: install everything
run: apt-get update && apt-get install -y fuse libfuse-dev cmake run: sudo apt-get update && sudo apt-get install -y fuse libfuse-dev cmake build-essential gcc g++ libssl-dev zlib1g-dev
- name: Configure CMake - name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
@@ -32,10 +41,9 @@ jobs:
- name: Build - name: Build
# Build your program with the given configuration # Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel $(nproc) run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel $(( $(nproc) - 2 ))
- name: Test - name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration. # Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --verbose --parallel $(nproc) -C ${{env.BUILD_TYPE}} run: cd ${{github.workspace}}/build && ctest --test-dir ${{github.workspace}}/build --verbose --parallel $(nproc) -C ${{env.BUILD_TYPE}}

7
.idea/misc.xml generated
View File

@@ -1,4 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" /> <component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="CidrRootsConfiguration">
<excludeRoots>
<file path="$PROJECT_DIR$/cmake-build-debug" />
<file path="$PROJECT_DIR$/cmake-build-relwithdebinfo" />
<file path="$PROJECT_DIR$/cmake-build-relwithsan" />
</excludeRoots>
</component>
</project> </project>

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
project(backup) project(backup)

View File

@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_subdirectory(change_detectors) add_subdirectory(change_detectors)

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
add_library(change_detectors srcs/ChangeDetector.cpp srcs/ChangeDetectorContainer.cpp srcs/ChangeDetectorFactory.cpp srcs/ComparableFile.cpp srcs/ContentsChangeDetector.cpp srcs/EditTimeChangeDetector.cpp srcs/SizeChangeDetector.cpp srcs/TypeChangeDetector.cpp) add_library(change_detectors srcs/ChangeDetector.cpp srcs/ChangeDetectorContainer.cpp srcs/ChangeDetectorFactory.cpp srcs/ComparableFile.cpp srcs/ContentsChangeDetector.cpp srcs/EditTimeChangeDetector.cpp srcs/SizeChangeDetector.cpp srcs/TypeChangeDetector.cpp)

View File

@@ -16,13 +16,13 @@ ComparableFile::ComparableFile(const File &file, const Repository *repo)
contents([file, repo]() { return std::make_unique<FileBuffer>(repo, file.id); }) {} contents([file, repo]() { return std::make_unique<FileBuffer>(repo, file.id); }) {}
ComparableFile::ComparableFile(const std::filesystem::path &p, const std::filesystem::path &base) ComparableFile::ComparableFile(const std::filesystem::path &p, const std::filesystem::path &base)
: path(p.lexically_relative(base).u8string()), type(File::getFileType(p)), bytes(File::getFileSize(p)), : path(p.lexically_relative(base).string()), type(File::getFileType(p)), bytes(File::getFileSize(p)),
mtime(File::getFileMtime(p)), mtime(File::getFileMtime(p)),
contents([p, path = this->path, type = this->type]() -> std::unique_ptr<std::streambuf> { contents([p, path = this->path, type = this->type]() -> std::unique_ptr<std::streambuf> {
if (type == File::Type::Normal) { if (type == File::Type::Normal) {
auto fb = std::make_unique<std::filebuf>(); auto fb = std::make_unique<std::filebuf>();
fb->open(p, std::ios::in | std::ios::binary); fb->open(p, std::ios::in | std::ios::binary);
if (!fb->is_open()) throw Exception("Can't open " + p.u8string() + " for reading!"); if (!fb->is_open()) throw Exception("Can't open " + p.string() + " for reading!");
return fb; return fb;
} }

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
add_library(chunkers srcs/Buzhash.cpp srcs/BuzhashChunker.cpp srcs/Chunker.cpp srcs/ChunkerFactory.cpp srcs/ConstChunker.cpp) add_library(chunkers srcs/Buzhash.cpp srcs/BuzhashChunker.cpp srcs/Chunker.cpp srcs/ChunkerFactory.cpp srcs/ConstChunker.cpp)

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
add_library(commands srcs/CommandDiff.cpp srcs/CommandList.cpp srcs/CommandListFiles.cpp srcs/CommandRestore.cpp srcs/CommandRun.cpp srcs/CommandsCommon.cpp srcs/Diff.cpp srcs/CommandMount.cpp) add_library(commands srcs/CommandDiff.cpp srcs/CommandList.cpp srcs/CommandListFiles.cpp srcs/CommandRestore.cpp srcs/CommandRun.cpp srcs/CommandsCommon.cpp srcs/Diff.cpp srcs/CommandMount.cpp)

View File

@@ -43,7 +43,7 @@ void CommandDiff::run(Context ctx) {
std::map<std::filesystem::path, File> files;///< Files in the first archive std::map<std::filesystem::path, File> files;///< Files in the first archive
for (auto id: archiveO1.files) { for (auto id: archiveO1.files) {
auto file = Serialize::deserialize<File>(ctx.repo->getObject(id)); auto file = Serialize::deserialize<File>(ctx.repo->getObject(id));
auto path = std::filesystem::u8path(file.name); auto path = std::filesystem::path(file.name);
if (isSubpath(ctx.repo->getConfig().getStr("prefix"), path)) files.emplace(file.getKey(), std::move(file)); if (isSubpath(ctx.repo->getConfig().getStr("prefix"), path)) files.emplace(file.getKey(), std::move(file));
} }
@@ -83,7 +83,7 @@ void CommandDiff::run(Context ctx) {
/// Exit when asked to /// Exit when asked to
if (Signals::shouldQuit) throw Exception("Quitting"); if (Signals::shouldQuit) throw Exception("Quitting");
auto file = Serialize::deserialize<File>(ctx.repo->getObject(id)); auto file = Serialize::deserialize<File>(ctx.repo->getObject(id));
if (isSubpath(ctx.repo->getConfig().getStr("prefix"), std::filesystem::u8path(file.name))) if (isSubpath(ctx.repo->getConfig().getStr("prefix"), std::filesystem::path(file.name)))
threadPool.push([&, file]() { processFile(ComparableFile{file, ctx.repo}); }); threadPool.push([&, file]() { processFile(ComparableFile{file, ctx.repo}); });
if (Signals::shouldQuit) break; if (Signals::shouldQuit) break;
} }
@@ -115,7 +115,7 @@ void CommandDiff::run(Context ctx) {
std::map<std::filesystem::path, File> files2;///< Files in the first archive std::map<std::filesystem::path, File> files2;///< Files in the first archive
for (auto id: archiveO2->files) { for (auto id: archiveO2->files) {
auto file = Serialize::deserialize<File>(ctx.repo->getObject(id)); auto file = Serialize::deserialize<File>(ctx.repo->getObject(id));
auto path = std::filesystem::u8path(file.name); auto path = std::filesystem::path(file.name);
if (isSubpath(ctx.repo->getConfig().getStr("prefix"), path)) if (isSubpath(ctx.repo->getConfig().getStr("prefix"), path))
files2.emplace(file.getKey(), std::move(file)); files2.emplace(file.getKey(), std::move(file));
} }
@@ -144,5 +144,5 @@ void CommandDiff::run(Context ctx) {
std::unique_lock finishedLock(threadPool.finishedLock); std::unique_lock finishedLock(threadPool.finishedLock);
threadPool.finished.wait(finishedLock, [&threadPool] { return threadPool.empty(); }); threadPool.finished.wait(finishedLock, [&threadPool] { return threadPool.empty(); });
if (diffMode == "normal") if (diffMode == "normal")
for (auto const &s: files) { ctx.logger->write(s.first.u8string() + " is removed\n", 0); } for (auto const &s: files) { ctx.logger->write(s.first.string() + " is removed\n", 0); }
} }

View File

@@ -24,7 +24,7 @@ CommandRestore::CommandRestore() : Command() {}
void CommandRestore::run(Context ctx) { void CommandRestore::run(Context ctx) {
Object::idType archive = ctx.repo->getConfig().getInt("aid"); Object::idType archive = ctx.repo->getConfig().getInt("aid");
std::filesystem::path to = std::filesystem::u8path(ctx.repo->getConfig().getStr("to")); std::filesystem::path to = std::filesystem::path(ctx.repo->getConfig().getStr("to"));
std::atomic<unsigned long long> filesToRestoreCount = 0; std::atomic<unsigned long long> filesToRestoreCount = 0;
std::atomic<unsigned long long> bytesToRestore = 0; std::atomic<unsigned long long> bytesToRestore = 0;
@@ -95,21 +95,21 @@ void CommandRestore::run(Context ctx) {
std::string CommandRestore::backupRestoreFile(const File &file, const std::filesystem::path &baseDir, std::string CommandRestore::backupRestoreFile(const File &file, const std::filesystem::path &baseDir,
workerStatsFunction &callback, Context ctx) { workerStatsFunction &callback, Context ctx) {
auto fullpath = baseDir / std::filesystem::u8path(file.name); auto fullpath = baseDir / std::filesystem::path(file.name);
std::filesystem::create_directories(fullpath.parent_path()); std::filesystem::create_directories(fullpath.parent_path());
if (file.fileType == File::Type::Directory) { if (file.fileType == File::Type::Directory) {
std::filesystem::create_directory(fullpath); std::filesystem::create_directory(fullpath);
callback(0, 0, 1); callback(0, 0, 1);
return fullpath.u8string(); return fullpath.string();
} }
if (file.fileType == File::Type::Symlink) { if (file.fileType == File::Type::Symlink) {
auto dest = Serialize::deserialize<Chunk>(ctx.repo->getObject(file.chunks.at(0))); auto dest = Serialize::deserialize<Chunk>(ctx.repo->getObject(file.chunks.at(0)));
std::filesystem::create_symlink(std::filesystem::u8path(std::string{dest.data.begin(), dest.data.end()}), std::filesystem::create_symlink(std::filesystem::path(std::string{dest.data.begin(), dest.data.end()}),
fullpath); fullpath);
callback(0, 0, 1); callback(0, 0, 1);
return fullpath.u8string(); return fullpath.string();
} }
std::ofstream ostream(fullpath, std::ios::binary | std::ios::out | std::ios::trunc); std::ofstream ostream(fullpath, std::ios::binary | std::ios::out | std::ios::trunc);
@@ -124,5 +124,5 @@ std::string CommandRestore::backupRestoreFile(const File &file, const std::files
} }
callback(0, 0, 1); callback(0, 0, 1);
return fullpath.u8string(); return fullpath.string();
} }

View File

@@ -79,14 +79,14 @@ void CommandRun::run(Context ctx) {
File::getFileType(absPath) == File::Type::Normal ? std::filesystem::file_size(absPath) : 0; File::getFileType(absPath) == File::Type::Normal ? std::filesystem::file_size(absPath) : 0;
runnerStats.filesToSaveCount++; runnerStats.filesToSaveCount++;
threadPool.push([&, relPath, absPath]() { threadPool.push([&, relPath, absPath]() {
addFile(backupChunkFile(absPath, relPath.u8string(), workerCallback, ctx)); addFile(backupChunkFile(absPath, relPath.string(), workerCallback, ctx));
progress.print("Copied: " + relPath.u8string(), 1); progress.print("Copied: " + relPath.string(), 1);
}); });
}; };
/// Task to process an individual file in the backup /// Task to process an individual file in the backup
std::function<void(std::filesystem::path)> processFile = [&, this](const std::filesystem::path &p) { std::function<void(std::filesystem::path)> processFile = [&, this](const std::filesystem::path &p) {
auto relPath = p.lexically_relative(from).u8string(); auto relPath = p.lexically_relative(from).string();
if (ctx.repo->exists(Object::ObjectType::File, relPath) != 0) { if (ctx.repo->exists(Object::ObjectType::File, relPath) != 0) {
File repoFile = Serialize::deserialize<File>(ctx.repo->getObject(Object::ObjectType::File, relPath)); File repoFile = Serialize::deserialize<File>(ctx.repo->getObject(Object::ObjectType::File, relPath));
@@ -144,10 +144,10 @@ Object::idType CommandRun::backupChunkFile(const std::filesystem::path &orig, co
ctx.repo->putObject(f); ctx.repo->putObject(f);
return f.id; return f.id;
} }
if (!std::filesystem::is_regular_file(orig)) throw Exception(orig.u8string() + "is a special file, not saving"); if (!std::filesystem::is_regular_file(orig)) throw Exception(orig.string() + "is a special file, not saving");
std::ifstream ifstream(orig, std::ios::in | std::ios::binary); std::ifstream ifstream(orig, std::ios::in | std::ios::binary);
if (!ifstream) throw Exception("Couldn't open " + orig.u8string() + " for reading"); if (!ifstream) throw Exception("Couldn't open " + orig.string() + " for reading");
std::unique_ptr<Chunker> chunker = ChunkerFactory::getChunker(ctx.repo->getConfig(), ifstream.rdbuf()); std::unique_ptr<Chunker> chunker = ChunkerFactory::getChunker(ctx.repo->getConfig(), ifstream.rdbuf());
SHA fileHash; SHA fileHash;
@@ -179,7 +179,7 @@ Object::idType CommandRun::backupChunkFile(const std::filesystem::path &orig, co
/// We might have exited in the loop before, so we don't save an incomplete file /// We might have exited in the loop before, so we don't save an incomplete file
if (Signals::shouldQuit) throw Exception("Quitting!"); if (Signals::shouldQuit) throw Exception("Quitting!");
if (size != File::getFileSize(orig)) { if (size != File::getFileSize(orig)) {
throw Exception("Something really bad happened or file " + orig.u8string() + " changed during backup"); throw Exception("Something really bad happened or file " + orig.string() + " changed during backup");
} }
File f(ctx.repo->getId(), saveAs, size, File::getFileMtime(orig), fileHash.getHash(), fileChunks, File f(ctx.repo->getId(), saveAs, size, File::getFileMtime(orig), fileHash.getHash(), fileChunks,
File::getFileType(orig)); File::getFileType(orig));

View File

@@ -18,16 +18,16 @@ void CommandsCommon::workerCallback(unsigned long long int bytesWritten, unsigne
} }
bool CommandsCommon::isSubpath(const std::filesystem::path &prefix, const std::filesystem::path &p) { bool CommandsCommon::isSubpath(const std::filesystem::path &prefix, const std::filesystem::path &p) {
if (prefix.u8string().size() > p.u8string().size()) return false; if (prefix.string().size() > p.string().size()) return false;
for (int i = 0; i < prefix.u8string().size(); i++) for (int i = 0; i < prefix.string().size(); i++)
if (p.u8string()[i] != prefix.u8string()[i]) return false; if (p.string()[i] != prefix.string()[i]) return false;
return true; return true;
} }
void CommandsCommon::processDirWithIgnore(const std::filesystem::path &dir, std::vector<std::string> ignore, void CommandsCommon::processDirWithIgnore(const std::filesystem::path &dir, std::vector<std::string> ignore,
const std::function<void(std::function<void()>)> &spawner, const std::function<void(std::function<void()>)> &spawner,
std::function<void(std::filesystem::directory_entry)> processFile) { std::function<void(std::filesystem::directory_entry)> processFile) {
if (!std::filesystem::is_directory(dir)) throw Exception(dir.u8string() + " is not a directory!"); if (!std::filesystem::is_directory(dir)) throw Exception(dir.string() + " is not a directory!");
/// Don't process the directory if it has a ".nobackup" file /// Don't process the directory if it has a ".nobackup" file
if (std::filesystem::exists(dir / ".nobackup")) return; if (std::filesystem::exists(dir / ".nobackup")) return;
@@ -47,7 +47,7 @@ void CommandsCommon::processDirWithIgnore(const std::filesystem::path &dir, std:
/// Don't process the entry if it matches any of the ignore rules /// Don't process the entry if it matches any of the ignore rules
if (std::any_of(ignore.begin(), ignore.end(), [dirEntry](auto pred) { if (std::any_of(ignore.begin(), ignore.end(), [dirEntry](auto pred) {
std::smatch m; std::smatch m;
auto s = dirEntry.path().filename().u8string(); auto s = dirEntry.path().filename().string();
return std::regex_match(s, m, std::regex(pred)); return std::regex_match(s, m, std::regex(pred));
})) }))
continue; continue;

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
find_package(OpenSSL REQUIRED) find_package(OpenSSL REQUIRED)

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)

View File

@@ -15,7 +15,7 @@
#include "objects/Chunk.h" #include "objects/Chunk.h"
DirEntry *getf(std::string path) { DirEntry *getf(std::string path) {
auto p = std::filesystem::relative(std::filesystem::u8path(path), "/"); auto p = std::filesystem::relative(std::filesystem::path(path), "/");
DirEntry *entry = RepoFS::root.get(); DirEntry *entry = RepoFS::root.get();
if (p != ".") if (p != ".")
for (auto const &subp: p) { entry = entry->children.at(subp).get(); } for (auto const &subp: p) { entry = entry->children.at(subp).get(); }
@@ -142,7 +142,7 @@ void RepoFS::start(Repository *repo, std::string path) {
auto a = Serialize::deserialize<Archive>(repo->getObject(r.second)); auto a = Serialize::deserialize<Archive>(repo->getObject(r.second));
for (auto const &f: a.files) { for (auto const &f: a.files) {
auto file = Serialize::deserialize<File>(repo->getObject(f)); auto file = Serialize::deserialize<File>(repo->getObject(f));
auto path = std::filesystem::u8path(file.name); auto path = std::filesystem::path(file.name);
DirEntry *entry = root->children[std::to_string(a.id)].get() DirEntry *entry = root->children[std::to_string(a.id)].get()
? root->children[std::to_string(a.id)].get() ? root->children[std::to_string(a.id)].get()
: (root->children[std::to_string(a.id)] = std::make_unique<DirEntry>()).get(); : (root->children[std::to_string(a.id)] = std::make_unique<DirEntry>()).get();
@@ -153,7 +153,7 @@ void RepoFS::start(Repository *repo, std::string path) {
: (entry->children[subp] = std::make_unique<DirEntry>()).get(); : (entry->children[subp] = std::make_unique<DirEntry>()).get();
} }
entry->file.emplace(file); entry->file.emplace(file);
entry->name = std::filesystem::u8path(file.name).filename().u8string(); entry->name = std::filesystem::path(file.name).filename().string();
} }
} }

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
add_library(repo srcs/FileRepository.cpp srcs/Object.cpp srcs/Repository.cpp srcs/objects/Archive.cpp srcs/objects/Chunk.cpp srcs/objects/File.cpp srcs/objects/FileBuffer.cpp) add_library(repo srcs/FileRepository.cpp srcs/Object.cpp srcs/Repository.cpp srcs/objects/Archive.cpp srcs/objects/Chunk.cpp srcs/objects/File.cpp srcs/objects/FileBuffer.cpp)

View File

@@ -15,7 +15,7 @@
FileRepository::FileRepository(Config config) FileRepository::FileRepository(Config config)
: Repository(std::move(config)), root(std::filesystem::path(this->config.getStr("repo"))), : Repository(std::move(config)), root(std::filesystem::path(this->config.getStr("repo"))),
writeCacheMax(config.getInt("repo-target") * 1024 * 1024) {} writeCacheMax(this->config.getInt("repo-target") * 1024 * 1024) {}
bool FileRepository::exists() { return std::filesystem::is_directory(root) && std::filesystem::exists(root / "info"); } bool FileRepository::exists() { return std::filesystem::is_directory(root) && std::filesystem::exists(root / "info"); }
@@ -58,7 +58,7 @@ bool FileRepository::init() {
if (exists()) throw Exception("Trying to initialize already existing repository!"); if (exists()) throw Exception("Trying to initialize already existing repository!");
if (!std::filesystem::is_directory(root) && !std::filesystem::create_directories(root)) if (!std::filesystem::is_directory(root) && !std::filesystem::create_directories(root))
throw Exception("Can't create directory " + root.u8string()); throw Exception("Can't create directory " + root.string());
writeFile(root / "info", CheckFilter::filterWriteStatic(Serialize::serialize(config))); writeFile(root / "info", CheckFilter::filterWriteStatic(Serialize::serialize(config)));
@@ -157,23 +157,23 @@ bool FileRepository::deleteObject(const Object &obj) {
std::vector<char> FileRepository::readFile(const std::filesystem::path &file, unsigned long long offset, std::vector<char> FileRepository::readFile(const std::filesystem::path &file, unsigned long long offset,
unsigned long long size) const { unsigned long long size) const {
if (size > absoluteMaxFileLimit) if (size > absoluteMaxFileLimit)
throw Exception("Tried to read " + std::to_string(size) + " bytes from " + file.u8string() + throw Exception("Tried to read " + std::to_string(size) + " bytes from " + file.string() +
" which is more than absoluteMaxFileLimit"); " which is more than absoluteMaxFileLimit");
std::ifstream ifstream(file, std::ios::binary | std::ios::in); std::ifstream ifstream(file, std::ios::binary | std::ios::in);
if (!ifstream.is_open()) throw Exception("Can't open file " + file.u8string() + " for reading!"); if (!ifstream.is_open()) throw Exception("Can't open file " + file.string() + " for reading!");
std::vector<char> buf(size); std::vector<char> buf(size);
if (ifstream.rdbuf()->pubseekpos(offset) == std::streampos(std::streamoff(-1))) if (ifstream.rdbuf()->pubseekpos(offset) == std::streampos(std::streamoff(-1)))
throw Exception("Unexpected end of file " + file.u8string()); throw Exception("Unexpected end of file " + file.string());
if (ifstream.rdbuf()->sgetn(buf.data(), size) != size) throw Exception("Unexpected end of file " + file.u8string()); if (ifstream.rdbuf()->sgetn(buf.data(), size) != size) throw Exception("Unexpected end of file " + file.string());
return buf; return buf;
} }
std::vector<char> FileRepository::readFile(const std::filesystem::path &file) const { std::vector<char> FileRepository::readFile(const std::filesystem::path &file) const {
if (!std::filesystem::is_regular_file(file)) throw Exception("File " + file.u8string() + " is not a regular file!"); if (!std::filesystem::is_regular_file(file)) throw Exception("File " + file.string() + " is not a regular file!");
auto fileSize = std::filesystem::file_size(file); auto fileSize = std::filesystem::file_size(file);
if (fileSize == 0) return {}; if (fileSize == 0) return {};
return readFile(file, 0, fileSize); return readFile(file, 0, fileSize);
@@ -181,10 +181,10 @@ std::vector<char> FileRepository::readFile(const std::filesystem::path &file) co
bool FileRepository::writeFile(const std::filesystem::path &file, const std::vector<char> &data) { bool FileRepository::writeFile(const std::filesystem::path &file, const std::vector<char> &data) {
std::ofstream ofstream(file, std::ios::binary | std::ios::trunc | std::ios::out); std::ofstream ofstream(file, std::ios::binary | std::ios::trunc | std::ios::out);
if (!ofstream.is_open()) throw Exception("Can't open file " + file.u8string() + " for writing!"); if (!ofstream.is_open()) throw Exception("Can't open file " + file.string() + " for writing!");
if (ofstream.rdbuf()->sputn(data.data(), data.size()) != data.size()) if (ofstream.rdbuf()->sputn(data.data(), data.size()) != data.size())
throw Exception("Couldn't write all the data for " + file.u8string()); throw Exception("Couldn't write all the data for " + file.string());
return true; return true;
} }

View File

@@ -42,20 +42,20 @@ File::Type File::getFileType(const std::filesystem::path &p) {
if (std::filesystem::is_symlink(p)) return Type::Symlink; if (std::filesystem::is_symlink(p)) return Type::Symlink;
if (std::filesystem::is_directory(p)) return Type::Directory; if (std::filesystem::is_directory(p)) return Type::Directory;
if (std::filesystem::is_regular_file(p)) return Type::Normal; if (std::filesystem::is_regular_file(p)) return Type::Normal;
throw Exception("Unsupported file type! " + p.u8string()); throw Exception("Unsupported file type! " + p.string());
} }
std::vector<char> File::getFileContents(const std::filesystem::path &p) { std::vector<char> File::getFileContents(const std::filesystem::path &p) {
auto type = getFileType(p); auto type = getFileType(p);
if (type == Type::Normal) throw Exception(p.u8string() + " is a normal file!"); if (type == Type::Normal) throw Exception(p.string() + " is a normal file!");
if (type == Type::Directory) { return {}; } if (type == Type::Directory) { return {}; }
if (type == Type::Symlink) { if (type == Type::Symlink) {
auto target = std::filesystem::read_symlink(p).u8string(); auto target = std::filesystem::read_symlink(p).string();
std::vector<char> target_null_term = {target.begin(), target.end()}; std::vector<char> target_null_term = {target.begin(), target.end()};
target_null_term.emplace_back('\0'); target_null_term.emplace_back('\0');
return target_null_term; return target_null_term;
} }
throw Exception("Error with file " + p.u8string()); throw Exception("Error with file " + p.string());
} }
unsigned long long File::getFileMtime(const std::filesystem::path &p) { unsigned long long File::getFileMtime(const std::filesystem::path &p) {
@@ -65,16 +65,16 @@ unsigned long long File::getFileMtime(const std::filesystem::path &p) {
std::chrono::duration_cast<std::chrono::seconds>(std::filesystem::last_write_time(p).time_since_epoch()) std::chrono::duration_cast<std::chrono::seconds>(std::filesystem::last_write_time(p).time_since_epoch())
.count()); .count());
else if (type == Type::Symlink) { else if (type == Type::Symlink) {
auto path = p.u8string(); auto path = p.string();
struct stat sb; struct stat sb;
if (lstat(path.c_str(), &sb) != 0) throw Exception("Error reading mtime for " + p.u8string()); if (lstat(path.c_str(), &sb) != 0) throw Exception("Error reading mtime for " + p.string());
#ifdef __APPLE__ #ifdef __APPLE__
return sb.st_mtimespec.tv_sec; return sb.st_mtimespec.tv_sec;
#else #else
return sb.st_mtime; return sb.st_mtime;
#endif #endif
} }
throw Exception("Error with file " + p.u8string()); throw Exception("Error with file " + p.string());
} }
unsigned long long File::getFileSize(const std::filesystem::path &p) { unsigned long long File::getFileSize(const std::filesystem::path &p) {

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
add_library(utils srcs/BytesFormatter.cpp srcs/Config.cpp srcs/Exception.cpp srcs/Logger.cpp srcs/Progress.cpp srcs/RunningAverage.cpp srcs/RunningDiffAverage.cpp srcs/Signals.cpp srcs/ThreadPool.cpp) add_library(utils srcs/BytesFormatter.cpp srcs/Config.cpp srcs/Exception.cpp srcs/Logger.cpp srcs/Progress.cpp srcs/RunningAverage.cpp srcs/RunningDiffAverage.cpp srcs/Signals.cpp srcs/ThreadPool.cpp)

View File

@@ -8,16 +8,17 @@ ThreadPool::ThreadPool(std::function<void(std::string)> onError, std::size_t wor
} }
ThreadPool::~ThreadPool() { ThreadPool::~ThreadPool() {
{
std::lock_guard lock(queueLock);
stop = true; stop = true;
somethingNew.notify_all(); somethingNew.notify_all();
}
for (auto &t: threads) { t.join(); } for (auto &t: threads) { t.join(); }
} }
void ThreadPool::push(std::function<void()> &&func) { void ThreadPool::push(std::function<void()> &&func) {
{
std::lock_guard lock(queueLock); std::lock_guard lock(queueLock);
queue.push(std::move(func)); queue.push(std::move(func));
}
somethingNew.notify_one(); somethingNew.notify_one();
} }
@@ -43,18 +44,15 @@ void ThreadPool::loop() {
queue.pop(); queue.pop();
qLock.unlock(); qLock.unlock();
try { try {
task(); task();
} catch (std::exception &e) { onError(std::string(e.what())); } } catch (std::exception &e) { onError(std::string(e.what())); }
qLock.lock();
{
std::lock_guard qLock(queueLock);
running--; running--;
if (queue.empty() && running == 0) { finished.notify_all(); } if (queue.empty() && running == 0) { finished.notify_all(); }
} }
} }
}
bool ThreadPool::empty() { bool ThreadPool::empty() {
std::lock_guard qLock(queueLock); std::lock_guard qLock(queueLock);

View File

@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
# GoogleTest requires at least C++14 # GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0") if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
add_executable( add_executable(
BuzhashTest BuzhashTest
@@ -8,5 +8,5 @@ target_link_libraries(
BuzhashTest PRIVATE BuzhashTest PRIVATE
GTest::gtest_main chunkers GTest::gtest_main chunkers
) )
gtest_discover_tests(BuzhashTest) gtest_discover_tests(BuzhashTest DISCOVERY_TIMEOUT 600)

View File

@@ -26,11 +26,11 @@ TEST(BuzhashTest, SimpleTest) {
for (int i = 0; i < loremipsum.length(); i++) { for (int i = 0; i < loremipsum.length(); i++) {
b2.feed((uint8_t) loremipsum[i]); b2.feed((uint8_t) loremipsum[i]);
if (b2.get() == h1) { if (b2.get() == h1) {
EXPECT_EQ(i, loremipsum.find("e eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non p")); ASSERT_EQ(i, loremipsum.find("e eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non p"));
h1found = true; h1found = true;
break; break;
} }
} }
EXPECT_EQ(h1found, true); ASSERT_EQ(h1found, true);
} }
} }

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
add_executable( add_executable(
@@ -11,5 +11,5 @@ target_link_libraries(
CLITests PRIVATE CLITests PRIVATE
GTest::gtest_main testUtils GTest::gtest_main testUtils
) )
gtest_discover_tests(CLITests) gtest_discover_tests(CLITests DISCOVERY_TIMEOUT 600)

View File

@@ -61,13 +61,13 @@ echo "testtestasdf9uuu" > "$TESTDATADIR"/testdata/4/filexd
echo "Data created" echo "Data created"
if ! $CMD init --repo "$"$TESTDATADIR"/testdataDIR"/testdir/to1 --compression zlib --compression-level 4 --encryption aes --password asdff --salt e; then if ! $CMD init --repo "$TESTDATADIR"/testdataDIR/testdir/to1 --compression zlib --compression-level 4 --encryption aes --password asdff --salt e; then
echo "Error creating repo!" echo "Error creating repo!"
exit 1 exit 1
fi fi
echo "Repo created" echo "Repo created"
OUT=$($CMD run --from "$TESTDATADIR"/testdata/1 --repo "$"$TESTDATADIR"/testdataDIR"/testdir/to1 --password asdff --progress simple --verbose 1) OUT=$($CMD run --from "$TESTDATADIR"/testdata/1 --repo "$TESTDATADIR"/testdataDIR/testdir/to1 --password asdff --progress simple --verbose 1)
echo "$OUT" echo "$OUT"
if ! ( ( echo "$OUT" | grep -q 'Copied: notempty/testfile' )\ if ! ( ( echo "$OUT" | grep -q 'Copied: notempty/testfile' )\
&& ( echo "$OUT" | grep -q 'Copied: notempty' )\ && ( echo "$OUT" | grep -q 'Copied: notempty' )\
@@ -87,7 +87,7 @@ if ! ( ( echo "$OUT" | grep -q 'Copied: notempty/testfile' )\
fi fi
echo "Backup 1 ok" echo "Backup 1 ok"
OUT=$($CMD run --from "$TESTDATADIR"/testdata/2 --repo "$"$TESTDATADIR"/testdataDIR"/testdir/to1 --password asdff --progress simple --verbose 1) OUT=$($CMD run --from "$TESTDATADIR"/testdata/2 --repo "$TESTDATADIR"/testdataDIR/testdir/to1 --password asdff --progress simple --verbose 1)
echo "$OUT" echo "$OUT"
if ! ( ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4 ' )\ if ! ( ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4 ' )\
&& ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test5 ' )\ && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test5 ' )\
@@ -100,7 +100,7 @@ if ! ( ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4 ' )\
fi fi
echo "Backup 2 ok" echo "Backup 2 ok"
OUT=$($CMD run --from "$TESTDATADIR"/testdata/3 --repo "$"$TESTDATADIR"/testdataDIR"/testdir/to1 --password asdff --progress simple --verbose 1) OUT=$($CMD run --from "$TESTDATADIR"/testdata/3 --repo "$TESTDATADIR"/testdataDIR/testdir/to1 --password asdff --progress simple --verbose 1)
echo "$OUT" echo "$OUT"
if ! ( ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4 ' )\ if ! ( ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4 ' )\
&& ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test5 ' )\ && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test5 ' )\
@@ -116,7 +116,7 @@ echo "Backup 3 ok"
i=$((0)) i=$((0))
AIDS=() AIDS=()
OUT=$($CMD list --repo "$"$TESTDATADIR"/testdataDIR"/testdir/to1 --password asdff) OUT=$($CMD list --repo "$TESTDATADIR"/testdataDIR/testdir/to1 --password asdff)
echo "$OUT" echo "$OUT"
while IFS= read -r l; do while IFS= read -r l; do
((i++)) ((i++))
@@ -124,7 +124,7 @@ while IFS= read -r l; do
AIDS+=("$aid") AIDS+=("$aid")
done <<< "$OUT" done <<< "$OUT"
OUT=$($CMD diff --from "$TESTDATADIR"/testdata/4 --repo "$"$TESTDATADIR"/testdataDIR"/testdir/to1 --password asdff --progress none --verbose 1 --aid ${AIDS[0]} --aid2 ${AIDS[1]}) OUT=$($CMD diff --from "$TESTDATADIR"/testdata/4 --repo "$TESTDATADIR"/testdataDIR/testdir/to1 --password asdff --progress none --verbose 1 --aid ${AIDS[0]} --aid2 ${AIDS[1]})
echo "$OUT" echo "$OUT"
if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && ( echo "$OUT" | grep -q 'filexd is different' ) && ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test7 is different' ) \ if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && ( echo "$OUT" | grep -q 'filexd is different' ) && ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test7 is different' ) \
&& ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4' ) && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test5' ) && ! ( echo "$OUT" | grep -q 'notemptyi2/ignoredir/testa' ) ); then && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4' ) && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test5' ) && ! ( echo "$OUT" | grep -q 'notemptyi2/ignoredir/testa' ) ); then
@@ -132,7 +132,7 @@ if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && (
exit 1 exit 1
fi fi
echo "OK comparing archive 1 and 2" echo "OK comparing archive 1 and 2"
OUT=$($CMD diff --from "$TESTDATADIR"/testdata/4 --repo "$"$TESTDATADIR"/testdataDIR"/testdir/to1 --password asdff --progress none --verbose 1 --aid ${AIDS[1]} --aid2 ${AIDS[2]}) OUT=$($CMD diff --from "$TESTDATADIR"/testdata/4 --repo "$TESTDATADIR"/testdataDIR/testdir/to1 --password asdff --progress none --verbose 1 --aid ${AIDS[1]} --aid2 ${AIDS[2]})
echo "$OUT" echo "$OUT"
if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && ( echo "$OUT" | grep -q 'filexd is different' ) && ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test7 is different' ) \ if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && ( echo "$OUT" | grep -q 'filexd is different' ) && ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test7 is different' ) \
&& ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4' ) && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test5' ) && ! ( echo "$OUT" | grep -q 'notemptyi2/ignoredir/testa' ) ); then && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4' ) && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test5' ) && ! ( echo "$OUT" | grep -q 'notemptyi2/ignoredir/testa' ) ); then
@@ -141,7 +141,7 @@ if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && (
fi fi
echo "OK comparing archive 2 and 3" echo "OK comparing archive 2 and 3"
OUT=$($CMD diff --from "$TESTDATADIR"/testdata/4 --repo "$"$TESTDATADIR"/testdataDIR"/testdir/to1 --password asdff --progress none --verbose 1 --aid ${AIDS[2]}) OUT=$($CMD diff --from "$TESTDATADIR"/testdata/4 --repo "$TESTDATADIR"/testdataDIR/testdir/to1 --password asdff --progress none --verbose 1 --aid ${AIDS[2]})
echo "$OUT" echo "$OUT"
if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && ( echo "$OUT" | grep -q 'filexd is different' ) && ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test7 is different' ) \ if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && ( echo "$OUT" | grep -q 'filexd is different' ) && ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test7 is different' ) \
&& ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4' ) && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test5' ) && ! ( echo "$OUT" | grep -q 'notemptyi2/ignoredir/testa' ) ); then && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4' ) && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test5' ) && ! ( echo "$OUT" | grep -q 'notemptyi2/ignoredir/testa' ) ); then
@@ -150,7 +150,7 @@ if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && (
fi fi
echo "OK comparing archive 3 and current" echo "OK comparing archive 3 and current"
OUT=$($CMD diff --from "$TESTDATADIR"/testdata/4 --repo "$"$TESTDATADIR"/testdataDIR"/testdir/to1 --password asdff --progress none --verbose 1 ) OUT=$($CMD diff --from "$TESTDATADIR"/testdata/4 --repo "$TESTDATADIR"/testdataDIR/testdir/to1 --password asdff --progress none --verbose 1 )
echo "$OUT" echo "$OUT"
if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && ( echo "$OUT" | grep -q 'filexd is different' ) && ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test7 is different' ) \ if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && ( echo "$OUT" | grep -q 'filexd is different' ) && ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test7 is different' ) \
&& ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4' ) && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test5' ) && ! ( echo "$OUT" | grep -q 'notemptyi2/ignoredir/testa' ) ); then && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4' ) && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test5' ) && ! ( echo "$OUT" | grep -q 'notemptyi2/ignoredir/testa' ) ); then
@@ -159,7 +159,7 @@ if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && (
fi fi
echo "OK comparing archive last (3) and current" echo "OK comparing archive last (3) and current"
OUT=$($CMD diff --from "$TESTDATADIR"/testdata/4 --repo "$"$TESTDATADIR"/testdataDIR"/testdir/to1 --password asdff --progress none --verbose 1 --aid ${AIDS[2]} --prefix notempty2/notemptyi2 ) OUT=$($CMD diff --from "$TESTDATADIR"/testdata/4 --repo "$TESTDATADIR"/testdataDIR/testdir/to1 --password asdff --progress none --verbose 1 --aid ${AIDS[2]} --prefix notempty2/notemptyi2 )
echo "$OUT" echo "$OUT"
if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && ! ( echo "$OUT" | grep -q 'filexd is different' ) && ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test7 is different' ) \ if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && ! ( echo "$OUT" | grep -q 'filexd is different' ) && ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test7 is different' ) \
&& ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4' ) && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test5' ) && ! ( echo "$OUT" | grep -q 'notemptyi2/ignoredir/testa' ) ); then && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4' ) && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test5' ) && ! ( echo "$OUT" | grep -q 'notemptyi2/ignoredir/testa' ) ); then
@@ -168,7 +168,7 @@ if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && !
fi fi
echo "OK comparing archive 3 and current with prefix " echo "OK comparing archive 3 and current with prefix "
OUT=$($CMD diff --from "$TESTDATADIR"/testdata/4 --repo "$"$TESTDATADIR"/testdataDIR"/testdir/to1 --password asdff --progress none --verbose 1 --prefix notempty2/notemptyi2 ) OUT=$($CMD diff --from "$TESTDATADIR"/testdata/4 --repo "$TESTDATADIR"/testdataDIR/testdir/to1 --password asdff --progress none --verbose 1 --prefix notempty2/notemptyi2 )
echo "$OUT" echo "$OUT"
if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && ! ( echo "$OUT" | grep -q 'filexd is different' ) && ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test7 is different' ) \ if ! ( ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test6 is different' ) && ! ( echo "$OUT" | grep -q 'filexd is different' ) && ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test7 is different' ) \
&& ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4' ) && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test5' ) && ! ( echo "$OUT" | grep -q 'notemptyi2/ignoredir/testa' ) ); then && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test4' ) && ! ( echo "$OUT" | grep -q 'notempty2/notemptyi2/test5' ) && ! ( echo "$OUT" | grep -q 'notemptyi2/ignoredir/testa' ) ); then
@@ -178,6 +178,6 @@ fi
echo "OK comparing archive last (3) and current with prefix " echo "OK comparing archive last (3) and current with prefix "
rm -rf "$"$TESTDATADIR"/testdataDIR" rm -rf "$TESTDATADIR"/testdataDIR
exit 0 exit 0

View File

@@ -9,15 +9,15 @@
TEST(CLITest, Backup) { TEST(CLITest, Backup) {
int ret = system("../../../tests/clitests/scripts/backup.sh"); int ret = system("../../../tests/clitests/scripts/backup.sh");
EXPECT_EQ(WEXITSTATUS(ret), 0); ASSERT_EQ(WEXITSTATUS(ret), 0);
} }
TEST(CLITest, Ignore) { TEST(CLITest, Ignore) {
int ret = system("../../../tests/clitests/scripts/ignore.sh"); int ret = system("../../../tests/clitests/scripts/ignore.sh");
EXPECT_EQ(WEXITSTATUS(ret), 0); ASSERT_EQ(WEXITSTATUS(ret), 0);
} }
TEST(CLITest, Diff) { TEST(CLITest, Diff) {
int ret = system("../../../tests/clitests/scripts/diff.sh"); int ret = system("../../../tests/clitests/scripts/diff.sh");
EXPECT_EQ(WEXITSTATUS(ret), 0); ASSERT_EQ(WEXITSTATUS(ret), 0);
} }

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
add_executable( add_executable(
CryptoTests CryptoTests
@@ -10,5 +10,5 @@ target_link_libraries(
GTest::gtest_main crypto GTest::gtest_main crypto
) )
gtest_discover_tests(CryptoTests) gtest_discover_tests(CryptoTests DISCOVERY_TIMEOUT 600)

View File

@@ -11,32 +11,32 @@ TEST(CryptoTests, AES) {
std::string in = "hello1"; std::string in = "hello1";
auto enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e"); auto enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e");
auto dec = AES::decrypt(enc, "p1", "e"); auto dec = AES::decrypt(enc, "p1", "e");
EXPECT_EQ(in, std::string(dec.begin(), dec.end())); ASSERT_EQ(in, std::string(dec.begin(), dec.end()));
in = ""; in = "";
enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e"); enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e");
dec = AES::decrypt(enc, "p1", "e"); dec = AES::decrypt(enc, "p1", "e");
EXPECT_EQ(in, std::string(dec.begin(), dec.end())); ASSERT_EQ(in, std::string(dec.begin(), dec.end()));
in = "1234567890asdfg"; in = "1234567890asdfg";
enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e"); enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e");
dec = AES::decrypt(enc, "p1", "e"); dec = AES::decrypt(enc, "p1", "e");
EXPECT_EQ(in, std::string(dec.begin(), dec.end())); ASSERT_EQ(in, std::string(dec.begin(), dec.end()));
in = "1234567890asdfgh"; in = "1234567890asdfgh";
enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e"); enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e");
dec = AES::decrypt(enc, "p1", "e"); dec = AES::decrypt(enc, "p1", "e");
EXPECT_EQ(in, std::string(dec.begin(), dec.end())); ASSERT_EQ(in, std::string(dec.begin(), dec.end()));
in = "1234567890asdfghe"; in = "1234567890asdfghe";
enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e"); enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e");
dec = AES::decrypt(enc, "p1", "e"); dec = AES::decrypt(enc, "p1", "e");
EXPECT_EQ(in, std::string(dec.begin(), dec.end())); ASSERT_EQ(in, std::string(dec.begin(), dec.end()));
in = "1234567890asdfgheq"; in = "1234567890asdfgheq";
enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e"); enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "p1", "e");
dec = AES::decrypt(enc, "p1", "e"); dec = AES::decrypt(enc, "p1", "e");
EXPECT_EQ(in, std::string(dec.begin(), dec.end())); ASSERT_EQ(in, std::string(dec.begin(), dec.end()));
} }
TEST(CryptoTests, SHA) { TEST(CryptoTests, SHA) {
@@ -47,6 +47,6 @@ TEST(CryptoTests, SHA) {
auto out = SHA::calculate(data); auto out = SHA::calculate(data);
EXPECT_EQ(out.size(), 32); ASSERT_EQ(out.size(), 32);
for (int i = 0; i < out.size(); i++) { EXPECT_EQ(static_cast<uint8_t>(out[i]), excepted[i]); } for (int i = 0; i < out.size(); i++) { ASSERT_EQ(static_cast<uint8_t>(out[i]), excepted[i]); }
} }

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
add_executable( add_executable(
FullTest FullTest
@@ -10,5 +10,5 @@ target_link_libraries(
GTest::gtest_main commands utils testUtils repo GTest::gtest_main commands utils testUtils repo
) )
gtest_discover_tests(FullTest) gtest_discover_tests(FullTest DISCOVERY_TIMEOUT 600)

View File

@@ -61,7 +61,7 @@ TEST(FullTest, Simple) {
} }
{ {
try { try {
EXPECT_EQ(std::filesystem::is_directory("Simple/testtores/testdir"), true); ASSERT_EQ(std::filesystem::is_directory("Simple/testtores/testdir"), true);
} catch (...) { } catch (...) {
std::cerr << "Empty directory doesn't exist!" << std::endl; std::cerr << "Empty directory doesn't exist!" << std::endl;
throw; throw;
@@ -71,11 +71,11 @@ TEST(FullTest, Simple) {
std::ifstream o(std::filesystem::path("Simple/testtores") / ("f" + std::to_string(i)), std::ifstream o(std::filesystem::path("Simple/testtores") / ("f" + std::to_string(i)),
std::ios::binary | std::ios::in); std::ios::binary | std::ios::in);
try { try {
EXPECT_EQ(o.is_open(), true); ASSERT_EQ(o.is_open(), true);
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
char c; char c;
EXPECT_EQ(o.get(c).operator bool(), true); ASSERT_EQ(o.get(c).operator bool(), true);
EXPECT_EQ(static_cast<char>(j % 256), c); ASSERT_EQ(static_cast<char>(j % 256), c);
} }
} catch (...) { } catch (...) {
std::cerr << "Error comparing file " << i << std::endl; std::cerr << "Error comparing file " << i << std::endl;
@@ -150,16 +150,16 @@ TEST(FullTest, SimpleWithIgnore) {
cmd.run(Context{&logger, repo.get()}); cmd.run(Context{&logger, repo.get()});
} }
{ {
EXPECT_EQ(std::filesystem::is_directory("SimpleWithIgnore/testtores/testdir"), true); ASSERT_EQ(std::filesystem::is_directory("SimpleWithIgnore/testtores/testdir"), true);
for (int i = 0; i < 257; i++) { for (int i = 0; i < 257; i++) {
std::ifstream o(std::filesystem::path("SimpleWithIgnore/testtores") / ("f" + std::to_string(i)), std::ifstream o(std::filesystem::path("SimpleWithIgnore/testtores") / ("f" + std::to_string(i)),
std::ios::binary | std::ios::in); std::ios::binary | std::ios::in);
EXPECT_EQ(o.is_open(), true); ASSERT_EQ(o.is_open(), true);
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
char c; char c;
EXPECT_EQ(o.get(c).operator bool(), true); ASSERT_EQ(o.get(c).operator bool(), true);
EXPECT_EQ(static_cast<char>(j % 256), c); ASSERT_EQ(static_cast<char>(j % 256), c);
} }
} }
@@ -167,31 +167,31 @@ TEST(FullTest, SimpleWithIgnore) {
std::ifstream file("SimpleWithIgnore/testtores/testdir2/.ignore"); std::ifstream file("SimpleWithIgnore/testtores/testdir2/.ignore");
std::string s; std::string s;
file >> s; file >> s;
EXPECT_EQ(s, "hello.txt"); ASSERT_EQ(s, "hello.txt");
} }
{ {
std::ifstream file("SimpleWithIgnore/testtores/testdir2/testdir3/.ignore"); std::ifstream file("SimpleWithIgnore/testtores/testdir2/testdir3/.ignore");
std::string s; std::string s;
file >> s; file >> s;
EXPECT_EQ(s, ".*\\.txt"); ASSERT_EQ(s, ".*\\.txt");
} }
{ {
std::ifstream file("SimpleWithIgnore/testtores/testdir2/hello.txt"); std::ifstream file("SimpleWithIgnore/testtores/testdir2/hello.txt");
EXPECT_EQ(!file, true); ASSERT_EQ(!file, true);
} }
{ {
std::ifstream file("SimpleWithIgnore/testtores/testdir2/testdir3/hello.txt"); std::ifstream file("SimpleWithIgnore/testtores/testdir2/testdir3/hello.txt");
EXPECT_EQ(!file, true); ASSERT_EQ(!file, true);
} }
{ {
std::ifstream file("SimpleWithIgnore/testtores/testdir2/testdir3/asdf.txt"); std::ifstream file("SimpleWithIgnore/testtores/testdir2/testdir3/asdf.txt");
EXPECT_EQ(!file, true); ASSERT_EQ(!file, true);
} }
{ {
std::ifstream file("SimpleWithIgnore/testtores/testdir2/testdir4/asdf.txt"); std::ifstream file("SimpleWithIgnore/testtores/testdir2/testdir4/asdf.txt");
std::string s; std::string s;
file >> s; file >> s;
EXPECT_EQ(s, "asdf2"); ASSERT_EQ(s, "asdf2");
} }
} }
} }
@@ -237,16 +237,16 @@ TEST(FullTest, SimpleWithCompress) {
cmd.run(Context{&logger, repo.get()}); cmd.run(Context{&logger, repo.get()});
} }
{ {
EXPECT_EQ(std::filesystem::is_directory("SimpleWithCompress/testtores/testdir"), true); ASSERT_EQ(std::filesystem::is_directory("SimpleWithCompress/testtores/testdir"), true);
for (int i = 0; i < 257; i++) { for (int i = 0; i < 257; i++) {
std::ifstream o(std::filesystem::path("SimpleWithCompress/testtores") / ("f" + std::to_string(i)), std::ifstream o(std::filesystem::path("SimpleWithCompress/testtores") / ("f" + std::to_string(i)),
std::ios::binary | std::ios::in); std::ios::binary | std::ios::in);
EXPECT_EQ(o.is_open(), true); ASSERT_EQ(o.is_open(), true);
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
char c; char c;
EXPECT_EQ(o.get(c).operator bool(), true); ASSERT_EQ(o.get(c).operator bool(), true);
EXPECT_EQ(static_cast<char>(j % 256), c); ASSERT_EQ(static_cast<char>(j % 256), c);
} }
} }
} }
@@ -290,10 +290,10 @@ TEST(FullTest, SimpleWithCompEnd) {
bool ok = true; bool ok = true;
try { try {
EXPECT_EQ(repo->open(), false); ASSERT_EQ(repo->open(), false);
ok = false; ok = false;
} catch (...) {} } catch (...) {}
EXPECT_EQ(ok, true); ASSERT_EQ(ok, true);
} }
{ {
Config conf; Config conf;
@@ -312,16 +312,16 @@ TEST(FullTest, SimpleWithCompEnd) {
cmd.run(Context{&logger, repo.get()}); cmd.run(Context{&logger, repo.get()});
} }
{ {
EXPECT_EQ(std::filesystem::is_directory("SimpleWithCompEnd/testtores/testdir"), true); ASSERT_EQ(std::filesystem::is_directory("SimpleWithCompEnd/testtores/testdir"), true);
for (int i = 0; i < 257; i++) { for (int i = 0; i < 257; i++) {
std::ifstream o(std::filesystem::path("SimpleWithCompEnd/testtores") / ("f" + std::to_string(i)), std::ifstream o(std::filesystem::path("SimpleWithCompEnd/testtores") / ("f" + std::to_string(i)),
std::ios::binary | std::ios::in); std::ios::binary | std::ios::in);
EXPECT_EQ(o.is_open(), true); ASSERT_EQ(o.is_open(), true);
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
char c; char c;
EXPECT_EQ(o.get(c).operator bool(), true); ASSERT_EQ(o.get(c).operator bool(), true);
EXPECT_EQ(static_cast<char>(j % 256), c); ASSERT_EQ(static_cast<char>(j % 256), c);
} }
} }
} }
@@ -440,7 +440,7 @@ TEST(FullTest, Fuzz) {
auto outstr = runnerout.str(); auto outstr = runnerout.str();
if (outstr.find("Error") == std::string::npos) ok = false; if (outstr.find("Error") == std::string::npos) ok = false;
} catch (...) {} } catch (...) {}
EXPECT_EQ(ok, true); ASSERT_EQ(ok, true);
} }
} }
} }

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
add_executable( add_executable(
FileRepositoryTest FileRepositoryTest
@@ -20,5 +20,5 @@ target_link_libraries(
GTest::gtest_main commands utils testUtils repo GTest::gtest_main commands utils testUtils repo
) )
gtest_discover_tests(ChunkTest) gtest_discover_tests(ChunkTest DISCOVERY_TIMEOUT 600)
gtest_discover_tests(FileRepositoryTest) gtest_discover_tests(FileRepositoryTest DISCOVERY_TIMEOUT 600)

View File

@@ -29,18 +29,18 @@ TEST(Chunk, Deserialize) {
std::vector<char> data2{'q', 'w', 'e', 'r', 'b'}; std::vector<char> data2{'q', 'w', 'e', 'r', 'b'};
Chunk o2e(777, {1}, data2); Chunk o2e(777, {1}, data2);
EXPECT_EQ(o1.id, o1e.id); ASSERT_EQ(o1.id, o1e.id);
EXPECT_EQ(o2.id, o2e.id); ASSERT_EQ(o2.id, o2e.id);
EXPECT_EQ((int) o1.type, (int) o1e.type); ASSERT_EQ((int) o1.type, (int) o1e.type);
EXPECT_EQ((int) o2.type, (int) o2e.type); ASSERT_EQ((int) o2.type, (int) o2e.type);
EXPECT_EQ(o1.data.size(), o1e.data.size()); ASSERT_EQ(o1.data.size(), o1e.data.size());
EXPECT_EQ(o2.data.size(), o2e.data.size()); ASSERT_EQ(o2.data.size(), o2e.data.size());
for (int i = 0; i < o1.data.size(); i++) { EXPECT_EQ(o1.data[i], o1e.data[i]); } for (int i = 0; i < o1.data.size(); i++) { ASSERT_EQ(o1.data[i], o1e.data[i]); }
for (int i = 0; i < o2.data.size(); i++) { EXPECT_EQ(o2.data[i], o2e.data[i]); } for (int i = 0; i < o2.data.size(); i++) { ASSERT_EQ(o2.data[i], o2e.data[i]); }
for (int i = 0; i < o1.SHA.size(); i++) { EXPECT_EQ(o1.SHA[i], o1e.SHA[i]); } for (int i = 0; i < o1.SHA.size(); i++) { ASSERT_EQ(o1.SHA[i], o1e.SHA[i]); }
for (int i = 0; i < o2.SHA.size(); i++) { EXPECT_EQ(o2.SHA[i], o2e.SHA[i]); } for (int i = 0; i < o2.SHA.size(); i++) { ASSERT_EQ(o2.SHA[i], o2e.SHA[i]); }
} }
} }

View File

@@ -32,8 +32,8 @@ TEST(FileRepository, Deserialize) {
repo.putObject(o2); repo.putObject(o2);
EXPECT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o1k), 666); ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o1k), 666);
EXPECT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 777); ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 777);
} }
{ {
Config conf; Config conf;
@@ -45,8 +45,8 @@ TEST(FileRepository, Deserialize) {
std::string o2k(16, '\0'); std::string o2k(16, '\0');
o2k[0] = 1; o2k[0] = 1;
o2k[1] = 2; o2k[1] = 2;
EXPECT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o1k), 666); ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o1k), 666);
EXPECT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 777); ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 777);
auto o1o = repo.getObject(666); auto o1o = repo.getObject(666);
auto o2o = repo.getObject(777); auto o2o = repo.getObject(777);
@@ -61,18 +61,18 @@ TEST(FileRepository, Deserialize) {
std::vector<char> data2{'q', 'w', 'e', 'r', static_cast<char>(255)}; std::vector<char> data2{'q', 'w', 'e', 'r', static_cast<char>(255)};
Chunk o2e(777, o2k, data2); Chunk o2e(777, o2k, data2);
EXPECT_EQ(o1.id, o1e.id); ASSERT_EQ(o1.id, o1e.id);
EXPECT_EQ(o2.id, o2e.id); ASSERT_EQ(o2.id, o2e.id);
EXPECT_EQ((int) o1.type, (int) o1e.type); ASSERT_EQ((int) o1.type, (int) o1e.type);
EXPECT_EQ((int) o2.type, (int) o2e.type); ASSERT_EQ((int) o2.type, (int) o2e.type);
auto o1d = o1.data; auto o1d = o1.data;
auto o1ed = o1e.data; auto o1ed = o1e.data;
auto o2d = o2.data; auto o2d = o2.data;
auto o2ed = o2e.data; auto o2ed = o2e.data;
EXPECT_EQ(o1.data.size(), o1e.data.size()); ASSERT_EQ(o1.data.size(), o1e.data.size());
EXPECT_EQ(o2.data.size(), o2e.data.size()); ASSERT_EQ(o2.data.size(), o2e.data.size());
for (int i = 0; i < o1.data.size(); i++) { EXPECT_EQ(o1.data[i], o1e.data[i]); } for (int i = 0; i < o1.data.size(); i++) { ASSERT_EQ(o1.data[i], o1e.data[i]); }
for (int i = 0; i < o2.data.size(); i++) { EXPECT_EQ(o2.data[i], o2e.data[i]); } for (int i = 0; i < o2.data.size(); i++) { ASSERT_EQ(o2.data[i], o2e.data[i]); }
} }
} }
@@ -103,8 +103,8 @@ TEST(FileRepository, Filters) {
repo.putObject(o2); repo.putObject(o2);
EXPECT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o1k), 666); ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o1k), 666);
EXPECT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 777); ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 777);
} }
{ {
Config conf; Config conf;
@@ -160,8 +160,8 @@ TEST(FileRepository, Filters) {
std::string o2k(16, '\0'); std::string o2k(16, '\0');
o2k[0] = 1; o2k[0] = 1;
o2k[1] = 2; o2k[1] = 2;
EXPECT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o1k), 666); ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o1k), 666);
EXPECT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 777); ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 777);
auto o1o = repo.getObject(666); auto o1o = repo.getObject(666);
auto o2o = repo.getObject(777); auto o2o = repo.getObject(777);
@@ -176,18 +176,18 @@ TEST(FileRepository, Filters) {
std::vector<char> data2{'q', 'w', 'e', 'r', 'b'}; std::vector<char> data2{'q', 'w', 'e', 'r', 'b'};
Chunk o2e(777, o2k, data2); Chunk o2e(777, o2k, data2);
EXPECT_EQ(o1.id, o1e.id); ASSERT_EQ(o1.id, o1e.id);
EXPECT_EQ(o2.id, o2e.id); ASSERT_EQ(o2.id, o2e.id);
EXPECT_EQ((int) o1.type, (int) o1e.type); ASSERT_EQ((int) o1.type, (int) o1e.type);
EXPECT_EQ((int) o2.type, (int) o2e.type); ASSERT_EQ((int) o2.type, (int) o2e.type);
auto o1d = o1.data; auto o1d = o1.data;
auto o1ed = o1e.data; auto o1ed = o1e.data;
auto o2d = o2.data; auto o2d = o2.data;
auto o2ed = o2e.data; auto o2ed = o2e.data;
EXPECT_EQ(o1.data.size(), o1e.data.size()); ASSERT_EQ(o1.data.size(), o1e.data.size());
EXPECT_EQ(o2.data.size(), o2e.data.size()); ASSERT_EQ(o2.data.size(), o2e.data.size());
for (int i = 0; i < o1.data.size(); i++) { EXPECT_EQ(o1.data[i], o1e.data[i]); } for (int i = 0; i < o1.data.size(); i++) { ASSERT_EQ(o1.data[i], o1e.data[i]); }
for (int i = 0; i < o2.data.size(); i++) { EXPECT_EQ(o2.data[i], o2e.data[i]); } for (int i = 0; i < o2.data.size(); i++) { ASSERT_EQ(o2.data[i], o2e.data[i]); }
} }
} }
@@ -209,15 +209,15 @@ TEST(FileRepository, IDsDisabled) {
std::vector<char> data2{'q', 'w', 'e', 'r', 'b'}; std::vector<char> data2{'q', 'w', 'e', 'r', 'b'};
Chunk o2(repo.getId(), o2k, data2); Chunk o2(repo.getId(), o2k, data2);
EXPECT_EQ(o1.id, 1); ASSERT_EQ(o1.id, 1);
EXPECT_EQ(o2.id, 2); ASSERT_EQ(o2.id, 2);
repo.putObject(o1); repo.putObject(o1);
repo.putObject(o2); repo.putObject(o2);
EXPECT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o1k), 1); ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o1k), 1);
EXPECT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 2); ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 2);
} }
{ {
Config conf; Config conf;
@@ -239,22 +239,22 @@ TEST(FileRepository, IDsDisabled) {
std::vector<char> data2{'q', 'w', 'e', 'r', 'b'}; std::vector<char> data2{'q', 'w', 'e', 'r', 'b'};
Chunk o2e(2, o2k, data2); Chunk o2e(2, o2k, data2);
EXPECT_EQ(o1.id, o1e.id); ASSERT_EQ(o1.id, o1e.id);
EXPECT_EQ(o2.id, o2e.id); ASSERT_EQ(o2.id, o2e.id);
EXPECT_EQ((int) o1.type, (int) o1e.type); ASSERT_EQ((int) o1.type, (int) o1e.type);
EXPECT_EQ((int) o2.type, (int) o2e.type); ASSERT_EQ((int) o2.type, (int) o2e.type);
auto o1d = o1.data; auto o1d = o1.data;
auto o1ed = o1e.data; auto o1ed = o1e.data;
auto o2d = o2.data; auto o2d = o2.data;
auto o2ed = o2e.data; auto o2ed = o2e.data;
EXPECT_EQ(o1.data.size(), o1e.data.size()); ASSERT_EQ(o1.data.size(), o1e.data.size());
EXPECT_EQ(o2.data.size(), o2e.data.size()); ASSERT_EQ(o2.data.size(), o2e.data.size());
for (int i = 0; i < o1.data.size(); i++) { EXPECT_EQ(o1.data[i], o1e.data[i]); } for (int i = 0; i < o1.data.size(); i++) { ASSERT_EQ(o1.data[i], o1e.data[i]); }
for (int i = 0; i < o2.data.size(); i++) { EXPECT_EQ(o2.data[i], o2e.data[i]); } for (int i = 0; i < o2.data.size(); i++) { ASSERT_EQ(o2.data[i], o2e.data[i]); }
EXPECT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o1k), 1); ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o1k), 1);
EXPECT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 2); ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 2);
repo.deleteObject(o1); repo.deleteObject(o1);
@@ -267,12 +267,12 @@ TEST(FileRepository, IDsDisabled) {
std::string o2k(16, '\0'); std::string o2k(16, '\0');
o2k[0] = 1; o2k[0] = 1;
EXPECT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 2); ASSERT_EQ(repo.getObjectId(Object::ObjectType::Chunk, o2k), 2);
auto id = repo.getId(); auto id = repo.getId();
EXPECT_EQ(id, 1); ASSERT_EQ(id, 1);
std::vector<char> data1{'a', 'b', 'c', 'e'}; std::vector<char> data1{'a', 'b', 'c', 'e'};
Chunk o1(id, o2k, data1); Chunk o1(id, o2k, data1);
EXPECT_EQ(repo.getId(), 3); ASSERT_EQ(repo.getId(), 3);
} }
} }

View File

@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.18)
add_library(testUtils srcs/Cleaner.cpp) add_library(testUtils srcs/Cleaner.cpp)