Compare commits

..

4 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
19 changed files with 157 additions and 145 deletions

View File

@@ -19,11 +19,18 @@ jobs:
runs-on: ubuntu-latest
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
run: sudo apt-get update && sudo apt-get install -y fuse libfuse-dev cmake build-essential gcc g++ libssl-dev zlib1g-dev

7
.idea/misc.xml generated
View File

@@ -1,4 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<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>

View File

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

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); }) {}
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)),
contents([p, path = this->path, type = this->type]() -> std::unique_ptr<std::streambuf> {
if (type == File::Type::Normal) {
auto fb = std::make_unique<std::filebuf>();
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;
}

View File

@@ -43,7 +43,7 @@ void CommandDiff::run(Context ctx) {
std::map<std::filesystem::path, File> files;///< Files in the first archive
for (auto id: archiveO1.files) {
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));
}
@@ -83,7 +83,7 @@ void CommandDiff::run(Context ctx) {
/// Exit when asked to
if (Signals::shouldQuit) throw Exception("Quitting");
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}); });
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
for (auto id: archiveO2->files) {
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))
files2.emplace(file.getKey(), std::move(file));
}
@@ -144,5 +144,5 @@ void CommandDiff::run(Context ctx) {
std::unique_lock finishedLock(threadPool.finishedLock);
threadPool.finished.wait(finishedLock, [&threadPool] { return threadPool.empty(); });
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) {
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> bytesToRestore = 0;
@@ -95,21 +95,21 @@ void CommandRestore::run(Context ctx) {
std::string CommandRestore::backupRestoreFile(const File &file, const std::filesystem::path &baseDir,
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());
if (file.fileType == File::Type::Directory) {
std::filesystem::create_directory(fullpath);
callback(0, 0, 1);
return fullpath.u8string();
return fullpath.string();
}
if (file.fileType == File::Type::Symlink) {
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);
callback(0, 0, 1);
return fullpath.u8string();
return fullpath.string();
}
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);
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;
runnerStats.filesToSaveCount++;
threadPool.push([&, relPath, absPath]() {
addFile(backupChunkFile(absPath, relPath.u8string(), workerCallback, ctx));
progress.print("Copied: " + relPath.u8string(), 1);
addFile(backupChunkFile(absPath, relPath.string(), workerCallback, ctx));
progress.print("Copied: " + relPath.string(), 1);
});
};
/// Task to process an individual file in the backup
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) {
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);
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);
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());
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
if (Signals::shouldQuit) throw Exception("Quitting!");
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::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) {
if (prefix.u8string().size() > p.u8string().size()) return false;
for (int i = 0; i < prefix.u8string().size(); i++)
if (p.u8string()[i] != prefix.u8string()[i]) return false;
if (prefix.string().size() > p.string().size()) return false;
for (int i = 0; i < prefix.string().size(); i++)
if (p.string()[i] != prefix.string()[i]) return false;
return true;
}
void CommandsCommon::processDirWithIgnore(const std::filesystem::path &dir, std::vector<std::string> ignore,
const std::function<void(std::function<void()>)> &spawner,
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
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
if (std::any_of(ignore.begin(), ignore.end(), [dirEntry](auto pred) {
std::smatch m;
auto s = dirEntry.path().filename().u8string();
auto s = dirEntry.path().filename().string();
return std::regex_match(s, m, std::regex(pred));
}))
continue;

View File

@@ -15,7 +15,7 @@
#include "objects/Chunk.h"
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();
if (p != ".")
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));
for (auto const &f: a.files) {
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()
? root->children[std::to_string(a.id)].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->file.emplace(file);
entry->name = std::filesystem::u8path(file.name).filename().u8string();
entry->name = std::filesystem::path(file.name).filename().string();
}
}

View File

@@ -58,7 +58,7 @@ bool FileRepository::init() {
if (exists()) throw Exception("Trying to initialize already existing repository!");
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)));
@@ -157,23 +157,23 @@ bool FileRepository::deleteObject(const Object &obj) {
std::vector<char> FileRepository::readFile(const std::filesystem::path &file, unsigned long long offset,
unsigned long long size) const {
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");
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);
if (ifstream.rdbuf()->pubseekpos(offset) == std::streampos(std::streamoff(-1)))
throw Exception("Unexpected end of file " + file.u8string());
if (ifstream.rdbuf()->sgetn(buf.data(), size) != size) 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.string());
return buf;
}
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);
if (fileSize == 0) return {};
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) {
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())
throw Exception("Couldn't write all the data for " + file.u8string());
throw Exception("Couldn't write all the data for " + file.string());
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_directory(p)) return Type::Directory;
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) {
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::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()};
target_null_term.emplace_back('\0');
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) {
@@ -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())
.count());
else if (type == Type::Symlink) {
auto path = p.u8string();
auto path = p.string();
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__
return sb.st_mtimespec.tv_sec;
#else
return sb.st_mtime;
#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) {

View File

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

View File

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

View File

@@ -26,11 +26,11 @@ TEST(BuzhashTest, SimpleTest) {
for (int i = 0; i < loremipsum.length(); i++) {
b2.feed((uint8_t) loremipsum[i]);
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;
break;
}
}
EXPECT_EQ(h1found, true);
ASSERT_EQ(h1found, true);
}
}

View File

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

View File

@@ -11,32 +11,32 @@ TEST(CryptoTests, AES) {
std::string in = "hello1";
auto enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "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 = "";
enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "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";
enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "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";
enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "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";
enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "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";
enc = AES::encrypt(std::vector<char>(in.begin(), in.end()), "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) {
@@ -47,6 +47,6 @@ TEST(CryptoTests, SHA) {
auto out = SHA::calculate(data);
EXPECT_EQ(out.size(), 32);
for (int i = 0; i < out.size(); i++) { EXPECT_EQ(static_cast<uint8_t>(out[i]), excepted[i]); }
ASSERT_EQ(out.size(), 32);
for (int i = 0; i < out.size(); i++) { ASSERT_EQ(static_cast<uint8_t>(out[i]), excepted[i]); }
}

View File

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

View File

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

View File

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