#pragma once #include #include #include #include #include #include #include #include class test_round_trip : public CxxTest::TestSuite { public: /// /// Read file as an XLSX-formatted ZIP file in the filesystem to a workbook, /// write the workbook back to memory, then ensure that the contents of the two files are equivalent. /// bool round_trip_matches_rw(const xlnt::path &source) { xlnt::workbook source_workbook; source_workbook.load(source); std::vector destination; source_workbook.save(destination); std::ifstream source_stream(source.string(), std::ios::binary); return xml_helper::xlsx_archives_match(xlnt::detail::to_vector(source_stream), destination); } bool round_trip_matches_rw(const xlnt::path &source, const std::string &password) { xlnt::workbook source_workbook; source_workbook.load(source, password); std::vector destination; source_workbook.save(destination); std::ifstream source_stream(source.string(), std::ios::binary); const auto source_decrypted = xlnt::detail::crypto_helper::decrypt_xlsx( xlnt::detail::to_vector(source_stream), password); return xml_helper::xlsx_archives_match(source_decrypted, destination); } void test_round_trip_empty_excel_rw() { const auto files = std::vector { "2_minimal", "3_default", "4_every_style", "10_comments_hyperlinks_formulae", "11_print_settings", "12_advanced_properties" }; for (const auto file : files) { auto path = path_helper::data_directory(file + ".xlsx"); TS_ASSERT(round_trip_matches_rw(path)); } } void test_round_trip_empty_excel_rw_encrypted() { const auto files = std::vector { "5_encrypted_agile", "6_encrypted_libre", "7_encrypted_standard", "8_encrypted_numbers" }; for (const auto file : files) { auto path = path_helper::data_directory(file + ".xlsx"); TS_ASSERT(round_trip_matches_rw(path, file == "7_encrypted_standard" ? "password" : "secret")); } } };