2014-05-09 03:32:12 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cxxtest/TestSuite.h>
|
|
|
|
|
2016-03-09 11:32:32 +08:00
|
|
|
#include <xlnt/packaging/app_properties.hpp>
|
2016-07-04 07:22:08 +08:00
|
|
|
#include <detail/workbook_serializer.hpp>
|
2015-10-14 12:03:48 +08:00
|
|
|
|
2015-11-03 21:38:09 +08:00
|
|
|
#include <helpers/path_helper.hpp>
|
2016-07-21 07:04:44 +08:00
|
|
|
#include <helpers/xml_helper.hpp>
|
2014-05-09 03:32:12 +08:00
|
|
|
|
2016-03-09 11:32:32 +08:00
|
|
|
class test_core : public CxxTest::TestSuite
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
void test_read_properties_core()
|
|
|
|
{
|
2016-07-21 07:04:44 +08:00
|
|
|
auto path = path_helper::get_data_directory() + "/genuine/empty.xlsx";
|
2015-10-30 07:37:07 +08:00
|
|
|
xlnt::workbook wb;
|
2015-11-02 12:52:19 +08:00
|
|
|
wb.load(path);
|
2015-10-30 11:16:31 +08:00
|
|
|
auto &prop = wb.get_properties();
|
2014-06-14 05:06:23 +08:00
|
|
|
TS_ASSERT_EQUALS(prop.creator, "*.*");
|
2014-07-17 07:53:45 +08:00
|
|
|
TS_ASSERT_EQUALS(prop.last_modified_by, "Charlie Clark");
|
2014-06-14 05:06:23 +08:00
|
|
|
TS_ASSERT_EQUALS(prop.created, xlnt::datetime(2010, 4, 9, 20, 43, 12));
|
2014-07-17 07:53:45 +08:00
|
|
|
TS_ASSERT_EQUALS(prop.modified, xlnt::datetime(2014, 1, 2, 14, 53, 6));
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_read_sheets_titles()
|
|
|
|
{
|
2016-07-21 07:04:44 +08:00
|
|
|
auto path = path_helper::get_data_directory() + "/genuine/empty.xlsx";
|
2015-10-15 06:05:13 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
const std::vector<std::string> expected_titles = {"Sheet1 - Text", "Sheet2 - Numbers", "Sheet3 - Formulas", "Sheet4 - Dates"};
|
2015-10-15 06:05:13 +08:00
|
|
|
|
|
|
|
std::size_t i = 0;
|
2015-10-30 11:16:31 +08:00
|
|
|
|
|
|
|
xlnt::workbook wb;
|
2015-11-02 12:52:19 +08:00
|
|
|
wb.load(path);
|
2015-10-30 11:16:31 +08:00
|
|
|
|
2015-11-02 12:52:19 +08:00
|
|
|
for(auto sheet : wb)
|
2014-05-13 01:42:28 +08:00
|
|
|
{
|
2015-11-02 12:52:19 +08:00
|
|
|
TS_ASSERT_EQUALS(sheet.get_title(), expected_titles.at(i++));
|
2014-05-13 01:42:28 +08:00
|
|
|
}
|
2014-06-14 05:06:23 +08:00
|
|
|
}
|
2014-05-09 03:32:12 +08:00
|
|
|
|
2014-07-17 07:53:45 +08:00
|
|
|
void test_read_properties_core_libre()
|
2014-06-14 05:06:23 +08:00
|
|
|
{
|
2016-07-21 07:04:44 +08:00
|
|
|
xlnt::zip_file archive(path_helper::get_data_directory() + "/genuine/empty_libre.xlsx");
|
2014-08-01 21:44:21 +08:00
|
|
|
auto content = archive.read("docProps/core.xml");
|
2015-10-30 11:16:31 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
xlnt::workbook_serializer serializer(wb);
|
2016-07-04 07:22:08 +08:00
|
|
|
pugi::xml_document xml;
|
2015-10-30 11:16:31 +08:00
|
|
|
serializer.read_properties_core(xml);
|
|
|
|
auto &prop = wb.get_properties();
|
2014-06-14 05:06:23 +08:00
|
|
|
TS_ASSERT_EQUALS(prop.excel_base_date, xlnt::calendar::windows_1900);
|
|
|
|
}
|
2014-05-09 03:32:12 +08:00
|
|
|
|
2014-07-17 07:53:45 +08:00
|
|
|
void test_read_sheets_titles_libre()
|
2014-06-14 05:06:23 +08:00
|
|
|
{
|
2016-07-21 07:04:44 +08:00
|
|
|
auto path = path_helper::get_data_directory() + "/genuine/empty_libre.xlsx";
|
2015-10-15 06:05:13 +08:00
|
|
|
|
2015-11-11 07:58:54 +08:00
|
|
|
const std::vector<std::string> expected_titles = {"Sheet1 - Text", "Sheet2 - Numbers", "Sheet3 - Formulas", "Sheet4 - Dates"};
|
2015-10-15 06:05:13 +08:00
|
|
|
|
|
|
|
std::size_t i = 0;
|
2015-10-30 11:16:31 +08:00
|
|
|
|
|
|
|
xlnt::workbook wb;
|
2015-11-02 12:52:19 +08:00
|
|
|
wb.load(path);
|
2015-10-30 11:16:31 +08:00
|
|
|
|
2015-11-02 12:52:19 +08:00
|
|
|
for(auto sheet : wb)
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2015-11-02 12:52:19 +08:00
|
|
|
TS_ASSERT_EQUALS(sheet.get_title(), expected_titles.at(i++));
|
2014-05-13 01:42:28 +08:00
|
|
|
}
|
2014-06-14 05:06:23 +08:00
|
|
|
}
|
2014-05-09 03:32:12 +08:00
|
|
|
|
|
|
|
void test_write_properties_core()
|
|
|
|
{
|
2015-10-30 11:16:31 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
xlnt::document_properties &prop = wb.get_properties();
|
2014-06-14 05:06:23 +08:00
|
|
|
prop.creator = "TEST_USER";
|
|
|
|
prop.last_modified_by = "SOMEBODY";
|
|
|
|
prop.created = xlnt::datetime(2010, 4, 1, 20, 30, 00);
|
|
|
|
prop.modified = xlnt::datetime(2010, 4, 5, 14, 5, 30);
|
2015-10-30 11:16:31 +08:00
|
|
|
xlnt::workbook_serializer serializer(wb);
|
2016-07-04 07:22:08 +08:00
|
|
|
pugi::xml_document xml;
|
|
|
|
serializer.write_properties_core(xml);
|
2016-07-21 07:04:44 +08:00
|
|
|
TS_ASSERT(xml_helper::compare_xml(path_helper::get_data_directory() + "/writer/expected/core.xml", xml));
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_write_properties_app()
|
|
|
|
{
|
2014-06-14 05:06:23 +08:00
|
|
|
xlnt::workbook wb;
|
2016-03-09 11:32:32 +08:00
|
|
|
wb.get_app_properties().application = "Microsoft Excel";
|
|
|
|
wb.get_app_properties().app_version = "12.0000";
|
2016-07-17 06:42:56 +08:00
|
|
|
wb.get_app_properties().company = "Company";
|
2014-06-14 05:06:23 +08:00
|
|
|
wb.create_sheet();
|
|
|
|
wb.create_sheet();
|
2015-10-30 11:16:31 +08:00
|
|
|
xlnt::workbook_serializer serializer(wb);
|
2016-07-04 07:22:08 +08:00
|
|
|
pugi::xml_document xml;
|
|
|
|
serializer.write_properties_app(xml);
|
2016-07-21 07:04:44 +08:00
|
|
|
TS_ASSERT(xml_helper::compare_xml(path_helper::get_data_directory() + "/writer/expected/app.xml", xml));
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
};
|