aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/test/llsdmessagebuilder_tut.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/test/llsdmessagebuilder_tut.cpp')
-rwxr-xr-xlinden/indra/test/llsdmessagebuilder_tut.cpp279
1 files changed, 279 insertions, 0 deletions
diff --git a/linden/indra/test/llsdmessagebuilder_tut.cpp b/linden/indra/test/llsdmessagebuilder_tut.cpp
new file mode 100755
index 0000000..d48584a
--- /dev/null
+++ b/linden/indra/test/llsdmessagebuilder_tut.cpp
@@ -0,0 +1,279 @@
1/**
2 * @file llsdmessagebuilder_tut.cpp
3 * @date February 2006
4 * @brief LLSDMessageBuilder unit tests
5 *
6 * Copyright (c) 2006-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 <tut/tut.h>
31#include "lltut.h"
32
33#include "llsdmessagebuilder.h"
34#include "llsdmessagereader.h"
35#include "llsdtraits.h"
36#include "llquaternion.h"
37#include "u64.h"
38#include "v3dmath.h"
39#include "v3math.h"
40#include "v4math.h"
41
42namespace tut
43{
44 struct LLSDMessageBuilderTestData {
45 static LLSDMessageBuilder defaultBuilder()
46 {
47 LLSDMessageBuilder builder;
48 builder.newMessage("name");
49 builder.nextBlock("block");
50 return builder;
51 }
52
53 static LLSDMessageReader setReader(const LLSDMessageBuilder& builder)
54 {
55 LLSDMessageReader reader;
56 reader.setMessage("name", builder.getMessage());
57 return reader;
58 }
59 };
60
61 typedef test_group<LLSDMessageBuilderTestData> LLSDMessageBuilderTestGroup;
62 typedef LLSDMessageBuilderTestGroup::object LLSDMessageBuilderTestObject;
63 LLSDMessageBuilderTestGroup llsdMessageBuilderTestGroup("LLSDMessageBuilder");
64
65 template<> template<>
66 void LLSDMessageBuilderTestObject::test<1>()
67 // construction and test of undefined
68 {
69 LLSDMessageBuilder builder = defaultBuilder();
70 LLSDMessageReader reader = setReader(builder);
71 }
72
73 template<> template<>
74 void LLSDMessageBuilderTestObject::test<2>()
75 // BOOL
76 {
77 BOOL outValue, inValue = TRUE;
78 LLSDMessageBuilder builder = defaultBuilder();
79 builder.addBOOL("var", inValue);
80 LLSDMessageReader reader = setReader(builder);
81 reader.getBOOL("block", "var", outValue);
82 ensure_equals("Ensure BOOL", inValue, outValue);
83 }
84
85 template<> template<>
86 void LLSDMessageBuilderTestObject::test<3>()
87 // U8
88 {
89 U8 outValue, inValue = 2;
90 LLSDMessageBuilder builder = defaultBuilder();
91 builder.addU8("var", inValue);
92 LLSDMessageReader reader = setReader(builder);
93 reader.getU8("block", "var", outValue);
94 ensure_equals("Ensure U8", inValue, outValue);
95 }
96
97 template<> template<>
98 void LLSDMessageBuilderTestObject::test<4>()
99 // S16
100 {
101 S16 outValue, inValue = 90;
102 LLSDMessageBuilder builder = defaultBuilder();
103 builder.addS16("var", inValue);
104 LLSDMessageReader reader = setReader(builder);
105 reader.getS16("block", "var", outValue);
106 ensure_equals("Ensure S16", inValue, outValue);
107 }
108
109 template<> template<>
110 void LLSDMessageBuilderTestObject::test<5>()
111 // U16
112 {
113 U16 outValue, inValue = 3;
114 LLSDMessageBuilder builder = defaultBuilder();
115 builder.addU16("var", inValue);
116 LLSDMessageReader reader = setReader(builder);
117 reader.getU16("block", "var", outValue);
118 ensure_equals("Ensure U16", inValue, outValue);
119 }
120
121 template<> template<>
122 void LLSDMessageBuilderTestObject::test<6>()
123 // S32
124 {
125 S32 outValue, inValue = 44;
126 LLSDMessageBuilder builder = defaultBuilder();
127 builder.addS32("var", inValue);
128 LLSDMessageReader reader = setReader(builder);
129 reader.getS32("block", "var", outValue);
130 ensure_equals("Ensure S32", inValue, outValue);
131 }
132
133 template<> template<>
134 void LLSDMessageBuilderTestObject::test<7>()
135 // F32
136 {
137 F32 outValue, inValue = 121.44;
138 LLSDMessageBuilder builder = defaultBuilder();
139 builder.addF32("var", inValue);
140 LLSDMessageReader reader = setReader(builder);
141 reader.getF32("block", "var", outValue);
142 ensure_equals("Ensure F32", inValue, outValue);
143 }
144
145 template<> template<>
146 void LLSDMessageBuilderTestObject::test<8>()
147 // U32
148 {
149 U32 outValue, inValue = 88;
150 LLSDMessageBuilder builder = defaultBuilder();
151 builder.addU32("var", inValue);
152 LLSDMessageReader reader = setReader(builder);
153 reader.getU32("block", "var", outValue);
154 ensure_equals("Ensure U32", inValue, outValue);
155 }
156
157 template<> template<>
158 void LLSDMessageBuilderTestObject::test<9>()
159 // U64
160 {
161 U64 outValue, inValue = 121;
162 LLSDMessageBuilder builder = defaultBuilder();
163 builder.addU64("var", inValue);
164 LLSDMessageReader reader = setReader(builder);
165 reader.getU64("block", "var", outValue);
166 ensure_equals("Ensure U64", inValue, outValue);
167 }
168
169 template<> template<>
170 void LLSDMessageBuilderTestObject::test<10>()
171 // F64
172 {
173 F64 outValue, inValue = 3232143.33;
174 LLSDMessageBuilder builder = defaultBuilder();
175 builder.addF64("var", inValue);
176 LLSDMessageReader reader = setReader(builder);
177 reader.getF64("block", "var", outValue);
178 ensure_equals("Ensure F64", inValue, outValue);
179 }
180
181 template<> template<>
182 void LLSDMessageBuilderTestObject::test<11>()
183 // Vector3
184 {
185 LLVector3 outValue, inValue = LLVector3(1,2,3);
186 LLSDMessageBuilder builder = defaultBuilder();
187 builder.addVector3("var", inValue);
188 LLSDMessageReader reader = setReader(builder);
189 reader.getVector3("block", "var", outValue);
190 ensure_equals("Ensure Vector3", inValue, outValue);
191 }
192
193 template<> template<>
194 void LLSDMessageBuilderTestObject::test<12>()
195 // Vector4
196 {
197 LLVector4 outValue, inValue = LLVector4(1,2,3,4);
198 LLSDMessageBuilder builder = defaultBuilder();
199 builder.addVector4("var", inValue);
200 LLSDMessageReader reader = setReader(builder);
201 reader.getVector4("block", "var", outValue);
202 ensure_equals("Ensure Vector4", inValue, outValue);
203 }
204
205 template<> template<>
206 void LLSDMessageBuilderTestObject::test<13>()
207 // Vector3d
208 {
209 LLVector3d outValue, inValue = LLVector3d(1,2,3);
210 LLSDMessageBuilder builder = defaultBuilder();
211 builder.addVector3d("var", inValue);
212 LLSDMessageReader reader = setReader(builder);
213 reader.getVector3d("block", "var", outValue);
214 ensure_equals("Ensure Vector3d", inValue, outValue);
215 }
216
217 template<> template<>
218 void LLSDMessageBuilderTestObject::test<14>()
219 // Quaternion
220 {
221 LLQuaternion outValue, inValue = LLQuaternion(1,2,3,4);
222 LLSDMessageBuilder builder = defaultBuilder();
223 builder.addQuat("var", inValue);
224 LLSDMessageReader reader = setReader(builder);
225 reader.getQuat("block", "var", outValue);
226 ensure_equals("Ensure Quaternion", inValue, outValue);
227 }
228
229 template<> template<>
230 void LLSDMessageBuilderTestObject::test<15>()
231 // UUID
232 {
233 LLUUID outValue, inValue;
234 inValue.generate();
235 LLSDMessageBuilder builder = defaultBuilder();
236 builder.addUUID("var", inValue);
237 LLSDMessageReader reader = setReader(builder);
238 reader.getUUID("block", "var", outValue);
239 ensure_equals("Ensure UUID", inValue, outValue);
240 }
241
242 template<> template<>
243 void LLSDMessageBuilderTestObject::test<16>()
244 // IPAddr
245 {
246 U32 outValue, inValue = 12344556;
247 LLSDMessageBuilder builder = defaultBuilder();
248 builder.addIPAddr("var", inValue);
249 LLSDMessageReader reader = setReader(builder);
250 reader.getIPAddr("block", "var", outValue);
251 ensure_equals("Ensure IPAddr", inValue, outValue);
252 }
253
254 template<> template<>
255 void LLSDMessageBuilderTestObject::test<17>()
256 // IPPort
257 {
258 U16 outValue, inValue = 80;
259 LLSDMessageBuilder builder = defaultBuilder();
260 builder.addIPPort("var", inValue);
261 LLSDMessageReader reader = setReader(builder);
262 reader.getIPPort("block", "var", outValue);
263 ensure_equals("Ensure IPPort", inValue, outValue);
264 }
265
266 template<> template<>
267 void LLSDMessageBuilderTestObject::test<18>()
268 {
269 std::string outValue, inValue = "testing";
270 LLSDMessageBuilder builder = defaultBuilder();
271 builder.addString("var", inValue.c_str());
272 LLSDMessageReader reader = setReader(builder);
273 char buffer[MAX_STRING];
274 reader.getString("block", "var", MAX_STRING, buffer);
275 outValue = buffer;
276 ensure_equals("Ensure String", inValue, outValue);
277 }
278}
279