初始化PHP-Xlswrite扩展
This commit is contained in:
15
library/libxlsxwriter/test/unit/styles/main.c
Normal file
15
library/libxlsxwriter/test/unit/styles/main.c
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Test runner for xmlwriter using ctest.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
#define CTEST_MAIN
|
||||
|
||||
#include "../ctest.h"
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
return ctest_main(argc, argv);
|
||||
}
|
||||
|
197
library/libxlsxwriter/test/unit/styles/test_styles.c
Normal file
197
library/libxlsxwriter/test/unit/styles/test_styles.c
Normal file
@ -0,0 +1,197 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test assembling a complete Styles file.
|
||||
CTEST(styles, styles01) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">"
|
||||
"<fonts count=\"1\">"
|
||||
"<font>"
|
||||
"<sz val=\"11\"/>"
|
||||
"<color theme=\"1\"/>"
|
||||
"<name val=\"Calibri\"/>"
|
||||
"<family val=\"2\"/>"
|
||||
"<scheme val=\"minor\"/>"
|
||||
"</font>"
|
||||
"</fonts>"
|
||||
"<fills count=\"2\">"
|
||||
"<fill>"
|
||||
"<patternFill patternType=\"none\"/>"
|
||||
"</fill>"
|
||||
"<fill>"
|
||||
"<patternFill patternType=\"gray125\"/>"
|
||||
"</fill>"
|
||||
"</fills>"
|
||||
"<borders count=\"1\">"
|
||||
"<border>"
|
||||
"<left/>"
|
||||
"<right/>"
|
||||
"<top/>"
|
||||
"<bottom/>"
|
||||
"<diagonal/>"
|
||||
"</border>"
|
||||
"</borders>"
|
||||
"<cellStyleXfs count=\"1\">"
|
||||
"<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\"/>"
|
||||
"</cellStyleXfs>"
|
||||
"<cellXfs count=\"1\">"
|
||||
"<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\"/>"
|
||||
"</cellXfs>"
|
||||
"<cellStyles count=\"1\">"
|
||||
"<cellStyle name=\"Normal\" xfId=\"0\" builtinId=\"0\"/>"
|
||||
"</cellStyles>"
|
||||
"<dxfs count=\"0\"/>"
|
||||
"<tableStyles count=\"0\" defaultTableStyle=\"TableStyleMedium9\" defaultPivotStyle=\"PivotStyleLight16\"/>"
|
||||
"</styleSheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format->has_font = 1;
|
||||
format->has_border = 1;
|
||||
|
||||
styles->file = testfile;
|
||||
styles->font_count = 1;
|
||||
styles->border_count = 1;
|
||||
styles->fill_count = 2;
|
||||
styles->xf_count = 1;
|
||||
|
||||
STAILQ_INSERT_TAIL(styles->xf_formats, format, list_pointers);
|
||||
|
||||
lxw_styles_assemble_xml_file(styles);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
||||
// Test assembling a complete Styles file.
|
||||
CTEST(styles, styles02) {
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">"
|
||||
"<fonts count=\"4\">"
|
||||
"<font>"
|
||||
"<sz val=\"11\"/>"
|
||||
"<color theme=\"1\"/>"
|
||||
"<name val=\"Calibri\"/>"
|
||||
"<family val=\"2\"/>"
|
||||
"<scheme val=\"minor\"/>"
|
||||
"</font>"
|
||||
"<font>"
|
||||
"<b/>"
|
||||
"<sz val=\"11\"/>"
|
||||
"<color theme=\"1\"/>"
|
||||
"<name val=\"Calibri\"/>"
|
||||
"<family val=\"2\"/>"
|
||||
"<scheme val=\"minor\"/>"
|
||||
"</font>"
|
||||
"<font>"
|
||||
"<i/>"
|
||||
"<sz val=\"11\"/>"
|
||||
"<color theme=\"1\"/>"
|
||||
"<name val=\"Calibri\"/>"
|
||||
"<family val=\"2\"/>"
|
||||
"<scheme val=\"minor\"/>"
|
||||
"</font>"
|
||||
"<font>"
|
||||
"<b/>"
|
||||
"<i/>"
|
||||
"<sz val=\"11\"/>"
|
||||
"<color theme=\"1\"/>"
|
||||
"<name val=\"Calibri\"/>"
|
||||
"<family val=\"2\"/>"
|
||||
"<scheme val=\"minor\"/>"
|
||||
"</font>"
|
||||
"</fonts>"
|
||||
"<fills count=\"2\">"
|
||||
"<fill>"
|
||||
"<patternFill patternType=\"none\"/>"
|
||||
"</fill>"
|
||||
"<fill>"
|
||||
"<patternFill patternType=\"gray125\"/>"
|
||||
"</fill>"
|
||||
"</fills>"
|
||||
"<borders count=\"1\">"
|
||||
"<border>"
|
||||
"<left/>"
|
||||
"<right/>"
|
||||
"<top/>"
|
||||
"<bottom/>"
|
||||
"<diagonal/>"
|
||||
"</border>"
|
||||
"</borders>"
|
||||
"<cellStyleXfs count=\"1\">"
|
||||
"<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\"/>"
|
||||
"</cellStyleXfs>"
|
||||
"<cellXfs count=\"4\">"
|
||||
"<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\"/>"
|
||||
"<xf numFmtId=\"0\" fontId=\"1\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyFont=\"1\"/>"
|
||||
"<xf numFmtId=\"0\" fontId=\"2\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyFont=\"1\"/>"
|
||||
"<xf numFmtId=\"0\" fontId=\"3\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyFont=\"1\"/>"
|
||||
"</cellXfs>"
|
||||
"<cellStyles count=\"1\">"
|
||||
"<cellStyle name=\"Normal\" xfId=\"0\" builtinId=\"0\"/>"
|
||||
"</cellStyles>"
|
||||
"<dxfs count=\"0\"/>"
|
||||
"<tableStyles count=\"0\" defaultTableStyle=\"TableStyleMedium9\" defaultPivotStyle=\"PivotStyleLight16\"/>"
|
||||
"</styleSheet>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format1 = lxw_format_new();
|
||||
lxw_format *format2 = lxw_format_new();
|
||||
lxw_format *format3 = lxw_format_new();
|
||||
lxw_format *format4 = lxw_format_new();
|
||||
|
||||
|
||||
format1->has_font = 1;
|
||||
format1->has_border = 1;
|
||||
|
||||
format2->bold = 1;
|
||||
format2->font_index = 1;
|
||||
format2->has_font = 1;
|
||||
|
||||
format3->italic = 1;
|
||||
format3->font_index = 2;
|
||||
format3->has_font = 1;
|
||||
|
||||
format4->bold = 1;
|
||||
format4->italic = 1;
|
||||
format4->font_index = 3;
|
||||
format4->has_font = 1;
|
||||
|
||||
styles->file = testfile;
|
||||
styles->font_count = 4;
|
||||
styles->border_count = 1;
|
||||
styles->fill_count = 2;
|
||||
styles->xf_count = 4;
|
||||
|
||||
STAILQ_INSERT_TAIL(styles->xf_formats, format1, list_pointers);
|
||||
STAILQ_INSERT_TAIL(styles->xf_formats, format2, list_pointers);
|
||||
STAILQ_INSERT_TAIL(styles->xf_formats, format3, list_pointers);
|
||||
STAILQ_INSERT_TAIL(styles->xf_formats, format4, list_pointers);
|
||||
|
||||
lxw_styles_assemble_xml_file(styles);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_border() function.
|
||||
CTEST(styles, write_border) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<border><left/><right/><top/><bottom/><diagonal/></border>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_border(styles, format, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_borders() function.
|
||||
CTEST(styles, write_borders) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<borders count=\"1\"><border><left/><right/><top/><bottom/><diagonal/></border></borders>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format->has_border = 1;
|
||||
|
||||
STAILQ_INSERT_TAIL(styles->xf_formats, format, list_pointers);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
styles->border_count = 1;
|
||||
|
||||
_write_borders(styles);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_cell_style() function.
|
||||
CTEST(styles, write_cell_style) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<cellStyle name=\"Normal\" xfId=\"0\" builtinId=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
styles->file = testfile;
|
||||
|
||||
_write_cell_style(styles, "Normal", 0, 0);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_cell_style_xfs() function.
|
||||
CTEST(styles, write_cell_style_xfs) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<cellStyleXfs count=\"1\"><xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\"/></cellStyleXfs>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
styles->file = testfile;
|
||||
|
||||
_write_cell_style_xfs(styles);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_cell_styles() function.
|
||||
CTEST(styles, write_cell_styles) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<cellStyles count=\"1\"><cellStyle name=\"Normal\" xfId=\"0\" builtinId=\"0\"/></cellStyles>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
styles->file = testfile;
|
||||
|
||||
_write_cell_styles(styles);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_cell_xfs() function.
|
||||
CTEST(styles, write_cell_xfs) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<cellXfs count=\"1\"><xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\"/></cellXfs>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
STAILQ_INSERT_TAIL(styles->xf_formats, format, list_pointers);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
styles->xf_count = 1;
|
||||
|
||||
_write_cell_xfs(styles);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_default_fill() function.
|
||||
CTEST(styles, write_default_fill) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<fill><patternFill patternType=\"none\"/></fill>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
styles->file = testfile;
|
||||
|
||||
_write_default_fill(styles, "none");
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_dxfs() function.
|
||||
CTEST(styles, write_dxfs) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<dxfs count=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
styles->file = testfile;
|
||||
|
||||
_write_dxfs(styles);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_fills() function.
|
||||
CTEST(styles, write_fills) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<fills count=\"2\"><fill><patternFill patternType=\"none\"/></fill><fill><patternFill patternType=\"gray125\"/></fill></fills>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
styles->fill_count = 2;
|
||||
styles->file = testfile;
|
||||
|
||||
_write_fills(styles);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
412
library/libxlsxwriter/test/unit/styles/test_styles_write_font.c
Normal file
412
library/libxlsxwriter/test/unit/styles/test_styles_write_font.c
Normal file
@ -0,0 +1,412 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font01) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><sz val=\"11\"/><color theme=\"1\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font02) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><b/><sz val=\"11\"/><color theme=\"1\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_bold(format);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font03) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><i/><sz val=\"11\"/><color theme=\"1\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_italic(format);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font04) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><u/><sz val=\"11\"/><color theme=\"1\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_underline(format, LXW_UNDERLINE_SINGLE);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font05) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><strike/><sz val=\"11\"/><color theme=\"1\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_font_strikeout(format);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font06) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><vertAlign val=\"superscript\"/><sz val=\"11\"/><color theme=\"1\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_font_script(format, LXW_FONT_SUPERSCRIPT);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font07) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><vertAlign val=\"subscript\"/><sz val=\"11\"/><color theme=\"1\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_font_script(format, LXW_FONT_SUBSCRIPT);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font08) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><sz val=\"11\"/><color theme=\"1\"/><name val=\"Arial\"/><family val=\"2\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_font_name(format, "Arial");
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font09) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><sz val=\"12\"/><color theme=\"1\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_font_size(format, 12);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font10) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><outline/><sz val=\"11\"/><color theme=\"1\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_font_outline(format);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font11) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><shadow/><sz val=\"11\"/><color theme=\"1\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_font_shadow(format);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font12) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><sz val=\"11\"/><color rgb=\"FFFF0000\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_font_color(format, LXW_COLOR_RED);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font13) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><b/><i/><strike/><outline/><shadow/><u/><vertAlign val=\"superscript\"/><sz val=\"12\"/><color rgb=\"FFFF0000\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_bold(format);
|
||||
format_set_italic(format);
|
||||
format_set_font_size(format, 12);
|
||||
format_set_font_color(format, LXW_COLOR_RED);
|
||||
format_set_font_strikeout(format);
|
||||
format_set_font_outline(format);
|
||||
format_set_font_shadow(format);
|
||||
format_set_font_script(format, LXW_FONT_SUPERSCRIPT);
|
||||
format_set_underline(format, LXW_UNDERLINE_SINGLE);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font14) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><u val=\"double\"/><sz val=\"11\"/><color theme=\"1\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_underline(format, LXW_UNDERLINE_DOUBLE);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font15) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><u val=\"singleAccounting\"/><sz val=\"11\"/><color theme=\"1\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_underline(format, LXW_UNDERLINE_SINGLE_ACCOUNTING);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font16) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><u val=\"doubleAccounting\"/><sz val=\"11\"/><color theme=\"1\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_underline(format, LXW_UNDERLINE_DOUBLE_ACCOUNTING);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_font17) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<font><u/><sz val=\"11\"/><color theme=\"10\"/><name val=\"Calibri\"/><family val=\"2\"/></font>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_underline(format, LXW_UNDERLINE_SINGLE);
|
||||
format_set_theme(format, 10);
|
||||
format->hyperlink = 1;
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font(styles, format, LXW_FALSE, LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_color() function.
|
||||
CTEST(styles, write_color) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<color theme=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font_color_theme(styles, 1);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_family() function.
|
||||
CTEST(styles, write_family) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<family val=\"2\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font_family(styles, 2);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_name() function.
|
||||
CTEST(styles, write_name) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<name val=\"Calibri\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font_name(styles, "Calibri", LXW_FALSE);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_scheme() function.
|
||||
CTEST(styles, write_scheme) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<scheme val=\"minor\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font_scheme(styles, "minor");
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_sz() function.
|
||||
CTEST(styles, write_sz) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<sz val=\"11\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
styles->file = testfile;
|
||||
|
||||
_write_font_size(styles, 11);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_font() function.
|
||||
CTEST(styles, write_fonts01) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<fonts count=\"1\"><font><sz val=\"11\"/><color theme=\"1\"/><name val=\"Calibri\"/><family val=\"2\"/><scheme val=\"minor\"/></font></fonts>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format->has_font = 1;
|
||||
|
||||
STAILQ_INSERT_TAIL(styles->xf_formats, format, list_pointers);
|
||||
|
||||
styles->file = testfile;
|
||||
styles->font_count = 1;
|
||||
|
||||
_write_fonts(styles);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_style_sheet() function.
|
||||
CTEST(styles, write_style_sheet) {
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] = "<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
styles->file = testfile;
|
||||
|
||||
_write_style_sheet(styles);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_style_xf() function.
|
||||
CTEST(styles, write_style_xf) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
styles->file = testfile;
|
||||
|
||||
_write_style_xf(styles, LXW_FALSE, 0);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test the _write_table_styles() function.
|
||||
CTEST(styles, write_table_styles) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<tableStyles count=\"0\" defaultTableStyle=\"TableStyleMedium9\" defaultPivotStyle=\"PivotStyleLight16\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
styles->file = testfile;
|
||||
|
||||
_write_table_styles(styles);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
||||
|
851
library/libxlsxwriter/test/unit/styles/test_styles_write_xf.c
Normal file
851
library/libxlsxwriter/test/unit/styles/test_styles_write_xf.c
Normal file
@ -0,0 +1,851 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
#include "../../../include/xlsxwriter/format.h"
|
||||
|
||||
// Test the _write_xf() method. Default properties.
|
||||
CTEST(styles, write_xf01) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Has font but is first XF.
|
||||
CTEST(styles, write_xf02) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format->has_font = 1;
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Has font but isn't first XF.
|
||||
CTEST(styles, write_xf03) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"1\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyFont=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format->has_font = 1;
|
||||
format->font_index = 1;
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Uses built-in number format.
|
||||
CTEST(styles, write_xf04) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"2\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyNumberFormat=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_num_format_index(format, 2);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Uses built-in number format + font.
|
||||
CTEST(styles, write_xf05) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"2\" fontId=\"1\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyNumberFormat=\"1\" applyFont=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_num_format_index(format, 2);
|
||||
format->has_font = 1;
|
||||
format->font_index = 1;
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Vertical alignment = top.
|
||||
CTEST(styles, write_xf06) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment vertical=\"top\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_VERTICAL_TOP);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Vertical alignment = centre.
|
||||
CTEST(styles, write_xf07) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment vertical=\"center\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_VERTICAL_CENTER);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Vertical alignment = bottom.
|
||||
CTEST(styles, write_xf08) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"/>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_VERTICAL_BOTTOM);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Vertical alignment = justify.
|
||||
CTEST(styles, write_xf09) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment vertical=\"justify\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_VERTICAL_JUSTIFY);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Vertical alignment = distributed.
|
||||
CTEST(styles, write_xf10) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment vertical=\"distributed\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_VERTICAL_DISTRIBUTED);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Horizontal alignment = left.
|
||||
CTEST(styles, write_xf11) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"left\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_LEFT);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Horizontal alignment = center.
|
||||
CTEST(styles, write_xf12) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"center\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_CENTER);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Horizontal alignment = right.
|
||||
CTEST(styles, write_xf13) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"right\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_RIGHT);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Horizontal alignment = left + indent.
|
||||
CTEST(styles, write_xf14) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"left\" indent=\"1\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_LEFT);
|
||||
format->indent = 1;
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Horizontal alignment = right + indent.
|
||||
CTEST(styles, write_xf15) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"right\" indent=\"1\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_RIGHT);
|
||||
format_set_indent(format, 1);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Horizontal alignment = fill.
|
||||
CTEST(styles, write_xf16) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"fill\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_FILL);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Horizontal alignment = justify.
|
||||
CTEST(styles, write_xf17) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"justify\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_JUSTIFY);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Horizontal alignment = center across.
|
||||
CTEST(styles, write_xf18) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"centerContinuous\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_CENTER_ACROSS);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Horizontal alignment = distributed.
|
||||
CTEST(styles, write_xf19) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"distributed\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_DISTRIBUTED);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Horizontal alignment = distributed + indent.
|
||||
CTEST(styles, write_xf20) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"distributed\" indent=\"1\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_DISTRIBUTED);
|
||||
format_set_indent(format, 1);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Horizontal alignment = justify distributed.
|
||||
CTEST(styles, write_xf21) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"distributed\" justifyLastLine=\"1\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_DISTRIBUTED);
|
||||
format->just_distrib = 1;
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Horizontal alignment = indent only.
|
||||
// This should default to left alignment.
|
||||
CTEST(styles, write_xf22) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"left\" indent=\"1\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_indent(format, 1);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Horizontal alignment = distributed + indent.
|
||||
// The justify_distributed should drop back to plain distributed if there
|
||||
// is an indent.
|
||||
CTEST(styles, write_xf23) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment horizontal=\"distributed\" indent=\"1\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_DISTRIBUTED);
|
||||
format_set_indent(format, 1);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Alignment = text wrap
|
||||
CTEST(styles, write_xf24) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment wrapText=\"1\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_text_wrap(format);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Alignment = shrink to fit
|
||||
CTEST(styles, write_xf25) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment shrinkToFit=\"1\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_shrink(format);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Alignment = reading order
|
||||
CTEST(styles, write_xf26) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment readingOrder=\"1\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_reading_order(format, 1);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Alignment = reading order
|
||||
CTEST(styles, write_xf27) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment readingOrder=\"2\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_reading_order(format, 2);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Alignment = rotation
|
||||
CTEST(styles, write_xf28) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment textRotation=\"45\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_rotation(format, 45);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Alignment = rotation
|
||||
CTEST(styles, write_xf29) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment textRotation=\"135\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_rotation(format, -45);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Alignment = rotation
|
||||
CTEST(styles, write_xf30) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment textRotation=\"255\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_rotation(format, 270);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Alignment = rotation
|
||||
CTEST(styles, write_xf31) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment textRotation=\"90\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_rotation(format, 90);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. Alignment = rotation
|
||||
CTEST(styles, write_xf32) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\"><alignment textRotation=\"180\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_rotation(format, -90);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. With cell protection.
|
||||
CTEST(styles, write_xf33) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyProtection=\"1\"><protection locked=\"0\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_unlocked(format);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. With cell protection.
|
||||
CTEST(styles, write_xf34) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyProtection=\"1\"><protection hidden=\"1\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_hidden(format);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. With cell protection.
|
||||
CTEST(styles, write_xf35) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyProtection=\"1\"><protection locked=\"0\" hidden=\"1\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_unlocked(format);
|
||||
format_set_hidden(format);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
||||
|
||||
|
||||
// Test the _write_xf() method. With cell protection + align.
|
||||
CTEST(styles, write_xf36) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<xf numFmtId=\"0\" fontId=\"0\" fillId=\"0\" borderId=\"0\" xfId=\"0\" applyAlignment=\"1\" applyProtection=\"1\"><alignment horizontal=\"right\"/><protection locked=\"0\" hidden=\"1\"/></xf>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
lxw_format *format = lxw_format_new();
|
||||
|
||||
format_set_align(format, LXW_ALIGN_RIGHT);
|
||||
format_set_unlocked(format);
|
||||
format_set_hidden(format);
|
||||
|
||||
styles->file = testfile;
|
||||
|
||||
_write_xf(styles, format);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
lxw_format_free(format);
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Tests for the libxlsxwriter library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/styles.h"
|
||||
|
||||
// Test _xml_declaration().
|
||||
CTEST(styles, xml_declaration) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_styles *styles = lxw_styles_new();
|
||||
styles->file = testfile;
|
||||
|
||||
_styles_xml_declaration(styles);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_styles_free(styles);
|
||||
}
|
Reference in New Issue
Block a user