mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
re-enable round-trip tests, continue condensing test files
This commit is contained in:
parent
0c100e166a
commit
7a18c816b6
|
@ -294,14 +294,12 @@ void xlsx_producer::write_property(const std::string &name, const variant &value
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vector_element.value_type() == variant::type::lpstr)
|
if (vector_element.value_type() == variant::type::lpstr)
|
||||||
{
|
{
|
||||||
write_element(constants::ns("vt"), "lpstr", vector_element.get<std::string>());
|
write_element(constants::ns("vt"), "lpstr", vector_element.get<std::string>());
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
else if (vector_element.value_type() == variant::type::i4)
|
else if (vector_element.value_type() == variant::type::i4)
|
||||||
{
|
{
|
||||||
write_element(constants::ns("vt"), "i4", vector_element.get<std::int32_t>());
|
write_element(constants::ns("vt"), "i4", vector_element.get<std::int32_t>());
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_mixed)
|
if (is_mixed)
|
||||||
|
|
|
@ -126,7 +126,7 @@ public:
|
||||||
void test_read_headers_and_footers()
|
void test_read_headers_and_footers()
|
||||||
{
|
{
|
||||||
xlnt::workbook wb;
|
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();
|
auto ws = wb.active_sheet();
|
||||||
|
|
||||||
TS_ASSERT_EQUALS(ws.cell("A1").value<std::string>(), "header");
|
TS_ASSERT_EQUALS(ws.cell("A1").value<std::string>(), "header");
|
||||||
|
@ -158,7 +158,7 @@ public:
|
||||||
void test_read_custom_properties()
|
void test_read_custom_properties()
|
||||||
{
|
{
|
||||||
xlnt::workbook wb;
|
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(wb.has_custom_property("Client"));
|
||||||
TS_ASSERT_EQUALS(wb.custom_property("Client").get<std::string>(), "me!");
|
TS_ASSERT_EQUALS(wb.custom_property("Client").get<std::string>(), "me!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,8 +31,9 @@ public:
|
||||||
|
|
||||||
void test_produce_empty()
|
void test_produce_empty()
|
||||||
{
|
{
|
||||||
xlnt::workbook wb = xlnt::workbook::empty();
|
xlnt::workbook wb;
|
||||||
TS_ASSERT(workbook_matches_file(wb, path_helper::data_directory("9_default-excel.xlsx")));
|
const auto path = path_helper::data_directory("3_default.xlsx");
|
||||||
|
TS_ASSERT(workbook_matches_file(wb, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_produce_simple_excel()
|
void test_produce_simple_excel()
|
||||||
|
@ -152,17 +153,26 @@ public:
|
||||||
sheet2.cell("A2").value("Sheet2!A2");
|
sheet2.cell("A2").value("Sheet2!A2");
|
||||||
sheet2.cell("A2").comment("Sheet2 comment2", comment_font, "Microsoft Office User");
|
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()
|
void test_save_after_clear_all_formulae()
|
||||||
{
|
{
|
||||||
xlnt::workbook wb;
|
xlnt::workbook wb;
|
||||||
wb.load(path_helper::data_directory("22_formulae.xlsx"));
|
const auto path = path_helper::data_directory("10_comments_hyperlinks_formulae.xlsx");
|
||||||
auto ws = wb.active_sheet();
|
wb.load(path);
|
||||||
TS_ASSERT(ws.cell("A1").has_formula());
|
|
||||||
TS_ASSERT_EQUALS(ws.cell("A1").formula(), "A2*A3");
|
auto ws1 = wb.sheet_by_index(0);
|
||||||
ws.cell("A1").clear_formula();
|
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");
|
wb.save("clear_formulae.xlsx");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,26 +12,6 @@
|
||||||
class test_round_trip : public CxxTest::TestSuite
|
class test_round_trip : public CxxTest::TestSuite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
|
||||||
/// 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.
|
|
||||||
/// </summary>
|
|
||||||
bool round_trip_matches_wrw(const xlnt::workbook &original)
|
|
||||||
{
|
|
||||||
std::vector<std::uint8_t> original_buffer;
|
|
||||||
original.save(original_buffer);
|
|
||||||
original.save("round_trip_in.xlsx");
|
|
||||||
|
|
||||||
xlnt::workbook resulting_workbook;
|
|
||||||
resulting_workbook.load(original_buffer);
|
|
||||||
|
|
||||||
std::vector<std::uint8_t> resulting_buffer;
|
|
||||||
resulting_workbook.save(resulting_buffer);
|
|
||||||
resulting_workbook.save("round_trip_out.xlsx");
|
|
||||||
|
|
||||||
return xml_helper::xlsx_archives_match(original_buffer, resulting_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read file as an XLSX-formatted ZIP file in the filesystem to a workbook,
|
/// 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.
|
/// 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);
|
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()
|
void test_round_trip_empty_excel_rw()
|
||||||
{
|
{
|
||||||
auto path = path_helper::data_directory("9_default-excel.xlsx");
|
const auto files = std::vector<std::string>
|
||||||
TS_ASSERT(round_trip_matches_rw(path));
|
{
|
||||||
|
"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));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -220,7 +220,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!compare_files(left_archive.read(left_member),
|
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;
|
std::cout << left_member.string() << std::endl;
|
||||||
match = false;
|
match = false;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user