From 7a18c816b6a5fb94e0a34cb8543baf0a88848ee5 Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Sun, 22 Jan 2017 14:54:07 -0500 Subject: [PATCH] re-enable round-trip tests, continue condensing test files --- source/detail/xlsx_producer.cpp | 8 +-- source/workbook/tests/test_consume_xlsx.hpp | 4 +- source/workbook/tests/test_produce_xlsx.hpp | 26 +++++--- source/workbook/tests/test_round_trip.hpp | 71 ++++++--------------- tests/helpers/xml_helper.hpp | 2 +- 5 files changed, 43 insertions(+), 68 deletions(-) diff --git a/source/detail/xlsx_producer.cpp b/source/detail/xlsx_producer.cpp index e4b5d877..22317b07 100644 --- a/source/detail/xlsx_producer.cpp +++ b/source/detail/xlsx_producer.cpp @@ -294,14 +294,12 @@ void xlsx_producer::write_property(const std::string &name, const variant &value } if (vector_element.value_type() == variant::type::lpstr) - { + { write_element(constants::ns("vt"), "lpstr", vector_element.get()); - break; - } + } else if (vector_element.value_type() == variant::type::i4) - { + { write_element(constants::ns("vt"), "i4", vector_element.get()); - break; } if (is_mixed) diff --git a/source/workbook/tests/test_consume_xlsx.hpp b/source/workbook/tests/test_consume_xlsx.hpp index e2e464c1..c18c13bb 100644 --- a/source/workbook/tests/test_consume_xlsx.hpp +++ b/source/workbook/tests/test_consume_xlsx.hpp @@ -126,7 +126,7 @@ public: void test_read_headers_and_footers() { xlnt::workbook wb; - wb.load(path_helper::data_directory("18_headers_and_footers.xlsx")); + wb.load(path_helper::data_directory("11_print_settings.xlsx")); auto ws = wb.active_sheet(); TS_ASSERT_EQUALS(ws.cell("A1").value(), "header"); @@ -158,7 +158,7 @@ public: void test_read_custom_properties() { xlnt::workbook wb; - wb.load(path_helper::data_directory("21_custom_properties.xlsx")); + wb.load(path_helper::data_directory("12_advanced_properties.xlsx")); TS_ASSERT(wb.has_custom_property("Client")); TS_ASSERT_EQUALS(wb.custom_property("Client").get(), "me!"); } diff --git a/source/workbook/tests/test_produce_xlsx.hpp b/source/workbook/tests/test_produce_xlsx.hpp index 84d67175..b2373a93 100644 --- a/source/workbook/tests/test_produce_xlsx.hpp +++ b/source/workbook/tests/test_produce_xlsx.hpp @@ -31,8 +31,9 @@ public: void test_produce_empty() { - xlnt::workbook wb = xlnt::workbook::empty(); - TS_ASSERT(workbook_matches_file(wb, path_helper::data_directory("9_default-excel.xlsx"))); + xlnt::workbook wb; + const auto path = path_helper::data_directory("3_default.xlsx"); + TS_ASSERT(workbook_matches_file(wb, path)); } void test_produce_simple_excel() @@ -152,17 +153,26 @@ public: sheet2.cell("A2").value("Sheet2!A2"); sheet2.cell("A2").comment("Sheet2 comment2", comment_font, "Microsoft Office User"); - TS_ASSERT(workbook_matches_file(wb, path_helper::data_directory("15_basic_comments.xlsx"))); + const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx"); + TS_ASSERT(workbook_matches_file(wb, path)); } void test_save_after_clear_all_formulae() { xlnt::workbook wb; - wb.load(path_helper::data_directory("22_formulae.xlsx")); - auto ws = wb.active_sheet(); - TS_ASSERT(ws.cell("A1").has_formula()); - TS_ASSERT_EQUALS(ws.cell("A1").formula(), "A2*A3"); - ws.cell("A1").clear_formula(); + const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx"); + wb.load(path); + + auto ws1 = wb.sheet_by_index(0); + TS_ASSERT(ws1.cell("C1").has_formula()); + TS_ASSERT_EQUALS(ws1.cell("C1").formula(), "CONCATENATE(C2,C3)"); + ws1.cell("C1").clear_formula(); + + auto ws2 = wb.sheet_by_index(1); + TS_ASSERT(ws2.cell("C1").has_formula()); + TS_ASSERT_EQUALS(ws2.cell("C1").formula(), "C2*C3"); + ws2.cell("C1").clear_formula(); + wb.save("clear_formulae.xlsx"); } }; diff --git a/source/workbook/tests/test_round_trip.hpp b/source/workbook/tests/test_round_trip.hpp index 6af33530..cb6948a2 100644 --- a/source/workbook/tests/test_round_trip.hpp +++ b/source/workbook/tests/test_round_trip.hpp @@ -12,26 +12,6 @@ class test_round_trip : public CxxTest::TestSuite { public: - /// - /// Write original to a memory as an XLSX-formatted ZIP, read it from memory back to a workbook, - /// then ensure that the resulting workbook matches the original. - /// - bool round_trip_matches_wrw(const xlnt::workbook &original) - { - std::vector original_buffer; - original.save(original_buffer); - original.save("round_trip_in.xlsx"); - - xlnt::workbook resulting_workbook; - resulting_workbook.load(original_buffer); - - std::vector resulting_buffer; - resulting_workbook.save(resulting_buffer); - resulting_workbook.save("round_trip_out.xlsx"); - - return xml_helper::xlsx_archives_match(original_buffer, resulting_buffer); - } - /// /// 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. @@ -57,39 +37,26 @@ public: return xml_helper::xlsx_archives_match(original_data, buffer); } - void test_round_trip_empty_wrw() - { - xlnt::workbook wb = xlnt::workbook::empty(); - TS_ASSERT(round_trip_matches_wrw(wb)); - } - void test_round_trip_empty_excel_rw() { - auto path = path_helper::data_directory("9_default-excel.xlsx"); - TS_ASSERT(round_trip_matches_rw(path)); + const auto files = std::vector + { + "2_minimal", + "3_default", + "4_every_style", + "5_encrypted_agile", + "6_encrypted_libre", + "7_encrypted_standard", + "8_encrypted_numbers", + "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_all_styles_rw() - { - auto path = path_helper::data_directory("10_all_styles.xlsx"); - TS_ASSERT(round_trip_matches_rw(path)); - } - - void test_round_trip_headers_footers() - { - auto path = path_helper::data_directory("18_headers_and_footers.xlsx"); - TS_ASSERT(round_trip_matches_rw(path)); - } - - void test_round_trip_row_and_col_props() - { - auto path = path_helper::data_directory("19_row_and_col_properties.xlsx"); - TS_ASSERT(round_trip_matches_rw(path)); - } - - void test_round_trip_page_breaks() - { - auto path = path_helper::data_directory("20_page_breaks.xlsx"); - TS_ASSERT(round_trip_matches_rw(path)); - } }; diff --git a/tests/helpers/xml_helper.hpp b/tests/helpers/xml_helper.hpp index 3b4d6e59..e7e64829 100644 --- a/tests/helpers/xml_helper.hpp +++ b/tests/helpers/xml_helper.hpp @@ -220,7 +220,7 @@ public: } if (!compare_files(left_archive.read(left_member), - left_archive.read(left_member), left_content_type)) + right_archive.read(left_member), left_content_type)) { std::cout << left_member.string() << std::endl; match = false;