diff options
Diffstat (limited to '')
-rw-r--r-- | linden/indra/test/llhttpdate_tut.cpp | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/linden/indra/test/llhttpdate_tut.cpp b/linden/indra/test/llhttpdate_tut.cpp new file mode 100644 index 0000000..5279a81 --- /dev/null +++ b/linden/indra/test/llhttpdate_tut.cpp | |||
@@ -0,0 +1,92 @@ | |||
1 | /** | ||
2 | * @file llhttpdate_tut.cpp | ||
3 | * @author Kartic Krishnamurthy | ||
4 | * @date Wednesday, 18 Jul 2007 17:00:00 GMT :) | ||
5 | * | ||
6 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
7 | * | ||
8 | * Second Life Viewer Source Code | ||
9 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
10 | * to you under the terms of the GNU General Public License, version 2.0 | ||
11 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
12 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
13 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
14 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlife.com/developers/opensource/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | */ | ||
29 | |||
30 | #include "linden_common.h" | ||
31 | #include "lltut.h" | ||
32 | |||
33 | #include "lldate.h" | ||
34 | #include "llframetimer.h" | ||
35 | |||
36 | #include <string> | ||
37 | #include <time.h> | ||
38 | |||
39 | namespace tut | ||
40 | { | ||
41 | struct httpdate_data | ||
42 | { | ||
43 | LLDate some_date; | ||
44 | }; | ||
45 | typedef test_group<httpdate_data> httpdate_test; | ||
46 | typedef httpdate_test::object httpdate_object; | ||
47 | tut::httpdate_test httpdate("httpdate"); | ||
48 | |||
49 | template<> template<> | ||
50 | void httpdate_object::test<1>() | ||
51 | { | ||
52 | static std::string epoch_expected = "Thursday, 01 Jan 1970 00:00:00 GMT" ; | ||
53 | ensure("Check Epoch in RFC 1123", ( epoch_expected == some_date.asRFC1123())); | ||
54 | } | ||
55 | |||
56 | template<> template<> | ||
57 | void httpdate_object::test<2>() | ||
58 | { | ||
59 | static std::string expected = "Wednesday, 18 Jul 2007 22:17:24 GMT" ; | ||
60 | some_date = LLDate(1184797044.037586); | ||
61 | ensure("Check some timestamp in RFC 1123", ( expected == some_date.asRFC1123())); | ||
62 | } | ||
63 | |||
64 | // This test of course most generic.. runs off current time | ||
65 | template<> template<> | ||
66 | void httpdate_object::test<3>() | ||
67 | { | ||
68 | //F64 sometime = LLFrameTimer::getTotalSeconds(); | ||
69 | time_t sometime; | ||
70 | time(&sometime); | ||
71 | some_date = LLDate((F64) sometime); | ||
72 | struct tm result; | ||
73 | char expected[255], *actual; | ||
74 | |||
75 | gmtime_r((time_t *)&sometime, &result); | ||
76 | /* | ||
77 | std::cout << " seconds: "<< result.tm_sec | ||
78 | << ", minutes: " << result.tm_min | ||
79 | << ", hours: " << result.tm_hour | ||
80 | << ", day of the month: " << result.tm_mday | ||
81 | << ", month: " << result.tm_mon | ||
82 | << ", year: " << result.tm_year | ||
83 | << ", day of the week: " << result.tm_wday | ||
84 | << ", day in the year: " << result.tm_yday | ||
85 | << ", DST: " << result.tm_isdst << std::endl; | ||
86 | */ | ||
87 | strftime(expected, 255, "%A, %d %h %Y %H:%M:%S GMT", &result); | ||
88 | actual = (char *) some_date.asRFC1123().c_str(); | ||
89 | // probably not a good idea to use strcmp but this is just a unit test | ||
90 | ensure("Current time in RFC 1123", (strcmp(expected, actual) == 0)); | ||
91 | } | ||
92 | } | ||