#pragma once #include #include #include #include #include #include class test_style_writer : public CxxTest::TestSuite { public: void test_write_number_formats() { xlnt::workbook wb; wb.get_active_sheet().get_cell("A1").set_number_format(xlnt::number_format("YYYY")); xlnt::excel_serializer excel_serializer(wb); xlnt::style_serializer style_serializer(excel_serializer.get_stylesheet()); pugi::xml_document observed; style_serializer.write_stylesheet(observed); pugi::xml_document expected_doc; std::string expected = " " " " " "; expected_doc.load(expected.c_str()); auto diff = Helper::compare_xml(expected_doc.child("numFmts"), observed.child("styleSheet").child("numFmts")); TS_ASSERT(diff); } void test_simple_styles() { xlnt::workbook wb; wb.set_guess_types(true); auto ws = wb.get_active_sheet(); ws.get_cell("A1").set_value("12.34%"); auto now = xlnt::date::today(); ws.get_cell("A2").set_value(now); ws.get_cell("A3").set_value("This is a test"); ws.get_cell("A4").set_value("31.31415"); ws.get_cell("A5"); ws.get_cell("D9").set_number_format(xlnt::number_format::number_00()); xlnt::protection locked(true, false); ws.get_cell("D9").set_protection(locked); xlnt::protection hidden(true, true); ws.get_cell("E1").set_protection(hidden); xlnt::excel_serializer e(wb); xlnt::style_serializer serializer(e.get_stylesheet()); pugi::xml_document xml; serializer.write_stylesheet(xml); TS_ASSERT(Helper::compare_xml(PathHelper::GetDataDirectory("/writer/expected/simple-styles.xml"), xml)); } void test_empty_workbook() { xlnt::workbook wb; xlnt::excel_serializer e(wb); xlnt::style_serializer serializer(e.get_stylesheet()); auto expected = "" " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " " ""; pugi::xml_document xml; serializer.write_stylesheet(xml); TS_ASSERT(Helper::compare_xml(expected, xml)); } };