初始化PHP-Xlswrite扩展
This commit is contained in:
15
library/libxlsxwriter/test/unit/chart/main.c
Normal file
15
library/libxlsxwriter/test/unit/chart/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);
|
||||
}
|
||||
|
156
library/libxlsxwriter/test/unit/chart/test_chart.c
Normal file
156
library/libxlsxwriter/test/unit/chart/test_chart.c
Normal file
@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Tests for the lib_xlsx_writer library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/chart.h"
|
||||
|
||||
// Test assembling a complete Chart file.
|
||||
CTEST(chart, chart01) {
|
||||
|
||||
lxw_chart_series *series1;
|
||||
lxw_chart_series *series2;
|
||||
|
||||
uint8_t data[5][3] = {
|
||||
{1, 2, 3},
|
||||
{2, 4, 6},
|
||||
{3, 6, 9},
|
||||
{4, 8, 12},
|
||||
{5, 10, 15}
|
||||
};
|
||||
|
||||
|
||||
|
||||
char* got;
|
||||
char exp[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<c:chartSpace xmlns:c=\"http://schemas.openxmlformats.org/drawingml/2006/chart\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
"<c:lang val=\"en-US\"/>"
|
||||
"<c:chart>"
|
||||
"<c:plotArea>"
|
||||
"<c:layout/>"
|
||||
"<c:barChart>"
|
||||
"<c:barDir val=\"bar\"/>"
|
||||
"<c:grouping val=\"clustered\"/>"
|
||||
"<c:ser>"
|
||||
"<c:idx val=\"0\"/>"
|
||||
"<c:order val=\"0\"/>"
|
||||
"<c:val>"
|
||||
"<c:numRef>"
|
||||
"<c:f>Sheet1!$A$1:$A$5</c:f>"
|
||||
"<c:numCache>"
|
||||
"<c:formatCode>General</c:formatCode>"
|
||||
"<c:ptCount val=\"5\"/>"
|
||||
"<c:pt idx=\"0\">"
|
||||
"<c:v>1</c:v>"
|
||||
"</c:pt>"
|
||||
"<c:pt idx=\"1\">"
|
||||
"<c:v>2</c:v>"
|
||||
"</c:pt>"
|
||||
"<c:pt idx=\"2\">"
|
||||
"<c:v>3</c:v>"
|
||||
"</c:pt>"
|
||||
"<c:pt idx=\"3\">"
|
||||
"<c:v>4</c:v>"
|
||||
"</c:pt>"
|
||||
"<c:pt idx=\"4\">"
|
||||
"<c:v>5</c:v>"
|
||||
"</c:pt>"
|
||||
"</c:numCache>"
|
||||
"</c:numRef>"
|
||||
"</c:val>"
|
||||
"</c:ser>"
|
||||
"<c:ser>"
|
||||
"<c:idx val=\"1\"/>"
|
||||
"<c:order val=\"1\"/>"
|
||||
"<c:val>"
|
||||
"<c:numRef>"
|
||||
"<c:f>Sheet1!$B$1:$B$5</c:f>"
|
||||
"<c:numCache>"
|
||||
"<c:formatCode>General</c:formatCode>"
|
||||
"<c:ptCount val=\"5\"/>"
|
||||
"<c:pt idx=\"0\">"
|
||||
"<c:v>2</c:v>"
|
||||
"</c:pt>"
|
||||
"<c:pt idx=\"1\">"
|
||||
"<c:v>4</c:v>"
|
||||
"</c:pt>"
|
||||
"<c:pt idx=\"2\">"
|
||||
"<c:v>6</c:v>"
|
||||
"</c:pt>"
|
||||
"<c:pt idx=\"3\">"
|
||||
"<c:v>8</c:v>"
|
||||
"</c:pt>"
|
||||
"<c:pt idx=\"4\">"
|
||||
"<c:v>10</c:v>"
|
||||
"</c:pt>"
|
||||
"</c:numCache>"
|
||||
"</c:numRef>"
|
||||
"</c:val>"
|
||||
"</c:ser>"
|
||||
"<c:axId val=\"50010001\"/>"
|
||||
"<c:axId val=\"50010002\"/>"
|
||||
"</c:barChart>"
|
||||
"<c:catAx>"
|
||||
"<c:axId val=\"50010001\"/>"
|
||||
"<c:scaling>"
|
||||
"<c:orientation val=\"minMax\"/>"
|
||||
"</c:scaling>"
|
||||
"<c:axPos val=\"l\"/>"
|
||||
"<c:tickLblPos val=\"nextTo\"/>"
|
||||
"<c:crossAx val=\"50010002\"/>"
|
||||
"<c:crosses val=\"autoZero\"/>"
|
||||
"<c:auto val=\"1\"/>"
|
||||
"<c:lblAlgn val=\"ctr\"/>"
|
||||
"<c:lblOffset val=\"100\"/>"
|
||||
"</c:catAx>"
|
||||
"<c:valAx>"
|
||||
"<c:axId val=\"50010002\"/>"
|
||||
"<c:scaling>"
|
||||
"<c:orientation val=\"minMax\"/>"
|
||||
"</c:scaling>"
|
||||
"<c:axPos val=\"b\"/>"
|
||||
"<c:majorGridlines/>"
|
||||
"<c:numFmt formatCode=\"General\" sourceLinked=\"1\"/>"
|
||||
"<c:tickLblPos val=\"nextTo\"/>"
|
||||
"<c:crossAx val=\"50010001\"/>"
|
||||
"<c:crosses val=\"autoZero\"/>"
|
||||
"<c:crossBetween val=\"between\"/>"
|
||||
"</c:valAx>"
|
||||
"</c:plotArea>"
|
||||
"<c:legend>"
|
||||
"<c:legendPos val=\"r\"/>"
|
||||
"<c:layout/>"
|
||||
"</c:legend>"
|
||||
"<c:plotVisOnly val=\"1\"/>"
|
||||
"</c:chart>"
|
||||
"<c:printSettings>"
|
||||
"<c:headerFooter/>"
|
||||
"<c:pageMargins b=\"0.75\" l=\"0.7\" r=\"0.7\" t=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
|
||||
"<c:pageSetup/>"
|
||||
"</c:printSettings>"
|
||||
"</c:chartSpace>";
|
||||
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_chart *chart = lxw_chart_new(LXW_CHART_BAR);
|
||||
chart->file = testfile;
|
||||
|
||||
series1 = chart_add_series(chart, NULL, "Sheet1!$A$1:$A$5");
|
||||
series2 = chart_add_series(chart, NULL, "Sheet1!$B$1:$B$5");
|
||||
|
||||
lxw_chart_add_data_cache(series1->values, data[0], 5, 3, 0);
|
||||
lxw_chart_add_data_cache(series2->values, data[0], 5, 3, 1);
|
||||
|
||||
lxw_chart_assemble_xml_file(chart);
|
||||
|
||||
RUN_XLSX_STREQ_SHORT(exp, got);
|
||||
|
||||
lxw_chart_free(chart);
|
||||
}
|
||||
|
150
library/libxlsxwriter/test/unit/chart/test_chart_write_legend.c
Normal file
150
library/libxlsxwriter/test/unit/chart/test_chart_write_legend.c
Normal file
@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Tests for the libxlsxwriter library.
|
||||
*
|
||||
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../ctest.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../../include/xlsxwriter/chart.h"
|
||||
|
||||
// Test the _write_legend() function.
|
||||
CTEST(chart, write_legend01) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<c:legend><c:legendPos val=\"r\"/><c:layout/></c:legend>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_chart *chart = lxw_chart_new(LXW_CHART_AREA);
|
||||
chart->file = testfile;
|
||||
|
||||
_chart_write_legend(chart);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_chart_free(chart);
|
||||
}
|
||||
|
||||
CTEST(chart, write_legend02) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<c:legend><c:legendPos val=\"r\"/><c:layout/></c:legend>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_chart *chart = lxw_chart_new(LXW_CHART_AREA);
|
||||
chart->file = testfile;
|
||||
|
||||
chart_legend_set_position(chart, LXW_CHART_LEGEND_RIGHT);
|
||||
_chart_write_legend(chart);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_chart_free(chart);
|
||||
}
|
||||
|
||||
CTEST(chart, write_legend03) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<c:legend><c:legendPos val=\"t\"/><c:layout/></c:legend>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_chart *chart = lxw_chart_new(LXW_CHART_AREA);
|
||||
chart->file = testfile;
|
||||
|
||||
chart_legend_set_position(chart, LXW_CHART_LEGEND_TOP);
|
||||
_chart_write_legend(chart);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_chart_free(chart);
|
||||
}
|
||||
|
||||
CTEST(chart, write_legend04) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<c:legend><c:legendPos val=\"l\"/><c:layout/></c:legend>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_chart *chart = lxw_chart_new(LXW_CHART_AREA);
|
||||
chart->file = testfile;
|
||||
|
||||
chart_legend_set_position(chart, LXW_CHART_LEGEND_LEFT);
|
||||
_chart_write_legend(chart);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_chart_free(chart);
|
||||
}
|
||||
|
||||
CTEST(chart, write_legend05) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<c:legend><c:legendPos val=\"b\"/><c:layout/></c:legend>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_chart *chart = lxw_chart_new(LXW_CHART_AREA);
|
||||
chart->file = testfile;
|
||||
|
||||
chart_legend_set_position(chart, LXW_CHART_LEGEND_BOTTOM);
|
||||
_chart_write_legend(chart);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_chart_free(chart);
|
||||
}
|
||||
|
||||
|
||||
CTEST(chart, write_legend06) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_chart *chart = lxw_chart_new(LXW_CHART_AREA);
|
||||
chart->file = testfile;
|
||||
|
||||
chart_legend_set_position(chart, LXW_CHART_LEGEND_NONE);
|
||||
_chart_write_legend(chart);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_chart_free(chart);
|
||||
}
|
||||
|
||||
|
||||
CTEST(chart, write_legend07) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<c:legend><c:legendPos val=\"r\"/><c:layout/><c:overlay val=\"1\"/></c:legend>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_chart *chart = lxw_chart_new(LXW_CHART_AREA);
|
||||
chart->file = testfile;
|
||||
|
||||
chart_legend_set_position(chart, LXW_CHART_LEGEND_OVERLAY_RIGHT);
|
||||
_chart_write_legend(chart);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_chart_free(chart);
|
||||
}
|
||||
|
||||
|
||||
CTEST(chart, write_legend08) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<c:legend><c:legendPos val=\"l\"/><c:layout/><c:overlay val=\"1\"/></c:legend>";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_chart *chart = lxw_chart_new(LXW_CHART_AREA);
|
||||
chart->file = testfile;
|
||||
|
||||
chart_legend_set_position(chart, LXW_CHART_LEGEND_OVERLAY_LEFT);
|
||||
_chart_write_legend(chart);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_chart_free(chart);
|
||||
}
|
@ -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/chart.h"
|
||||
|
||||
// Test _xml_declaration().
|
||||
CTEST(chart, xml_declaration) {
|
||||
|
||||
char* got;
|
||||
char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
|
||||
FILE* testfile = lxw_tmpfile(NULL);
|
||||
|
||||
lxw_chart *chart = lxw_chart_new(LXW_CHART_AREA);
|
||||
chart->file = testfile;
|
||||
|
||||
_chart_xml_declaration(chart);
|
||||
|
||||
RUN_XLSX_STREQ(exp, got);
|
||||
|
||||
lxw_chart_free(chart);
|
||||
}
|
Reference in New Issue
Block a user