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:
|
2014-05-14 04:32:33 +08:00
|
|
|
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;
|
2014-05-14 04:32:33 +08:00
|
|
|
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()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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));
|
2014-05-14 04:32:33 +08:00
|
|
|
assert new_wb;*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_write_workbook_rels()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"workbook.xml.rels"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_write_workbook()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"workbook.xml"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void test_write_string_table()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"sharedStrings.xml"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_write_worksheet()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"sheet1.xml"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_write_hidden_worksheet()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*xlnt::workbook wb;
|
|
|
|
auto ws = wb.create_sheet();
|
2014-05-13 01:42:28 +08:00
|
|
|
ws.sheet_state = ws.SHEETSTATE_HIDDEN;
|
2014-05-14 04:32:33 +08:00
|
|
|
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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"sheet1.xml"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_write_bool()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"sheet1_bool.xml"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_write_formula()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"sheet1_formula.xml"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_write_style()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"sheet1_style.xml"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_write_height()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"sheet1_height.xml"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_write_hyperlink()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"sheet1_hyperlink.xml"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_write_hyperlink_rels()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*xlnt::workbook wb;
|
|
|
|
auto ws = wb.create_sheet();
|
2014-05-13 01:42:28 +08:00
|
|
|
TS_ASSERT_EQUALS(0, len(ws.relationships));
|
2014-05-14 04:32:33 +08:00
|
|
|
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));
|
2014-05-14 04:32:33 +08:00
|
|
|
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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"sheet1_hyperlink.xml.rels"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_hyperlink_value()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
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()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"workbook_auto_filter.xml"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_freeze_panes_horiz()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"sheet1_freeze_panes_horiz.xml"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_freeze_panes_vert()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"sheet1_freeze_panes_vert.xml"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_freeze_panes_both()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"sheet1_freeze_panes_both.xml"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_long_number()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"long_number.xml"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_decimal()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"decimal.xml"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_short_number()
|
|
|
|
{
|
2014-05-14 04:32:33 +08:00
|
|
|
/*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", \
|
2014-05-14 04:32:33 +08:00
|
|
|
"short_number.xml"), content);*/
|
2014-05-09 03:32:12 +08:00
|
|
|
}
|
|
|
|
};
|