xlnt/source/tests/PropsTestSuite.h

117 lines
3.2 KiB
C
Raw Normal View History

2014-05-09 03:32:12 +08:00
#pragma once
#include <iostream>
#include <cxxtest/TestSuite.h>
2014-05-10 03:54:06 +08:00
#include "../xlnt.h"
2014-05-09 03:32:12 +08:00
class PropsTestSuite : public CxxTest::TestSuite
{
public:
PropsTestSuite()
{
}
void test_1()
{
}
2014-05-13 01:42:28 +08:00
class TestReaderProps
{
void setup_class(cls)
{
cls.genuine_filename = os.path.join(DATADIR, "genuine", "empty.xlsx");
cls.archive = ZipFile(cls.genuine_filename, "r", ZIP_DEFLATED);
}
void teardown_class(cls)
{
cls.archive.close();
}
};
2014-05-09 03:32:12 +08:00
void test_read_properties_core()
{
2014-05-13 01:42:28 +08:00
content = archive.read(ARC_CORE)
prop = read_properties_core(content)
TS_ASSERT_EQUALS(prop.creator, "*.*")
eacute = chr(233)
TS_ASSERT_EQUALS(prop.last_modified_by, "Aur" + eacute + "lien Camp" + eacute + "as")
TS_ASSERT_EQUALS(prop.created, datetime(2010, 4, 9, 20, 43, 12))
TS_ASSERT_EQUALS(prop.modified, datetime(2011, 2, 9, 13, 49, 32))
2014-05-09 03:32:12 +08:00
}
void test_read_sheets_titles()
{
2014-05-13 01:42:28 +08:00
content = archive.read(ARC_WORKBOOK);
sheet_titles = read_sheets_titles(content);
TS_ASSERT_EQUALS(sheet_titles, \
["Sheet1 - Text", "Sheet2 - Numbers", "Sheet3 - Formulas", "Sheet4 - Dates"]);
2014-05-09 03:32:12 +08:00
}
2014-05-13 01:42:28 +08:00
Just tests that the correct date / time format is returned from LibreOffice saved version
2014-05-09 03:32:12 +08:00
2014-05-13 01:42:28 +08:00
void setup_class(cls)
{
cls.genuine_filename = os.path.join(DATADIR, "genuine", "empty_libre.xlsx")
cls.archive = ZipFile(cls.genuine_filename, "r", ZIP_DEFLATED)
}
2014-05-09 03:32:12 +08:00
2014-05-13 01:42:28 +08:00
void teardown_class(cls)
{
cls.archive.close()
}
2014-05-09 03:32:12 +08:00
void test_read_properties_core2()
{
2014-05-13 01:42:28 +08:00
content = archive.read(ARC_CORE)
prop = read_properties_core(content)
TS_ASSERT_EQUALS(prop.excel_base_date, CALENDAR_WINDOWS_1900)
2014-05-09 03:32:12 +08:00
}
void test_read_sheets_titles2()
{
2014-05-13 01:42:28 +08:00
content = archive.read(ARC_WORKBOOK)
sheet_titles = read_sheets_titles(content)
TS_ASSERT_EQUALS(sheet_titles, \
["Sheet1 - Text", "Sheet2 - Numbers", "Sheet3 - Formulas", "Sheet4 - Dates"])
2014-05-09 03:32:12 +08:00
}
2014-05-13 01:42:28 +08:00
void setup_class(cls)
{
make_tmpdir()
cls.tmp_filename = os.path.join(TMPDIR, "test.xlsx")
cls.prop = DocumentProperties()
}
2014-05-09 03:32:12 +08:00
2014-05-13 01:42:28 +08:00
void teardown_class(cls)
{
clean_tmpdir()
}
2014-05-09 03:32:12 +08:00
void test_write_properties_core()
{
2014-05-13 01:42:28 +08:00
prop.creator = "TEST_USER"
prop.last_modified_by = "SOMEBODY"
prop.created = datetime(2010, 4, 1, 20, 30, 00)
prop.modified = datetime(2010, 4, 5, 14, 5, 30)
content = write_properties_core(prop)
assert_equals_file_content(
os.path.join(DATADIR, "writer", "expected", "core.xml"),
content)
2014-05-09 03:32:12 +08:00
}
void test_write_properties_app()
{
2014-05-13 01:42:28 +08:00
wb = Workbook()
wb.create_sheet()
wb.create_sheet()
content = write_properties_app(wb)
assert_equals_file_content(
os.path.join(DATADIR, "writer", "expected", "app.xml"),
content)
2014-05-09 03:32:12 +08:00
}
};