horcrux/test/main.cpp

44 lines
1.5 KiB
C++

#include "test.h"
#include "gtest/gtest.h"
/* Utility functions */
horcrux::raw_data generic_read_file(const std::string& filename) {
auto ifstream = std::ifstream{filename, std::ios::binary};
auto path = std::filesystem::path{filename};
auto size = std::filesystem::file_size(path);
horcrux::raw_data buf(size);
ifstream.read(reinterpret_cast<char*>(buf.data()), size);
return buf;
}
std::vector<std::string> get_created_filenames(
const horcrux::FsCryptoOutput& out) {
std::vector<std::string> result(out.created_files.size());
transform(out.created_files.begin(), out.created_files.end(),
result.begin(), [](auto path) { return path.string(); } );
return result;
}
void delete_created_files(const horcrux::FsCryptoOutput& out) {
std::for_each(out.created_files.begin(), out.created_files.end(),
[](auto f) { std::filesystem::remove(f); } );
}
std::vector<std::string> get_encrypted_files(const std::string& folder,
const std::string& basename) {
std::vector<std::string> result;
for (auto& p: std::filesystem::directory_iterator(folder)) {
if (p.path().string().starts_with(basename)
&& p.path().string().ends_with(".enc")) {
result.push_back(p.path().string());
}
}
std::sort(result.begin(), result.end());
return result;
}
int main(int argc, char *argv[]) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}