aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/test/lldate_tut.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/test/lldate_tut.cpp206
1 files changed, 206 insertions, 0 deletions
diff --git a/linden/indra/test/lldate_tut.cpp b/linden/indra/test/lldate_tut.cpp
new file mode 100644
index 0000000..f8813e3
--- /dev/null
+++ b/linden/indra/test/lldate_tut.cpp
@@ -0,0 +1,206 @@
1/**
2 * @file lldate_tut.cpp
3 * @author Adroit
4 * @date 2007-02
5 * @brief LLDate test cases.
6 *
7 * Copyright (c) 2007-2007, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlife.com/developers/opensource/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlife.com/developers/opensource/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 */
30
31#include <tut/tut.h>
32#include "linden_common.h"
33#include "lldate.h"
34
35#define VALID_DATE "2003-04-30T04:00:00Z"
36#define VALID_DATE_LEAP "2004-02-29T04:00:00Z"
37#define VALID_DATE_HOUR_BOUNDARY "2003-04-30T23:59:59Z"
38
39// invalid format
40#define INVALID_DATE_MISSING_YEAR "-04-30T22:59:59Z"
41#define INVALID_DATE_MISSING_MONTH "1900-0430T22:59:59Z"
42#define INVALID_DATE_MISSING_DATE "1900-0430-T22:59:59Z"
43#define INVALID_DATE_MISSING_T "1900-04-30-22:59:59Z"
44#define INVALID_DATE_MISSING_HOUR "1900-04-30T:59:59Z"
45#define INVALID_DATE_MISSING_MIN "1900-04-30T01::59Z"
46#define INVALID_DATE_MISSING_SEC "1900-04-30T01:59Z"
47#define INVALID_DATE_MISSING_Z "1900-04-30T01:59:23"
48#define INVALID_DATE_EMPTY ""
49
50// invalid values
51// apr 1.1.1 seems to not care about constraining the date to valid
52// dates. Put these back when the parser checks.
53#define LL_DATE_PARSER_CHECKS_BOUNDARY 0
54//#define INVALID_DATE_24HOUR_BOUNDARY "2003-04-30T24:00:00Z"
55//#define INVALID_DATE_LEAP "2003-04-29T04:00:00Z"
56//#define INVALID_DATE_HOUR "2003-04-30T24:59:59Z"
57//#define INVALID_DATE_MIN "2003-04-30T22:69:59Z"
58//#define INVALID_DATE_SEC "2003-04-30T22:59:69Z"
59//#define INVALID_DATE_YEAR "0-04-30T22:59:59Z"
60//#define INVALID_DATE_MONTH "2003-13-30T22:59:59Z"
61//#define INVALID_DATE_DAY "2003-04-35T22:59:59Z"
62
63namespace tut
64{
65 struct date_test
66 {
67
68 };
69 typedef test_group<date_test> date_test_t;
70 typedef date_test_t::object date_test_object_t;
71 tut::date_test_t tut_date_test("date_test");
72
73 /* format validation */
74 template<> template<>
75 void date_test_object_t::test<1>()
76 {
77 LLDate date(VALID_DATE);
78 std::string expected_string;
79 bool result;
80 expected_string = VALID_DATE;
81 ensure_equals("Valid Date failed" , expected_string, date.asString());
82
83 result = date.fromString(VALID_DATE_LEAP);
84 expected_string = VALID_DATE_LEAP;
85 ensure_equals("VALID_DATE_LEAP failed" , expected_string, date.asString());
86
87 result = date.fromString(VALID_DATE_HOUR_BOUNDARY);
88 expected_string = VALID_DATE_HOUR_BOUNDARY;
89 ensure_equals("VALID_DATE_HOUR_BOUNDARY failed" , expected_string, date.asString());
90
91 result = date.fromString(INVALID_DATE_MISSING_YEAR);
92 ensure_equals("INVALID_DATE_MISSING_YEAR should have failed" , result, false);
93
94 result = date.fromString(INVALID_DATE_MISSING_MONTH);
95 ensure_equals("INVALID_DATE_MISSING_MONTH should have failed" , result, false);
96
97 result = date.fromString(INVALID_DATE_MISSING_DATE);
98 ensure_equals("INVALID_DATE_MISSING_DATE should have failed" , result, false);
99
100 result = date.fromString(INVALID_DATE_MISSING_T);
101 ensure_equals("INVALID_DATE_MISSING_T should have failed" , result, false);
102
103 result = date.fromString(INVALID_DATE_MISSING_HOUR);
104 ensure_equals("INVALID_DATE_MISSING_HOUR should have failed" , result, false);
105
106 result = date.fromString(INVALID_DATE_MISSING_MIN);
107 ensure_equals("INVALID_DATE_MISSING_MIN should have failed" , result, false);
108
109 result = date.fromString(INVALID_DATE_MISSING_SEC);
110 ensure_equals("INVALID_DATE_MISSING_SEC should have failed" , result, false);
111
112 result = date.fromString(INVALID_DATE_MISSING_Z);
113 ensure_equals("INVALID_DATE_MISSING_Z should have failed" , result, false);
114
115 result = date.fromString(INVALID_DATE_EMPTY);
116 ensure_equals("INVALID_DATE_EMPTY should have failed" , result, false);
117 }
118
119 /* Invalid Value Handling */
120 template<> template<>
121 void date_test_object_t::test<2>()
122 {
123#if LL_DATE_PARSER_CHECKS_BOUNDARY
124 LLDate date;
125 std::string expected_string;
126 bool result;
127
128 result = date.fromString(INVALID_DATE_24HOUR_BOUNDARY);
129 ensure_equals("INVALID_DATE_24HOUR_BOUNDARY should have failed" , result, false);
130 ensure_equals("INVALID_DATE_24HOUR_BOUNDARY date still set to old value on failure!" , date.secondsSinceEpoch(), 0);
131
132 result = date.fromString(INVALID_DATE_LEAP);
133 ensure_equals("INVALID_DATE_LEAP should have failed" , result, false);
134
135 result = date.fromString(INVALID_DATE_HOUR);
136 ensure_equals("INVALID_DATE_HOUR should have failed" , result, false);
137
138 result = date.fromString(INVALID_DATE_MIN);
139 ensure_equals("INVALID_DATE_MIN should have failed" , result, false);
140
141 result = date.fromString(INVALID_DATE_SEC);
142 ensure_equals("INVALID_DATE_SEC should have failed" , result, false);
143
144 result = date.fromString(INVALID_DATE_YEAR);
145 ensure_equals("INVALID_DATE_YEAR should have failed" , result, false);
146
147 result = date.fromString(INVALID_DATE_MONTH);
148 ensure_equals("INVALID_DATE_MONTH should have failed" , result, false);
149
150 result = date.fromString(INVALID_DATE_DAY);
151 ensure_equals("INVALID_DATE_DAY should have failed" , result, false);
152#endif
153 }
154
155 /* API checks */
156 template<> template<>
157 void date_test_object_t::test<3>()
158 {
159 LLDate date;
160 std::istringstream stream(VALID_DATE);
161 std::string expected_string = VALID_DATE;
162 date.fromStream(stream);
163 ensure_equals("fromStream failed", date.asString(), expected_string);
164 }
165
166 template<> template<>
167 void date_test_object_t::test<4>()
168 {
169 LLDate date1(VALID_DATE);
170 LLDate date2(date1);
171 ensure_equals("LLDate(const LLDate& date) constructor failed", date1.asString(), date2.asString());
172 }
173
174 template<> template<>
175 void date_test_object_t::test<5>()
176 {
177 LLDate date1(VALID_DATE);
178 LLDate date2(date1.secondsSinceEpoch());
179 ensure_equals("secondsSinceEpoch not equal",date1.secondsSinceEpoch(), date2.secondsSinceEpoch());
180 ensure_equals("LLDate created using secondsSinceEpoch not equal", date1.asString(), date2.asString());
181 }
182
183 template<> template<>
184 void date_test_object_t::test<6>()
185 {
186 LLDate date(VALID_DATE);
187 std::ostringstream stream;
188 stream << date;
189 std::string expected_str = VALID_DATE;
190 ensure_equals("ostringstream failed", expected_str, stream.str());
191 }
192
193 template<> template<>
194 void date_test_object_t::test<7>()
195 {
196 LLDate date;
197 std::istringstream stream(VALID_DATE);
198 stream >> date;
199 std::string expected_str = VALID_DATE;
200 std::ostringstream out_stream;
201 out_stream << date;
202
203 ensure_equals("<< failed", date.asString(),expected_str);
204 ensure_equals("<< to >> failed", stream.str(),out_stream.str());
205 }
206}