xlnt/source/tests/WriteTestSuite.h

242 lines
7.4 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-13 07:59:33 +08:00
#include "TemporaryDirectory.h"
2014-05-09 03:32:12 +08:00
class WriteTestSuite : public CxxTest::TestSuite
{
public:
std::string TMPDIR;
2014-05-09 03:32:12 +08:00
WriteTestSuite()
{
}
void test_write_empty_workbook()
{
2014-05-13 07:59:33 +08:00
TemporaryDirectory temp_dir;
xlnt::workbook wb;
auto dest_filename = TMPDIR + "/empty_book.xlsx";
wb.save(dest_filename);
TS_ASSERT(xlnt::file::exists(dest_filename));
2014-05-09 03:32:12 +08:00
}
void test_write_virtual_workbook()
{
/*xlnt::workbook old_wb;
2014-05-13 01:42:28 +08:00
saved_wb = save_virtual_workbook(old_wb);
new_wb = load_workbook(BytesIO(saved_wb));
assert new_wb;*/
2014-05-09 03:32:12 +08:00
}
void test_write_workbook_rels()
{
/*xlnt::workbook wb;
2014-05-13 01:42:28 +08:00
content = write_workbook_rels(wb);
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"workbook.xml.rels"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_write_workbook()
{
/*xlnt::workbook wb;
2014-05-13 01:42:28 +08:00
content = write_workbook(wb);
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"workbook.xml"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_write_string_table()
{
/*table = {"hello": 1, "world" : 2, "nice" : 3};
2014-05-13 01:42:28 +08:00
content = write_string_table(table);
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"sharedStrings.xml"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_write_worksheet()
{
/*xlnt::workbook wb;
auto ws = wb.create_sheet();
ws.cell("F42") = "hello";
2014-05-13 01:42:28 +08:00
content = write_worksheet(ws, {"hello": 0}, {});
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"sheet1.xml"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_write_hidden_worksheet()
{
/*xlnt::workbook wb;
auto ws = wb.create_sheet();
2014-05-13 01:42:28 +08:00
ws.sheet_state = ws.SHEETSTATE_HIDDEN;
ws.cell("F42") = "hello";
2014-05-13 01:42:28 +08:00
content = write_worksheet(ws, {"hello": 0}, {});
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"sheet1.xml"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_write_bool()
{
/*xlnt::workbook wb;
auto ws = wb.create_sheet();
ws.cell("F42") = False;
ws.cell("F43") = True;
2014-05-13 01:42:28 +08:00
content = write_worksheet(ws, {}, {});
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"sheet1_bool.xml"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_write_formula()
{
/*xlnt::workbook wb;
auto ws = wb.create_sheet();
ws.cell("F1") = 10;
ws.cell("F2") = 32;
ws.cell("F3") = "=F1+F2";
2014-05-13 01:42:28 +08:00
content = write_worksheet(ws, {}, {});
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"sheet1_formula.xml"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_write_style()
{
/*xlnt::workbook wb;
auto ws = wb.create_sheet();
ws.cell("F1") = "13%";
2014-05-13 01:42:28 +08:00
style_id_by_hash = StyleWriter(wb).get_style_by_hash();
content = write_worksheet(ws, {}, style_id_by_hash);
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"sheet1_style.xml"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_write_height()
{
/*xlnt::workbook wb;
auto ws = wb.create_sheet();
ws.cell("F1") = 10;
2014-05-13 01:42:28 +08:00
ws.row_dimensions[ws.cell("F1").row].height = 30;
content = write_worksheet(ws, {}, {});
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"sheet1_height.xml"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_write_hyperlink()
{
/*xlnt::workbook wb;
auto ws = wb.create_sheet();
ws.cell("A1") = "test";
2014-05-13 01:42:28 +08:00
ws.cell("A1").hyperlink = "http:test.com";
content = write_worksheet(ws, {"test": 0}, {});
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"sheet1_hyperlink.xml"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_write_hyperlink_rels()
{
/*xlnt::workbook wb;
auto ws = wb.create_sheet();
2014-05-13 01:42:28 +08:00
TS_ASSERT_EQUALS(0, len(ws.relationships));
ws.cell("A1") = "test";
2014-05-13 01:42:28 +08:00
ws.cell("A1").hyperlink = "http:test.com/";
TS_ASSERT_EQUALS(1, len(ws.relationships));
ws.cell("A2") = "test";
2014-05-13 01:42:28 +08:00
ws.cell("A2").hyperlink = "http:test2.com/";
TS_ASSERT_EQUALS(2, len(ws.relationships));
content = write_worksheet_rels(ws, 1);
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"sheet1_hyperlink.xml.rels"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_hyperlink_value()
{
xlnt::workbook wb;
auto ws = wb.create_sheet();
ws.cell("A1").set_hyperlink("http:test.com");
TS_ASSERT_EQUALS("http:test.com", ws.cell("A1"));
ws.cell("A1") = "test";
TS_ASSERT_EQUALS("test", ws.cell("A1"));
2014-05-09 03:32:12 +08:00
}
void test_write_auto_filter()
{
/*xlnt::workbook wb;
auto ws = wb[0];
ws.cell("F42") = "hello";
2014-05-13 01:42:28 +08:00
ws.auto_filter = "A1:F1";
content = write_worksheet(ws, {"hello": 0}, {});
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"sheet1_auto_filter.xml"), content);
2014-05-09 03:32:12 +08:00
2014-05-13 01:42:28 +08:00
content = write_workbook(wb);
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"workbook_auto_filter.xml"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_freeze_panes_horiz()
{
/*xlnt::workbook wb;
auto ws = wb.create_sheet();
ws.cell("F42") = "hello";
2014-05-13 01:42:28 +08:00
ws.freeze_panes = "A4";
content = write_worksheet(ws, {"hello": 0}, {});
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"sheet1_freeze_panes_horiz.xml"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_freeze_panes_vert()
{
/*xlnt::workbook wb;
auto ws = wb.create_sheet();
ws.cell("F42") = "hello";
2014-05-13 01:42:28 +08:00
ws.freeze_panes = "D1";
content = write_worksheet(ws, {"hello": 0}, {});
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"sheet1_freeze_panes_vert.xml"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_freeze_panes_both()
{
/*xlnt::workbook wb;
auto ws = wb.create_sheet();
ws.cell("F42") = "hello";
2014-05-13 01:42:28 +08:00
ws.freeze_panes = "D4";
content = write_worksheet(ws, {"hello": 0}, {});
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"sheet1_freeze_panes_both.xml"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_long_number()
{
/*xlnt::workbook wb;
auto ws = wb.create_sheet();
ws.cell("A1") = 9781231231230;
2014-05-13 01:42:28 +08:00
content = write_worksheet(ws, {}, {});
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"long_number.xml"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_decimal()
{
/*xlnt::workbook wb;
auto ws = wb.create_sheet();
ws.cell("A1") = decimal.Decimal("3.14");
2014-05-13 01:42:28 +08:00
content = write_worksheet(ws, {}, {});
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"decimal.xml"), content);*/
2014-05-09 03:32:12 +08:00
}
void test_short_number()
{
/*xlnt::workbook wb;
auto ws = wb.create_sheet();
ws.cell("A1") = 1234567890;
2014-05-13 01:42:28 +08:00
content = write_worksheet(ws, {}, {});
assert_equals_file_content(os.path.join(DATADIR, "writer", "expected", \
"short_number.xml"), content);*/
2014-05-09 03:32:12 +08:00
}
};