horcrux/test/main.cpp

44 lines
1.5 KiB
C++
Raw Permalink Normal View History

2020-12-12 21:19:10 +00:00
#include "test.h"
2020-12-12 23:56:18 +00:00
#include "gtest/gtest.h"
2020-12-12 21:19:10 +00:00
/* Utility functions */
2020-12-13 23:56:07 +00:00
horcrux::raw_data generic_read_file(const std::string& filename) {
2020-12-12 23:56:18 +00:00
auto ifstream = std::ifstream{filename, std::ios::binary};
auto path = std::filesystem::path{filename};
auto size = std::filesystem::file_size(path);
2020-12-13 23:56:07 +00:00
horcrux::raw_data buf(size);
2020-12-12 23:56:18 +00:00
ifstream.read(reinterpret_cast<char*>(buf.data()), size);
return buf;
2020-12-12 21:19:10 +00:00
}
2020-12-12 23:56:18 +00:00
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;
2020-12-12 21:19:10 +00:00
}
2020-12-12 23:56:18 +00:00
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); } );
2020-12-12 21:19:10 +00:00
}
2020-12-12 23:56:18 +00:00
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;
2020-12-12 21:19:10 +00:00
}
2020-12-11 11:38:02 +00:00
int main(int argc, char *argv[]) {
2020-12-12 23:56:18 +00:00
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
2020-12-11 11:38:02 +00:00
}