File: test_core.c

package info (click to toggle)
libxlsxwriter 1.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,888 kB
  • sloc: ansic: 65,861; python: 2,106; makefile: 693; perl: 229; sh: 224; xml: 168; cpp: 73; javascript: 5
file content (115 lines) | stat: -rw-r--r-- 4,134 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * Tests for the lib_xlsx_writer library.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright 2014-2026, 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
#define strdup _strdup
#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);
}