/* * Tests for the lib_xlsx_writer library. * * Copyright 2014, John McNamara, jmcnamara@cpan.org * */ #include #include "../helper.h" #include "xlsxwriter/core.h" #include "xlsxwriter/workbook.h" // Test assembling a complete core file. TEST(core, core01) { char* got; char exp[] = "\n" "" "A User" "A User" "2010-01-01T00:00:00Z" "2010-01-01T00:00:00Z" ""; FILE* testfile = tmpfile(); lxw_core *core = _new_core(); lxw_workbook *workbook = new_workbook(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 = mktime(&tmp_tm); core->properties->author = strdup("A User"); _core_assemble_xml_file(core); RUN_XLSX_STREQ_SHORT(exp, got); _free_workbook(workbook); _free_core(core); } // Test assembling a complete core file. TEST(core, core02) { char* got; char exp[] = "\n" "" "This is an example spreadsheet" "With document properties" "A Person" "Sample, Example, Properties" "Created with libxlsxwriter" "A Person" "2011-04-06T19:45:15Z" "2011-04-06T19:45:15Z" "Example spreadsheets" "Quo" ""; FILE* testfile = tmpfile(); lxw_core *core = _new_core(); lxw_workbook *workbook = new_workbook(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 = mktime(&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"); _core_assemble_xml_file(core); RUN_XLSX_STREQ_SHORT(exp, got); _free_workbook(workbook); _free_core(core); }