#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(buf.data()), size); return buf; } std::vector get_created_filenames( const horcrux::FsCryptoOutput& out) { std::vector 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 get_encrypted_files(const std::string& folder, const std::string& basename) { std::vector 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; } void check_files_status(){ const std::filesystem::path p_folder{folder}; const std::filesystem::path p_noexist{noexist}; const std::filesystem::path p_empty{empty}; const std::filesystem::path p_text{text}; const std::filesystem::path p_image{image}; EXPECT_EQ(false, std::filesystem::exists(p_noexist)); EXPECT_EQ(0, std::filesystem::file_size(p_empty)); EXPECT_EQ(1388, std::filesystem::file_size(p_text)); EXPECT_EQ(124106, std::filesystem::file_size(p_image)); } int main(int argc, char *argv[]) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }