// Test assembling a Worksheet file with different span ranges. CTEST(worksheet, spans03) { 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=\"XFD1\"/>" "<sheetViews>" "<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>" "</sheetViews>" "<sheetFormatPr defaultRowHeight=\"15\"/>" "<sheetData>" "<row r=\"1\" spans=\"16384:16384\">" "<c r=\"XFD1\">" "<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 = tmpfile(); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; worksheet_select(worksheet); worksheet_write_number(worksheet, 0, 16383, 123, NULL); lxw_worksheet_assemble_xml_file(worksheet); RUN_XLSX_STREQ_SHORT(exp, got); lxw_worksheet_free(worksheet); }
/* Test the _write_page_setup() method. Without any page setup. */ CTEST(worksheet, write_page_setup01) { char* got; char exp[] = ""; FILE* testfile = tmpfile(); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; _worksheet_write_page_setup(worksheet); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }
/* Test the _write_page_setup() method. With set_paper(); */ CTEST(worksheet, write_page_setup04) { char* got; char exp[] = "<pageSetup paperSize=\"9\" orientation=\"portrait\"/>"; FILE* testfile = tmpfile(); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; worksheet_set_paper(worksheet, 9); _worksheet_write_page_setup(worksheet); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }
/* Test the _write_page_setup() method. With set_landscape(); */ CTEST(worksheet, write_page_setup02) { char* got; char exp[] = "<pageSetup orientation=\"landscape\"/>"; FILE* testfile = tmpfile(); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; worksheet_set_landscape(worksheet); _worksheet_write_page_setup(worksheet); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }
// Test the _write_sheet_format_pr() function. CTEST(worksheet, write_sheet_format_pr) { char* got; char exp[] = "<sheetFormatPr defaultRowHeight=\"15\"/>"; FILE* testfile = lxw_tmpfile(NULL); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; _worksheet_write_sheet_format_pr(worksheet); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }
/* 1. Test the _write_sheet_pr() method. */ CTEST(worksheet, write_write_sheet_pr01) { char* got; char exp[] = "<sheetPr><pageSetUpPr fitToPage=\"1\"/></sheetPr>"; FILE* testfile = lxw_tmpfile(NULL); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; worksheet->fit_page = 1; _worksheet_write_sheet_pr(worksheet); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }
/* 2. Test the _write_sheet_pr() method. */ CTEST(worksheet, write_write_sheet_pr02) { char* got; char exp[] = "<sheetPr><tabColor rgb=\"FFFF0000\"/></sheetPr>"; FILE* testfile = lxw_tmpfile(NULL); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; worksheet_set_tab_color(worksheet, LXW_COLOR_RED); _worksheet_write_sheet_pr(worksheet); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }
/* Test the _write_page_setup() method. With print_across(); */ CTEST(worksheet, write_page_setup05) { char* got; char exp[] = "<pageSetup pageOrder=\"overThenDown\" orientation=\"portrait\"/>"; FILE* testfile = tmpfile(); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; worksheet_print_across(worksheet); _worksheet_write_page_setup(worksheet); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }
// Test the _write_sheet_data() function. CTEST(worksheet, write_sheet_data) { char* got; char exp[] = "<sheetData/>"; FILE* testfile = lxw_tmpfile(NULL); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; _worksheet_write_sheet_data(worksheet); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }
/* 5. Test the _write_sheet_views() method with selection set. */ CTEST(worksheet, set_selection05) { char* got; char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><selection activeCell=\"D3\" sqref=\"D3:F4\"/></sheetView></sheetViews>"; FILE* testfile = tmpfile(); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; worksheet_select(worksheet); worksheet_set_selection(worksheet, RANGE("D3:F4")); _worksheet_write_sheet_views(worksheet); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }
/* 1. Test the _write_sheet_views() method with selection set. */ CTEST(worksheet, set_selection01) { char* got; char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"/></sheetViews>"; FILE* testfile = tmpfile(); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; worksheet_select(worksheet); worksheet_set_selection(worksheet, 0, 0, 0, 0); _worksheet_write_sheet_views(worksheet); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }
// Test the _write_row() function. CTEST(worksheet, write_row) { char* got; char exp[] = "<row r=\"1\"/>"; FILE* testfile = lxw_tmpfile(NULL); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; lxw_row *row = _get_row_list(worksheet->table, 0); _write_row(worksheet, row, NULL); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }
/* 2. Test the _write_sheet_views() method with split panes + selection. */ CTEST(worksheet, set_selection32) { char* got; char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"1350\" topLeftCell=\"B1\" activePane=\"topRight\"/><selection pane=\"topRight\" activeCell=\"B1\" sqref=\"B1\"/></sheetView></sheetViews>"; FILE* testfile = lxw_tmpfile(NULL); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; worksheet_select(worksheet); worksheet_set_selection(worksheet, RANGE("B1:B1")); worksheet_split_panes(worksheet, 0, 8.43); _worksheet_write_sheet_views(worksheet); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }
/* 4. Test the _write_sheet_views() method with freeze panes. */ CTEST(worksheet, set_selection24) { char* got; char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"1\" topLeftCell=\"E1\" activePane=\"topRight\" state=\"frozen\"/><selection pane=\"topRight\"/></sheetView></sheetViews>"; FILE* testfile = tmpfile(); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; worksheet_select(worksheet); worksheet_set_selection(worksheet, RANGE("A1:A1")); worksheet_freeze_panes_opt(worksheet, 0, 1, 0, 4, 0); _worksheet_write_sheet_views(worksheet); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }
/* 4. Test the _write_sheet_views() method with split panes + selection. */ CTEST(worksheet, set_selection34) { char* got; char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"6150\" ySplit=\"1200\" topLeftCell=\"G4\" activePane=\"bottomRight\"/><selection pane=\"topRight\" activeCell=\"G1\" sqref=\"G1\"/><selection pane=\"bottomLeft\" activeCell=\"A4\" sqref=\"A4\"/><selection pane=\"bottomRight\" activeCell=\"I5\" sqref=\"I5\"/></sheetView></sheetViews>"; FILE* testfile = lxw_tmpfile(NULL); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; worksheet_select(worksheet); worksheet_set_selection(worksheet, RANGE("I5:I5")); worksheet_split_panes(worksheet, 45, 54.14); _worksheet_write_sheet_views(worksheet); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }
/* 5. Test the _write_sheet_views() method with freeze panes. */ CTEST(worksheet, set_selection25) { char* got; char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane xSplit=\"6\" ySplit=\"3\" topLeftCell=\"I7\" activePane=\"bottomRight\" state=\"frozen\"/><selection pane=\"topRight\" activeCell=\"G1\" sqref=\"G1\"/><selection pane=\"bottomLeft\" activeCell=\"A4\" sqref=\"A4\"/><selection pane=\"bottomRight\" activeCell=\"G4\" sqref=\"G4\"/></sheetView></sheetViews>"; FILE* testfile = tmpfile(); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; worksheet_select(worksheet); worksheet_set_selection(worksheet, RANGE("G4:G4")); worksheet_freeze_panes_opt(worksheet, 3, 6, 6, 8, 0); _worksheet_write_sheet_views(worksheet); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }
/* 1. Test the _write_sheet_views() method with split panes + selection. */ CTEST(worksheet, set_selection31) { char* got; char exp[] = "<sheetViews><sheetView tabSelected=\"1\" workbookViewId=\"0\"><pane ySplit=\"600\" topLeftCell=\"A2\" activePane=\"bottomLeft\"/><selection pane=\"bottomLeft\" activeCell=\"A2\" sqref=\"A2\"/></sheetView></sheetViews>"; FILE* testfile = lxw_tmpfile(NULL); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; worksheet_select(worksheet); worksheet_set_selection(worksheet, RANGE("A2:A2")); worksheet_split_panes(worksheet, 15, 0); _worksheet_write_sheet_views(worksheet); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }
// Test some out of bound writes. CTEST(worksheet, spans06) { int err; FILE* testfile = tmpfile(); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; worksheet_select(worksheet); err = worksheet_write_number(worksheet, 0, 16384, 123, NULL); ASSERT_EQUAL(-LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err); err = worksheet_write_number(worksheet, 1048576, 0, 123, NULL); ASSERT_EQUAL(-LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err); err = worksheet_write_number(worksheet, 1048576, 16384, 123, NULL); ASSERT_EQUAL(-LXW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE, err); lxw_worksheet_assemble_xml_file(worksheet); lxw_worksheet_free(worksheet); }
// Test assembling a Worksheet file with different span ranges. CTEST(worksheet, spans05) { int i; 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:T20\"/>" "<sheetViews>" "<sheetView tabSelected=\"1\" workbookViewId=\"0\"/>" "</sheetViews>" "<sheetFormatPr defaultRowHeight=\"15\"/>" "<sheetData>" "<row r=\"1\" spans=\"1:16\">" "<c r=\"A1\">" "<v>1</v>" "</c>" "</row>" "<row r=\"2\" spans=\"1:16\">" "<c r=\"B2\">" "<v>2</v>" "</c>" "</row>" "<row r=\"3\" spans=\"1:16\">" "<c r=\"C3\">" "<v>3</v>" "</c>" "</row>" "<row r=\"4\" spans=\"1:16\">" "<c r=\"D4\">" "<v>4</v>" "</c>" "</row>" "<row r=\"5\" spans=\"1:16\">" "<c r=\"E5\">" "<v>5</v>" "</c>" "</row>" "<row r=\"6\" spans=\"1:16\">" "<c r=\"F6\">" "<v>6</v>" "</c>" "</row>" "<row r=\"7\" spans=\"1:16\">" "<c r=\"G7\">" "<v>7</v>" "</c>" "</row>" "<row r=\"8\" spans=\"1:16\">" "<c r=\"H8\">" "<v>8</v>" "</c>" "</row>" "<row r=\"9\" spans=\"1:16\">" "<c r=\"I9\">" "<v>9</v>" "</c>" "</row>" "<row r=\"10\" spans=\"1:16\">" "<c r=\"J10\">" "<v>10</v>" "</c>" "</row>" "<row r=\"11\" spans=\"1:16\">" "<c r=\"K11\">" "<v>11</v>" "</c>" "</row>" "<row r=\"12\" spans=\"1:16\">" "<c r=\"L12\">" "<v>12</v>" "</c>" "</row>" "<row r=\"13\" spans=\"1:16\">" "<c r=\"M13\">" "<v>13</v>" "</c>" "</row>" "<row r=\"14\" spans=\"1:16\">" "<c r=\"N14\">" "<v>14</v>" "</c>" "</row>" "<row r=\"15\" spans=\"1:16\">" "<c r=\"O15\">" "<v>15</v>" "</c>" "</row>" "<row r=\"16\" spans=\"1:16\">" "<c r=\"P16\">" "<v>16</v>" "</c>" "</row>" "<row r=\"17\" spans=\"17:20\">" "<c r=\"Q17\">" "<v>17</v>" "</c>" "</row>" "<row r=\"18\" spans=\"17:20\">" "<c r=\"R18\">" "<v>18</v>" "</c>" "</row>" "<row r=\"19\" spans=\"17:20\">" "<c r=\"S19\">" "<v>19</v>" "</c>" "</row>" "<row r=\"20\" spans=\"17:20\">" "<c r=\"T20\">" "<v>20</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 = tmpfile(); lxw_worksheet *worksheet = lxw_worksheet_new(NULL); worksheet->file = testfile; worksheet_select(worksheet); for (i = 0; i < 20; i++) worksheet_write_number(worksheet, i, i, i + 1, NULL); lxw_worksheet_assemble_xml_file(worksheet); RUN_XLSX_STREQ(exp, got); lxw_worksheet_free(worksheet); }