diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/test/lltut.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/test/lltut.cpp')
-rw-r--r-- | linden/indra/test/lltut.cpp | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/linden/indra/test/lltut.cpp b/linden/indra/test/lltut.cpp new file mode 100644 index 0000000..31b83e6 --- /dev/null +++ b/linden/indra/test/lltut.cpp | |||
@@ -0,0 +1,168 @@ | |||
1 | /** | ||
2 | * @file lltut.cpp | ||
3 | * @author Mark Lentczner | ||
4 | * @date 5/16/06 | ||
5 | * @brief MacTester | ||
6 | * | ||
7 | * Copyright (c) 2006-2007, Linden Research, Inc. | ||
8 | * | ||
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 "lltut.h" | ||
31 | #include "llsd.h" | ||
32 | |||
33 | namespace tut | ||
34 | { | ||
35 | template<> | ||
36 | void ensure_equals(const char* msg, const LLDate& actual, | ||
37 | const LLDate& expected) | ||
38 | { | ||
39 | ensure_equals(msg, | ||
40 | actual.secondsSinceEpoch(), expected.secondsSinceEpoch()); | ||
41 | } | ||
42 | |||
43 | template<> | ||
44 | void ensure_equals(const char* msg, const LLURI& actual, | ||
45 | const LLURI& expected) | ||
46 | { | ||
47 | ensure_equals(msg, | ||
48 | actual.asString(), expected.asString()); | ||
49 | } | ||
50 | |||
51 | template<> | ||
52 | void ensure_equals(const char* msg, | ||
53 | const std::vector<U8>& actual, const std::vector<U8>& expected) | ||
54 | { | ||
55 | std::string s(msg); | ||
56 | |||
57 | ensure_equals(s + " size", actual.size(), expected.size()); | ||
58 | |||
59 | std::vector<U8>::const_iterator i, j; | ||
60 | int k; | ||
61 | for (i = actual.begin(), j = expected.begin(), k = 0; | ||
62 | i != actual.end(); | ||
63 | ++i, ++j, ++k) | ||
64 | { | ||
65 | ensure_equals(s + " field", *i, *j); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | template<> | ||
70 | void ensure_equals(const char* m, const LLSD& actual, | ||
71 | const LLSD& expected) | ||
72 | { | ||
73 | const std::string& msg = m; | ||
74 | |||
75 | ensure_equals(msg + " type", actual.type(), expected.type()); | ||
76 | switch (actual.type()) | ||
77 | { | ||
78 | case LLSD::TypeUndefined: | ||
79 | return; | ||
80 | |||
81 | case LLSD::TypeBoolean: | ||
82 | ensure_equals(msg + " boolean", actual.asBoolean(), expected.asBoolean()); | ||
83 | return; | ||
84 | |||
85 | case LLSD::TypeInteger: | ||
86 | ensure_equals(msg + " integer", actual.asInteger(), expected.asInteger()); | ||
87 | return; | ||
88 | |||
89 | case LLSD::TypeReal: | ||
90 | ensure_equals(msg + " real", actual.asReal(), expected.asReal()); | ||
91 | return; | ||
92 | |||
93 | case LLSD::TypeString: | ||
94 | ensure_equals(msg + " string", actual.asString(), expected.asString()); | ||
95 | return; | ||
96 | |||
97 | case LLSD::TypeUUID: | ||
98 | ensure_equals(msg + " uuid", actual.asUUID(), expected.asUUID()); | ||
99 | return; | ||
100 | |||
101 | case LLSD::TypeDate: | ||
102 | ensure_equals(msg + " date", actual.asDate(), expected.asDate()); | ||
103 | return; | ||
104 | |||
105 | case LLSD::TypeURI: | ||
106 | ensure_equals(msg + " uri", actual.asURI(), expected.asURI()); | ||
107 | return; | ||
108 | |||
109 | case LLSD::TypeBinary: | ||
110 | ensure_equals(msg + " binary", actual.asBinary(), expected.asBinary()); | ||
111 | return; | ||
112 | |||
113 | case LLSD::TypeMap: | ||
114 | { | ||
115 | ensure_equals(msg + " map size", actual.size(), expected.size()); | ||
116 | |||
117 | LLSD::map_const_iterator actual_iter = actual.beginMap(); | ||
118 | LLSD::map_const_iterator expected_iter = expected.beginMap(); | ||
119 | |||
120 | while(actual_iter != actual.endMap()) | ||
121 | { | ||
122 | ensure_equals(msg + " map keys", | ||
123 | actual_iter->first, expected_iter->first); | ||
124 | ensure_equals(msg + "[" + actual_iter->first + "]", | ||
125 | actual_iter->second, expected_iter->second); | ||
126 | ++actual_iter; | ||
127 | ++expected_iter; | ||
128 | } | ||
129 | return; | ||
130 | } | ||
131 | case LLSD::TypeArray: | ||
132 | { | ||
133 | ensure_equals(msg + " array size", actual.size(), expected.size()); | ||
134 | |||
135 | for(int i = 0; i < actual.size(); ++i) | ||
136 | { | ||
137 | ensure_equals(msg + llformat("[%d]", i), | ||
138 | actual[i], expected[i]); | ||
139 | } | ||
140 | return; | ||
141 | } | ||
142 | } | ||
143 | } | ||
144 | |||
145 | void ensure_starts_with(const std::string& msg, | ||
146 | const std::string& actual, const std::string& expectedStart) | ||
147 | { | ||
148 | if( actual.find(expectedStart, 0) != 0 ) | ||
149 | { | ||
150 | std::stringstream ss; | ||
151 | ss << msg << ": " << "expected to find " << expectedStart | ||
152 | << " at start of actual " << actual; | ||
153 | throw failure(ss.str().c_str()); | ||
154 | } | ||
155 | } | ||
156 | |||
157 | void ensure_contains(const std::string& msg, | ||
158 | const std::string& actual, const std::string& expectedSubString) | ||
159 | { | ||
160 | if( actual.find(expectedSubString, 0) == std::string::npos ) | ||
161 | { | ||
162 | std::stringstream ss; | ||
163 | ss << msg << ": " << "expected to find " << expectedSubString | ||
164 | << " in actual " << actual; | ||
165 | throw failure(ss.str().c_str()); | ||
166 | } | ||
167 | } | ||
168 | } | ||