File: test_datetime_validate.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 (110 lines) | stat: -rw-r--r-- 2,570 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
/*
 * Tests for the libxlsxwriter library.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 * Copyright 2014-2026, John McNamara, jmcnamara@cpan.org.
 *
 */

#include "../ctest.h"
#include "../helper.h"

#include "../../../include/xlsxwriter/utility.h"

// Test valid datetime.
CTEST(utility, test_datetime_validate01) {

    lxw_datetime datetime = {2025, 10, 30, 21, 07, 0.0};

    lxw_error exp = LXW_NO_ERROR;
    lxw_error got = lxw_datetime_validate(&datetime);

    ASSERT_EQUAL(exp, got);
}

// Test valid datetime (time only).
CTEST(utility, test_datetime_validate02) {

    lxw_datetime datetime = {0, 0, 0, 21, 07, 0.0};

    lxw_error exp = LXW_NO_ERROR;
    lxw_error got = lxw_datetime_validate(&datetime);

    ASSERT_EQUAL(exp, got);
}

// Test valid datetime (1900 epoch).
CTEST(utility, test_datetime_validate03) {

    lxw_datetime datetime = {1899, 12, 31, 21, 07, 0.0};

    lxw_error exp = LXW_NO_ERROR;
    lxw_error got = lxw_datetime_validate(&datetime);

    ASSERT_EQUAL(exp, got);
}

// Test invalid year.
CTEST(utility, test_datetime_validate04) {

    lxw_datetime datetime = {1800, 10, 30, 21, 07, 0.0};

    lxw_error exp = LXW_ERROR_DATETIME_VALIDATION;
    lxw_error got = lxw_datetime_validate(&datetime);

    ASSERT_EQUAL(exp, got);
}

// Test invalid month.
CTEST(utility, test_datetime_validate05) {

    lxw_datetime datetime = {1900, 13, 30, 21, 07, 0.0};

    lxw_error exp = LXW_ERROR_DATETIME_VALIDATION;
    lxw_error got = lxw_datetime_validate(&datetime);

    ASSERT_EQUAL(exp, got);
}


// Test invalid day.
CTEST(utility, test_datetime_validate06) {

    lxw_datetime datetime = {1900, 10, 32, 21, 07, 0.0};

    lxw_error exp = LXW_ERROR_DATETIME_VALIDATION;
    lxw_error got = lxw_datetime_validate(&datetime);

    ASSERT_EQUAL(exp, got);
}

// Test invalid hour.
CTEST(utility, test_datetime_validate07) {

    lxw_datetime datetime = {1900, 1, 1, 24, 07, 0.0};

    lxw_error exp = LXW_ERROR_DATETIME_VALIDATION;
    lxw_error got = lxw_datetime_validate(&datetime);

    ASSERT_EQUAL(exp, got);
}

// Test invalid minute.
CTEST(utility, test_datetime_validate08) {
    lxw_datetime datetime = {1900, 1, 1, 21, 60, 0.0};

    lxw_error exp = LXW_ERROR_DATETIME_VALIDATION;
    lxw_error got = lxw_datetime_validate(&datetime);

    ASSERT_EQUAL(exp, got);
}

// Test invalid second.
CTEST(utility, test_datetime_validate09) {
    lxw_datetime datetime = {1900, 1, 1, 21, 07, 60.0};

    lxw_error exp = LXW_ERROR_DATETIME_VALIDATION;
    lxw_error got = lxw_datetime_validate(&datetime);

    ASSERT_EQUAL(exp, got);
}