#include "gtest/gtest.h" #include "io.h" #include "test.h" TEST(IoTests, FsPlainInput) { EXPECT_THROW(horcrux::FsPlainInput input{noexist}, std::invalid_argument); EXPECT_THROW(horcrux::FsPlainInput input{folder}, std::invalid_argument); EXPECT_THROW(horcrux::FsPlainInput input{empty}, std::invalid_argument); EXPECT_NO_THROW(horcrux::FsPlainInput input{text}); EXPECT_NO_THROW(horcrux::FsPlainInput input{image}); } TEST(IoTests, FsPlainInputReadText) { auto input = horcrux::FsPlainInput{text}; auto buf = generic_read_file(text); EXPECT_EQ(buf, input.read()); } TEST(IoTests, FsPlainInputReadImg) { auto input = horcrux::FsPlainInput{image}; auto buf = generic_read_file(image); EXPECT_EQ(buf, input.read()); } TEST(IoTests, FsCryptoOutput) { EXPECT_THROW(horcrux::FsCryptoOutput output(noexist, 1), std::invalid_argument); EXPECT_NO_THROW(horcrux::FsCryptoOutput output(folder, 1)); EXPECT_THROW(horcrux::FsCryptoOutput output(folder, 0), std::invalid_argument); EXPECT_THROW(horcrux::FsCryptoOutput output(empty, 1), std::invalid_argument); EXPECT_THROW(horcrux::FsCryptoOutput output(text, 1), std::invalid_argument); EXPECT_THROW(horcrux::FsCryptoOutput output(image, 1), std::invalid_argument); } TEST(IoTests, FsCryptoOutputWriteImage){ auto ifstream = std::ifstream{image, std::ios::binary}; auto buf = generic_read_file(image); horcrux::FsCryptoOutput out(folder, 10); auto written = out.write(buf); EXPECT_EQ(written, buf.size()); EXPECT_EQ(10, out.created_files.size()); delete_created_files(out); } TEST(IoTests, FsCryptoOutputWriteText){ auto buf = generic_read_file(text); horcrux::FsCryptoOutput out(folder, 2); auto written = out.write(buf); EXPECT_EQ(written, buf.size()); EXPECT_EQ(2, out.created_files.size()); delete_created_files(out); } TEST(IoTest, FsCryptoInput){ EXPECT_THROW(horcrux::FsCryptoInput output({noexist, text, image}), std::invalid_argument); EXPECT_THROW(horcrux::FsCryptoInput output({folder, text, image}), std::invalid_argument); EXPECT_THROW(horcrux::FsCryptoInput output(std::vector{}), std::invalid_argument); EXPECT_THROW(horcrux::FsCryptoInput output({empty}), std::invalid_argument); EXPECT_THROW(horcrux::FsCryptoInput output({empty, empty}), std::invalid_argument); EXPECT_NO_THROW(horcrux::FsCryptoInput output({empty, empty, text})); EXPECT_NO_THROW(horcrux::FsCryptoInput output({image, empty, text})); } TEST(IoTest, FsCryptoInputImage){ auto buf = generic_read_file(image); //split image using FsCryptoOutput auto out = horcrux::FsCryptoOutput(folder, 7); auto written = out.write(buf); EXPECT_EQ(written, buf.size()); auto files = get_created_filenames(out); auto in = horcrux::FsCryptoInput(files); auto read = in.read(); EXPECT_EQ(read, buf); files.push_back(text); in = horcrux::FsCryptoInput(files); read = in.read(); EXPECT_NE(read, buf); delete_created_files(out); } TEST(IoTest, FsPlainOuput){ EXPECT_NO_THROW(horcrux::FsPlainOutput output{noexist}); EXPECT_THROW(horcrux::FsPlainOutput output{folder}, std::invalid_argument); EXPECT_NO_THROW(horcrux::FsPlainOutput output{empty}); EXPECT_NO_THROW(horcrux::FsPlainOutput output{text}); EXPECT_NO_THROW(horcrux::FsPlainOutput output{image}); } TEST(IoTest, FsPlainOutputWrite){ auto buf = generic_read_file(image); auto out = horcrux::FsPlainOutput(noexist); auto written = out.write(buf); EXPECT_EQ(written, buf.size()); auto buf2 = generic_read_file(noexist); EXPECT_EQ(buf, buf2); std::filesystem::remove(noexist); } TEST(IoTest, PlainToPlain){ auto buf = generic_read_file(image); auto in = horcrux::FsPlainInput(image); auto out = horcrux::FsPlainOutput(noexist); //Execute Plain To Plain out.write(in.read()); //Check outcome auto buf2 = generic_read_file(noexist); EXPECT_EQ(buf, buf2); std::filesystem::remove(noexist); } TEST(IoTest, PlainToCrypto){ auto buf = generic_read_file(image); auto in = horcrux::FsPlainInput(image); auto out = horcrux::FsCryptoOutput(folder, 5); //Execute Plain to Crypto out.write(in.read()); //use FsCryptoInput to re-join the files and check the outcome auto files = get_created_filenames(out); auto in_test = horcrux::FsCryptoInput(files); auto buf2 = in_test.read(); EXPECT_EQ(buf, buf2); delete_created_files(out); } TEST(IoTest, CryptoToCrypto){ auto buf = generic_read_file(image); // First use FsCryptoOutput to split the files auto out_test = horcrux::FsCryptoOutput(folder, 8); out_test.write(buf); //use FsCryptoInput to re-join the files auto files = get_created_filenames(out_test); auto in = horcrux::FsCryptoInput(files); auto out = horcrux::FsCryptoOutput(folder, 5, "test"); //Execute Crypto to Crypto out.write(in.read()); //use FsCryptoInput to re-join the files and check the outcome files = get_created_filenames(out); auto in_test = horcrux::FsCryptoInput(files); auto buf2 = in_test.read(); EXPECT_EQ(buf, buf2); delete_created_files(out_test); delete_created_files(out); } TEST(IoTest, CryptoToPlain){ auto buf = generic_read_file(image); // First use FsCryptoOutput to split the files auto out_test = horcrux::FsCryptoOutput(folder, 8); out_test.write(buf); //use FsCryptoInput to re-join the files auto files = get_created_filenames(out_test); auto in = horcrux::FsCryptoInput(files); auto out = horcrux::FsPlainOutput(noexist); //Execute Crypto to Plain out.write(in.read()); //check the outcome auto buf2 = generic_read_file(noexist); EXPECT_EQ(buf, buf2); delete_created_files(out_test); std::filesystem::remove(noexist); }