xlnt/tests/test_style.hpp

291 lines
8.4 KiB
C++
Raw Normal View History

2014-05-09 03:32:12 +08:00
#pragma once
#include <iostream>
#include <cxxtest/TestSuite.h>
2014-06-06 04:19:31 +08:00
#include <xlnt/xlnt.hpp>
2014-05-09 03:32:12 +08:00
2014-06-06 04:19:31 +08:00
class test_style : public CxxTest::TestSuite
2014-05-09 03:32:12 +08:00
{
public:
test_style() : writer_(workbook_)
2014-05-09 03:32:12 +08:00
{
workbook_.set_guess_types(true);
auto now = xlnt::datetime::now();
auto ws = workbook_.get_active_sheet();
ws.get_cell("A1").set_value("12.34%"); // 2
2014-08-02 04:46:54 +08:00
ws.get_cell("B1").set_value(now); // 3
ws.get_cell("C1").set_value(now);
ws.get_cell("D1").set_value("This is a test"); // 1
ws.get_cell("E1").set_value("31.31415"); // 3
xlnt::style st; // 4
st.set_number_format(xlnt::number_format(xlnt::number_format::format::number_00));
st.set_protection(xlnt::protection(xlnt::protection::type::unprotected));
2014-08-02 04:46:54 +08:00
ws.get_cell("F1").set_style(st);
xlnt::style st2; // 5
st.set_protection(xlnt::protection(xlnt::protection::type::unprotected));
2014-08-02 04:46:54 +08:00
ws.get_cell("G1").set_style(st2);
2014-05-09 03:32:12 +08:00
}
void test_create_style_table()
2014-05-09 03:32:12 +08:00
{
TS_ASSERT_EQUALS(5, writer_.get_styles().size());
2014-05-09 03:32:12 +08:00
}
void test_write_style_table()
2014-05-09 03:32:12 +08:00
{
2014-08-02 04:46:54 +08:00
auto path = PathHelper::GetDataDirectory("/writer/expected/simple-styles.xml");
pugi::xml_document expected;
2014-08-02 04:46:54 +08:00
expected.load_file(path.c_str());
auto content = writer_.write_table();
pugi::xml_document observed;
observed.load(content.c_str());
auto diff = Helper::compare_xml(expected, observed);
TS_ASSERT(diff);
2014-05-09 03:32:12 +08:00
}
void test_no_style()
{
xlnt::workbook wb;
xlnt::style_writer w(wb);
TS_ASSERT_EQUALS(w.get_styles().size(), 1); // there is always the empty (default) style
2014-05-09 03:32:12 +08:00
}
void test_nb_style()
{
TS_SKIP("not implemented");
2014-05-09 03:32:12 +08:00
}
void test_style_unicity()
{
TS_SKIP("not implemented");
2014-05-09 03:32:12 +08:00
}
void test_fonts()
{
auto expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">"
" <fonts count=\"2\">"
" <font>"
" <sz val=\"11\" />"
" <color theme=\"1\" />"
" <name val=\"Calibri\" />"
" <family val=\"2\" />"
" <scheme val=\"minor\" />"
" </font>"
" <font>"
" <sz val=\"12.0\" />"
" <color rgb=\"00000000\" />"
" <name val=\"Calibri\" />"
" <family val=\"2\" />"
" <b />"
" </font>"
" </fonts>"
"</styleSheet>";
pugi::xml_document expected_doc;
expected_doc.load(expected);
std::string observed = "";
pugi::xml_document observed_doc;
observed_doc.load(observed.c_str());
auto diff = Helper::compare_xml(expected_doc, observed_doc);
TS_ASSERT(diff);
}
void test_fonts_with_underline()
{
auto expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">"
" <fonts count=\"2\">"
" <font>"
" <sz val=\"11\" />"
" <color theme=\"1\" />"
" <name val=\"Calibri\" />"
" <family val=\"2\" />"
" <scheme val=\"minor\" />"
" </font>"
" <font>"
" <sz val=\"12.0\" />"
" <color rgb=\"00000000\" />"
" <name val=\"Calibri\" />"
" <family val=\"2\" />"
" <b />"
" <u />"
" </font>"
" </fonts>"
"</styleSheet>";
pugi::xml_document expected_doc;
expected_doc.load(expected);
std::string observed = "";
pugi::xml_document observed_doc;
observed_doc.load(observed.c_str());
auto diff = Helper::compare_xml(expected_doc, observed_doc);
TS_ASSERT(diff);
2014-05-09 03:32:12 +08:00
}
void test_fills()
{
auto expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">"
" <fills count=\"3\">"
" <fill>"
" <patternFill patternType=\"none\" />"
" </fill>"
" <fill>"
" <patternFill patternType=\"gray125\" />"
" </fill>"
" <fill>"
" <patternFill patternType=\"solid\">"
" <fgColor rgb=\"0000FF00\" />"
" </patternFill>"
" </fill>"
" </fills>"
"</styleSheet>";
pugi::xml_document expected_doc;
expected_doc.load(expected);
std::string observed = "";
pugi::xml_document observed_doc;
observed_doc.load(observed.c_str());
auto diff = Helper::compare_xml(expected_doc, observed_doc);
TS_ASSERT(diff);
2014-05-09 03:32:12 +08:00
}
void test_borders()
{
auto expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">"
" <borders count=\"2\">"
" <border>"
" <left />"
" <right />"
" <top />"
" <bottom />"
" <diagonal />"
" </border>"
" <border>"
" <left />"
" <right />"
" <top style=\"thin\">"
" <color rgb=\"0000FF00\" />"
" </top>"
" <bottom />"
" <diagonal />"
" </border>"
" </borders>"
"</styleSheet>";
pugi::xml_document expected_doc;
expected_doc.load(expected);
std::string observed = "";
pugi::xml_document observed_doc;
observed_doc.load(observed.c_str());
auto diff = Helper::compare_xml(expected_doc, observed_doc);
TS_ASSERT(diff);
}
void test_write_color()
{
TS_SKIP("not implemented");
2014-05-09 03:32:12 +08:00
}
void test_write_cell_xfs_1()
{
TS_SKIP("not implemented");
2014-05-09 03:32:12 +08:00
}
void test_alignment()
{
TS_SKIP("not implemented");
2014-05-09 03:32:12 +08:00
}
void test_alignment_rotation()
{
TS_SKIP("not implemented");
2014-05-09 03:32:12 +08:00
}
void test_alignment_indent()
{
TS_SKIP("not implemented");
2014-05-09 03:32:12 +08:00
}
void test_rewrite_styles()
2014-05-09 03:32:12 +08:00
{
TS_SKIP("not implemented");
2014-05-09 03:32:12 +08:00
}
void test_write_dxf()
2014-05-09 03:32:12 +08:00
{
auto expected =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">"
" <dxfs count=\"1\">"
" <dxf>"
" <font>"
" <color rgb=\"FFFFFFFF\" />"
" <b val=\"1\" />"
" <i val=\"1\" />"
" <u val=\"single\" />"
" <strike />"
" </font>"
" <fill>"
" <patternFill patternType=\"solid\">"
" <fgColor rgb=\"FFEE1111\" />"
" <bgColor rgb=\"FFEE1111\" />"
" </patternFill>"
" </fill>"
" <border>"
" <left style=\"medium\">"
" <color rgb=\"000000FF\" />"
" </left>"
" <right style=\"medium\">"
" <color rgb=\"000000FF\" />"
" </right>"
" <top style=\"medium\">"
" <color rgb=\"000000FF\" />"
" </top>"
" <bottom style=\"medium\">"
" <color rgb=\"000000FF\" />"
" </bottom>"
" </border>"
" </dxf>"
" </dxfs>"
"</styleSheet>";
pugi::xml_document expected_doc;
expected_doc.load(expected);
std::string observed = "";
pugi::xml_document observed_doc;
observed_doc.load(observed.c_str());
auto diff = Helper::compare_xml(expected_doc, observed_doc);
TS_ASSERT(diff);
2014-05-09 03:32:12 +08:00
}
void test_protection()
{
TS_SKIP("not implemented");
2014-05-09 03:32:12 +08:00
}
private:
xlnt::workbook workbook_;
xlnt::style_writer writer_;
2014-05-09 03:32:12 +08:00
};