/* 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);
}
/* 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(NULL == got);

    lxw_workbook_free(workbook);
}
/* 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(exp == got);

    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(NULL == got);

    lxw_workbook_free(workbook);
}
// 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);
}
// 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);
}
// 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);
}
Example #8
0
/* 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);
}
/* 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);
}