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-06-14 05:06:23 +08:00
|
|
|
#include "helpers/path_helper.hpp"
|
|
|
|
#include "helpers/helper.hpp"
|
2014-05-09 03:32:12 +08:00
|
|
|
|
2014-06-06 04:19:31 +08:00
|
|
|
class test_props : public CxxTest::TestSuite
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
void test_read_properties_core()
|
|
|
|
{
|
2014-08-01 21:44:21 +08:00
|
|
|
xlnt::zip_file archive(PathHelper::GetDataDirectory() + "/genuine/empty.xlsx");
|
|
|
|
auto content = archive.read("docProps/core.xml");
|
2014-06-14 05:06:23 +08:00
|
|
|
auto prop = xlnt::reader::read_properties_core(content);
|
|
|
|
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()
|
|
|
|
{
|
2014-08-01 21:44:21 +08:00
|
|
|
xlnt::zip_file archive(PathHelper::GetDataDirectory() + "/genuine/empty.xlsx");
|
|
|
|
auto content = archive.read("docProps/core.xml");
|
2014-06-14 05:06:23 +08:00
|
|
|
std::vector<std::string> expected_titles = {"Sheet1 - Text", "Sheet2 - Numbers", "Sheet3 - Formulas", "Sheet4 - Dates"};
|
|
|
|
int i = 0;
|
|
|
|
for(auto sheet : xlnt::reader::read_sheets(archive))
|
2014-05-13 01:42:28 +08:00
|
|
|
{
|
2014-06-14 05:06:23 +08:00
|
|
|
TS_ASSERT_EQUALS(sheet.second, expected_titles[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
|
|
|
{
|
2014-08-01 21:44:21 +08:00
|
|
|
xlnt::zip_file archive(PathHelper::GetDataDirectory() + "/genuine/empty_libre.xlsx");
|
|
|
|
auto content = archive.read("docProps/core.xml");
|
2014-06-14 05:06:23 +08:00
|
|
|
auto prop = xlnt::reader::read_properties_core(content);
|
|
|
|
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
|
|
|
{
|
2014-08-01 21:44:21 +08:00
|
|
|
xlnt::zip_file archive(PathHelper::GetDataDirectory() + "/genuine/empty_libre.xlsx");
|
|
|
|
auto content = archive.read("docProps/core.xml");
|
2014-06-14 05:06:23 +08:00
|
|
|
std::vector<std::string> expected_titles = {"Sheet1 - Text", "Sheet2 - Numbers", "Sheet3 - Formulas", "Sheet4 - Dates"};
|
|
|
|
int i = 0;
|
|
|
|
for(auto sheet : xlnt::reader::read_sheets(archive))
|
2014-05-09 03:32:12 +08:00
|
|
|
{
|
2014-06-14 05:06:23 +08:00
|
|
|
TS_ASSERT_EQUALS(sheet.second, expected_titles[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()
|
|
|
|
{
|
2014-06-14 05:06:23 +08:00
|
|
|
xlnt::document_properties prop;
|
|
|
|
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);
|
|
|
|
auto content = xlnt::writer::write_properties_core(prop);
|
|
|
|
TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/core.xml", content));
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_write_properties_app()
|
|
|
|
{
|
2014-06-14 05:06:23 +08:00
|
|
|
xlnt::workbook wb;
|
|
|
|
wb.create_sheet();
|
|
|
|
wb.create_sheet();
|
|
|
|
auto content = xlnt::writer::write_properties_app(wb);
|
|
|
|
TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/app.xml", content));
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
};
|