初始化PHP-Xlswrite扩展

This commit is contained in:
ykxiao
2024-03-05 10:01:08 +08:00
commit 879cf9584d
2483 changed files with 1054962 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
###############################################################################
#
# Makefile for libxlsxwriter library.
#
# Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
#
# Keep the output quiet by default.
Q=@
ifdef V
Q=
endif
# Directory variables.
INC_DIR = ../../../include
LIB_DIR = ../../../src
# Flags passed to the C compiler.
CFLAGS += -DTESTING -DCOLOR_OK -g -Wall -Wextra -Wno-unused-parameter $(GCOV)
# Make targets and objects.
SRCS = $(wildcard test*.c)
TESTS = $(patsubst %.c,%,$(SRCS))
OBJS = $(patsubst %.c,%.o,$(SRCS))
# Libs to link.
LIBS_A = $(LIB_DIR)/libxlsxwriter_test.a
LIBS_O = -lz
ifdef USE_SYSTEM_MINIZIP
LIBS_O += -lminizip
CFLAGS += -DUSE_SYSTEM_MINIZIP
endif
# Link libcrypto if needed.
ifdef USE_OPENSSL_MD5
LIBS_O += -lcrypto
endif
# Use a third party double number formatting function.
ifdef USE_DTOA_LIBRARY
CFLAGS += -DUSE_DTOA_LIBRARY
endif
# Make all the individual tests.
all : $(TESTS)
# Clean all the things!
clean :
$(Q)rm -f $(TESTS) test_all *.o *.gcno *.gcda
# Build the testscases.
%.o: %.c
$(Q)$(CC) -I$(INC_DIR) $(CFLAGS) -c $<
test_%: main.o test_%.o $(LIBS_A)
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS_O)
# Link all the tests into one test executable.
test_all : main.o $(OBJS) $(LIBS_A)
$(Q)$(CC) $(CFLAGS) -o $@ $^ $(LIBS_O)
# Run the tests.
test : all test_all
$(Q)./test_all

View 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);
}

View File

@@ -0,0 +1,168 @@
/*
* Tests for the lib_xlsx_writer library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/app.h"
// Test assembling a complete App file.
CTEST(app, app01) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\" xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\">"
"<Application>Microsoft Excel</Application>"
"<DocSecurity>0</DocSecurity>"
"<ScaleCrop>false</ScaleCrop>"
"<HeadingPairs>"
"<vt:vector size=\"2\" baseType=\"variant\">"
"<vt:variant>"
"<vt:lpstr>Worksheets</vt:lpstr>"
"</vt:variant>"
"<vt:variant>"
"<vt:i4>1</vt:i4>"
"</vt:variant>"
"</vt:vector>"
"</HeadingPairs>"
"<TitlesOfParts>"
"<vt:vector size=\"1\" baseType=\"lpstr\">"
"<vt:lpstr>Sheet1</vt:lpstr>"
"</vt:vector>"
"</TitlesOfParts>"
"<Company>"
"</Company>"
"<LinksUpToDate>false</LinksUpToDate>"
"<SharedDoc>false</SharedDoc>"
"<HyperlinksChanged>false</HyperlinksChanged>"
"<AppVersion>12.0000</AppVersion>"
"</Properties>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_app *app = lxw_app_new();
app->file = testfile;
lxw_app_add_part_name(app,"Sheet1");
lxw_app_add_heading_pair(app, "Worksheets", "1");
lxw_app_assemble_xml_file(app);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_app_free(app);
}
// Test assembling a complete App file.
CTEST(app, app02) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\" xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\">"
"<Application>Microsoft Excel</Application>"
"<DocSecurity>0</DocSecurity>"
"<ScaleCrop>false</ScaleCrop>"
"<HeadingPairs>"
"<vt:vector size=\"2\" baseType=\"variant\">"
"<vt:variant>"
"<vt:lpstr>Worksheets</vt:lpstr>"
"</vt:variant>"
"<vt:variant>"
"<vt:i4>2</vt:i4>"
"</vt:variant>"
"</vt:vector>"
"</HeadingPairs>"
"<TitlesOfParts>"
"<vt:vector size=\"2\" baseType=\"lpstr\">"
"<vt:lpstr>Sheet1</vt:lpstr>"
"<vt:lpstr>Sheet2</vt:lpstr>"
"</vt:vector>"
"</TitlesOfParts>"
"<Company>"
"</Company>"
"<LinksUpToDate>false</LinksUpToDate>"
"<SharedDoc>false</SharedDoc>"
"<HyperlinksChanged>false</HyperlinksChanged>"
"<AppVersion>12.0000</AppVersion>"
"</Properties>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_app *app = lxw_app_new();
app->file = testfile;
lxw_app_add_part_name(app,"Sheet1");
lxw_app_add_part_name(app,"Sheet2");
lxw_app_add_heading_pair(app, "Worksheets", "2");
lxw_app_assemble_xml_file(app);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_app_free(app);
}
// Test assembling a complete App file.
CTEST(app, app03) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\" xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\">"
"<Application>Microsoft Excel</Application>"
"<DocSecurity>0</DocSecurity>"
"<ScaleCrop>false</ScaleCrop>"
"<HeadingPairs>"
"<vt:vector size=\"4\" baseType=\"variant\">"
"<vt:variant>"
"<vt:lpstr>Worksheets</vt:lpstr>"
"</vt:variant>"
"<vt:variant>"
"<vt:i4>1</vt:i4>"
"</vt:variant>"
"<vt:variant>"
"<vt:lpstr>Named Ranges</vt:lpstr>"
"</vt:variant>"
"<vt:variant>"
"<vt:i4>1</vt:i4>"
"</vt:variant>"
"</vt:vector>"
"</HeadingPairs>"
"<TitlesOfParts>"
"<vt:vector size=\"2\" baseType=\"lpstr\">"
"<vt:lpstr>Sheet1</vt:lpstr>"
"<vt:lpstr>Sheet1!Print_Titles</vt:lpstr>"
"</vt:vector>"
"</TitlesOfParts>"
"<Company>"
"</Company>"
"<LinksUpToDate>false</LinksUpToDate>"
"<SharedDoc>false</SharedDoc>"
"<HyperlinksChanged>false</HyperlinksChanged>"
"<AppVersion>12.0000</AppVersion>"
"</Properties>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_app *app = lxw_app_new();
app->file = testfile;
lxw_app_add_part_name(app,"Sheet1");
lxw_app_add_part_name(app,"Sheet1!Print_Titles");
lxw_app_add_heading_pair(app, "Worksheets", "1");
lxw_app_add_heading_pair(app, "Named Ranges", "1");
lxw_app_assemble_xml_file(app);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_app_free(app);
}

View File

@@ -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/app.h"
// Test _xml_declaration().
CTEST(app, xml_declaration) {
char* got;
char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
FILE* testfile = lxw_tmpfile(NULL);
lxw_app *app = lxw_app_new();
app->file = testfile;
_app_xml_declaration(app);
RUN_XLSX_STREQ(exp, got);
lxw_app_free(app);
}

View 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);
}

View 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);
}

View 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);
}

View File

@@ -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);
}

View 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);
}

View File

@@ -0,0 +1,40 @@
/*
* Tests for the lib_xlsx_writer library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/chartsheet.h"
#include "../../../include/xlsxwriter/drawing.h"
// Test assembling a complete Chartsheet file.
CTEST(chartsheet, chartsheet) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<chartsheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<sheetPr/>"
"<sheetViews>"
"<sheetView workbookViewId=\"0\"/>"
"</sheetViews>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"<drawing r:id=\"rId1\"/>"
"</chartsheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_chartsheet *chartsheet = lxw_chartsheet_new(NULL);
chartsheet->file = testfile;
chartsheet->worksheet->drawing = lxw_drawing_new();
lxw_chartsheet_assemble_xml_file(chartsheet);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_chartsheet_free(chartsheet);
}

View File

@@ -0,0 +1,169 @@
/*
* Tests for the lib_xlsx_writer library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/chartsheet.h"
/* 1. Test the _write_sheet_protection() method. */
CTEST(chartsheet, write_write_sheet_protection01) {
char* got;
char exp[] = "<sheetProtection content=\"1\" objects=\"1\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_chartsheet *chartsheet = lxw_chartsheet_new(NULL);
chartsheet->file = testfile;
chartsheet->worksheet->file = testfile;
chartsheet_protect(chartsheet, NULL, NULL);
_chartsheet_write_sheet_protection(chartsheet);
RUN_XLSX_STREQ(exp, got);
lxw_chartsheet_free(chartsheet);
}
/* 2. Test the _write_sheet_protection() method. */
CTEST(chartsheet, write_write_sheet_protection02) {
char* got;
char exp[] = "<sheetProtection password=\"83AF\" content=\"1\" objects=\"1\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_chartsheet *chartsheet = lxw_chartsheet_new(NULL);
chartsheet->file = testfile;
chartsheet->worksheet->file = testfile;
chartsheet_protect(chartsheet, "password", NULL);
_chartsheet_write_sheet_protection(chartsheet);
RUN_XLSX_STREQ(exp, got);
lxw_chartsheet_free(chartsheet);
}
/* 3. Test the _write_sheet_protection() method. */
CTEST(chartsheet, write_write_sheet_protection03) {
char* got;
char exp[] = "<sheetProtection content=\"1\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_chartsheet *chartsheet = lxw_chartsheet_new(NULL);
chartsheet->file = testfile;
chartsheet->worksheet->file = testfile;
lxw_protection options = {.no_objects = 1};
chartsheet_protect(chartsheet, NULL, &options);
_chartsheet_write_sheet_protection(chartsheet);
RUN_XLSX_STREQ(exp, got);
lxw_chartsheet_free(chartsheet);
}
/* 4. Test the _write_sheet_protection() method. */
CTEST(chartsheet, write_write_sheet_protection04) {
char* got;
char exp[] = "<sheetProtection objects=\"1\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_chartsheet *chartsheet = lxw_chartsheet_new(NULL);
chartsheet->file = testfile;
chartsheet->worksheet->file = testfile;
lxw_protection options = {.no_content = 1};
chartsheet_protect(chartsheet, NULL, &options);
_chartsheet_write_sheet_protection(chartsheet);
RUN_XLSX_STREQ(exp, got);
lxw_chartsheet_free(chartsheet);
}
/* 5. Test the _write_sheet_protection() method. */
CTEST(chartsheet, write_write_sheet_protection05) {
char* got;
char exp[] = "";
FILE* testfile = lxw_tmpfile(NULL);
lxw_chartsheet *chartsheet = lxw_chartsheet_new(NULL);
chartsheet->file = testfile;
chartsheet->worksheet->file = testfile;
lxw_protection options = {.no_content = 1, .no_objects = 1};
chartsheet_protect(chartsheet, NULL, &options);
_chartsheet_write_sheet_protection(chartsheet);
RUN_XLSX_STREQ(exp, got);
lxw_chartsheet_free(chartsheet);
}
/* 6. Test the _write_sheet_protection() method. */
CTEST(chartsheet, write_write_sheet_protection06) {
char* got;
char exp[] = "<sheetProtection password=\"83AF\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_chartsheet *chartsheet = lxw_chartsheet_new(NULL);
chartsheet->file = testfile;
chartsheet->worksheet->file = testfile;
lxw_protection options = {.no_content = 1, .no_objects = 1};
chartsheet_protect(chartsheet, "password", &options);
_chartsheet_write_sheet_protection(chartsheet);
RUN_XLSX_STREQ(exp, got);
lxw_chartsheet_free(chartsheet);
}
/* 7. Test the _write_sheet_protection() method. */
CTEST(chartsheet, write_write_sheet_protection07) {
char* got;
char exp[] = "<sheetProtection password=\"83AF\" content=\"1\" objects=\"1\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_chartsheet *chartsheet = lxw_chartsheet_new(NULL);
chartsheet->file = testfile;
chartsheet->worksheet->file = testfile;
lxw_protection options = {
.objects = 1,
.scenarios = 1,
.format_cells = 1,
.format_columns = 1,
.format_rows = 1,
.insert_columns = 1,
.insert_rows = 1,
.insert_hyperlinks = 1,
.delete_columns = 1,
.delete_rows = 1,
.no_select_locked_cells = 1,
.sort = 1,
.autofilter = 1,
.pivot_tables = 1,
.no_select_unlocked_cells = 1,
};
chartsheet_protect(chartsheet, "password", &options);
_chartsheet_write_sheet_protection(chartsheet);
RUN_XLSX_STREQ(exp, got);
lxw_chartsheet_free(chartsheet);
}

View File

@@ -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/chartsheet.h"
// Test _xml_declaration().
CTEST(chartsheet, xml_declaration) {
char* got;
char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
FILE* testfile = tmpfile();
lxw_chartsheet *chartsheet = lxw_chartsheet_new(NULL);
chartsheet->file = testfile;
_chartsheet_xml_declaration(chartsheet);
RUN_XLSX_STREQ(exp, got);
lxw_chartsheet_free(chartsheet);
}

View 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);
}

View File

@@ -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/comment.h"
// Test _xml_declaration().
CTEST(comment, xml_declaration) {
char* got;
char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
FILE* testfile = tmpfile();
lxw_comment *comment = lxw_comment_new();
comment->file = testfile;
_comment_xml_declaration(comment);
RUN_XLSX_STREQ(exp, got);
lxw_comment_free(comment);
}

View 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);
}

View File

@@ -0,0 +1,52 @@
/*
* Tests for the lib_xlsx_writer library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/content_types.h"
// Test assembling a complete ContentTypes file.
CTEST(content_types, content_types01) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\">"
"<Default Extension=\"rels\" ContentType=\"application/vnd.openxmlformats-package.relationships+xml\"/>"
"<Default Extension=\"xml\" ContentType=\"application/xml\"/>"
"<Default Extension=\"jpeg\" ContentType=\"image/jpeg\"/>"
"<Override PartName=\"/docProps/app.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.extended-properties+xml\"/>"
"<Override PartName=\"/docProps/core.xml\" ContentType=\"application/vnd.openxmlformats-package.core-properties+xml\"/>"
"<Override PartName=\"/xl/styles.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml\"/>"
"<Override PartName=\"/xl/theme/theme1.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.theme+xml\"/>"
"<Override PartName=\"/xl/workbook.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml\"/>"
"<Override PartName=\"/xl/worksheets/sheet1.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml\"/>"
"<Override PartName=\"/xl/sharedStrings.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml\"/>"
"<Override PartName=\"/xl/calcChain.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.calcChain+xml\"/>"
"</Types>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_content_types *content_types = lxw_content_types_new();
content_types->file = testfile;
lxw_ct_add_override(content_types, "/xl/workbook.xml",
LXW_APP_DOCUMENT "spreadsheetml.sheet.main+xml");
lxw_ct_add_worksheet_name(content_types, "/xl/worksheets/sheet1.xml");
lxw_ct_add_default(content_types, "jpeg", "image/jpeg");
lxw_ct_add_shared_strings(content_types);
lxw_ct_add_calc_chain(content_types);
lxw_content_types_assemble_xml_file(content_types);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_content_types_free(content_types);
}

View File

@@ -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/content_types.h"
// Test the _write_default() function.
CTEST(content_types, write_default) {
char* got;
char exp[] = "<Default Extension=\"xml\" ContentType=\"application/xml\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_content_types *content_types = lxw_content_types_new();
content_types->file = testfile;
_write_default(content_types, "xml", "application/xml");
RUN_XLSX_STREQ(exp, got);
lxw_content_types_free(content_types);
}

View File

@@ -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/content_types.h"
// Test the _write_override() function.
CTEST(content_types, write_override) {
char* got;
char exp[] = "<Override PartName=\"/docProps/core.xml\" ContentType=\"app...\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_content_types *content_types = lxw_content_types_new();
content_types->file = testfile;
_write_override(content_types, "/docProps/core.xml", "app...");
RUN_XLSX_STREQ(exp, got);
lxw_content_types_free(content_types);
}

View File

@@ -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/content_types.h"
// Test _xml_declaration().
CTEST(content_types, xml_declaration) {
char* got;
char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
FILE* testfile = lxw_tmpfile(NULL);
lxw_content_types *content_types = lxw_content_types_new();
content_types->file = testfile;
_content_types_xml_declaration(content_types);
RUN_XLSX_STREQ(exp, got);
lxw_content_types_free(content_types);
}

View 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);
}

View File

@@ -0,0 +1,113 @@
/*
* Tests for the lib_xlsx_writer library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/core.h"
#include "../../../include/xlsxwriter/workbook.h"
#ifdef _WIN32
#define timegm _mkgmtime
#endif
// Test assembling a complete core file.
CTEST(core, core01) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<cp:coreProperties xmlns:cp=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:dcmitype=\"http://purl.org/dc/dcmitype/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
"<dc:creator>A User</dc:creator>"
"<cp:lastModifiedBy>A User</cp:lastModifiedBy>"
"<dcterms:created xsi:type=\"dcterms:W3CDTF\">2010-01-01T00:00:00Z</dcterms:created>"
"<dcterms:modified xsi:type=\"dcterms:W3CDTF\">2010-01-01T00:00:00Z</dcterms:modified>"
"</cp:coreProperties>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_core *core = lxw_core_new();
lxw_workbook *workbook = workbook_new(NULL);
core->file = testfile;
core->properties = workbook->properties;
// Add data to the core->properties.
struct tm tmp_tm;
tmp_tm.tm_year = 110;
tmp_tm.tm_mon = 0;
tmp_tm.tm_mday = 1;
tmp_tm.tm_hour = 0;
tmp_tm.tm_min = 0;
tmp_tm.tm_sec = 0;
tmp_tm.tm_isdst = -1;
core->properties->created = timegm(&tmp_tm);
core->properties->author = strdup("A User");
lxw_core_assemble_xml_file(core);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_workbook_free(workbook);
lxw_core_free(core);
}
// Test assembling a complete core file.
CTEST(core, core02) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<cp:coreProperties xmlns:cp=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:dcmitype=\"http://purl.org/dc/dcmitype/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
"<dc:title>This is an example spreadsheet</dc:title>"
"<dc:subject>With document properties</dc:subject>"
"<dc:creator>A Person</dc:creator>"
"<cp:keywords>Sample, Example, Properties</cp:keywords>"
"<dc:description>Created with libxlsxwriter</dc:description>"
"<cp:lastModifiedBy>A Person</cp:lastModifiedBy>"
"<dcterms:created xsi:type=\"dcterms:W3CDTF\">2011-04-06T19:45:15Z</dcterms:created>"
"<dcterms:modified xsi:type=\"dcterms:W3CDTF\">2011-04-06T19:45:15Z</dcterms:modified>"
"<cp:category>Example spreadsheets</cp:category>"
"<cp:contentStatus>Quo</cp:contentStatus>"
"</cp:coreProperties>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_core *core = lxw_core_new();
lxw_workbook *workbook = workbook_new(NULL);
core->file = testfile;
core->properties = workbook->properties;
// Add data to the core->properties.
struct tm tmp_tm;
tmp_tm.tm_year = 111;
tmp_tm.tm_mon = 3;
tmp_tm.tm_mday = 6;
tmp_tm.tm_hour = 19;
tmp_tm.tm_min = 45;
tmp_tm.tm_sec = 15;
tmp_tm.tm_isdst = -1;
core->properties->created = timegm(&tmp_tm);
core->properties->title = strdup("This is an example spreadsheet");
core->properties->subject = strdup("With document properties");
core->properties->author = strdup("A Person");
core->properties->keywords = strdup("Sample, Example, Properties");
core->properties->comments = strdup("Created with libxlsxwriter");
core->properties->category = strdup("Example spreadsheets");
core->properties->status = strdup("Quo");
lxw_core_assemble_xml_file(core);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_workbook_free(workbook);
lxw_core_free(core);
}

View File

@@ -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/core.h"
// Test _xml_declaration().
CTEST(core, xml_declaration) {
char* got;
char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
FILE* testfile = lxw_tmpfile(NULL);
lxw_core *core = lxw_core_new();
core->file = testfile;
_core_xml_declaration(core);
RUN_XLSX_STREQ(exp, got);
lxw_core_free(core);
}

View File

@@ -0,0 +1,493 @@
/* Copyright 2011,2012 Bas van den Berg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* https://github.com/bvdberg/ctest */
#ifndef CTEST_H
#define CTEST_H
#include <math.h>
#include <float.h>
typedef void (*SetupFunc)(void*);
typedef void (*TearDownFunc)(void*);
struct ctest {
const char* ssname; // suite name
const char* ttname; // test name
void (*run)();
int skip;
void* data;
SetupFunc setup;
TearDownFunc teardown;
unsigned int magic;
};
#define __FNAME(sname, tname) __ctest_##sname##_##tname##_run
#define __TNAME(sname, tname) __ctest_##sname##_##tname
#define __CTEST_MAGIC (0xdeadbeef)
#ifdef __APPLE__
#define __Test_Section __attribute__ ((unused,section ("__DATA, .ctest")))
#elif defined(_MSC_VER)
#define __Test_Section
#else
#define __Test_Section __attribute__ ((unused,section (".ctest")))
#endif
#define __CTEST_STRUCT(sname, tname, _skip, __data, __setup, __teardown) \
struct ctest __TNAME(sname, tname) __Test_Section = { \
.ssname=#sname, \
.ttname=#tname, \
.run = __FNAME(sname, tname), \
.skip = _skip, \
.data = __data, \
.setup = (SetupFunc)__setup, \
.teardown = (TearDownFunc)__teardown, \
.magic = __CTEST_MAGIC };
#define CTEST_DATA(sname) struct sname##_data
#ifndef _MSC_VER
#define ATTR_WEAK __attribute__ ((weak))
#else
#define ATTR_WEAK
#endif
#define CTEST_SETUP(sname) \
void ATTR_WEAK sname##_setup(struct sname##_data* data)
#define CTEST_TEARDOWN(sname) \
void ATTR_WEAK sname##_teardown(struct sname##_data* data)
#define __CTEST_INTERNAL(sname, tname, _skip) \
void __FNAME(sname, tname)(); \
__CTEST_STRUCT(sname, tname, _skip, NULL, NULL, NULL) \
void __FNAME(sname, tname)()
#ifdef __APPLE__
#define SETUP_FNAME(sname) NULL
#define TEARDOWN_FNAME(sname) NULL
#else
#define SETUP_FNAME(sname) sname##_setup
#define TEARDOWN_FNAME(sname) sname##_teardown
#endif
#define __CTEST2_INTERNAL(sname, tname, _skip) \
static struct sname##_data __ctest_##sname##_data; \
CTEST_SETUP(sname); \
CTEST_TEARDOWN(sname); \
void __FNAME(sname, tname)(struct sname##_data* data); \
__CTEST_STRUCT(sname, tname, _skip, &__ctest_##sname##_data, SETUP_FNAME(sname), TEARDOWN_FNAME(sname)) \
void __FNAME(sname, tname)(struct sname##_data* data)
void CTEST_LOG(char *fmt, ...);
void CTEST_ERR(char *fmt, ...); // doesn't return
#define CTEST(sname, tname) __CTEST_INTERNAL(sname, tname, 0)
#define CTEST_SKIP(sname, tname) __CTEST_INTERNAL(sname, tname, 1)
#define CTEST2(sname, tname) __CTEST2_INTERNAL(sname, tname, 0)
#define CTEST2_SKIP(sname, tname) __CTEST2_INTERNAL(sname, tname, 1)
void assert_str(const char* exp, const char* real, const char* caller, int line);
#define ASSERT_STR(exp, real) assert_str(exp, real, __FILE__, __LINE__)
void assert_data(const unsigned char* exp, int expsize,
const unsigned char* real, int realsize,
const char* caller, int line);
#define ASSERT_DATA(exp, expsize, real, realsize) \
assert_data(exp, expsize, real, realsize, __FILE__, __LINE__)
void assert_equal(long exp, long real, const char* caller, int line);
#define ASSERT_EQUAL(exp, real) assert_equal(exp, real, __FILE__, __LINE__)
void assert_not_equal(long exp, long real, const char* caller, int line);
#define ASSERT_NOT_EQUAL(exp, real) assert_not_equal(exp, real, __FILE__, __LINE__)
void assert_double(double exp, double real, const char* caller, int line);
#define ASSERT_DOUBLE(exp, real) assert_double(exp, real, __FILE__, __LINE__)
void assert_null(void* real, const char* caller, int line);
#define ASSERT_NULL(real) assert_null((void*)real, __FILE__, __LINE__)
void assert_not_null(const void* real, const char* caller, int line);
#define ASSERT_NOT_NULL(real) assert_not_null(real, __FILE__, __LINE__)
void assert_true(int real, const char* caller, int line);
#define ASSERT_TRUE(real) assert_true(real, __FILE__, __LINE__)
void assert_false(int real, const char* caller, int line);
#define ASSERT_FALSE(real) assert_false(real, __FILE__, __LINE__)
void assert_fail(const char* caller, int line);
#define ASSERT_FAIL() assert_fail(__FILE__, __LINE__)
#ifdef CTEST_MAIN
#include <setjmp.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#ifndef _MSC_VER
#include <sys/time.h>
#include <unistd.h>
#else
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <windows.h>
#endif
#ifdef __APPLE__
#include <dlfcn.h>
#endif
//#define COLOR_OK
static size_t ctest_errorsize;
static char* ctest_errormsg;
#define MSG_SIZE 4096
static char ctest_errorbuffer[MSG_SIZE];
static jmp_buf ctest_err;
static int color_output = 1;
static const char* suite_name;
typedef int (*filter_func)(struct ctest*);
#define ANSI_BLACK "\033[0;30m"
#define ANSI_RED "\033[0;31m"
#define ANSI_GREEN "\033[0;32m"
#define ANSI_YELLOW "\033[0;33m"
#define ANSI_BLUE "\033[0;34m"
#define ANSI_MAGENTA "\033[0;35m"
#define ANSI_CYAN "\033[0;36m"
#define ANSI_GREY "\033[0;37m"
#define ANSI_DARKGREY "\033[01;30m"
#define ANSI_BRED "\033[01;31m"
#define ANSI_BGREEN "\033[01;32m"
#define ANSI_BYELLOW "\033[01;33m"
#define ANSI_BBLUE "\033[01;34m"
#define ANSI_BMAGENTA "\033[01;35m"
#define ANSI_BCYAN "\033[01;36m"
#define ANSI_WHITE "\033[01;37m"
#define ANSI_NORMAL "\033[0m"
static CTEST(suite, test) { }
static void msg_start(const char* color, const char* title) {
int size;
if (color_output) {
size = snprintf(ctest_errormsg, ctest_errorsize, "%s", color);
ctest_errorsize -= size;
ctest_errormsg += size;
}
size = snprintf(ctest_errormsg, ctest_errorsize, " %s: ", title);
ctest_errorsize -= size;
ctest_errormsg += size;
}
static void msg_end() {
int size;
if (color_output) {
size = snprintf(ctest_errormsg, ctest_errorsize, ANSI_NORMAL);
ctest_errorsize -= size;
ctest_errormsg += size;
}
size = snprintf(ctest_errormsg, ctest_errorsize, "\n");
ctest_errorsize -= size;
ctest_errormsg += size;
}
void CTEST_LOG(char *fmt, ...)
{
va_list argp;
msg_start(ANSI_BLUE, "LOG");
va_start(argp, fmt);
int size = vsnprintf(ctest_errormsg, ctest_errorsize, fmt, argp);
ctest_errorsize -= size;
ctest_errormsg += size;
va_end(argp);
msg_end();
}
void CTEST_ERR(char *fmt, ...)
{
va_list argp;
msg_start(ANSI_RED, "ERR");
va_start(argp, fmt);
int size = vsnprintf(ctest_errormsg, ctest_errorsize, fmt, argp);
ctest_errorsize -= size;
ctest_errormsg += size;
va_end(argp);
msg_end();
longjmp(ctest_err, 1);
}
void assert_str(const char* exp, const char* real, const char* caller, int line) {
if ((exp == NULL && real != NULL) ||
(exp != NULL && real == NULL) ||
(exp && real && strcmp(exp, real) != 0)) {
CTEST_ERR("%s:%d\n\texpected '%s',\n\tgot '%s'", caller, line, exp, real);
}
}
void assert_data(const unsigned char* exp, int expsize,
const unsigned char* real, int realsize,
const char* caller, int line) {
int i;
if (expsize != realsize) {
CTEST_ERR("%s:%d\n\texpected %d bytes,\n\tgot %d", caller, line, expsize, realsize);
}
for (i=0; i<expsize; i++) {
if (exp[i] != real[i]) {
CTEST_ERR("%s:%d expected 0x%02x at offset %d\n\tgot 0x%02x",
caller, line, exp[i], i, real[i]);
}
}
}
void assert_equal(long exp, long real, const char* caller, int line) {
if (exp != real) {
CTEST_ERR("%s:%d\n\texpected %ld,\n\tgot %ld", caller, line, exp, real);
}
}
void assert_not_equal(long exp, long real, const char* caller, int line) {
if ((exp) == (real)) {
CTEST_ERR("%s:%d should not be %ld", caller, line, real);
}
}
void assert_double(double exp, double real, const char* caller, int line) {
double diff = fabs(exp - real);
exp = fabs(exp);
real = fabs(real);
double largest = (real > exp) ? real : exp;
if (diff > largest * FLT_EPSILON) {
CTEST_ERR("%s:%d\n\texpected %g,\n\tgot %g", caller, line, exp, real);
}
}
void assert_null(void* real, const char* caller, int line) {
if ((real) != NULL) {
CTEST_ERR("%s:%d should be NULL", caller, line);
}
}
void assert_not_null(const void* real, const char* caller, int line) {
if (real == NULL) {
CTEST_ERR("%s:%d should not be NULL", caller, line);
}
}
void assert_true(int real, const char* caller, int line) {
if ((real) == 0) {
CTEST_ERR("%s:%d should be true", caller, line);
}
}
void assert_false(int real, const char* caller, int line) {
if ((real) != 0) {
CTEST_ERR("%s:%d should be false", caller, line);
}
}
void assert_fail(const char* caller, int line) {
CTEST_ERR("%s:%d shouldn't come here", caller, line);
}
static int suite_all(struct ctest* t) {
return 1;
}
static int suite_filter(struct ctest* t) {
return strncmp(suite_name, t->ssname, strlen(suite_name)) == 0;
}
#ifdef _MSC_VER
// We need a portable `gettimeofday` implementation.
// winsock2.h includes `struct timeval`.
#define EPOCH_TIME 116444736000000000ull
#define HECTONANOSEC_PER_SEC 10000000ull
static int gettimeofday(struct timeval* tp, void* tz)
{
int res = 0;
union {
uint64_t ns100;
FILETIME file_time;
} now;
SYSTEMTIME system_time;
uint64_t value;
if (tp != NULL) {
GetSystemTimeAsFileTime(&now.file_time);
now.ns100 -= EPOCH_TIME;
tp->tv_sec = now.ns100 / HECTONANOSEC_PER_SEC;
tp->tv_usec = (long) (now.ns100 % HECTONANOSEC_PER_SEC) / 10;
}
return res;
}
#endif
static uint64_t getCurrentTime() {
struct timeval now;
gettimeofday(&now, NULL);
uint64_t now64 = now.tv_sec;
now64 *= 1000000;
now64 += (now.tv_usec);
return now64;
}
static void color_print(const char* color, const char* text) {
if (color_output)
printf("%s%s"ANSI_NORMAL"\n", color, text);
else
printf("%s\n", text);
}
#ifdef __APPLE__
static void *find_symbol(struct ctest *test, const char *fname)
{
size_t len = strlen(test->ssname) + 1 + strlen(fname);
char *symbol_name = (char *) malloc(len + 1);
memset(symbol_name, 0, len + 1);
snprintf(symbol_name, len + 1, "%s_%s", test->ssname, fname);
//fprintf(stderr, ">>>> dlsym: loading %s\n", symbol_name);
void *symbol = dlsym(RTLD_DEFAULT, symbol_name);
if (!symbol) {
//fprintf(stderr, ">>>> ERROR: %s\n", dlerror());
}
// returns NULL on error
free(symbol_name);
return symbol;
}
#endif
int ctest_main(int argc, const char *argv[])
{
static int total = 0;
static int num_ok = 0;
static int num_fail = 0;
static int num_skip = 0;
static int index = 1;
static filter_func filter = suite_all;
if (argc == 2) {
suite_name = argv[1];
filter = suite_filter;
}
color_output = isatty(1);
uint64_t t1 = getCurrentTime();
struct ctest* ctest_begin = &__TNAME(suite, test);
struct ctest* ctest_end = &__TNAME(suite, test);
// find begin and end of section by comparing magics
while (1) {
struct ctest* t = ctest_begin-1;
if (t->magic != __CTEST_MAGIC) break;
ctest_begin--;
}
while (1) {
struct ctest* t = ctest_end+1;
if (t->magic != __CTEST_MAGIC) break;
ctest_end++;
}
ctest_end++; // end after last one
static struct ctest* test;
for (test = ctest_begin; test != ctest_end; test++) {
if (test == &__ctest_suite_test) continue;
if (filter(test)) total++;
}
for (test = ctest_begin; test != ctest_end; test++) {
if (test == &__ctest_suite_test) continue;
if (filter(test)) {
ctest_errorbuffer[0] = 0;
ctest_errorsize = MSG_SIZE-1;
ctest_errormsg = ctest_errorbuffer;
printf("TEST %d/%d %s:%s ", index, total, test->ssname, test->ttname);
fflush(stdout);
if (test->skip) {
color_print(ANSI_BYELLOW, "[SKIPPED]");
num_skip++;
} else {
int result = setjmp(ctest_err);
if (result == 0) {
#ifdef __APPLE__
if (!test->setup) {
test->setup = find_symbol(test, "setup");
}
if (!test->teardown) {
test->teardown = find_symbol(test, "teardown");
}
#endif
if (test->setup) test->setup(test->data);
if (test->data)
test->run(test->data);
else
test->run();
if (test->teardown) test->teardown(test->data);
// if we got here it's ok
#ifdef COLOR_OK
color_print(ANSI_GREEN, "[OK]");
#else
printf("[OK]\n");
#endif
num_ok++;
} else {
color_print(ANSI_RED, "[FAIL]");
num_fail++;
}
if (ctest_errorsize != MSG_SIZE-1) printf("%s", ctest_errorbuffer);
}
index++;
}
}
uint64_t t2 = getCurrentTime();
const char* color = (num_fail) ? ANSI_RED : ANSI_GREEN;
char results[80];
snprintf(results, sizeof(results),"\nRESULTS: %d tests (%d ok, %d failed, %d skipped) ran in %lld ms",
total, num_ok, num_fail, num_skip, (long long int)(t2 - t1)/1000);
color_print(color, results);
return num_fail;
}
#endif
#endif

View 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);
}

View File

@@ -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/custom.h"
// Test _xml_declaration().
CTEST(custom, xml_declaration) {
char* got;
char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
FILE* testfile = lxw_tmpfile(NULL);
lxw_custom *custom = lxw_custom_new();
custom->file = testfile;
_custom_xml_declaration(custom);
RUN_XLSX_STREQ(exp, got);
lxw_custom_free(custom);
}

View 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);
}

View File

@@ -0,0 +1,102 @@
/*
* Tests for the lib_xlsx_writer library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include <string.h>
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/drawing.h"
#include "../../../include/xlsxwriter/worksheet.h"
// Test assembling a complete Drawing file.
CTEST(drawing, drawing_image01) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<xdr:wsDr xmlns:xdr=\"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">"
"<xdr:twoCellAnchor editAs=\"oneCell\">"
"<xdr:from>"
"<xdr:col>2</xdr:col>"
"<xdr:colOff>0</xdr:colOff>"
"<xdr:row>1</xdr:row>"
"<xdr:rowOff>0</xdr:rowOff>"
"</xdr:from>"
"<xdr:to>"
"<xdr:col>3</xdr:col>"
"<xdr:colOff>533257</xdr:colOff>"
"<xdr:row>6</xdr:row>"
"<xdr:rowOff>190357</xdr:rowOff>"
"</xdr:to>"
"<xdr:pic>"
"<xdr:nvPicPr>"
"<xdr:cNvPr id=\"2\" name=\"Picture 1\" descr=\"republic.png\"/>"
"<xdr:cNvPicPr>"
"<a:picLocks noChangeAspect=\"1\"/>"
"</xdr:cNvPicPr>"
"</xdr:nvPicPr>"
"<xdr:blipFill>"
"<a:blip xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" r:embed=\"rId1\"/>"
"<a:stretch>"
"<a:fillRect/>"
"</a:stretch>"
"</xdr:blipFill>"
"<xdr:spPr>"
"<a:xfrm>"
"<a:off x=\"1219200\" y=\"190500\"/>"
"<a:ext cx=\"1142857\" cy=\"1142857\"/>"
"</a:xfrm>"
"<a:prstGeom prst=\"rect\">"
"<a:avLst/>"
"</a:prstGeom>"
"</xdr:spPr>"
"</xdr:pic>"
"<xdr:clientData/>"
"</xdr:twoCellAnchor>"
"</xdr:wsDr>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_drawing *drawing = lxw_drawing_new();
drawing->file = testfile;
drawing->embedded = LXW_TRUE;
lxw_drawing_object *drawing_object = calloc(1, sizeof(lxw_drawing_object));
drawing_object->type = LXW_DRAWING_IMAGE;
drawing_object->anchor = LXW_OBJECT_MOVE_DONT_SIZE;
drawing_object->from.col = 2;
drawing_object->from.col_offset = 0;
drawing_object->from.row = 1;
drawing_object->from.row_offset = 0;
drawing_object->to.col = 3;
drawing_object->to.col_offset = 533257;
drawing_object->to.row = 6;
drawing_object->to.row_offset = 190357;
drawing_object->description = strdup("republic.png");
drawing_object->col_absolute = 1219200;
drawing_object->row_absolute = 190500;
drawing_object->width = 1142857;
drawing_object->height = 1142857;
drawing_object->rel_index = 1;
lxw_add_drawing_object(drawing, drawing_object);
lxw_drawing_assemble_xml_file(drawing);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_drawing_free(drawing);
}

View File

@@ -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/drawing.h"
// Test _xml_declaration().
CTEST(drawing, xml_declaration) {
char* got;
char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
FILE* testfile = lxw_tmpfile(NULL);
lxw_drawing *drawing = lxw_drawing_new();
drawing->file = testfile;
_drawing_xml_declaration(drawing);
RUN_XLSX_STREQ(exp, got);
lxw_drawing_free(drawing);
}

View File

@@ -0,0 +1,137 @@
#include <stdio.h>
#include <stdlib.h>
#include "../../include/xlsxwriter/utility.h"
/* Compare expected results with the XML data written to the output
* test file.
*/
#define RUN_XLSX_STREQ(exp, got) \
fflush(testfile); \
int file_size = ftell(testfile); \
\
got = (char*)calloc(file_size + 1, 1); \
\
rewind(testfile); \
(void)fread(got, file_size, 1, testfile); \
\
ASSERT_STR((exp), (got)); \
\
if (got) \
free(got); \
\
fclose(testfile)
/* Compare expected results with the XML data written to the output
* test file. Same as the previous macro but only shows the difference
* from where it starts. Suitable for long strings of XML data.
*/
#define RUN_XLSX_STREQ_SHORT(exp, got) \
fflush(testfile); \
int file_size = ftell(testfile); \
\
got = (char*)calloc(file_size + 1, 1); \
\
rewind(testfile); \
(void)fread(got, file_size, 1, testfile); \
\
/* Start comparison from first difference. */ \
char *got_short = got; \
char *exp_short = exp; \
while (*exp_short && *exp_short == *got_short) { \
exp_short++; \
got_short++; \
} \
\
ASSERT_STR(exp_short, got_short); \
\
if (got) \
free(got); \
\
fclose(testfile)
#define TEST_COL_TO_NAME(num, abs, exp) \
lxw_col_to_name(got, num, abs); \
ASSERT_STR(exp, got);
#define TEST_ROWCOL_TO_CELL(row, col, exp) \
lxw_rowcol_to_cell(got, row, col); \
ASSERT_STR(exp, got);
#define TEST_ROWCOL_TO_CELL_ABS(row, col, row_abs, col_abs, exp) \
lxw_rowcol_to_cell_abs(got, row, col, row_abs, col_abs); \
ASSERT_STR(exp, got);
#define TEST_ROWCOL_TO_RANGE(row1, col1, row2, col2, exp) \
lxw_rowcol_to_range(got, row1, col1, row2, col2); \
ASSERT_STR(exp, got);
#define TEST_ROWCOL_TO_RANGE_ABS(row1, col1, row2, col2, exp) \
lxw_rowcol_to_range_abs(got, row1, col1, row2, col2); \
ASSERT_STR(exp, got);
#define TEST_ROWCOL_TO_FORMULA_ABS(sheet, row1, col1, row2, col2, exp) \
lxw_rowcol_to_formula_abs(got, sheet, row1, col1, row2, col2); \
ASSERT_STR(exp, got);
#define TEST_DATETIME_TIME(_hour, _min, _sec, exp) \
datetime = (lxw_datetime*)calloc(1, sizeof(lxw_datetime)); \
datetime->hour = _hour; \
datetime->min = _min; \
datetime->sec = _sec; \
\
got = lxw_datetime_to_excel_datetime(datetime); \
\
ASSERT_DOUBLE(exp, got); \
free(datetime);
#define TEST_DATETIME_DATE(_year, _month, _day, exp) \
datetime = (lxw_datetime*)calloc(1, sizeof(lxw_datetime)); \
datetime->year = _year; \
datetime->month = _month; \
datetime->day = _day; \
\
got = lxw_datetime_to_excel_datetime(datetime); \
\
ASSERT_DOUBLE(exp, got); \
free(datetime);
#define TEST_DATETIME_DATE_1904(_year, _month, _day, exp) \
datetime = (lxw_datetime*)calloc(1, sizeof(lxw_datetime)); \
datetime->year = _year; \
datetime->month = _month; \
datetime->day = _day; \
\
got = lxw_datetime_to_excel_date_epoch(datetime, 1); \
\
ASSERT_DOUBLE(exp, got); \
free(datetime);
#define TEST_DATETIME(_year, _month, _day, _hour, _min, _sec, exp) \
datetime = (lxw_datetime*)calloc(1, sizeof(lxw_datetime)); \
datetime->year = _year; \
datetime->month = _month; \
datetime->day = _day; \
datetime->hour = _hour; \
datetime->min = _min; \
datetime->sec = _sec; \
\
got = lxw_datetime_to_excel_datetime(datetime); \
\
ASSERT_DOUBLE(exp, got); \
free(datetime);
#define TEST_UNIXTIME(_unixtime, exp) \
got = lxw_unixtime_to_excel_date(_unixtime); \
ASSERT_DOUBLE(exp, got);
#define TEST_UNIXTIME_1904(_unixtime, exp) \
got = lxw_unixtime_to_excel_date_epoch(_unixtime, 1); \
ASSERT_DOUBLE(exp, got);

View 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);
}

View File

@@ -0,0 +1,28 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "xlsxwriter/metadata.h"
// Test _xml_declaration().
CTEST(metadata, xml_declaration) {
char* got;
char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
FILE* testfile = tmpfile();
lxw_metadata *metadata = lxw_metadata_new();
metadata->file = testfile;
_metadata_xml_declaration(metadata);
RUN_XLSX_STREQ(exp, got);
lxw_metadata_free(metadata);
}

View 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);
}

View File

@@ -0,0 +1,70 @@
/*
* Tests for the lib_xlsx_writer library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/relationships.h"
// Test assembling a complete Relationships file.
CTEST(relationships, relationships01) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">"
"<Relationship Id=\"rId1\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet\" Target=\"worksheets/sheet1.xml\"/>"
"<Relationship Id=\"rId2\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme\" Target=\"theme/theme1.xml\"/>"
"<Relationship Id=\"rId3\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles\" Target=\"styles.xml\"/>"
"<Relationship Id=\"rId4\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings\" Target=\"sharedStrings.xml\"/>"
"<Relationship Id=\"rId5\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain\" Target=\"calcChain.xml\"/>"
"</Relationships>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_relationships *rels = lxw_relationships_new();
rels->file = testfile;
lxw_add_document_relationship(rels, "/worksheet", "worksheets/sheet1.xml");
lxw_add_document_relationship(rels, "/theme", "theme/theme1.xml");
lxw_add_document_relationship(rels, "/styles", "styles.xml");
lxw_add_document_relationship(rels, "/sharedStrings", "sharedStrings.xml");
lxw_add_document_relationship(rels, "/calcChain", "calcChain.xml");
lxw_relationships_assemble_xml_file(rels);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_free_relationships(rels);
}
// Test assembling a complete Relationships file.
CTEST(relationships, relationships02) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">"
"<Relationship Id=\"rId1\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink\" Target=\"www.foo.com\" TargetMode=\"External\"/>"
"<Relationship Id=\"rId2\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink\" Target=\"link00.xlsx\" TargetMode=\"External\"/>"
"</Relationships>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_relationships *rels = lxw_relationships_new();
rels->file = testfile;
lxw_add_worksheet_relationship(rels, "/hyperlink", "www.foo.com", "External");
lxw_add_worksheet_relationship(rels, "/hyperlink", "link00.xlsx", "External");
lxw_relationships_assemble_xml_file(rels);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_free_relationships(rels);
}

View File

@@ -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/relationships.h"
// Test _xml_declaration().
CTEST(relationships, xml_declaration) {
char* got;
char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
FILE* testfile = lxw_tmpfile(NULL);
lxw_relationships *relationships = lxw_relationships_new();
relationships->file = testfile;
_relationships_xml_declaration(relationships);
RUN_XLSX_STREQ(exp, got);
lxw_free_relationships(relationships);
}

View 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);
}

View File

@@ -0,0 +1,84 @@
/*
* Tests for the lib_xlsx_writer library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/shared_strings.h"
// Test assembling a complete SharedStrings file.
CTEST(sst, sst01) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<sst xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" count=\"7\" uniqueCount=\"3\">"
"<si>"
"<t>neptune</t>"
"</si>"
"<si>"
"<t>mars</t>"
"</si>"
"<si>"
"<t>venus</t>"
"</si>"
"</sst>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_sst *sst = lxw_sst_new();
sst->file = testfile;
lxw_get_sst_index(sst, "neptune", LXW_FALSE);
lxw_get_sst_index(sst, "neptune", LXW_FALSE);
lxw_get_sst_index(sst, "neptune", LXW_FALSE);
lxw_get_sst_index(sst, "mars", LXW_FALSE);
lxw_get_sst_index(sst, "mars", LXW_FALSE);
lxw_get_sst_index(sst, "venus", LXW_FALSE);
lxw_get_sst_index(sst, "venus", LXW_FALSE);
lxw_sst_assemble_xml_file(sst);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_sst_free(sst);
}
// Test assembling a complete SharedStrings file.
CTEST(sst, sst02) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<sst xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" count=\"3\" uniqueCount=\"3\">"
"<si>"
"<t>abcdefg</t>"
"</si>"
"<si>"
"<t xml:space=\"preserve\"> abcdefg</t>"
"</si>"
"<si>"
"<t xml:space=\"preserve\">abcdefg </t>"
"</si>"
"</sst>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_sst *sst = lxw_sst_new();
sst->file = testfile;
// Test strings with whitespace that must be preserved.
lxw_get_sst_index(sst, "abcdefg", LXW_FALSE);
lxw_get_sst_index(sst, " abcdefg", LXW_FALSE);
lxw_get_sst_index(sst, "abcdefg ", LXW_FALSE);
lxw_sst_assemble_xml_file(sst);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_sst_free(sst);
}

View File

@@ -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/shared_strings.h"
// Test _xml_declaration().
CTEST(sst, xml_declaration) {
char* got;
char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
FILE* testfile = lxw_tmpfile(NULL);
lxw_sst *sst = lxw_sst_new();
sst->file = testfile;
_sst_xml_declaration(sst);
RUN_XLSX_STREQ(exp, got);
lxw_sst_free(sst);
}

View 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);
}

View 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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View 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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}

View 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);
}

View File

@@ -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);
}

View 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);
}

View 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);
}

View File

@@ -0,0 +1,43 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/utility.h"
// Test _xl_col_to_name().
CTEST(utility, lxw_col_to_name) {
char got[LXW_MAX_COL_NAME_LENGTH];
TEST_COL_TO_NAME(0, 0, "A");
TEST_COL_TO_NAME(1, 0, "B");
TEST_COL_TO_NAME(2, 0, "C");
TEST_COL_TO_NAME(9, 0, "J");
TEST_COL_TO_NAME(24, 0, "Y");
TEST_COL_TO_NAME(25, 0, "Z");
TEST_COL_TO_NAME(26, 0, "AA");
TEST_COL_TO_NAME(254, 0, "IU");
TEST_COL_TO_NAME(255, 0, "IV");
TEST_COL_TO_NAME(256, 0, "IW");
TEST_COL_TO_NAME(16383, 0, "XFD");
TEST_COL_TO_NAME(16384, 0, "XFE");
TEST_COL_TO_NAME(0, 1, "$A");
TEST_COL_TO_NAME(1, 1, "$B");
TEST_COL_TO_NAME(2, 1, "$C");
TEST_COL_TO_NAME(9, 1, "$J");
TEST_COL_TO_NAME(24, 1, "$Y");
TEST_COL_TO_NAME(25, 1, "$Z");
TEST_COL_TO_NAME(26, 1, "$AA");
TEST_COL_TO_NAME(254, 1, "$IU");
TEST_COL_TO_NAME(255, 1, "$IV");
TEST_COL_TO_NAME(256, 1, "$IW");
TEST_COL_TO_NAME(16383, 1, "$XFD");
TEST_COL_TO_NAME(16384, 1, "$XFE");
}

View File

@@ -0,0 +1,673 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/utility.h"
// Test _datetime_to_excel_date().
CTEST(utility, test_datetime_date_and_time) {
double got;
lxw_datetime *datetime;
TEST_DATETIME(1899, 12, 31, 0, 0, 0.000, 0);
TEST_DATETIME(1982, 8, 25, 0, 15, 20.213, 30188.010650613425);
TEST_DATETIME(2065, 4, 19, 0, 16, 48.290, 60376.011670023145);
TEST_DATETIME(2147, 12, 15, 0, 55, 25.446, 90565.038488958337);
TEST_DATETIME(2230, 8, 10, 1, 2, 46.891, 120753.04359827546);
TEST_DATETIME(2313, 4, 6, 1, 4, 15.597, 150942.04462496529);
TEST_DATETIME(2395, 11, 30, 1, 9, 40.889, 181130.04838991899);
TEST_DATETIME(2478, 7, 25, 1, 11, 32.560, 211318.04968240741);
TEST_DATETIME(2561, 3, 21, 1, 30, 19.169, 241507.06272186342);
TEST_DATETIME(2643, 11, 15, 1, 48, 25.580, 271695.07529606484);
TEST_DATETIME(2726, 7, 12, 2, 3, 31.919, 301884.08578609955);
TEST_DATETIME(2809, 3, 6, 2, 11, 11.986, 332072.09111094906);
TEST_DATETIME(2891, 10, 31, 2, 24, 37.095, 362261.10042934027);
TEST_DATETIME(2974, 6, 26, 2, 35, 7.220, 392449.10772245371);
TEST_DATETIME(3057, 2, 19, 2, 45, 12.109, 422637.1147234838);
TEST_DATETIME(3139, 10, 17, 3, 6, 39.990, 452826.12962951389);
TEST_DATETIME(3222, 6, 11, 3, 8, 8.251, 483014.13065105322);
TEST_DATETIME(3305, 2, 5, 3, 19, 12.576, 513203.13834);
TEST_DATETIME(3387, 10, 1, 3, 29, 42.574, 543391.14563164348);
TEST_DATETIME(3470, 5, 27, 3, 37, 30.813, 573579.15105107636);
TEST_DATETIME(3553, 1, 21, 4, 14, 38.231, 603768.17683137732);
TEST_DATETIME(3635, 9, 16, 4, 16, 28.559, 633956.17810832174);
TEST_DATETIME(3718, 5, 13, 4, 17, 58.222, 664145.17914608796);
TEST_DATETIME(3801, 1, 6, 4, 21, 41.794, 694333.18173372687);
TEST_DATETIME(3883, 9, 2, 4, 56, 35.792, 724522.20596981479);
TEST_DATETIME(3966, 4, 28, 5, 25, 14.885, 754710.2258667245);
TEST_DATETIME(4048, 12, 21, 5, 26, 5.724, 784898.22645513888);
TEST_DATETIME(4131, 8, 18, 5, 46, 44.068, 815087.24078782403);
TEST_DATETIME(4214, 4, 13, 5, 48, 1.141, 845275.24167987274);
TEST_DATETIME(4296, 12, 7, 5, 53, 52.315, 875464.24574438657);
TEST_DATETIME(4379, 8, 3, 6, 14, 48.580, 905652.26028449077);
TEST_DATETIME(4462, 3, 28, 6, 46, 15.738, 935840.28212659725);
TEST_DATETIME(4544, 11, 22, 7, 31, 20.407, 966029.31343063654);
TEST_DATETIME(4627, 7, 19, 7, 58, 33.754, 996217.33233511576);
TEST_DATETIME(4710, 3, 15, 8, 7, 43.130, 1026406.3386936343);
TEST_DATETIME(4792, 11, 7, 8, 29, 11.091, 1056594.3536005903);
TEST_DATETIME(4875, 7, 4, 9, 8, 15.328, 1086783.3807329629);
TEST_DATETIME(4958, 2, 27, 9, 30, 41.781, 1116971.3963169097);
TEST_DATETIME(5040, 10, 23, 9, 34, 4.462, 1147159.3986627546);
TEST_DATETIME(5123, 6, 20, 9, 37, 23.945, 1177348.4009715857);
TEST_DATETIME(5206, 2, 12, 9, 37, 56.655, 1207536.4013501736);
TEST_DATETIME(5288, 10, 8, 9, 45, 12.230, 1237725.406391551);
TEST_DATETIME(5371, 6, 4, 9, 54, 14.782, 1267913.412671088);
TEST_DATETIME(5454, 1, 28, 9, 54, 22.108, 1298101.4127558796);
TEST_DATETIME(5536, 9, 24, 10, 1, 36.151, 1328290.4177795255);
TEST_DATETIME(5619, 5, 20, 12, 9, 48.602, 1358478.5068125231);
TEST_DATETIME(5702, 1, 14, 12, 34, 8.549, 1388667.5237100578);
TEST_DATETIME(5784, 9, 8, 12, 56, 6.495, 1418855.5389640625);
TEST_DATETIME(5867, 5, 6, 12, 58, 58.217, 1449044.5409515856);
TEST_DATETIME(5949, 12, 30, 12, 59, 54.263, 1479232.5416002662);
TEST_DATETIME(6032, 8, 24, 13, 34, 41.331, 1509420.5657561459);
TEST_DATETIME(6115, 4, 21, 13, 58, 28.601, 1539609.5822754744);
TEST_DATETIME(6197, 12, 14, 14, 2, 16.899, 1569797.5849178126);
TEST_DATETIME(6280, 8, 10, 14, 36, 17.444, 1599986.6085352316);
TEST_DATETIME(6363, 4, 6, 14, 37, 57.451, 1630174.60969272);
TEST_DATETIME(6445, 11, 30, 14, 57, 42.757, 1660363.6234115392);
TEST_DATETIME(6528, 7, 26, 15, 10, 48.307, 1690551.6325035533);
TEST_DATETIME(6611, 3, 22, 15, 14, 39.890, 1720739.635183912);
TEST_DATETIME(6693, 11, 15, 15, 19, 47.988, 1750928.6387498612);
TEST_DATETIME(6776, 7, 11, 16, 4, 24.344, 1781116.6697262037);
TEST_DATETIME(6859, 3, 7, 16, 22, 23.952, 1811305.6822216667);
TEST_DATETIME(6941, 10, 31, 16, 29, 55.999, 1841493.6874536921);
TEST_DATETIME(7024, 6, 26, 16, 58, 20.259, 1871681.7071789235);
TEST_DATETIME(7107, 2, 21, 17, 4, 2.415, 1901870.7111390624);
TEST_DATETIME(7189, 10, 16, 17, 18, 29.630, 1932058.7211762732);
TEST_DATETIME(7272, 6, 11, 17, 47, 21.323, 1962247.7412190163);
TEST_DATETIME(7355, 2, 5, 17, 53, 29.866, 1992435.7454845603);
TEST_DATETIME(7437, 10, 2, 17, 53, 41.076, 2022624.7456143056);
TEST_DATETIME(7520, 5, 28, 17, 55, 6.044, 2052812.7465977315);
TEST_DATETIME(7603, 1, 21, 18, 14, 49.151, 2083000.7602910995);
TEST_DATETIME(7685, 9, 16, 18, 17, 45.738, 2113189.7623349307);
TEST_DATETIME(7768, 5, 12, 18, 29, 59.700, 2143377.7708298611);
TEST_DATETIME(7851, 1, 7, 18, 33, 21.233, 2173566.773162419);
TEST_DATETIME(7933, 9, 2, 19, 14, 24.673, 2203754.8016744559);
TEST_DATETIME(8016, 4, 27, 19, 17, 12.816, 2233942.8036205554);
TEST_DATETIME(8098, 12, 22, 19, 23, 36.418, 2264131.8080603937);
TEST_DATETIME(8181, 8, 17, 19, 46, 25.908, 2294319.8239109721);
TEST_DATETIME(8264, 4, 13, 20, 7, 47.314, 2324508.8387420601);
TEST_DATETIME(8346, 12, 8, 20, 31, 37.603, 2354696.855296331);
TEST_DATETIME(8429, 8, 3, 20, 39, 57.770, 2384885.8610853008);
TEST_DATETIME(8512, 3, 29, 20, 50, 17.067, 2415073.8682530904);
TEST_DATETIME(8594, 11, 22, 21, 2, 57.827, 2445261.8770581828);
TEST_DATETIME(8677, 7, 19, 21, 23, 5.519, 2475450.8910360998);
TEST_DATETIME(8760, 3, 14, 21, 34, 49.572, 2505638.8991848612);
TEST_DATETIME(8842, 11, 8, 21, 39, 5.944, 2535827.9021521294);
TEST_DATETIME(8925, 7, 4, 21, 39, 18.426, 2566015.9022965971);
TEST_DATETIME(9008, 2, 28, 21, 46, 7.769, 2596203.9070343636);
TEST_DATETIME(9090, 10, 24, 21, 57, 55.662, 2626392.9152275696);
TEST_DATETIME(9173, 6, 19, 22, 19, 11.732, 2656580.9299968979);
TEST_DATETIME(9256, 2, 13, 22, 23, 51.376, 2686769.9332335186);
TEST_DATETIME(9338, 10, 9, 22, 27, 58.771, 2716957.9360968866);
TEST_DATETIME(9421, 6, 5, 22, 43, 30.392, 2747146.9468795368);
TEST_DATETIME(9504, 1, 30, 22, 48, 25.834, 2777334.9502990046);
TEST_DATETIME(9586, 9, 24, 22, 53, 51.727, 2807522.9540709145);
TEST_DATETIME(9669, 5, 20, 23, 12, 56.536, 2837711.9673210187);
TEST_DATETIME(9752, 1, 14, 23, 15, 54.109, 2867899.9693762613);
TEST_DATETIME(9834, 9, 10, 23, 17, 12.632, 2898088.9702850925);
TEST_DATETIME(9999, 12, 31, 23, 59, 59.000, 2958465.999988426);
}
CTEST(utility, test_datetime_date_only) {
double got;
lxw_datetime *datetime;
// Params = (year, month, day, excel_date).
TEST_DATETIME_DATE(1899, 12, 31, 0);
TEST_DATETIME_DATE(1900, 1, 1, 1);
TEST_DATETIME_DATE(1900, 2, 27, 58);
TEST_DATETIME_DATE(1900, 2, 28, 59);
TEST_DATETIME_DATE(1900, 3, 1, 61);
TEST_DATETIME_DATE(1900, 3, 2, 62);
TEST_DATETIME_DATE(1900, 3, 11, 71);
TEST_DATETIME_DATE(1900, 4, 8, 99);
TEST_DATETIME_DATE(1900, 9, 12, 256);
TEST_DATETIME_DATE(1901, 5, 3, 489);
TEST_DATETIME_DATE(1901, 10, 13, 652);
TEST_DATETIME_DATE(1902, 2, 15, 777);
TEST_DATETIME_DATE(1902, 6, 6, 888);
TEST_DATETIME_DATE(1902, 9, 25, 999);
TEST_DATETIME_DATE(1902, 9, 27, 1001);
TEST_DATETIME_DATE(1903, 4, 26, 1212);
TEST_DATETIME_DATE(1903, 8, 5, 1313);
TEST_DATETIME_DATE(1903, 12, 31, 1461);
TEST_DATETIME_DATE(1904, 1, 1, 1462);
TEST_DATETIME_DATE(1904, 2, 28, 1520);
TEST_DATETIME_DATE(1904, 2, 29, 1521);
TEST_DATETIME_DATE(1904, 3, 1, 1522);
TEST_DATETIME_DATE(1907, 2, 27, 2615);
TEST_DATETIME_DATE(1907, 2, 28, 2616);
TEST_DATETIME_DATE(1907, 3, 1, 2617);
TEST_DATETIME_DATE(1907, 3, 2, 2618);
TEST_DATETIME_DATE(1907, 3, 3, 2619);
TEST_DATETIME_DATE(1907, 3, 4, 2620);
TEST_DATETIME_DATE(1907, 3, 5, 2621);
TEST_DATETIME_DATE(1907, 3, 6, 2622);
TEST_DATETIME_DATE(1999, 1, 1, 36161);
TEST_DATETIME_DATE(1999, 1, 31, 36191);
TEST_DATETIME_DATE(1999, 2, 1, 36192);
TEST_DATETIME_DATE(1999, 2, 28, 36219);
TEST_DATETIME_DATE(1999, 3, 1, 36220);
TEST_DATETIME_DATE(1999, 3, 31, 36250);
TEST_DATETIME_DATE(1999, 4, 1, 36251);
TEST_DATETIME_DATE(1999, 4, 30, 36280);
TEST_DATETIME_DATE(1999, 5, 1, 36281);
TEST_DATETIME_DATE(1999, 5, 31, 36311);
TEST_DATETIME_DATE(1999, 6, 1, 36312);
TEST_DATETIME_DATE(1999, 6, 30, 36341);
TEST_DATETIME_DATE(1999, 7, 1, 36342);
TEST_DATETIME_DATE(1999, 7, 31, 36372);
TEST_DATETIME_DATE(1999, 8, 1, 36373);
TEST_DATETIME_DATE(1999, 8, 31, 36403);
TEST_DATETIME_DATE(1999, 9, 1, 36404);
TEST_DATETIME_DATE(1999, 9, 30, 36433);
TEST_DATETIME_DATE(1999, 10, 1, 36434);
TEST_DATETIME_DATE(1999, 10, 31, 36464);
TEST_DATETIME_DATE(1999, 11, 1, 36465);
TEST_DATETIME_DATE(1999, 11, 30, 36494);
TEST_DATETIME_DATE(1999, 12, 1, 36495);
TEST_DATETIME_DATE(1999, 12, 31, 36525);
TEST_DATETIME_DATE(2000, 1, 1, 36526);
TEST_DATETIME_DATE(2000, 1, 31, 36556);
TEST_DATETIME_DATE(2000, 2, 1, 36557);
TEST_DATETIME_DATE(2000, 2, 29, 36585);
TEST_DATETIME_DATE(2000, 3, 1, 36586);
TEST_DATETIME_DATE(2000, 3, 31, 36616);
TEST_DATETIME_DATE(2000, 4, 1, 36617);
TEST_DATETIME_DATE(2000, 4, 30, 36646);
TEST_DATETIME_DATE(2000, 5, 1, 36647);
TEST_DATETIME_DATE(2000, 5, 31, 36677);
TEST_DATETIME_DATE(2000, 6, 1, 36678);
TEST_DATETIME_DATE(2000, 6, 30, 36707);
TEST_DATETIME_DATE(2000, 7, 1, 36708);
TEST_DATETIME_DATE(2000, 7, 31, 36738);
TEST_DATETIME_DATE(2000, 8, 1, 36739);
TEST_DATETIME_DATE(2000, 8, 31, 36769);
TEST_DATETIME_DATE(2000, 9, 1, 36770);
TEST_DATETIME_DATE(2000, 9, 30, 36799);
TEST_DATETIME_DATE(2000, 10, 1, 36800);
TEST_DATETIME_DATE(2000, 10, 31, 36830);
TEST_DATETIME_DATE(2000, 11, 1, 36831);
TEST_DATETIME_DATE(2000, 11, 30, 36860);
TEST_DATETIME_DATE(2000, 12, 1, 36861);
TEST_DATETIME_DATE(2000, 12, 31, 36891);
TEST_DATETIME_DATE(2001, 1, 1, 36892);
TEST_DATETIME_DATE(2001, 1, 31, 36922);
TEST_DATETIME_DATE(2001, 2, 1, 36923);
TEST_DATETIME_DATE(2001, 2, 28, 36950);
TEST_DATETIME_DATE(2001, 3, 1, 36951);
TEST_DATETIME_DATE(2001, 3, 31, 36981);
TEST_DATETIME_DATE(2001, 4, 1, 36982);
TEST_DATETIME_DATE(2001, 4, 30, 37011);
TEST_DATETIME_DATE(2001, 5, 1, 37012);
TEST_DATETIME_DATE(2001, 5, 31, 37042);
TEST_DATETIME_DATE(2001, 6, 1, 37043);
TEST_DATETIME_DATE(2001, 6, 30, 37072);
TEST_DATETIME_DATE(2001, 7, 1, 37073);
TEST_DATETIME_DATE(2001, 7, 31, 37103);
TEST_DATETIME_DATE(2001, 8, 1, 37104);
TEST_DATETIME_DATE(2001, 8, 31, 37134);
TEST_DATETIME_DATE(2001, 9, 1, 37135);
TEST_DATETIME_DATE(2001, 9, 30, 37164);
TEST_DATETIME_DATE(2001, 10, 1, 37165);
TEST_DATETIME_DATE(2001, 10, 31, 37195);
TEST_DATETIME_DATE(2001, 11, 1, 37196);
TEST_DATETIME_DATE(2001, 11, 30, 37225);
TEST_DATETIME_DATE(2001, 12, 1, 37226);
TEST_DATETIME_DATE(2001, 12, 31, 37256);
TEST_DATETIME_DATE(2400, 1, 1, 182623);
TEST_DATETIME_DATE(2400, 1, 31, 182653);
TEST_DATETIME_DATE(2400, 2, 1, 182654);
TEST_DATETIME_DATE(2400, 2, 29, 182682);
TEST_DATETIME_DATE(2400, 3, 1, 182683);
TEST_DATETIME_DATE(2400, 3, 31, 182713);
TEST_DATETIME_DATE(2400, 4, 1, 182714);
TEST_DATETIME_DATE(2400, 4, 30, 182743);
TEST_DATETIME_DATE(2400, 5, 1, 182744);
TEST_DATETIME_DATE(2400, 5, 31, 182774);
TEST_DATETIME_DATE(2400, 6, 1, 182775);
TEST_DATETIME_DATE(2400, 6, 30, 182804);
TEST_DATETIME_DATE(2400, 7, 1, 182805);
TEST_DATETIME_DATE(2400, 7, 31, 182835);
TEST_DATETIME_DATE(2400, 8, 1, 182836);
TEST_DATETIME_DATE(2400, 8, 31, 182866);
TEST_DATETIME_DATE(2400, 9, 1, 182867);
TEST_DATETIME_DATE(2400, 9, 30, 182896);
TEST_DATETIME_DATE(2400, 10, 1, 182897);
TEST_DATETIME_DATE(2400, 10, 31, 182927);
TEST_DATETIME_DATE(2400, 11, 1, 182928);
TEST_DATETIME_DATE(2400, 11, 30, 182957);
TEST_DATETIME_DATE(2400, 12, 1, 182958);
TEST_DATETIME_DATE(2400, 12, 31, 182988);
TEST_DATETIME_DATE(4000, 1, 1, 767011);
TEST_DATETIME_DATE(4000, 1, 31, 767041);
TEST_DATETIME_DATE(4000, 2, 1, 767042);
TEST_DATETIME_DATE(4000, 2, 29, 767070);
TEST_DATETIME_DATE(4000, 3, 1, 767071);
TEST_DATETIME_DATE(4000, 3, 31, 767101);
TEST_DATETIME_DATE(4000, 4, 1, 767102);
TEST_DATETIME_DATE(4000, 4, 30, 767131);
TEST_DATETIME_DATE(4000, 5, 1, 767132);
TEST_DATETIME_DATE(4000, 5, 31, 767162);
TEST_DATETIME_DATE(4000, 6, 1, 767163);
TEST_DATETIME_DATE(4000, 6, 30, 767192);
TEST_DATETIME_DATE(4000, 7, 1, 767193);
TEST_DATETIME_DATE(4000, 7, 31, 767223);
TEST_DATETIME_DATE(4000, 8, 1, 767224);
TEST_DATETIME_DATE(4000, 8, 31, 767254);
TEST_DATETIME_DATE(4000, 9, 1, 767255);
TEST_DATETIME_DATE(4000, 9, 30, 767284);
TEST_DATETIME_DATE(4000, 10, 1, 767285);
TEST_DATETIME_DATE(4000, 10, 31, 767315);
TEST_DATETIME_DATE(4000, 11, 1, 767316);
TEST_DATETIME_DATE(4000, 11, 30, 767345);
TEST_DATETIME_DATE(4000, 12, 1, 767346);
TEST_DATETIME_DATE(4000, 12, 31, 767376);
TEST_DATETIME_DATE(4321, 1, 1, 884254);
TEST_DATETIME_DATE(4321, 1, 31, 884284);
TEST_DATETIME_DATE(4321, 2, 1, 884285);
TEST_DATETIME_DATE(4321, 2, 28, 884312);
TEST_DATETIME_DATE(4321, 3, 1, 884313);
TEST_DATETIME_DATE(4321, 3, 31, 884343);
TEST_DATETIME_DATE(4321, 4, 1, 884344);
TEST_DATETIME_DATE(4321, 4, 30, 884373);
TEST_DATETIME_DATE(4321, 5, 1, 884374);
TEST_DATETIME_DATE(4321, 5, 31, 884404);
TEST_DATETIME_DATE(4321, 6, 1, 884405);
TEST_DATETIME_DATE(4321, 6, 30, 884434);
TEST_DATETIME_DATE(4321, 7, 1, 884435);
TEST_DATETIME_DATE(4321, 7, 31, 884465);
TEST_DATETIME_DATE(4321, 8, 1, 884466);
TEST_DATETIME_DATE(4321, 8, 31, 884496);
TEST_DATETIME_DATE(4321, 9, 1, 884497);
TEST_DATETIME_DATE(4321, 9, 30, 884526);
TEST_DATETIME_DATE(4321, 10, 1, 884527);
TEST_DATETIME_DATE(4321, 10, 31, 884557);
TEST_DATETIME_DATE(4321, 11, 1, 884558);
TEST_DATETIME_DATE(4321, 11, 30, 884587);
TEST_DATETIME_DATE(4321, 12, 1, 884588);
TEST_DATETIME_DATE(4321, 12, 31, 884618);
TEST_DATETIME_DATE(9999, 1, 1, 2958101);
TEST_DATETIME_DATE(9999, 1, 31, 2958131);
TEST_DATETIME_DATE(9999, 2, 1, 2958132);
TEST_DATETIME_DATE(9999, 2, 28, 2958159);
TEST_DATETIME_DATE(9999, 3, 1, 2958160);
TEST_DATETIME_DATE(9999, 3, 31, 2958190);
TEST_DATETIME_DATE(9999, 4, 1, 2958191);
TEST_DATETIME_DATE(9999, 4, 30, 2958220);
TEST_DATETIME_DATE(9999, 5, 1, 2958221);
TEST_DATETIME_DATE(9999, 5, 31, 2958251);
TEST_DATETIME_DATE(9999, 6, 1, 2958252);
TEST_DATETIME_DATE(9999, 6, 30, 2958281);
TEST_DATETIME_DATE(9999, 7, 1, 2958282);
TEST_DATETIME_DATE(9999, 7, 31, 2958312);
TEST_DATETIME_DATE(9999, 8, 1, 2958313);
TEST_DATETIME_DATE(9999, 8, 31, 2958343);
TEST_DATETIME_DATE(9999, 9, 1, 2958344);
TEST_DATETIME_DATE(9999, 9, 30, 2958373);
TEST_DATETIME_DATE(9999, 10, 1, 2958374);
TEST_DATETIME_DATE(9999, 10, 31, 2958404);
TEST_DATETIME_DATE(9999, 11, 1, 2958405);
TEST_DATETIME_DATE(9999, 11, 30, 2958434);
TEST_DATETIME_DATE(9999, 12, 1, 2958435);
TEST_DATETIME_DATE(9999, 12, 31, 2958465);
}
CTEST(utility, test_datetime_date_only_1904) {
double got;
lxw_datetime *datetime;
// Params = (year, month, day, excel_date).
TEST_DATETIME_DATE_1904(1904, 1, 1, 0);
TEST_DATETIME_DATE_1904(1904, 1, 31, 30);
TEST_DATETIME_DATE_1904(1904, 2, 1, 31);
TEST_DATETIME_DATE_1904(1904, 2, 29, 59);
TEST_DATETIME_DATE_1904(1904, 3, 1, 60);
TEST_DATETIME_DATE_1904(1904, 3, 31, 90);
TEST_DATETIME_DATE_1904(1904, 4, 1, 91);
TEST_DATETIME_DATE_1904(1904, 4, 30, 120);
TEST_DATETIME_DATE_1904(1904, 5, 1, 121);
TEST_DATETIME_DATE_1904(1904, 5, 31, 151);
TEST_DATETIME_DATE_1904(1904, 6, 1, 152);
TEST_DATETIME_DATE_1904(1904, 6, 30, 181);
TEST_DATETIME_DATE_1904(1904, 7, 1, 182);
TEST_DATETIME_DATE_1904(1904, 7, 31, 212);
TEST_DATETIME_DATE_1904(1904, 8, 1, 213);
TEST_DATETIME_DATE_1904(1904, 8, 31, 243);
TEST_DATETIME_DATE_1904(1904, 9, 1, 244);
TEST_DATETIME_DATE_1904(1904, 9, 30, 273);
TEST_DATETIME_DATE_1904(1904, 10, 1, 274);
TEST_DATETIME_DATE_1904(1904, 10, 31, 304);
TEST_DATETIME_DATE_1904(1904, 11, 1, 305);
TEST_DATETIME_DATE_1904(1904, 11, 30, 334);
TEST_DATETIME_DATE_1904(1904, 12, 1, 335);
TEST_DATETIME_DATE_1904(1904, 12, 31, 365);
TEST_DATETIME_DATE_1904(1907, 2, 27, 1153);
TEST_DATETIME_DATE_1904(1907, 2, 28, 1154);
TEST_DATETIME_DATE_1904(1907, 3, 1, 1155);
TEST_DATETIME_DATE_1904(1907, 3, 2, 1156);
TEST_DATETIME_DATE_1904(1907, 3, 3, 1157);
TEST_DATETIME_DATE_1904(1907, 3, 4, 1158);
TEST_DATETIME_DATE_1904(1907, 3, 5, 1159);
TEST_DATETIME_DATE_1904(1907, 3, 6, 1160);
TEST_DATETIME_DATE_1904(1999, 1, 1, 34699);
TEST_DATETIME_DATE_1904(1999, 1, 31, 34729);
TEST_DATETIME_DATE_1904(1999, 2, 1, 34730);
TEST_DATETIME_DATE_1904(1999, 2, 28, 34757);
TEST_DATETIME_DATE_1904(1999, 3, 1, 34758);
TEST_DATETIME_DATE_1904(1999, 3, 31, 34788);
TEST_DATETIME_DATE_1904(1999, 4, 1, 34789);
TEST_DATETIME_DATE_1904(1999, 4, 30, 34818);
TEST_DATETIME_DATE_1904(1999, 5, 1, 34819);
TEST_DATETIME_DATE_1904(1999, 5, 31, 34849);
TEST_DATETIME_DATE_1904(1999, 6, 1, 34850);
TEST_DATETIME_DATE_1904(1999, 6, 30, 34879);
TEST_DATETIME_DATE_1904(1999, 7, 1, 34880);
TEST_DATETIME_DATE_1904(1999, 7, 31, 34910);
TEST_DATETIME_DATE_1904(1999, 8, 1, 34911);
TEST_DATETIME_DATE_1904(1999, 8, 31, 34941);
TEST_DATETIME_DATE_1904(1999, 9, 1, 34942);
TEST_DATETIME_DATE_1904(1999, 9, 30, 34971);
TEST_DATETIME_DATE_1904(1999, 10, 1, 34972);
TEST_DATETIME_DATE_1904(1999, 10, 31, 35002);
TEST_DATETIME_DATE_1904(1999, 11, 1, 35003);
TEST_DATETIME_DATE_1904(1999, 11, 30, 35032);
TEST_DATETIME_DATE_1904(1999, 12, 1, 35033);
TEST_DATETIME_DATE_1904(1999, 12, 31, 35063);
TEST_DATETIME_DATE_1904(2000, 1, 1, 35064);
TEST_DATETIME_DATE_1904(2000, 1, 31, 35094);
TEST_DATETIME_DATE_1904(2000, 2, 1, 35095);
TEST_DATETIME_DATE_1904(2000, 2, 29, 35123);
TEST_DATETIME_DATE_1904(2000, 3, 1, 35124);
TEST_DATETIME_DATE_1904(2000, 3, 31, 35154);
TEST_DATETIME_DATE_1904(2000, 4, 1, 35155);
TEST_DATETIME_DATE_1904(2000, 4, 30, 35184);
TEST_DATETIME_DATE_1904(2000, 5, 1, 35185);
TEST_DATETIME_DATE_1904(2000, 5, 31, 35215);
TEST_DATETIME_DATE_1904(2000, 6, 1, 35216);
TEST_DATETIME_DATE_1904(2000, 6, 30, 35245);
TEST_DATETIME_DATE_1904(2000, 7, 1, 35246);
TEST_DATETIME_DATE_1904(2000, 7, 31, 35276);
TEST_DATETIME_DATE_1904(2000, 8, 1, 35277);
TEST_DATETIME_DATE_1904(2000, 8, 31, 35307);
TEST_DATETIME_DATE_1904(2000, 9, 1, 35308);
TEST_DATETIME_DATE_1904(2000, 9, 30, 35337);
TEST_DATETIME_DATE_1904(2000, 10, 1, 35338);
TEST_DATETIME_DATE_1904(2000, 10, 31, 35368);
TEST_DATETIME_DATE_1904(2000, 11, 1, 35369);
TEST_DATETIME_DATE_1904(2000, 11, 30, 35398);
TEST_DATETIME_DATE_1904(2000, 12, 1, 35399);
TEST_DATETIME_DATE_1904(2000, 12, 31, 35429);
TEST_DATETIME_DATE_1904(2001, 1, 1, 35430);
TEST_DATETIME_DATE_1904(2001, 1, 31, 35460);
TEST_DATETIME_DATE_1904(2001, 2, 1, 35461);
TEST_DATETIME_DATE_1904(2001, 2, 28, 35488);
TEST_DATETIME_DATE_1904(2001, 3, 1, 35489);
TEST_DATETIME_DATE_1904(2001, 3, 31, 35519);
TEST_DATETIME_DATE_1904(2001, 4, 1, 35520);
TEST_DATETIME_DATE_1904(2001, 4, 30, 35549);
TEST_DATETIME_DATE_1904(2001, 5, 1, 35550);
TEST_DATETIME_DATE_1904(2001, 5, 31, 35580);
TEST_DATETIME_DATE_1904(2001, 6, 1, 35581);
TEST_DATETIME_DATE_1904(2001, 6, 30, 35610);
TEST_DATETIME_DATE_1904(2001, 7, 1, 35611);
TEST_DATETIME_DATE_1904(2001, 7, 31, 35641);
TEST_DATETIME_DATE_1904(2001, 8, 1, 35642);
TEST_DATETIME_DATE_1904(2001, 8, 31, 35672);
TEST_DATETIME_DATE_1904(2001, 9, 1, 35673);
TEST_DATETIME_DATE_1904(2001, 9, 30, 35702);
TEST_DATETIME_DATE_1904(2001, 10, 1, 35703);
TEST_DATETIME_DATE_1904(2001, 10, 31, 35733);
TEST_DATETIME_DATE_1904(2001, 11, 1, 35734);
TEST_DATETIME_DATE_1904(2001, 11, 30, 35763);
TEST_DATETIME_DATE_1904(2001, 12, 1, 35764);
TEST_DATETIME_DATE_1904(2001, 12, 31, 35794);
TEST_DATETIME_DATE_1904(2400, 1, 1, 181161);
TEST_DATETIME_DATE_1904(2400, 1, 31, 181191);
TEST_DATETIME_DATE_1904(2400, 2, 1, 181192);
TEST_DATETIME_DATE_1904(2400, 2, 29, 181220);
TEST_DATETIME_DATE_1904(2400, 3, 1, 181221);
TEST_DATETIME_DATE_1904(2400, 3, 31, 181251);
TEST_DATETIME_DATE_1904(2400, 4, 1, 181252);
TEST_DATETIME_DATE_1904(2400, 4, 30, 181281);
TEST_DATETIME_DATE_1904(2400, 5, 1, 181282);
TEST_DATETIME_DATE_1904(2400, 5, 31, 181312);
TEST_DATETIME_DATE_1904(2400, 6, 1, 181313);
TEST_DATETIME_DATE_1904(2400, 6, 30, 181342);
TEST_DATETIME_DATE_1904(2400, 7, 1, 181343);
TEST_DATETIME_DATE_1904(2400, 7, 31, 181373);
TEST_DATETIME_DATE_1904(2400, 8, 1, 181374);
TEST_DATETIME_DATE_1904(2400, 8, 31, 181404);
TEST_DATETIME_DATE_1904(2400, 9, 1, 181405);
TEST_DATETIME_DATE_1904(2400, 9, 30, 181434);
TEST_DATETIME_DATE_1904(2400, 10, 1, 181435);
TEST_DATETIME_DATE_1904(2400, 10, 31, 181465);
TEST_DATETIME_DATE_1904(2400, 11, 1, 181466);
TEST_DATETIME_DATE_1904(2400, 11, 30, 181495);
TEST_DATETIME_DATE_1904(2400, 12, 1, 181496);
TEST_DATETIME_DATE_1904(2400, 12, 31, 181526);
TEST_DATETIME_DATE_1904(4000, 1, 1, 765549);
TEST_DATETIME_DATE_1904(4000, 1, 31, 765579);
TEST_DATETIME_DATE_1904(4000, 2, 1, 765580);
TEST_DATETIME_DATE_1904(4000, 2, 29, 765608);
TEST_DATETIME_DATE_1904(4000, 3, 1, 765609);
TEST_DATETIME_DATE_1904(4000, 3, 31, 765639);
TEST_DATETIME_DATE_1904(4000, 4, 1, 765640);
TEST_DATETIME_DATE_1904(4000, 4, 30, 765669);
TEST_DATETIME_DATE_1904(4000, 5, 1, 765670);
TEST_DATETIME_DATE_1904(4000, 5, 31, 765700);
TEST_DATETIME_DATE_1904(4000, 6, 1, 765701);
TEST_DATETIME_DATE_1904(4000, 6, 30, 765730);
TEST_DATETIME_DATE_1904(4000, 7, 1, 765731);
TEST_DATETIME_DATE_1904(4000, 7, 31, 765761);
TEST_DATETIME_DATE_1904(4000, 8, 1, 765762);
TEST_DATETIME_DATE_1904(4000, 8, 31, 765792);
TEST_DATETIME_DATE_1904(4000, 9, 1, 765793);
TEST_DATETIME_DATE_1904(4000, 9, 30, 765822);
TEST_DATETIME_DATE_1904(4000, 10, 1, 765823);
TEST_DATETIME_DATE_1904(4000, 10, 31, 765853);
TEST_DATETIME_DATE_1904(4000, 11, 1, 765854);
TEST_DATETIME_DATE_1904(4000, 11, 30, 765883);
TEST_DATETIME_DATE_1904(4000, 12, 1, 765884);
TEST_DATETIME_DATE_1904(4000, 12, 31, 765914);
TEST_DATETIME_DATE_1904(4321, 1, 1, 882792);
TEST_DATETIME_DATE_1904(4321, 1, 31, 882822);
TEST_DATETIME_DATE_1904(4321, 2, 1, 882823);
TEST_DATETIME_DATE_1904(4321, 2, 28, 882850);
TEST_DATETIME_DATE_1904(4321, 3, 1, 882851);
TEST_DATETIME_DATE_1904(4321, 3, 31, 882881);
TEST_DATETIME_DATE_1904(4321, 4, 1, 882882);
TEST_DATETIME_DATE_1904(4321, 4, 30, 882911);
TEST_DATETIME_DATE_1904(4321, 5, 1, 882912);
TEST_DATETIME_DATE_1904(4321, 5, 31, 882942);
TEST_DATETIME_DATE_1904(4321, 6, 1, 882943);
TEST_DATETIME_DATE_1904(4321, 6, 30, 882972);
TEST_DATETIME_DATE_1904(4321, 7, 1, 882973);
TEST_DATETIME_DATE_1904(4321, 7, 31, 883003);
TEST_DATETIME_DATE_1904(4321, 8, 1, 883004);
TEST_DATETIME_DATE_1904(4321, 8, 31, 883034);
TEST_DATETIME_DATE_1904(4321, 9, 1, 883035);
TEST_DATETIME_DATE_1904(4321, 9, 30, 883064);
TEST_DATETIME_DATE_1904(4321, 10, 1, 883065);
TEST_DATETIME_DATE_1904(4321, 10, 31, 883095);
TEST_DATETIME_DATE_1904(4321, 11, 1, 883096);
TEST_DATETIME_DATE_1904(4321, 11, 30, 883125);
TEST_DATETIME_DATE_1904(4321, 12, 1, 883126);
TEST_DATETIME_DATE_1904(4321, 12, 31, 883156);
TEST_DATETIME_DATE_1904(9999, 1, 1, 2956639);
TEST_DATETIME_DATE_1904(9999, 1, 31, 2956669);
TEST_DATETIME_DATE_1904(9999, 2, 1, 2956670);
TEST_DATETIME_DATE_1904(9999, 2, 28, 2956697);
TEST_DATETIME_DATE_1904(9999, 3, 1, 2956698);
TEST_DATETIME_DATE_1904(9999, 3, 31, 2956728);
TEST_DATETIME_DATE_1904(9999, 4, 1, 2956729);
TEST_DATETIME_DATE_1904(9999, 4, 30, 2956758);
TEST_DATETIME_DATE_1904(9999, 5, 1, 2956759);
TEST_DATETIME_DATE_1904(9999, 5, 31, 2956789);
TEST_DATETIME_DATE_1904(9999, 6, 1, 2956790);
TEST_DATETIME_DATE_1904(9999, 6, 30, 2956819);
TEST_DATETIME_DATE_1904(9999, 7, 1, 2956820);
TEST_DATETIME_DATE_1904(9999, 7, 31, 2956850);
TEST_DATETIME_DATE_1904(9999, 8, 1, 2956851);
TEST_DATETIME_DATE_1904(9999, 8, 31, 2956881);
TEST_DATETIME_DATE_1904(9999, 9, 1, 2956882);
TEST_DATETIME_DATE_1904(9999, 9, 30, 2956911);
TEST_DATETIME_DATE_1904(9999, 10, 1, 2956912);
TEST_DATETIME_DATE_1904(9999, 10, 31, 2956942);
TEST_DATETIME_DATE_1904(9999, 11, 1, 2956943);
TEST_DATETIME_DATE_1904(9999, 11, 30, 2956972);
TEST_DATETIME_DATE_1904(9999, 12, 1, 2956973);
TEST_DATETIME_DATE_1904(9999, 12, 31, 2957003);
}
CTEST(utility, test_datetime_time_only) {
double got;
lxw_datetime *datetime;
TEST_DATETIME_TIME( 0, 0, 0.000, 0);
TEST_DATETIME_TIME( 0, 15, 20.213, 1.0650613425925924E-2);
TEST_DATETIME_TIME( 0, 16, 48.290, 1.1670023148148148E-2);
TEST_DATETIME_TIME( 0, 55, 25.446, 3.8488958333333337E-2);
TEST_DATETIME_TIME( 1, 2, 46.891, 4.3598275462962965E-2);
TEST_DATETIME_TIME( 1, 4, 15.597, 4.4624965277777782E-2);
TEST_DATETIME_TIME( 1, 9, 40.889, 4.8389918981481483E-2);
TEST_DATETIME_TIME( 1, 11, 32.560, 4.9682407407407404E-2);
TEST_DATETIME_TIME( 1, 30, 19.169, 6.2721863425925936E-2);
TEST_DATETIME_TIME( 1, 48, 25.580, 7.5296064814814809E-2);
TEST_DATETIME_TIME( 2, 3, 31.919, 8.5786099537037031E-2);
TEST_DATETIME_TIME( 2, 11, 11.986, 9.1110949074074077E-2);
TEST_DATETIME_TIME( 2, 24, 37.095, 0.10042934027777778);
TEST_DATETIME_TIME( 2, 35, 7.220, 0.1077224537037037);
TEST_DATETIME_TIME( 2, 45, 12.109, 0.11472348379629631);
TEST_DATETIME_TIME( 3, 6, 39.990, 0.12962951388888888);
TEST_DATETIME_TIME( 3, 8, 8.251, 0.13065105324074075);
TEST_DATETIME_TIME( 3, 19, 12.576, 0.13833999999999999);
TEST_DATETIME_TIME( 3, 29, 42.574, 0.14563164351851851);
TEST_DATETIME_TIME( 3, 37, 30.813, 0.1510510763888889);
TEST_DATETIME_TIME( 4, 14, 38.231, 0.1768313773148148);
TEST_DATETIME_TIME( 4, 16, 28.559, 0.17810832175925925);
TEST_DATETIME_TIME( 4, 17, 58.222, 0.17914608796296297);
TEST_DATETIME_TIME( 4, 21, 41.794, 0.18173372685185185);
TEST_DATETIME_TIME( 4, 56, 35.792, 0.2059698148148148);
TEST_DATETIME_TIME( 5, 25, 14.885, 0.22586672453703704);
TEST_DATETIME_TIME( 5, 26, 5.724, 0.22645513888888891);
TEST_DATETIME_TIME( 5, 46, 44.068, 0.24078782407407406);
TEST_DATETIME_TIME( 5, 48, 1.141, 0.2416798726851852);
TEST_DATETIME_TIME( 5, 53, 52.315, 0.24574438657407408);
TEST_DATETIME_TIME( 6, 14, 48.580, 0.26028449074074073);
TEST_DATETIME_TIME( 6, 46, 15.738, 0.28212659722222222);
TEST_DATETIME_TIME( 7, 31, 20.407, 0.31343063657407405);
TEST_DATETIME_TIME( 7, 58, 33.754, 0.33233511574074076);
TEST_DATETIME_TIME( 8, 7, 43.130, 0.33869363425925925);
TEST_DATETIME_TIME( 8, 29, 11.091, 0.35360059027777774);
TEST_DATETIME_TIME( 9, 8, 15.328, 0.380732962962963);
TEST_DATETIME_TIME( 9, 30, 41.781, 0.39631690972222228);
TEST_DATETIME_TIME( 9, 34, 4.462, 0.39866275462962958);
TEST_DATETIME_TIME( 9, 37, 23.945, 0.40097158564814817);
TEST_DATETIME_TIME( 9, 37, 56.655, 0.40135017361111114);
TEST_DATETIME_TIME( 9, 45, 12.230, 0.40639155092592594);
TEST_DATETIME_TIME( 9, 54, 14.782, 0.41267108796296298);
TEST_DATETIME_TIME( 9, 54, 22.108, 0.41275587962962962);
TEST_DATETIME_TIME(10, 1, 36.151, 0.41777952546296299);
TEST_DATETIME_TIME(12, 9, 48.602, 0.50681252314814818);
TEST_DATETIME_TIME(12, 34, 8.549, 0.52371005787037039);
TEST_DATETIME_TIME(12, 56, 6.495, 0.53896406249999995);
TEST_DATETIME_TIME(12, 58, 58.217, 0.54095158564814816);
TEST_DATETIME_TIME(12, 59, 54.263, 0.54160026620370372);
TEST_DATETIME_TIME(13, 34, 41.331, 0.56575614583333333);
TEST_DATETIME_TIME(13, 58, 28.601, 0.58227547453703699);
TEST_DATETIME_TIME(14, 2, 16.899, 0.58491781249999997);
TEST_DATETIME_TIME(14, 36, 17.444, 0.60853523148148148);
TEST_DATETIME_TIME(14, 37, 57.451, 0.60969271990740748);
TEST_DATETIME_TIME(14, 57, 42.757, 0.6234115393518519);
TEST_DATETIME_TIME(15, 10, 48.307, 0.6325035532407407);
TEST_DATETIME_TIME(15, 14, 39.890, 0.63518391203703706);
TEST_DATETIME_TIME(15, 19, 47.988, 0.63874986111111109);
TEST_DATETIME_TIME(16, 4, 24.344, 0.66972620370370362);
TEST_DATETIME_TIME(16, 22, 23.952, 0.68222166666666662);
TEST_DATETIME_TIME(16, 29, 55.999, 0.6874536921296297);
TEST_DATETIME_TIME(16, 58, 20.259, 0.70717892361111112);
TEST_DATETIME_TIME(17, 4, 2.415, 0.71113906250000003);
TEST_DATETIME_TIME(17, 18, 29.630, 0.72117627314814825);
TEST_DATETIME_TIME(17, 47, 21.323, 0.74121901620370367);
TEST_DATETIME_TIME(17, 53, 29.866, 0.74548456018518516);
TEST_DATETIME_TIME(17, 53, 41.076, 0.74561430555555563);
TEST_DATETIME_TIME(17, 55, 6.044, 0.74659773148148145);
TEST_DATETIME_TIME(18, 14, 49.151, 0.760291099537037);
TEST_DATETIME_TIME(18, 17, 45.738, 0.76233493055555546);
TEST_DATETIME_TIME(18, 29, 59.700, 0.77082986111111118);
TEST_DATETIME_TIME(18, 33, 21.233, 0.77316241898148153);
TEST_DATETIME_TIME(19, 14, 24.673, 0.80167445601851861);
TEST_DATETIME_TIME(19, 17, 12.816, 0.80362055555555545);
TEST_DATETIME_TIME(19, 23, 36.418, 0.80806039351851855);
TEST_DATETIME_TIME(19, 46, 25.908, 0.82391097222222232);
TEST_DATETIME_TIME(20, 7, 47.314, 0.83874206018518516);
TEST_DATETIME_TIME(20, 31, 37.603, 0.85529633101851854);
TEST_DATETIME_TIME(20, 39, 57.770, 0.86108530092592594);
TEST_DATETIME_TIME(20, 50, 17.067, 0.86825309027777775);
TEST_DATETIME_TIME(21, 2, 57.827, 0.87705818287037041);
TEST_DATETIME_TIME(21, 23, 5.519, 0.891036099537037);
TEST_DATETIME_TIME(21, 34, 49.572, 0.89918486111111118);
TEST_DATETIME_TIME(21, 39, 5.944, 0.90215212962962965);
TEST_DATETIME_TIME(21, 39, 18.426, 0.90229659722222222);
TEST_DATETIME_TIME(21, 46, 7.769, 0.90703436342592603);
TEST_DATETIME_TIME(21, 57, 55.662, 0.91522756944444439);
TEST_DATETIME_TIME(22, 19, 11.732, 0.92999689814814823);
TEST_DATETIME_TIME(22, 23, 51.376, 0.93323351851851843);
TEST_DATETIME_TIME(22, 27, 58.771, 0.93609688657407408);
TEST_DATETIME_TIME(22, 43, 30.392, 0.94687953703703709);
TEST_DATETIME_TIME(22, 48, 25.834, 0.95029900462962968);
TEST_DATETIME_TIME(22, 53, 51.727, 0.95407091435185187);
TEST_DATETIME_TIME(23, 12, 56.536, 0.96732101851851848);
TEST_DATETIME_TIME(23, 15, 54.109, 0.96937626157407408);
TEST_DATETIME_TIME(23, 17, 12.632, 0.97028509259259266);
TEST_DATETIME_TIME(23, 59, 59.999, 0.99999998842592586);
}
CTEST(utility, test_unixtime) {
double got;
TEST_UNIXTIME(-2209075200, 0); // 1899-12-31 00:00
TEST_UNIXTIME(-2209032000, 0.5); // 1899-12-31 12:00
TEST_UNIXTIME(-2208988800, 1); // 1900-01-01 00:00
TEST_UNIXTIME(-2208945600, 1.5); // 1900-01-01 12:00
TEST_UNIXTIME(-2203977600, 59); // 1900-02-28 00:00
TEST_UNIXTIME(-2203934400, 59.5); // 1900-02-28 12:00
TEST_UNIXTIME(-2203891200, 61); // 1900-03-01 00:00
TEST_UNIXTIME(-2203848000, 61.5); // 1900-03-01 12:00
TEST_UNIXTIME(0, 25569); // 1970-01-01 00:00
TEST_UNIXTIME(43200, 25569.5); // 1970-01-01 12:00
TEST_UNIXTIME(946684800, 36526); // 2000-01-01 00:00
TEST_UNIXTIME(946728000, 36526.5); // 2000-01-01 12:00
TEST_UNIXTIME(253370764800, 2958101); // 9999-01-01 00:00
TEST_UNIXTIME(253370808000, 2958101.5); // 9999-01-01 12:00
}
CTEST(utility, test_unixtime_1904) {
double got;
TEST_UNIXTIME_1904(-2082844800, 0); // 1904-01-01 00:00
TEST_UNIXTIME_1904(-2082801600, 0.5); // 1904-01-01 12:00
TEST_UNIXTIME_1904(0, 24107); // 1970-01-01 00:00
TEST_UNIXTIME_1904(43200, 24107.5); // 1970-01-01 12:00
TEST_UNIXTIME_1904(946684800, 35064); // 2000-01-01 00:00
TEST_UNIXTIME_1904(946728000, 35064.5); // 2000-01-01 12:00
}

View File

@@ -0,0 +1,23 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/utility.h"
// Test lxw_utf8_strlen().
CTEST(utility, lxw_utf8_strlen) {
ASSERT_EQUAL(0, lxw_utf8_strlen(""));
ASSERT_EQUAL(3, lxw_utf8_strlen("Foo"));
ASSERT_EQUAL(4, lxw_utf8_strlen("café"));
ASSERT_EQUAL(4, lxw_utf8_strlen("cake"));
ASSERT_EQUAL(21, lxw_utf8_strlen("Это фраза на русском!"));
}

View File

@@ -0,0 +1,51 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/utility.h"
// Test _xl_get_col().
CTEST(utility, lxw_name_to_col) {
ASSERT_EQUAL(0, lxw_name_to_col("A1"));
ASSERT_EQUAL(1, lxw_name_to_col("B1"));
ASSERT_EQUAL(2, lxw_name_to_col("C1"));
ASSERT_EQUAL(9, lxw_name_to_col("J1"));
ASSERT_EQUAL(24, lxw_name_to_col("Y1"));
ASSERT_EQUAL(25, lxw_name_to_col("Z1"));
ASSERT_EQUAL(26, lxw_name_to_col("AA1"));
ASSERT_EQUAL(254, lxw_name_to_col("IU1"));
ASSERT_EQUAL(255, lxw_name_to_col("IV1"));
ASSERT_EQUAL(256, lxw_name_to_col("IW1"));
ASSERT_EQUAL(16383, lxw_name_to_col("XFD1"));
ASSERT_EQUAL(16384, lxw_name_to_col("XFE1"));
ASSERT_EQUAL(0, lxw_name_to_col("$A1"));
ASSERT_EQUAL(0, lxw_name_to_col("A$1"));
ASSERT_EQUAL(0, lxw_name_to_col("$A$1"));
}
// Test _xl_get_col_2().
CTEST(utility, lxw_name_to_col_2) {
ASSERT_EQUAL(0, lxw_name_to_col_2("AAA:A"));
ASSERT_EQUAL(1, lxw_name_to_col_2("AAA:B"));
ASSERT_EQUAL(2, lxw_name_to_col_2("AAA:C"));
ASSERT_EQUAL(9, lxw_name_to_col_2("AAA:J"));
ASSERT_EQUAL(24, lxw_name_to_col_2("AAA:Y"));
ASSERT_EQUAL(25, lxw_name_to_col_2("AAA:Z"));
ASSERT_EQUAL(26, lxw_name_to_col_2("AAA:AA"));
ASSERT_EQUAL(254, lxw_name_to_col_2("AAA:IU"));
ASSERT_EQUAL(255, lxw_name_to_col_2("AAA:IV"));
ASSERT_EQUAL(256, lxw_name_to_col_2("AAA:IW"));
ASSERT_EQUAL(16383, lxw_name_to_col_2("AAA:XFD"));
ASSERT_EQUAL(16384, lxw_name_to_col_2("AAA:XFE"));
ASSERT_EQUAL(16384, lxw_name_to_col_2("AAA1:XFE1"));
ASSERT_EQUAL(16384, lxw_name_to_col_2("$AAA:$XFE"));
}

View File

@@ -0,0 +1,26 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/utility.h"
// Test _datetime_to_excel_date().
CTEST(utility, lxw_quote_sheetname) {
ASSERT_STR("Sheet1", lxw_quote_sheetname("Sheet1"));
ASSERT_STR("Sheet.2", lxw_quote_sheetname("Sheet.2"));
ASSERT_STR("Sheet_3", lxw_quote_sheetname("Sheet_3"));
ASSERT_STR("'Sheet4'", lxw_quote_sheetname("'Sheet4'"));
ASSERT_STR("'Sheet 5'", lxw_quote_sheetname("Sheet 5"));
ASSERT_STR("'Sheet!6'", lxw_quote_sheetname("Sheet!6"));
ASSERT_STR("'Sheet''7'", lxw_quote_sheetname("Sheet'7"));
ASSERT_STR("'a''''''''''''''''''''''''''''''''''''''''''''''''''''''''''b'",
lxw_quote_sheetname("a'''''''''''''''''''''''''''''b"));
}

View File

@@ -0,0 +1,63 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/utility.h"
// Test xl_rowcol_to_cell().
CTEST(utility, lxw_rowcol_to_cell) {
char got[LXW_MAX_CELL_NAME_LENGTH];
TEST_ROWCOL_TO_CELL(0, 0, "A1");
TEST_ROWCOL_TO_CELL(0, 1, "B1");
TEST_ROWCOL_TO_CELL(0, 2, "C1");
TEST_ROWCOL_TO_CELL(0, 9, "J1");
TEST_ROWCOL_TO_CELL(1, 0, "A2");
TEST_ROWCOL_TO_CELL(2, 0, "A3");
TEST_ROWCOL_TO_CELL(9, 0, "A10");
TEST_ROWCOL_TO_CELL(1, 24, "Y2");
TEST_ROWCOL_TO_CELL(7, 25, "Z8");
TEST_ROWCOL_TO_CELL(9, 26, "AA10");
TEST_ROWCOL_TO_CELL(1, 254, "IU2");
TEST_ROWCOL_TO_CELL(1, 255, "IV2");
TEST_ROWCOL_TO_CELL(1, 256, "IW2");
TEST_ROWCOL_TO_CELL(0, 16383, "XFD1");
TEST_ROWCOL_TO_CELL(1048576, 16384, "XFE1048577");
}
// Test xl_rowcol_to_cell_abs().
CTEST(utility, lxw_rowcol_to_cell_abs) {
char got[LXW_MAX_CELL_NAME_LENGTH];
TEST_ROWCOL_TO_CELL_ABS(0, 0, 0, 0, "A1");
TEST_ROWCOL_TO_CELL_ABS(0, 1, 0, 0, "B1");
TEST_ROWCOL_TO_CELL_ABS(0, 2, 0, 0, "C1");
TEST_ROWCOL_TO_CELL_ABS(0, 9, 0, 0, "J1");
TEST_ROWCOL_TO_CELL_ABS(1, 0, 0, 0, "A2");
TEST_ROWCOL_TO_CELL_ABS(2, 0, 0, 0, "A3");
TEST_ROWCOL_TO_CELL_ABS(9, 0, 0, 0, "A10");
TEST_ROWCOL_TO_CELL_ABS(1, 24, 0, 0, "Y2");
TEST_ROWCOL_TO_CELL_ABS(7, 25, 0, 0, "Z8");
TEST_ROWCOL_TO_CELL_ABS(9, 26, 0, 0, "AA10");
TEST_ROWCOL_TO_CELL_ABS(1, 254, 0, 0, "IU2");
TEST_ROWCOL_TO_CELL_ABS(1, 255, 0, 0, "IV2");
TEST_ROWCOL_TO_CELL_ABS(1, 256, 0, 0, "IW2");
TEST_ROWCOL_TO_CELL_ABS(0, 16383, 0, 0, "XFD1");
TEST_ROWCOL_TO_CELL_ABS(1048576, 16384, 0, 0, "XFE1048577");
TEST_ROWCOL_TO_CELL_ABS(0, 0, 1, 0, "A$1");
TEST_ROWCOL_TO_CELL_ABS(0, 0, 0, 1, "$A1");
TEST_ROWCOL_TO_CELL_ABS(0, 0, 1, 1, "$A$1");
TEST_ROWCOL_TO_CELL_ABS(1048576, 16384, 1, 0, "XFE$1048577");
TEST_ROWCOL_TO_CELL_ABS(1048576, 16384, 0, 1, "$XFE1048577");
TEST_ROWCOL_TO_CELL_ABS(1048576, 16384, 1, 1, "$XFE$1048577");
}

View File

@@ -0,0 +1,37 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/utility.h"
// Test lxw_rowcol_to_formula_abs().
CTEST(utility, lxw_rowcol_to_formula_abs) {
char got[LXW_MAX_FORMULA_RANGE_LENGTH];
TEST_ROWCOL_TO_FORMULA_ABS("Sheet1", 0, 0, 0, 1, "Sheet1!$A$1:$B$1");
TEST_ROWCOL_TO_FORMULA_ABS("Sheet1", 0, 2, 0, 9, "Sheet1!$C$1:$J$1");
TEST_ROWCOL_TO_FORMULA_ABS("Sheet1", 1, 0, 2, 0, "Sheet1!$A$2:$A$3");
TEST_ROWCOL_TO_FORMULA_ABS("Sheet1", 9, 0, 1, 24, "Sheet1!$A$10:$Y$2");
TEST_ROWCOL_TO_FORMULA_ABS("Sheet1", 7, 25, 9, 26, "Sheet1!$Z$8:$AA$10");
TEST_ROWCOL_TO_FORMULA_ABS("Sheet1", 1, 254, 1, 255, "Sheet1!$IU$2:$IV$2");
TEST_ROWCOL_TO_FORMULA_ABS("Sheet1", 1, 256, 0, 16383, "Sheet1!$IW$2:$XFD$1");
TEST_ROWCOL_TO_FORMULA_ABS("Sheet1", 0, 0, 1048576, 16384, "Sheet1!$A$1:$XFE$1048577");
TEST_ROWCOL_TO_FORMULA_ABS("Sheet1", 1048575, 16383, 1048576, 16384, "Sheet1!$XFD$1048576:$XFE$1048577");
TEST_ROWCOL_TO_FORMULA_ABS("New data", 1, 2, 8, 2, "'New data'!$C$2:$C$9");
TEST_ROWCOL_TO_FORMULA_ABS("'New data'", 1, 2, 8, 2, "'New data'!$C$2:$C$9");
// Test ranges that resolve to single cells.
TEST_ROWCOL_TO_FORMULA_ABS("Sheet1", 0, 0, 0, 0, "Sheet1!$A$1");
TEST_ROWCOL_TO_FORMULA_ABS("Sheet1", 1048576, 16384, 1048576, 16384, "Sheet1!$XFE$1048577");
}

View File

@@ -0,0 +1,53 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/utility.h"
// Test lxw_rowcol_to_range().
CTEST(utility, lxw_rowcol_to_range) {
char got[LXW_MAX_CELL_RANGE_LENGTH];
TEST_ROWCOL_TO_RANGE(0, 0, 0, 1, "A1:B1");
TEST_ROWCOL_TO_RANGE(0, 2, 0, 9, "C1:J1");
TEST_ROWCOL_TO_RANGE(1, 0, 2, 0, "A2:A3");
TEST_ROWCOL_TO_RANGE(9, 0, 1, 24, "A10:Y2");
TEST_ROWCOL_TO_RANGE(7, 25, 9, 26, "Z8:AA10");
TEST_ROWCOL_TO_RANGE(1, 254, 1, 255, "IU2:IV2");
TEST_ROWCOL_TO_RANGE(1, 256, 0, 16383, "IW2:XFD1");
TEST_ROWCOL_TO_RANGE(0, 0, 1048576, 16384, "A1:XFE1048577");
TEST_ROWCOL_TO_RANGE(1048575, 16383, 1048576, 16384, "XFD1048576:XFE1048577");
// Test ranges that resolve to single cells.
TEST_ROWCOL_TO_RANGE(0, 0, 0, 0, "A1");
TEST_ROWCOL_TO_RANGE(1048576, 16384, 1048576, 16384, "XFE1048577");
}
// Test lxw_rowcol_to_range_abs().
CTEST(utility, lxw_rowcol_to_range_abs) {
char got[LXW_MAX_CELL_RANGE_LENGTH];
TEST_ROWCOL_TO_RANGE_ABS(0, 0, 0, 1, "$A$1:$B$1");
TEST_ROWCOL_TO_RANGE_ABS(0, 2, 0, 9, "$C$1:$J$1");
TEST_ROWCOL_TO_RANGE_ABS(1, 0, 2, 0, "$A$2:$A$3");
TEST_ROWCOL_TO_RANGE_ABS(9, 0, 1, 24, "$A$10:$Y$2");
TEST_ROWCOL_TO_RANGE_ABS(7, 25, 9, 26, "$Z$8:$AA$10");
TEST_ROWCOL_TO_RANGE_ABS(1, 254, 1, 255, "$IU$2:$IV$2");
TEST_ROWCOL_TO_RANGE_ABS(1, 256, 0, 16383, "$IW$2:$XFD$1");
TEST_ROWCOL_TO_RANGE_ABS(0, 0, 1048576, 16384, "$A$1:$XFE$1048577");
TEST_ROWCOL_TO_RANGE_ABS(1048575, 16383, 1048576, 16384, "$XFD$1048576:$XFE$1048577");
// Test ranges that resolve to single cells.
TEST_ROWCOL_TO_RANGE_ABS(0, 0, 0, 0, "$A$1");
TEST_ROWCOL_TO_RANGE_ABS(1048576, 16384, 1048576, 16384, "$XFE$1048577");
}

View File

@@ -0,0 +1,30 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/utility.h"
// Test lxw_strerror() to ensure the error_string array doesn't go out of sync.
CTEST(utility, lxw_strerror) {
ASSERT_STR("No error.",
lxw_strerror(LXW_NO_ERROR));
ASSERT_STR("Error encountered when creating a tmpfile during file assembly.",
lxw_strerror(LXW_ERROR_CREATING_TMPFILE));
ASSERT_STR("Maximum number of worksheet URLs (65530) exceeded.",
lxw_strerror(LXW_ERROR_WORKSHEET_MAX_NUMBER_URLS_EXCEEDED));
ASSERT_STR("Unknown error number.",
lxw_strerror(LXW_MAX_ERRNO));
ASSERT_STR("Unknown error number.",
lxw_strerror(LXW_MAX_ERRNO + 1));
}

View File

@@ -0,0 +1,32 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/utility.h"
// Test _xl_get_row().
CTEST(utility, lxw_name_to_row) {
ASSERT_EQUAL(0, lxw_name_to_row("A1"));
ASSERT_EQUAL(0, lxw_name_to_row("$A$1"));
ASSERT_EQUAL(1, lxw_name_to_row("B2"));
ASSERT_EQUAL(2, lxw_name_to_row("C3"));
ASSERT_EQUAL(9, lxw_name_to_row("J10"));
ASSERT_EQUAL(24, lxw_name_to_row("Y25"));
ASSERT_EQUAL(25, lxw_name_to_row("Z26"));
ASSERT_EQUAL(26, lxw_name_to_row("AA27"));
ASSERT_EQUAL(254, lxw_name_to_row("IU255"));
ASSERT_EQUAL(255, lxw_name_to_row("IV256"));
ASSERT_EQUAL(256, lxw_name_to_row("IW257"));
ASSERT_EQUAL(16383, lxw_name_to_row("XFD16384"));
ASSERT_EQUAL(16384, lxw_name_to_row("XFE16385"));
ASSERT_EQUAL(1048576, lxw_name_to_row("XFE1048577"));
ASSERT_EQUAL(1048576, lxw_name_to_row("$XFE$1048577"));
}

View 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);
}

View 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);
}

View File

@@ -0,0 +1,112 @@
/*
* Tests for the lib_xlsx_writer library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/workbook.h"
#include "../../../include/xlsxwriter/shared_strings.h"
// Test assembling a complete Workbook file.
CTEST(workbook, workbook01) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<workbook xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<fileVersion appName=\"xl\" lastEdited=\"4\" lowestEdited=\"4\" rupBuild=\"4505\"/>"
"<workbookPr defaultThemeVersion=\"124226\"/>"
"<bookViews>"
"<workbookView xWindow=\"240\" yWindow=\"15\" windowWidth=\"16095\" windowHeight=\"9660\"/>"
"</bookViews>"
"<sheets>"
"<sheet name=\"Sheet1\" sheetId=\"1\" r:id=\"rId1\"/>"
"</sheets>"
"<calcPr calcId=\"124519\" fullCalcOnLoad=\"1\"/>"
"</workbook>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
workbook_add_worksheet(workbook, NULL);
lxw_workbook_assemble_xml_file(workbook);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_workbook_free(workbook);
}
// Test assembling a complete Workbook file.
CTEST(workbook, workbook02) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<workbook xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<fileVersion appName=\"xl\" lastEdited=\"4\" lowestEdited=\"4\" rupBuild=\"4505\"/>"
"<workbookPr defaultThemeVersion=\"124226\"/>"
"<bookViews>"
"<workbookView xWindow=\"240\" yWindow=\"15\" windowWidth=\"16095\" windowHeight=\"9660\"/>"
"</bookViews>"
"<sheets>"
"<sheet name=\"Sheet1\" sheetId=\"1\" r:id=\"rId1\"/>"
"<sheet name=\"Sheet2\" sheetId=\"2\" r:id=\"rId2\"/>"
"</sheets>"
"<calcPr calcId=\"124519\" fullCalcOnLoad=\"1\"/>"
"</workbook>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
workbook_add_worksheet(workbook, NULL);
workbook_add_worksheet(workbook, NULL);
lxw_workbook_assemble_xml_file(workbook);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_workbook_free(workbook);
}
// Test assembling a complete Workbook file.
CTEST(workbook, workbook03) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<workbook xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<fileVersion appName=\"xl\" lastEdited=\"4\" lowestEdited=\"4\" rupBuild=\"4505\"/>"
"<workbookPr defaultThemeVersion=\"124226\"/>"
"<bookViews>"
"<workbookView xWindow=\"240\" yWindow=\"15\" windowWidth=\"16095\" windowHeight=\"9660\"/>"
"</bookViews>"
"<sheets>"
"<sheet name=\"Non Default Name\" sheetId=\"1\" r:id=\"rId1\"/>"
"<sheet name=\"Another Name\" sheetId=\"2\" r:id=\"rId2\"/>"
"</sheets>"
"<calcPr calcId=\"124519\" fullCalcOnLoad=\"1\"/>"
"</workbook>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
workbook_add_worksheet(workbook, "Non Default Name");
workbook_add_worksheet(workbook, "Another Name");
lxw_workbook_assemble_xml_file(workbook);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_workbook_free(workbook);
}

View File

@@ -0,0 +1,75 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/workbook.h"
#include "../../../include/xlsxwriter/shared_strings.h"
/* Test finding a worksheet that does exist (implicit naming). */
CTEST(workbook, get_worksheet_by_name01) {
lxw_workbook *workbook = workbook_new(NULL);
lxw_worksheet *exp = workbook_add_worksheet(workbook, NULL);
lxw_worksheet *got = workbook_get_worksheet_by_name(workbook, "Sheet1");
ASSERT_TRUE(got == exp);
lxw_workbook_free(workbook);
}
/* Test finding a worksheet that does exist (explicit naming). */
CTEST(workbook, get_worksheet_by_name02) {
lxw_workbook *workbook = workbook_new(NULL);
lxw_worksheet *exp = workbook_add_worksheet(workbook, "FOO");
lxw_worksheet *got = workbook_get_worksheet_by_name(workbook, "FOO");
ASSERT_TRUE(got == exp);
lxw_workbook_free(workbook);
}
/* Test finding a worksheet that doesn't exist. */
CTEST(workbook, get_worksheet_by_name03) {
lxw_workbook *workbook = workbook_new(NULL);
workbook_add_worksheet(workbook, NULL);
lxw_worksheet *got = workbook_get_worksheet_by_name(workbook, "FOO");
ASSERT_TRUE(got == NULL);
lxw_workbook_free(workbook);
}
/* Test finding a worksheet when no worksheets exist. */
CTEST(workbook, get_worksheet_by_name04) {
lxw_workbook *workbook = workbook_new(NULL);
lxw_worksheet *got = workbook_get_worksheet_by_name(workbook, "FOO");
ASSERT_TRUE(got == NULL);
lxw_workbook_free(workbook);
}
/* Test finding a worksheet with a NULL name. */
CTEST(workbook, get_worksheet_by_name05) {
lxw_workbook *workbook = workbook_new(NULL);
workbook_add_worksheet(workbook, NULL);
lxw_worksheet *got = workbook_get_worksheet_by_name(workbook, NULL);
ASSERT_TRUE(got == NULL);
lxw_workbook_free(workbook);
}

View File

@@ -0,0 +1,146 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/workbook.h"
#include "../../../include/xlsxwriter/shared_strings.h"
/* Test a valid sheet name. */
CTEST(workbook, validate_worksheet_name01) {
const char* sheetname = "123456789_123456789_123456789_1";
lxw_workbook *workbook = workbook_new(NULL);
lxw_error exp = LXW_NO_ERROR;
lxw_error got = workbook_validate_sheet_name(workbook, sheetname);
ASSERT_EQUAL(exp, got);
lxw_workbook_free(workbook);
}
/* Test a sheet name that is too long. */
CTEST(workbook, validate_worksheet_name02) {
const char* sheetname = "123456789_123456789_123456789_12";
lxw_workbook *workbook = workbook_new(NULL);
lxw_error exp = LXW_ERROR_SHEETNAME_LENGTH_EXCEEDED;
lxw_error got = workbook_validate_sheet_name(workbook, sheetname);
ASSERT_EQUAL(exp, got);
lxw_workbook_free(workbook);
}
/* Test a sheet name contains invalid characters. */
CTEST(workbook, validate_worksheet_name03) {
const char* sheetname = "Sheet[1]";
lxw_workbook *workbook = workbook_new(NULL);
lxw_error exp = LXW_ERROR_INVALID_SHEETNAME_CHARACTER;
lxw_error got = workbook_validate_sheet_name(workbook, sheetname);
ASSERT_EQUAL(exp, got);
lxw_workbook_free(workbook);
}
/* Test a sheet name that already exists. */
CTEST(workbook, validate_worksheet_name04) {
const char* sheetname = "Sheet1";
lxw_workbook *workbook = workbook_new(NULL);
workbook_add_worksheet(workbook, sheetname);
lxw_error exp = LXW_ERROR_SHEETNAME_ALREADY_USED;
lxw_error got = workbook_validate_sheet_name(workbook, sheetname);
ASSERT_EQUAL(exp, got);
lxw_workbook_free(workbook);
}
/* Test a sheet name that starts with an apostrophe. */
CTEST(workbook, validate_worksheet_name05) {
const char* sheetname = "'Sheet1";
lxw_workbook *workbook = workbook_new(NULL);
lxw_error exp = LXW_ERROR_SHEETNAME_START_END_APOSTROPHE;
lxw_error got = workbook_validate_sheet_name(workbook, sheetname);
ASSERT_EQUAL(exp, got);
lxw_workbook_free(workbook);
}
/* Test a sheet name that ends with an apostrophe. */
CTEST(workbook, validate_worksheet_name06) {
const char* sheetname = "Sheet1'";
lxw_workbook *workbook = workbook_new(NULL);
lxw_error exp = LXW_ERROR_SHEETNAME_START_END_APOSTROPHE;
lxw_error got = workbook_validate_sheet_name(workbook, sheetname);
ASSERT_EQUAL(exp, got);
lxw_workbook_free(workbook);
}
/* Test a sheet name that already exists, case insensitive. */
CTEST(workbook, validate_worksheet_name07) {
const char* sheetname = "Sheet1";
lxw_workbook *workbook = workbook_new(NULL);
workbook_add_worksheet(workbook, sheetname);
lxw_error exp = LXW_ERROR_SHEETNAME_ALREADY_USED;
lxw_error got = workbook_validate_sheet_name(workbook, "sheet1");
ASSERT_EQUAL(exp, got);
lxw_workbook_free(workbook);
}
/* Test a sheet name that already exists, case insensitive. */
CTEST(workbook, validate_worksheet_name08) {
const char* sheetname = "Café";
lxw_workbook *workbook = workbook_new(NULL);
workbook_add_worksheet(workbook, sheetname);
lxw_error exp = LXW_ERROR_SHEETNAME_ALREADY_USED;
lxw_error got = workbook_validate_sheet_name(workbook, "café");
ASSERT_EQUAL(exp, got);
lxw_workbook_free(workbook);
}
/* Test a sheet name that already exists, case insensitive. */
CTEST(workbook, validate_worksheet_name09) {
const char* sheetname = "abcde";
lxw_workbook *workbook = workbook_new(NULL);
workbook_add_worksheet(workbook, sheetname);
lxw_error exp = LXW_ERROR_SHEETNAME_ALREADY_USED;
lxw_error got = workbook_validate_sheet_name(workbook, "ABCDE");
ASSERT_EQUAL(exp, got);
lxw_workbook_free(workbook);
}

View File

@@ -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/workbook.h"
// Test the _write_book_views() function.
CTEST(workbook, write_book_views) {
char* got;
char exp[] = "<bookViews><workbookView xWindow=\"240\" yWindow=\"15\" windowWidth=\"16095\" windowHeight=\"9660\"/></bookViews>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
_write_book_views(workbook);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}

View File

@@ -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/workbook.h"
// Test the _write_calc_pr() function.
CTEST(workbook, write_calc_pr) {
char* got;
char exp[] = "<calcPr calcId=\"124519\" fullCalcOnLoad=\"1\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
_write_calc_pr(workbook);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}

View File

@@ -0,0 +1,30 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/workbook.h"
/* Test the _write_defined_name() method. */
CTEST(workbook, write_defined_name) {
char* got;
char exp[] = "<definedName name=\"_xlnm.Print_Titles\" localSheetId=\"0\">Sheet1!$1:$1</definedName>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_defined_name defined_name = {0, 0, "_xlnm.Print_Titles", "", "Sheet1!$1:$1", "", "", {NULL, NULL}};
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
_write_defined_name(workbook, &defined_name);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}

View File

@@ -0,0 +1,66 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/workbook.h"
/* Test the _write_defined_names() method. */
CTEST(workbook, write_defined_names) {
char* got;
char exp[] = "<definedNames><definedName name=\"_xlnm.Print_Titles\" localSheetId=\"0\">Sheet1!$1:$1</definedName></definedNames>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
workbook_add_worksheet(workbook, NULL);
_store_defined_name(workbook, "_xlnm.Print_Titles", "", "Sheet1!$1:$1", 0, 0);
_write_defined_names(workbook);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}
/* Test the _write_defined_name() method. */
CTEST(workbook, write_defined_names_sorted) {
char* got;
char exp[] = "<definedNames><definedName name=\"_Egg\">Sheet1!$A$1</definedName><definedName name=\"_Fog\">Sheet1!$A$1</definedName><definedName name=\"aaa\" localSheetId=\"1\">Sheet2!$A$1</definedName><definedName name=\"Abc\">Sheet1!$A$1</definedName><definedName name=\"Bar\" localSheetId=\"2\">'Sheet 3'!$A$1</definedName><definedName name=\"Bar\" localSheetId=\"0\">Sheet1!$A$1</definedName><definedName name=\"Bar\" localSheetId=\"1\">Sheet2!$A$1</definedName><definedName name=\"Baz\">0.98</definedName><definedName name=\"car\" localSheetId=\"2\">\"Saab 900\"</definedName></definedNames>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
workbook_add_worksheet(workbook, NULL);
workbook_add_worksheet(workbook, NULL);
workbook_add_worksheet(workbook, "Sheet 3");
workbook_define_name(workbook, "'Sheet 3'!Bar", "='Sheet 3'!$A$1");
workbook_define_name(workbook, "Abc", "=Sheet1!$A$1" );
workbook_define_name(workbook, "Baz", "=0.98" );
workbook_define_name(workbook, "Sheet1!Bar", "=Sheet1!$A$1" );
workbook_define_name(workbook, "Sheet2!Bar", "=Sheet2!$A$1" );
workbook_define_name(workbook, "Sheet2!aaa", "=Sheet2!$A$1" );
workbook_define_name(workbook, "'Sheet 3'!car", "=\"Saab 900\"" );
workbook_define_name(workbook, "_Egg", "=Sheet1!$A$1" );
workbook_define_name(workbook, "_Fog", "=Sheet1!$A$1" );
_write_defined_names(workbook);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}

View File

@@ -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/workbook.h"
// Test the _write_file_version() function.
CTEST(workbook, write_file_version) {
char* got;
char exp[] = "<fileVersion appName=\"xl\" lastEdited=\"4\" lowestEdited=\"4\" rupBuild=\"4505\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
_write_file_version(workbook);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}

View File

@@ -0,0 +1,66 @@
/*
* Tests for the lib_xlsx_writer library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/workbook.h"
// Test the _write_sheet() function.
CTEST(workbook, write_sheet1) {
char* got;
char exp[] = "<sheet name=\"Sheet1\" sheetId=\"1\" r:id=\"rId1\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
_write_sheet(workbook, "Sheet1", 1, 0);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}
// Test the _write_sheet() function.
CTEST(workbook, write_sheet2) {
char* got;
char exp[] = "<sheet name=\"Sheet1\" sheetId=\"1\" state=\"hidden\" r:id=\"rId1\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
_write_sheet(workbook, "Sheet1", 1, 1);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}
// Test the _write_sheet() function.
CTEST(workbook, write_sheet3) {
char* got;
char exp[] = "<sheet name=\"Bits &amp; Bobs\" sheetId=\"1\" r:id=\"rId1\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
_write_sheet(workbook, "Bits & Bobs", 1, 0);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}

View File

@@ -0,0 +1,32 @@
/*
* Tests for the lib_xlsx_writer library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/workbook.h"
// Test the _write_sheets() function.
CTEST(workbook, write_sheets) {
char* got;
char exp[] = "<sheets><sheet name=\"Sheet1\" sheetId=\"1\" r:id=\"rId1\"/></sheets>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
workbook_add_worksheet(workbook, NULL);
_write_sheets(workbook);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}

View File

@@ -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/workbook.h"
// Test the _write_workbook() function.
CTEST(workbook, write_workbook) {
char* got;
char exp[] = "<workbook xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
_write_workbook(workbook);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}

View File

@@ -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/workbook.h"
// Test the _write_workbook_pr() function.
CTEST(workbook, write_workbook_pr) {
char* got;
char exp[] = "<workbookPr defaultThemeVersion=\"124226\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
_write_workbook_pr(workbook);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}

View File

@@ -0,0 +1,70 @@
/*
* Tests for the lib_xlsx_writer library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/workbook.h"
// Test the _write_workbook_view() function.
CTEST(workbook, write_workbook_view1) {
char* got;
char exp[] = "<workbookView xWindow=\"240\" yWindow=\"15\" windowWidth=\"16095\" windowHeight=\"9660\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
_write_workbook_view(workbook);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}
// Test the _write_workbook_view() function.
CTEST(workbook, write_workbook_view2) {
char* got;
char exp[] = "<workbookView xWindow=\"240\" yWindow=\"15\" windowWidth=\"16095\" windowHeight=\"9660\" activeTab=\"1\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
workbook->active_sheet = 1;
_write_workbook_view(workbook);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}
// Test the _write_workbook_view() function.
CTEST(workbook, write_workbook_view3) {
char* got;
char exp[] = "<workbookView xWindow=\"240\" yWindow=\"15\" windowWidth=\"16095\" windowHeight=\"9660\" firstSheet=\"2\" activeTab=\"1\"/>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
workbook->active_sheet = 1;
workbook->first_sheet = 2;
_write_workbook_view(workbook);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}

View File

@@ -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/workbook.h"
// Test _xml_declaration().
CTEST(workbook, xml_declaration) {
char* got;
char exp[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
FILE* testfile = lxw_tmpfile(NULL);
lxw_workbook *workbook = workbook_new(NULL);
workbook->file = testfile;
_workbook_xml_declaration(workbook);
RUN_XLSX_STREQ(exp, got);
lxw_workbook_free(workbook);
}

View 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);
}

View File

@@ -0,0 +1,137 @@
/*
* Tests for the lib_xlsx_writer library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/shared_strings.h"
// Test assembling a complete Worksheet file.
CTEST(worksheet, worksheet01) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<dimension ref=\"A1\"/>"
"<sheetViews>"
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
"</sheetViews>"
"<sheetFormatPr defaultRowHeight=\"15\"/>"
"<sheetData/>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"</worksheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile;
worksheet_select(worksheet);
lxw_worksheet_assemble_xml_file(worksheet);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
}
// Test assembling a complete Worksheet file.
CTEST(worksheet, worksheet02) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<dimension ref=\"A1\"/>"
"<sheetViews>"
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
"</sheetViews>"
"<sheetFormatPr defaultRowHeight=\"15\"/>"
"<sheetData>"
"<row r=\"1\" spans=\"1:1\">"
"<c r=\"A1\">"
"<v>123</v>"
"</c>"
"</row>"
"</sheetData>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"</worksheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile;
worksheet_select(worksheet);
worksheet_write_number(worksheet, 0, 0, 123, NULL);
lxw_worksheet_assemble_xml_file(worksheet);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
}
// Test assembling a complete Worksheet file.
CTEST(worksheet, worksheet03) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<dimension ref=\"A1:E9\"/>"
"<sheetViews>"
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
"</sheetViews>"
"<sheetFormatPr defaultRowHeight=\"15\"/>"
"<sheetData>"
"<row r=\"1\" spans=\"1:5\">"
"<c r=\"A1\" t=\"s\">"
"<v>0</v>"
"</c>"
"</row>"
"<row r=\"2\" spans=\"1:5\">"
"<c r=\"C2\">"
"<v>123</v>"
"</c>"
"</row>"
"<row r=\"4\" spans=\"1:5\">"
"<c r=\"B4\" t=\"s\">"
"<v>1</v>"
"</c>"
"</row>"
"<row r=\"9\" spans=\"1:5\">"
"<c r=\"E9\">"
"<v>890</v>"
"</c>"
"</row>"
"</sheetData>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"</worksheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile;
worksheet->sst = lxw_sst_new();
worksheet_select(worksheet);
worksheet_write_string(worksheet, 0, 0, "Foo", NULL);
worksheet_write_number(worksheet, 1, 2, 123, NULL);
worksheet_write_string(worksheet, 3, 1, "Bar", NULL);
worksheet_write_number(worksheet, 8, 4, 890, NULL);
lxw_worksheet_assemble_xml_file(worksheet);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_sst_free(worksheet->sst);
lxw_worksheet_free(worksheet);
}

View File

@@ -0,0 +1,121 @@
/*
* Tests for the lib_xlsx_writer library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/shared_strings.h"
// Test assembling a complete Worksheet file.
CTEST(merged_range, array_formula01) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<dimension ref=\"A1:C7\"/>"
"<sheetViews>"
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
"</sheetViews>"
"<sheetFormatPr defaultRowHeight=\"15\"/>"
"<sheetData>"
"<row r=\"1\" spans=\"1:3\">"
"<c r=\"A1\">"
"<f t=\"array\" ref=\"A1\">SUM(B1:C1*B2:C2)</f>"
"<v>9500</v>"
"</c>"
"<c r=\"B1\">"
"<v>500</v>"
"</c>"
"<c r=\"C1\">"
"<v>300</v>"
"</c>"
"</row>"
"<row r=\"2\" spans=\"1:3\">"
"<c r=\"A2\">"
"<f t=\"array\" ref=\"A2\">SUM(B1:C1*B2:C2)</f>"
"<v>9500</v>"
"</c>"
"<c r=\"B2\">"
"<v>10</v>"
"</c>"
"<c r=\"C2\">"
"<v>15</v>"
"</c>"
"</row>"
"<row r=\"5\" spans=\"1:3\">"
"<c r=\"A5\">"
"<f t=\"array\" ref=\"A5:A7\">TREND(C5:C7,B5:B7)</f>"
"<v>22196</v>"
"</c>"
"<c r=\"B5\">"
"<v>1</v>"
"</c>"
"<c r=\"C5\">"
"<v>20234</v>"
"</c>"
"</row>"
"<row r=\"6\" spans=\"1:3\">"
"<c r=\"A6\">"
"<v>0</v>"
"</c>"
"<c r=\"B6\">"
"<v>2</v>"
"</c>"
"<c r=\"C6\">"
"<v>21003</v>"
"</c>"
"</row>"
"<row r=\"7\" spans=\"1:3\">"
"<c r=\"A7\">"
"<v>0</v>"
"</c>"
"<c r=\"B7\">"
"<v>3</v>"
"</c>"
"<c r=\"C7\">"
"<v>10000</v>"
"</c>"
"</row>"
"</sheetData>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"</worksheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile;
//worksheet->sst = _new_sst();
worksheet_select(worksheet);
lxw_format *format = lxw_format_new();
format->xf_index = 1;
worksheet_write_array_formula_num(worksheet, 0, 0, 0, 0, "{=SUM(B1:C1*B2:C2)}", NULL, 9500);
worksheet_write_array_formula_num(worksheet, 1, 0, 1, 0, "{=SUM(B1:C1*B2:C2)}", NULL, 9500);
worksheet_write_array_formula_num(worksheet, 4, 0, 6, 0, "{=TREND(C5:C7,B5:B7)}", NULL, 22196);
worksheet_write_number(worksheet, 0, 1, 500, NULL);
worksheet_write_number(worksheet, 1, 1, 10, NULL);
worksheet_write_number(worksheet, 4, 1, 1, NULL);
worksheet_write_number(worksheet, 5, 1, 2, NULL);
worksheet_write_number(worksheet, 6, 1, 3, NULL);
worksheet_write_number(worksheet, 0, 2, 300, NULL);
worksheet_write_number(worksheet, 1, 2, 15, NULL);
worksheet_write_number(worksheet, 4, 2, 20234, NULL);
worksheet_write_number(worksheet, 5, 2, 21003, NULL);
worksheet_write_number(worksheet, 6, 2, 10000, NULL);
lxw_worksheet_assemble_xml_file(worksheet);
RUN_XLSX_STREQ_SHORT(exp, got);
//_free_sst(worksheet->sst);
lxw_worksheet_free(worksheet);
}

View File

@@ -0,0 +1,84 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/shared_strings.h"
// Test assembling a complete Worksheet file.
CTEST(worksheet, worksheet_condtional_format01) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<dimension ref=\"A1:A4\"/>"
"<sheetViews>"
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
"</sheetViews>"
"<sheetFormatPr defaultRowHeight=\"15\"/>"
"<sheetData>"
"<row r=\"1\" spans=\"1:1\">"
"<c r=\"A1\">"
"<v>10</v>"
"</c>"
"</row>"
"<row r=\"2\" spans=\"1:1\">"
"<c r=\"A2\">"
"<v>20</v>"
"</c>"
"</row>"
"<row r=\"3\" spans=\"1:1\">"
"<c r=\"A3\">"
"<v>30</v>"
"</c>"
"</row>"
"<row r=\"4\" spans=\"1:1\">"
"<c r=\"A4\">"
"<v>40</v>"
"</c>"
"</row>"
"</sheetData>"
"<conditionalFormatting sqref=\"A1\">"
"<cfRule type=\"cellIs\" priority=\"1\" operator=\"greaterThan\">"
"<formula>5</formula>"
"</cfRule>"
"</conditionalFormatting>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"</worksheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile;
worksheet_select(worksheet);
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_GREATER_THAN;
conditional_format->value = 5;
conditional_format->format = NULL;
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
free(conditional_format);
lxw_worksheet_assemble_xml_file(worksheet);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
}

View File

@@ -0,0 +1,163 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/shared_strings.h"
// Test assembling a complete Worksheet file.
CTEST(worksheet, worksheet_condtional_format02) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<dimension ref=\"A1:B4\"/>"
"<sheetViews>"
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
"</sheetViews>"
"<sheetFormatPr defaultRowHeight=\"15\"/>"
"<sheetData>"
"<row r=\"1\" spans=\"1:2\">"
"<c r=\"A1\">"
"<v>10</v>"
"</c>"
"<c r=\"B1\">"
"<v>5</v>"
"</c>"
"</row>"
"<row r=\"2\" spans=\"1:2\">"
"<c r=\"A2\">"
"<v>20</v>"
"</c>"
"</row>"
"<row r=\"3\" spans=\"1:2\">"
"<c r=\"A3\">"
"<v>30</v>"
"</c>"
"</row>"
"<row r=\"4\" spans=\"1:2\">"
"<c r=\"A4\">"
"<v>40</v>"
"</c>"
"</row>"
"</sheetData>"
"<conditionalFormatting sqref=\"A1\">"
"<cfRule type=\"cellIs\" priority=\"1\" operator=\"greaterThan\">"
"<formula>$B$1</formula>"
"</cfRule>"
"</conditionalFormatting>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"</worksheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile;
worksheet_select(worksheet);
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
worksheet_write_number(worksheet, CELL("B1"), 5, NULL);
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_GREATER_THAN;
conditional_format->value_string = "$B$1";
conditional_format->format = NULL;
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
free(conditional_format);
lxw_worksheet_assemble_xml_file(worksheet);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
}
// This version uses a range formula "$B$1" -> "=$B$1".
CTEST(worksheet, worksheet_condtional_format02b) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<dimension ref=\"A1:B4\"/>"
"<sheetViews>"
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
"</sheetViews>"
"<sheetFormatPr defaultRowHeight=\"15\"/>"
"<sheetData>"
"<row r=\"1\" spans=\"1:2\">"
"<c r=\"A1\">"
"<v>10</v>"
"</c>"
"<c r=\"B1\">"
"<v>5</v>"
"</c>"
"</row>"
"<row r=\"2\" spans=\"1:2\">"
"<c r=\"A2\">"
"<v>20</v>"
"</c>"
"</row>"
"<row r=\"3\" spans=\"1:2\">"
"<c r=\"A3\">"
"<v>30</v>"
"</c>"
"</row>"
"<row r=\"4\" spans=\"1:2\">"
"<c r=\"A4\">"
"<v>40</v>"
"</c>"
"</row>"
"</sheetData>"
"<conditionalFormatting sqref=\"A1\">"
"<cfRule type=\"cellIs\" priority=\"1\" operator=\"greaterThan\">"
"<formula>$B$1</formula>"
"</cfRule>"
"</conditionalFormatting>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"</worksheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile;
worksheet_select(worksheet);
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
worksheet_write_number(worksheet, CELL("B1"), 5, NULL);
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_GREATER_THAN;
conditional_format->value_string = "=$B$1";
conditional_format->format = NULL;
worksheet_conditional_format_cell(worksheet, CELL("A1"), conditional_format);
free(conditional_format);
lxw_worksheet_assemble_xml_file(worksheet);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
}

View File

@@ -0,0 +1,181 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/shared_strings.h"
// Test assembling a complete Worksheet file.
CTEST(worksheet, worksheet_condtional_format03) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<dimension ref=\"A1:A4\"/>"
"<sheetViews>"
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
"</sheetViews>"
"<sheetFormatPr defaultRowHeight=\"15\"/>"
"<sheetData>"
"<row r=\"1\" spans=\"1:1\">"
"<c r=\"A1\">"
"<v>10</v>"
"</c>"
"</row>"
"<row r=\"2\" spans=\"1:1\">"
"<c r=\"A2\">"
"<v>20</v>"
"</c>"
"</row>"
"<row r=\"3\" spans=\"1:1\">"
"<c r=\"A3\">"
"<v>30</v>"
"</c>"
"</row>"
"<row r=\"4\" spans=\"1:1\">"
"<c r=\"A4\">"
"<v>40</v>"
"</c>"
"</row>"
"</sheetData>"
"<conditionalFormatting sqref=\"A1:A4\">"
"<cfRule type=\"cellIs\" priority=\"1\" operator=\"between\">"
"<formula>20</formula>"
"<formula>30</formula>"
"</cfRule>"
"<cfRule type=\"cellIs\" priority=\"2\" operator=\"notBetween\">"
"<formula>20</formula>"
"<formula>30</formula>"
"</cfRule>"
"</conditionalFormatting>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"</worksheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile;
worksheet_select(worksheet);
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_BETWEEN;
conditional_format->min_value = 20;
conditional_format->max_value = 30;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_NOT_BETWEEN;
conditional_format->min_value = 20;
conditional_format->max_value = 30;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
free(conditional_format);
lxw_worksheet_assemble_xml_file(worksheet);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
}
// Test cell references.
CTEST(worksheet, worksheet_condtional_format03b) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<dimension ref=\"A1:A4\"/>"
"<sheetViews>"
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
"</sheetViews>"
"<sheetFormatPr defaultRowHeight=\"15\"/>"
"<sheetData>"
"<row r=\"1\" spans=\"1:1\">"
"<c r=\"A1\">"
"<v>10</v>"
"</c>"
"</row>"
"<row r=\"2\" spans=\"1:1\">"
"<c r=\"A2\">"
"<v>20</v>"
"</c>"
"</row>"
"<row r=\"3\" spans=\"1:1\">"
"<c r=\"A3\">"
"<v>30</v>"
"</c>"
"</row>"
"<row r=\"4\" spans=\"1:1\">"
"<c r=\"A4\">"
"<v>40</v>"
"</c>"
"</row>"
"</sheetData>"
"<conditionalFormatting sqref=\"A1:A4\">"
"<cfRule type=\"cellIs\" priority=\"1\" operator=\"between\">"
"<formula>$B$1</formula>"
"<formula>$B$2</formula>"
"</cfRule>"
"<cfRule type=\"cellIs\" priority=\"2\" operator=\"notBetween\">"
"<formula>$B$1</formula>"
"<formula>$B$2</formula>"
"</cfRule>"
"</conditionalFormatting>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"</worksheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile;
worksheet_select(worksheet);
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_BETWEEN;
conditional_format->min_value_string = "$B$1";
conditional_format->max_value_string = "$B$2";
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_CELL;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_NOT_BETWEEN;
conditional_format->min_value_string = "=$B$1";
conditional_format->max_value_string = "=$B$2";
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
free(conditional_format);
lxw_worksheet_assemble_xml_file(worksheet);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
}

View File

@@ -0,0 +1,84 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/shared_strings.h"
// Test assembling a complete Worksheet file.
CTEST(worksheet, worksheet_condtional_format04) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<dimension ref=\"A1:A4\"/>"
"<sheetViews>"
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
"</sheetViews>"
"<sheetFormatPr defaultRowHeight=\"15\"/>"
"<sheetData>"
"<row r=\"1\" spans=\"1:1\">"
"<c r=\"A1\">"
"<v>10</v>"
"</c>"
"</row>"
"<row r=\"2\" spans=\"1:1\">"
"<c r=\"A2\">"
"<v>20</v>"
"</c>"
"</row>"
"<row r=\"3\" spans=\"1:1\">"
"<c r=\"A3\">"
"<v>30</v>"
"</c>"
"</row>"
"<row r=\"4\" spans=\"1:1\">"
"<c r=\"A4\">"
"<v>40</v>"
"</c>"
"</row>"
"</sheetData>"
"<conditionalFormatting sqref=\"A1:A4\">"
"<cfRule type=\"duplicateValues\" priority=\"1\"/>"
"<cfRule type=\"uniqueValues\" priority=\"2\"/>"
"</conditionalFormatting>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"</worksheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile;
worksheet_select(worksheet);
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
conditional_format->type = LXW_CONDITIONAL_TYPE_DUPLICATE;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_UNIQUE;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
free(conditional_format);
lxw_worksheet_assemble_xml_file(worksheet);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
}

View File

@@ -0,0 +1,123 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/shared_strings.h"
// Test assembling a complete Worksheet file.
CTEST(worksheet, worksheet_condtional_format05) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<dimension ref=\"A1:A4\"/>"
"<sheetViews>"
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
"</sheetViews>"
"<sheetFormatPr defaultRowHeight=\"15\"/>"
"<sheetData>"
"<row r=\"1\" spans=\"1:1\">"
"<c r=\"A1\">"
"<v>10</v>"
"</c>"
"</row>"
"<row r=\"2\" spans=\"1:1\">"
"<c r=\"A2\">"
"<v>20</v>"
"</c>"
"</row>"
"<row r=\"3\" spans=\"1:1\">"
"<c r=\"A3\">"
"<v>30</v>"
"</c>"
"</row>"
"<row r=\"4\" spans=\"1:1\">"
"<c r=\"A4\">"
"<v>40</v>"
"</c>"
"</row>"
"</sheetData>"
"<conditionalFormatting sqref=\"A1:A4\">"
"<cfRule type=\"aboveAverage\" priority=\"1\"/>"
"<cfRule type=\"aboveAverage\" priority=\"2\" aboveAverage=\"0\"/>"
"<cfRule type=\"aboveAverage\" priority=\"3\" equalAverage=\"1\"/>"
"<cfRule type=\"aboveAverage\" priority=\"4\" aboveAverage=\"0\" equalAverage=\"1\"/>"
"<cfRule type=\"aboveAverage\" priority=\"5\" stdDev=\"1\"/>"
"<cfRule type=\"aboveAverage\" priority=\"6\" aboveAverage=\"0\" stdDev=\"1\"/>"
"<cfRule type=\"aboveAverage\" priority=\"7\" stdDev=\"2\"/>"
"<cfRule type=\"aboveAverage\" priority=\"8\" aboveAverage=\"0\" stdDev=\"2\"/>"
"<cfRule type=\"aboveAverage\" priority=\"9\" stdDev=\"3\"/>"
"<cfRule type=\"aboveAverage\" priority=\"10\" aboveAverage=\"0\" stdDev=\"3\"/>"
"</conditionalFormatting>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"</worksheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile;
worksheet_select(worksheet);
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_ABOVE;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_BELOW;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_ABOVE_OR_EQUAL;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_BELOW_OR_EQUAL;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_1_STD_DEV_ABOVE;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_1_STD_DEV_BELOW;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_2_STD_DEV_ABOVE;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_2_STD_DEV_BELOW;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_3_STD_DEV_ABOVE;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_AVERAGE;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_AVERAGE_3_STD_DEV_BELOW;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
free(conditional_format);
lxw_worksheet_assemble_xml_file(worksheet);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
}

View File

@@ -0,0 +1,181 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/shared_strings.h"
// Test assembling a complete Worksheet file.
CTEST(worksheet, worksheet_condtional_format06) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<dimension ref=\"A1:A4\"/>"
"<sheetViews>"
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
"</sheetViews>"
"<sheetFormatPr defaultRowHeight=\"15\"/>"
"<sheetData>"
"<row r=\"1\" spans=\"1:1\">"
"<c r=\"A1\">"
"<v>10</v>"
"</c>"
"</row>"
"<row r=\"2\" spans=\"1:1\">"
"<c r=\"A2\">"
"<v>20</v>"
"</c>"
"</row>"
"<row r=\"3\" spans=\"1:1\">"
"<c r=\"A3\">"
"<v>30</v>"
"</c>"
"</row>"
"<row r=\"4\" spans=\"1:1\">"
"<c r=\"A4\">"
"<v>40</v>"
"</c>"
"</row>"
"</sheetData>"
"<conditionalFormatting sqref=\"A1:A4\">"
"<cfRule type=\"top10\" priority=\"1\" rank=\"10\"/>"
"<cfRule type=\"top10\" priority=\"2\" bottom=\"1\" rank=\"10\"/>"
"<cfRule type=\"top10\" priority=\"3\" percent=\"1\" rank=\"10\"/>"
"<cfRule type=\"top10\" priority=\"4\" percent=\"1\" bottom=\"1\" rank=\"10\"/>"
"</conditionalFormatting>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"</worksheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile;
worksheet_select(worksheet);
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
conditional_format->type = LXW_CONDITIONAL_TYPE_TOP;
conditional_format->value = 10;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_BOTTOM;
conditional_format->value = 10;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_TOP;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TOP_OR_BOTTOM_PERCENT;
conditional_format->value = 10;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_BOTTOM;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TOP_OR_BOTTOM_PERCENT;
conditional_format->value = 10;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
free(conditional_format);
lxw_worksheet_assemble_xml_file(worksheet);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
}
// Test int truncation.
CTEST(worksheet, worksheet_condtional_format06b) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<dimension ref=\"A1:A4\"/>"
"<sheetViews>"
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
"</sheetViews>"
"<sheetFormatPr defaultRowHeight=\"15\"/>"
"<sheetData>"
"<row r=\"1\" spans=\"1:1\">"
"<c r=\"A1\">"
"<v>10</v>"
"</c>"
"</row>"
"<row r=\"2\" spans=\"1:1\">"
"<c r=\"A2\">"
"<v>20</v>"
"</c>"
"</row>"
"<row r=\"3\" spans=\"1:1\">"
"<c r=\"A3\">"
"<v>30</v>"
"</c>"
"</row>"
"<row r=\"4\" spans=\"1:1\">"
"<c r=\"A4\">"
"<v>40</v>"
"</c>"
"</row>"
"</sheetData>"
"<conditionalFormatting sqref=\"A1:A4\">"
"<cfRule type=\"top10\" priority=\"1\" rank=\"10\"/>"
"<cfRule type=\"top10\" priority=\"2\" bottom=\"1\" rank=\"10\"/>"
"<cfRule type=\"top10\" priority=\"3\" percent=\"1\" rank=\"10\"/>"
"<cfRule type=\"top10\" priority=\"4\" percent=\"1\" bottom=\"1\" rank=\"10\"/>"
"</conditionalFormatting>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"</worksheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile;
worksheet_select(worksheet);
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
conditional_format->type = LXW_CONDITIONAL_TYPE_TOP;
conditional_format->value = 10.1;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_BOTTOM;
conditional_format->value = 10.2;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_TOP;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TOP_OR_BOTTOM_PERCENT;
conditional_format->value = 10.3;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_BOTTOM;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TOP_OR_BOTTOM_PERCENT;
conditional_format->value = 10.4;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
free(conditional_format);
lxw_worksheet_assemble_xml_file(worksheet);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
}

View File

@@ -0,0 +1,105 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/shared_strings.h"
// Test assembling a complete Worksheet file.
CTEST(worksheet, worksheet_condtional_format07) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<dimension ref=\"A1:A4\"/>"
"<sheetViews>"
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
"</sheetViews>"
"<sheetFormatPr defaultRowHeight=\"15\"/>"
"<sheetData>"
"<row r=\"1\" spans=\"1:1\">"
"<c r=\"A1\">"
"<v>10</v>"
"</c>"
"</row>"
"<row r=\"2\" spans=\"1:1\">"
"<c r=\"A2\">"
"<v>20</v>"
"</c>"
"</row>"
"<row r=\"3\" spans=\"1:1\">"
"<c r=\"A3\">"
"<v>30</v>"
"</c>"
"</row>"
"<row r=\"4\" spans=\"1:1\">"
"<c r=\"A4\">"
"<v>40</v>"
"</c>"
"</row>"
"</sheetData>"
"<conditionalFormatting sqref=\"A1:A4\">"
"<cfRule type=\"containsText\" priority=\"1\" operator=\"containsText\" text=\"foo\">"
"<formula>NOT(ISERROR(SEARCH(\"foo\",A1)))</formula>"
"</cfRule>"
"<cfRule type=\"notContainsText\" priority=\"2\" operator=\"notContains\" text=\"foo\">"
"<formula>ISERROR(SEARCH(\"foo\",A1))</formula>"
"</cfRule>"
"<cfRule type=\"beginsWith\" priority=\"3\" operator=\"beginsWith\" text=\"b\">"
"<formula>LEFT(A1,1)=\"b\"</formula>"
"</cfRule>"
"<cfRule type=\"endsWith\" priority=\"4\" operator=\"endsWith\" text=\"b\">"
"<formula>RIGHT(A1,1)=\"b\"</formula>"
"</cfRule>"
"</conditionalFormatting>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"</worksheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile;
worksheet_select(worksheet);
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
conditional_format->type = LXW_CONDITIONAL_TYPE_TEXT;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TEXT_CONTAINING;
conditional_format->value_string = "foo";
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_TEXT;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TEXT_NOT_CONTAINING;
conditional_format->value_string = "foo";
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_TEXT;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TEXT_BEGINS_WITH;
conditional_format->value_string = "b";
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_TEXT;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TEXT_ENDS_WITH;
conditional_format->value_string = "b";
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
free(conditional_format);
lxw_worksheet_assemble_xml_file(worksheet);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
}

View File

@@ -0,0 +1,144 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/shared_strings.h"
// Test assembling a complete Worksheet file.
CTEST(worksheet, worksheet_condtional_format08) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<dimension ref=\"A1:A4\"/>"
"<sheetViews>"
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
"</sheetViews>"
"<sheetFormatPr defaultRowHeight=\"15\"/>"
"<sheetData>"
"<row r=\"1\" spans=\"1:1\">"
"<c r=\"A1\">"
"<v>10</v>"
"</c>"
"</row>"
"<row r=\"2\" spans=\"1:1\">"
"<c r=\"A2\">"
"<v>20</v>"
"</c>"
"</row>"
"<row r=\"3\" spans=\"1:1\">"
"<c r=\"A3\">"
"<v>30</v>"
"</c>"
"</row>"
"<row r=\"4\" spans=\"1:1\">"
"<c r=\"A4\">"
"<v>40</v>"
"</c>"
"</row>"
"</sheetData>"
"<conditionalFormatting sqref=\"A1:A4\">"
"<cfRule type=\"timePeriod\" priority=\"1\" timePeriod=\"yesterday\">"
"<formula>FLOOR(A1,1)=TODAY()-1</formula>"
"</cfRule>"
"<cfRule type=\"timePeriod\" priority=\"2\" timePeriod=\"today\">"
"<formula>FLOOR(A1,1)=TODAY()</formula>"
"</cfRule>"
"<cfRule type=\"timePeriod\" priority=\"3\" timePeriod=\"tomorrow\">"
"<formula>FLOOR(A1,1)=TODAY()+1</formula>"
"</cfRule>"
"<cfRule type=\"timePeriod\" priority=\"4\" timePeriod=\"last7Days\">"
"<formula>AND(TODAY()-FLOOR(A1,1)&lt;=6,FLOOR(A1,1)&lt;=TODAY())</formula>"
"</cfRule>"
"<cfRule type=\"timePeriod\" priority=\"5\" timePeriod=\"lastWeek\">"
"<formula>AND(TODAY()-ROUNDDOWN(A1,0)&gt;=(WEEKDAY(TODAY())),TODAY()-ROUNDDOWN(A1,0)&lt;(WEEKDAY(TODAY())+7))</formula>"
"</cfRule>"
"<cfRule type=\"timePeriod\" priority=\"6\" timePeriod=\"thisWeek\">"
"<formula>AND(TODAY()-ROUNDDOWN(A1,0)&lt;=WEEKDAY(TODAY())-1,ROUNDDOWN(A1,0)-TODAY()&lt;=7-WEEKDAY(TODAY()))</formula>"
"</cfRule>"
"<cfRule type=\"timePeriod\" priority=\"7\" timePeriod=\"nextWeek\">"
"<formula>AND(ROUNDDOWN(A1,0)-TODAY()&gt;(7-WEEKDAY(TODAY())),ROUNDDOWN(A1,0)-TODAY()&lt;(15-WEEKDAY(TODAY())))</formula>"
"</cfRule>"
"<cfRule type=\"timePeriod\" priority=\"8\" timePeriod=\"lastMonth\">"
"<formula>AND(MONTH(A1)=MONTH(TODAY())-1,OR(YEAR(A1)=YEAR(TODAY()),AND(MONTH(A1)=1,YEAR(A1)=YEAR(TODAY())-1)))</formula>"
"</cfRule>"
"<cfRule type=\"timePeriod\" priority=\"9\" timePeriod=\"thisMonth\">"
"<formula>AND(MONTH(A1)=MONTH(TODAY()),YEAR(A1)=YEAR(TODAY()))</formula>"
"</cfRule>"
"<cfRule type=\"timePeriod\" priority=\"10\" timePeriod=\"nextMonth\">"
"<formula>AND(MONTH(A1)=MONTH(TODAY())+1,OR(YEAR(A1)=YEAR(TODAY()),AND(MONTH(A1)=12,YEAR(A1)=YEAR(TODAY())+1)))</formula>"
"</cfRule>"
"</conditionalFormatting>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"</worksheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile;
worksheet_select(worksheet);
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_YESTERDAY;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_TODAY;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_TOMORROW;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_LAST_7_DAYS;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_LAST_WEEK;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_THIS_WEEK;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_NEXT_WEEK;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_LAST_MONTH;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_THIS_MONTH;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_TIME_PERIOD;
conditional_format->criteria = LXW_CONDITIONAL_CRITERIA_TIME_PERIOD_NEXT_MONTH;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
free(conditional_format);
lxw_worksheet_assemble_xml_file(worksheet);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
}

View File

@@ -0,0 +1,97 @@
/*
* Tests for the libxlsxwriter library.
*
* Copyright 2014-2021, John McNamara, jmcnamara@cpan.org
*
*/
#include "../ctest.h"
#include "../helper.h"
#include "../../../include/xlsxwriter/worksheet.h"
#include "../../../include/xlsxwriter/shared_strings.h"
// Test assembling a complete Worksheet file.
CTEST(worksheet, worksheet_condtional_format09) {
char* got;
char exp[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
"<dimension ref=\"A1:A4\"/>"
"<sheetViews>"
"<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>"
"</sheetViews>"
"<sheetFormatPr defaultRowHeight=\"15\"/>"
"<sheetData>"
"<row r=\"1\" spans=\"1:1\">"
"<c r=\"A1\">"
"<v>10</v>"
"</c>"
"</row>"
"<row r=\"2\" spans=\"1:1\">"
"<c r=\"A2\">"
"<v>20</v>"
"</c>"
"</row>"
"<row r=\"3\" spans=\"1:1\">"
"<c r=\"A3\">"
"<v>30</v>"
"</c>"
"</row>"
"<row r=\"4\" spans=\"1:1\">"
"<c r=\"A4\">"
"<v>40</v>"
"</c>"
"</row>"
"</sheetData>"
"<conditionalFormatting sqref=\"A1:A4\">"
"<cfRule type=\"containsBlanks\" priority=\"1\">"
"<formula>LEN(TRIM(A1))=0</formula>"
"</cfRule>"
"<cfRule type=\"notContainsBlanks\" priority=\"2\">"
"<formula>LEN(TRIM(A1))&gt;0</formula>"
"</cfRule>"
"<cfRule type=\"containsErrors\" priority=\"3\">"
"<formula>ISERROR(A1)</formula>"
"</cfRule>"
"<cfRule type=\"notContainsErrors\" priority=\"4\">"
"<formula>NOT(ISERROR(A1))</formula>"
"</cfRule>"
"</conditionalFormatting>"
"<pageMargins left=\"0.7\" right=\"0.7\" top=\"0.75\" bottom=\"0.75\" header=\"0.3\" footer=\"0.3\"/>"
"</worksheet>";
FILE* testfile = lxw_tmpfile(NULL);
lxw_worksheet *worksheet = lxw_worksheet_new(NULL);
worksheet->file = testfile;
worksheet_select(worksheet);
worksheet_write_number(worksheet, CELL("A1"), 10, NULL);
worksheet_write_number(worksheet, CELL("A2"), 20, NULL);
worksheet_write_number(worksheet, CELL("A3"), 30, NULL);
worksheet_write_number(worksheet, CELL("A4"), 40, NULL);
lxw_conditional_format *conditional_format = calloc(1, sizeof(lxw_conditional_format));
conditional_format->type = LXW_CONDITIONAL_TYPE_BLANKS;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_NO_BLANKS;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_ERRORS;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
conditional_format->type = LXW_CONDITIONAL_TYPE_NO_ERRORS;
worksheet_conditional_format_range(worksheet, RANGE("A1:A4"), conditional_format);
free(conditional_format);
lxw_worksheet_assemble_xml_file(worksheet);
RUN_XLSX_STREQ_SHORT(exp, got);
lxw_worksheet_free(worksheet);
}

Some files were not shown because too many files have changed in this diff Show More