#pragma once #include #include #include #include #include "helpers/path_helper.hpp" namespace xlnt { xlnt::workbook load_workbook(const std::vector &bytes) { return xlnt::workbook(); } std::string write_workbook_rels(xlnt::workbook &wb) { return ""; } std::string write_root_rels(xlnt::workbook &wb) { return ""; } std::string write_defined_names(xlnt::workbook &wb) { return ""; } } class test_write_workbook : public CxxTest::TestSuite { public: void test_write_auto_filter() { xlnt::workbook wb; auto ws = wb.create_sheet(); ws.get_cell("F42").set_value("hello"); ws.get_auto_filter() = "A1:F1"; auto content = xlnt::write_workbook(wb); auto diff = Helper::compare_xml(PathHelper::read_file("workbook_auto_filter.xml"), content); TS_ASSERT(!diff); } void test_write_hidden_worksheet() { xlnt::workbook wb; auto ws = wb.create_sheet(); ws.set_sheet_state(xlnt::page_setup::sheet_state::hidden); wb.create_sheet(); auto xml = xlnt::write_workbook(wb); std::string expected = "" " " " " " " " " " " " " " " " " " " " " ""; auto diff = Helper::compare_xml(xml, expected); TS_ASSERT(!diff); } void test_write_hidden_single_worksheet() { xlnt::workbook wb; auto ws = wb.get_active_sheet(); ws.set_sheet_state(xlnt::page_setup::sheet_state::hidden); TS_ASSERT_THROWS(xlnt::write_workbook(wb), xlnt::value_error); } void test_write_empty_workbook() { xlnt::workbook wb; std::string dest_filename = "empty_book.xlsx"; xlnt::save_workbook(wb, dest_filename); TS_ASSERT(PathHelper::FileExists(dest_filename)); } void test_write_virtual_workbook() { xlnt::workbook old_wb; auto saved_wb = xlnt::save_virtual_workbook(old_wb); auto new_wb = xlnt::load_workbook(saved_wb); TS_ASSERT(new_wb != nullptr); } void test_write_workbook_rels() { xlnt::workbook wb; auto content = xlnt::write_workbook_rels(wb); auto filename = "workbook.xml.rels"; auto diff = Helper::compare_xml(PathHelper::read_file(filename), content); TS_ASSERT(!diff); } void test_write_workbook_() { xlnt::workbook wb; auto content = xlnt::write_workbook(wb); auto filename = "workbook.xml"; auto diff = Helper::compare_xml(PathHelper::read_file(filename), content); TS_ASSERT(!diff); } void test_write_named_range() { xlnt::workbook wb; auto ws = wb.create_sheet(); xlnt::named_range xlrange("test_range", {{ws, "A1:B5"}}); wb.add_named_range(xlrange); auto xml = xlnt::write_defined_names(wb); std::string expected = "" "'Sheet'!$A$1:$B$5" ""; auto diff = Helper::compare_xml(xml, expected); TS_ASSERT(!diff); } void test_read_workbook_code_name() { // with open(tmpl, "rb") as expected: // TS_ASSERT(read_workbook_code_name(expected.read()) == code_name } void test_write_workbook_code_name() { xlnt::workbook wb; wb.set_code_name("MyWB"); auto content = xlnt::write_workbook(wb); std::string expected = "" " " " " " " " " " " " " " " " " " " ""; auto diff = Helper::compare_xml(content, expected); TS_ASSERT(!diff); } void test_write_root_rels() { xlnt::workbook wb; auto xml = xlnt::write_root_rels(wb); std::string expected = "" " " " " " " ""; auto diff = Helper::compare_xml(xml, expected); TS_ASSERT(!diff); } private: xlnt::workbook wb_; };