|
ferencd@0
|
1 //
|
|
ferencd@0
|
2 // VMime library (http://www.vmime.org)
|
|
ferencd@0
|
3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
|
|
ferencd@0
|
4 //
|
|
ferencd@0
|
5 // This program is free software; you can redistribute it and/or
|
|
ferencd@0
|
6 // modify it under the terms of the GNU General Public License as
|
|
ferencd@0
|
7 // published by the Free Software Foundation; either version 3 of
|
|
ferencd@0
|
8 // the License, or (at your option) any later version.
|
|
ferencd@0
|
9 //
|
|
ferencd@0
|
10 // This program is distributed in the hope that it will be useful,
|
|
ferencd@0
|
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
ferencd@0
|
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
ferencd@0
|
13 // General Public License for more details.
|
|
ferencd@0
|
14 //
|
|
ferencd@0
|
15 // You should have received a copy of the GNU General Public License along
|
|
ferencd@0
|
16 // with this program; if not, write to the Free Software Foundation, Inc.,
|
|
ferencd@0
|
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
ferencd@0
|
18 //
|
|
ferencd@0
|
19 // Linking this library statically or dynamically with other modules is making
|
|
ferencd@0
|
20 // a combined work based on this library. Thus, the terms and conditions of
|
|
ferencd@0
|
21 // the GNU General Public License cover the whole combination.
|
|
ferencd@0
|
22 //
|
|
ferencd@0
|
23
|
|
ferencd@0
|
24 #include "tests/testUtils.hpp"
|
|
ferencd@0
|
25
|
|
ferencd@0
|
26
|
|
ferencd@0
|
27 VMIME_TEST_SUITE_BEGIN(datetimeTest)
|
|
ferencd@0
|
28
|
|
ferencd@0
|
29 VMIME_TEST_LIST_BEGIN
|
|
ferencd@0
|
30 VMIME_TEST(testParse)
|
|
ferencd@0
|
31 VMIME_TEST(testGenerate)
|
|
ferencd@0
|
32 VMIME_TEST(testCompare)
|
|
ferencd@0
|
33 VMIME_TEST_LIST_END
|
|
ferencd@0
|
34
|
|
ferencd@0
|
35
|
|
ferencd@0
|
36 void testParse()
|
|
ferencd@0
|
37 {
|
|
ferencd@0
|
38 struct datetimePair
|
|
ferencd@0
|
39 {
|
|
ferencd@0
|
40 vmime::string parseBuffer;
|
|
ferencd@0
|
41 vmime::datetime result;
|
|
ferencd@0
|
42 };
|
|
ferencd@0
|
43
|
|
ferencd@0
|
44 // Here, we can't test all the possible structures for date/time,
|
|
ferencd@0
|
45 // so we test some cases. Don't forget to add a new test case
|
|
ferencd@0
|
46 // each time you encounter a bug in date/time parsing (after
|
|
ferencd@0
|
47 // you have fixed it).
|
|
ferencd@0
|
48 datetimePair pairs[] =
|
|
ferencd@0
|
49 {
|
|
ferencd@0
|
50 { /* 1 */ "Mon, 8 Nov 2004 13:42:56 +0000 (GMT)",
|
|
ferencd@0
|
51 vmime::datetime(2004, 11, 8, 13, 42, 56, vmime::datetime::GMT) },
|
|
ferencd@0
|
52
|
|
ferencd@0
|
53 { /* 2 */ "Sun, 7 Nov 2004 00:43:22 -0500 (EST)",
|
|
ferencd@0
|
54 vmime::datetime(2004, 11, 7, 0, 43, 22, vmime::datetime::GMT_5) },
|
|
ferencd@0
|
55
|
|
ferencd@0
|
56 { /* 3 */ "Thu Nov 18 12:11:16 2004",
|
|
ferencd@0
|
57 vmime::datetime(vmime::datetime::now().getYear(), 11, 18, 12, 11, 16, vmime::datetime::GMT) },
|
|
ferencd@0
|
58
|
|
ferencd@0
|
59 { /* 4 */ "Sat, 18, 2004 22:36:32 -0400",
|
|
ferencd@0
|
60 vmime::datetime(2004, 1, 18, 22, 36, 32, vmime::datetime::GMT_4) },
|
|
ferencd@0
|
61
|
|
ferencd@0
|
62 { /* 5 */ "Mon Dec 13 21:57:18 2004",
|
|
ferencd@0
|
63 vmime::datetime(vmime::datetime::now().getYear(), 12, 13, 21, 57, 18, vmime::datetime::GMT) },
|
|
ferencd@0
|
64
|
|
ferencd@0
|
65 { /* 6 */ "18 Nov 2004 21:44:54 +0300",
|
|
ferencd@0
|
66 vmime::datetime(2004, 11, 18, 21, 44, 54, vmime::datetime::GMT3) }
|
|
ferencd@0
|
67 };
|
|
ferencd@0
|
68
|
|
ferencd@0
|
69 for (unsigned int i = 0 ; i < sizeof(pairs) / sizeof(pairs[0]) ; ++i)
|
|
ferencd@0
|
70 {
|
|
ferencd@0
|
71 vmime::datetime d;
|
|
ferencd@0
|
72 d.parse(pairs[i].parseBuffer);
|
|
ferencd@0
|
73
|
|
ferencd@0
|
74 std::ostringstream oss;
|
|
ferencd@0
|
75 oss << (i + 1);
|
|
ferencd@0
|
76
|
|
ferencd@0
|
77 VASSERT_EQ(oss.str(), pairs[i].result, d);
|
|
ferencd@0
|
78 }
|
|
ferencd@0
|
79 }
|
|
ferencd@0
|
80
|
|
ferencd@0
|
81 void testGenerate()
|
|
ferencd@0
|
82 {
|
|
ferencd@0
|
83 vmime::datetime d1(2005, 7, 8, 4, 5, 6, 1 * 60 + 23);
|
|
ferencd@0
|
84
|
|
ferencd@0
|
85 VASSERT_EQ("1", "Fri, 8 Jul 2005 04:05:06 +0123", d1.generate());
|
|
ferencd@0
|
86 }
|
|
ferencd@0
|
87
|
|
ferencd@0
|
88 void testCompare()
|
|
ferencd@0
|
89 {
|
|
ferencd@0
|
90 // Date1 = Date2
|
|
ferencd@0
|
91 vmime::datetime d1(2005, 4, 22, 14, 6, 0, vmime::datetime::GMT2);
|
|
ferencd@0
|
92 vmime::datetime d2(2005, 4, 22, 10, 6, 0, vmime::datetime::GMT_2);
|
|
ferencd@0
|
93
|
|
ferencd@0
|
94 VASSERT_EQ("1.1", true, d1 == d2);
|
|
ferencd@0
|
95 VASSERT_EQ("1.2", false, d1 != d2);
|
|
ferencd@0
|
96 VASSERT_EQ("1.3", true, d1 <= d2);
|
|
ferencd@0
|
97 VASSERT_EQ("1.4", false, d1 < d2);
|
|
ferencd@0
|
98 VASSERT_EQ("1.5", true, d1 >= d2);
|
|
ferencd@0
|
99 VASSERT_EQ("1.6", false, d1 > d2);
|
|
ferencd@0
|
100
|
|
ferencd@0
|
101 // Date1 < Date2
|
|
ferencd@0
|
102 vmime::datetime d3(2005, 4, 22, 14, 6, 0);
|
|
ferencd@0
|
103 vmime::datetime d4(2005, 4, 22, 15, 6, 0);
|
|
ferencd@0
|
104
|
|
ferencd@0
|
105 VASSERT_EQ("2.1", false, d3 == d4);
|
|
ferencd@0
|
106 VASSERT_EQ("2.2", true, d3 != d4);
|
|
ferencd@0
|
107 VASSERT_EQ("2.3", true, d3 <= d4);
|
|
ferencd@0
|
108 VASSERT_EQ("2.4", true, d3 < d4);
|
|
ferencd@0
|
109 VASSERT_EQ("2.5", false, d3 >= d4);
|
|
ferencd@0
|
110 VASSERT_EQ("2.6", false, d3 > d4);
|
|
ferencd@0
|
111
|
|
ferencd@0
|
112 // Date1 > Date2
|
|
ferencd@0
|
113 vmime::datetime d5(2005, 4, 22, 15, 6, 0);
|
|
ferencd@0
|
114 vmime::datetime d6(2005, 4, 22, 14, 6, 0);
|
|
ferencd@0
|
115
|
|
ferencd@0
|
116 VASSERT_EQ("3.1", false, d5 == d6);
|
|
ferencd@0
|
117 VASSERT_EQ("3.2", true, d5 != d6);
|
|
ferencd@0
|
118 VASSERT_EQ("3.3", false, d5 <= d6);
|
|
ferencd@0
|
119 VASSERT_EQ("3.4", false, d5 < d6);
|
|
ferencd@0
|
120 VASSERT_EQ("3.5", true, d5 >= d6);
|
|
ferencd@0
|
121 VASSERT_EQ("3.6", true, d5 > d6);
|
|
ferencd@0
|
122 }
|
|
ferencd@0
|
123
|
|
ferencd@0
|
124 VMIME_TEST_SUITE_END
|
|
ferencd@0
|
125
|