diff options
author | Jacek Antonelli | 2008-08-15 23:45:02 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:02 -0500 |
commit | d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd (patch) | |
tree | 7ed0c2c27d717801238a2e6b5749cd5bf88c3059 /linden/indra/test/llmessagetemplateparser_tut.cpp | |
parent | Second Life viewer sources 1.17.3.0 (diff) | |
download | meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.zip meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.gz meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.bz2 meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.xz |
Second Life viewer sources 1.18.0.6
Diffstat (limited to 'linden/indra/test/llmessagetemplateparser_tut.cpp')
-rw-r--r-- | linden/indra/test/llmessagetemplateparser_tut.cpp | 370 |
1 files changed, 370 insertions, 0 deletions
diff --git a/linden/indra/test/llmessagetemplateparser_tut.cpp b/linden/indra/test/llmessagetemplateparser_tut.cpp new file mode 100644 index 0000000..74b4c55 --- /dev/null +++ b/linden/indra/test/llmessagetemplateparser_tut.cpp | |||
@@ -0,0 +1,370 @@ | |||
1 | /** | ||
2 | * @file llmessagetemplateparser_tut.cpp | ||
3 | * @date April 2007 | ||
4 | * @brief LLMessageTemplateParser 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 | #include "llmessagetemplateparser.h" | ||
33 | |||
34 | namespace tut | ||
35 | { | ||
36 | struct LLMessageTemplateParserTestData { | ||
37 | LLMessageTemplateParserTestData() : mMessage("unset message") | ||
38 | { | ||
39 | } | ||
40 | |||
41 | ~LLMessageTemplateParserTestData() | ||
42 | { | ||
43 | } | ||
44 | |||
45 | void ensure_next(LLTemplateTokenizer & tokens, | ||
46 | std::string value, | ||
47 | U32 line) | ||
48 | { | ||
49 | std::string next = tokens.next(); | ||
50 | ensure_equals(mMessage + " token matches", next, value); | ||
51 | ensure_equals(mMessage + " line matches", tokens.line(), line); | ||
52 | } | ||
53 | |||
54 | char * prehash(const char * name) | ||
55 | { | ||
56 | return gMessageStringTable.getString(name); | ||
57 | } | ||
58 | |||
59 | void ensure_block_attributes(std::string identifier, | ||
60 | const LLMessageTemplate * message, | ||
61 | const char * name, | ||
62 | EMsgBlockType type, | ||
63 | S32 number, | ||
64 | S32 total_size) | ||
65 | { | ||
66 | const LLMessageBlock * block = message->getBlock(prehash(name)); | ||
67 | identifier = identifier + ":" + message->mName + ":" + name + " block"; | ||
68 | ensure(identifier + " exists", block != NULL); | ||
69 | ensure_equals(identifier + " name", block->mName, prehash(name)); | ||
70 | ensure_equals(identifier + " type", block->mType, type); | ||
71 | ensure_equals(identifier + " number", block->mNumber, number); | ||
72 | ensure_equals(identifier + " total size", block->mTotalSize, total_size); | ||
73 | } | ||
74 | |||
75 | void ensure_variable_attributes(std::string identifier, | ||
76 | const LLMessageBlock * block, | ||
77 | const char * name, | ||
78 | EMsgVariableType type, | ||
79 | S32 size) | ||
80 | { | ||
81 | const LLMessageVariable * var = block->getVariable(prehash(name)); | ||
82 | identifier = identifier + ":" + block->mName + ":" + name + " variable"; | ||
83 | ensure(identifier + " exists", var != NULL); | ||
84 | ensure_equals( | ||
85 | identifier + " name", var->getName(), prehash(name)); | ||
86 | ensure_equals( | ||
87 | identifier + " type", var->getType(), type); | ||
88 | ensure_equals(identifier + " size", var->getSize(), size); | ||
89 | } | ||
90 | |||
91 | std::string mMessage; | ||
92 | |||
93 | }; | ||
94 | |||
95 | typedef test_group<LLMessageTemplateParserTestData> LLMessageTemplateParserTestGroup; | ||
96 | typedef LLMessageTemplateParserTestGroup::object LLMessageTemplateParserTestObject; | ||
97 | LLMessageTemplateParserTestGroup llMessageTemplateParserTestGroup("LLMessageTemplateParser"); | ||
98 | |||
99 | template<> template<> | ||
100 | void LLMessageTemplateParserTestObject::test<1>() | ||
101 | // tests tokenizer constructor and next methods | ||
102 | { | ||
103 | mMessage = "test method 1 walkthrough"; | ||
104 | LLTemplateTokenizer tokens("first line\nnext\t line\n\nfourth"); | ||
105 | ensure_next(tokens, "first", 1); | ||
106 | ensure_next(tokens, "line", 1); | ||
107 | ensure_next(tokens, "next", 2); | ||
108 | ensure_next(tokens, "line", 2); | ||
109 | ensure_next(tokens, "fourth", 4); | ||
110 | |||
111 | tokens = LLTemplateTokenizer("\n\t{ \t Test1 Fixed \n 523 }\n\n"); | ||
112 | ensure(tokens.want("{")); | ||
113 | ensure_next(tokens, "Test1", 2); | ||
114 | ensure_next(tokens, "Fixed", 2); | ||
115 | ensure_next(tokens, "523", 3); | ||
116 | ensure(tokens.want("}")); | ||
117 | |||
118 | tokens = LLTemplateTokenizer("first line\nnext\t line\n\nfourth"); | ||
119 | ensure(tokens.want("first")); | ||
120 | ensure_next(tokens, "line", 1); | ||
121 | ensure_next(tokens, "next", 2); | ||
122 | ensure_next(tokens, "line", 2); | ||
123 | ensure(tokens.want("fourth")); | ||
124 | } | ||
125 | |||
126 | template<> template<> | ||
127 | void LLMessageTemplateParserTestObject::test<2>() | ||
128 | // tests tokenizer want method | ||
129 | { | ||
130 | // *NOTE: order matters | ||
131 | LLTemplateTokenizer tokens("first line\nnext\t line\n\nfourth"); | ||
132 | ensure_equals("wants first token", tokens.want("first"), true); | ||
133 | ensure_equals("doesn't want blar token", tokens.want("blar"), false); | ||
134 | ensure_equals("wants line token", tokens.want("line"), true); | ||
135 | } | ||
136 | |||
137 | template<> template<> | ||
138 | void LLMessageTemplateParserTestObject::test<3>() | ||
139 | // tests tokenizer eof methods | ||
140 | { | ||
141 | LLTemplateTokenizer tokens("single\n\n"); | ||
142 | ensure_equals("is not at eof at beginning", tokens.atEOF(), false); | ||
143 | ensure_equals("doesn't want eof", tokens.wantEOF(), false); | ||
144 | ensure_equals("wants the first token just to consume it", | ||
145 | tokens.want("single"), true); | ||
146 | ensure_equals("is not at eof in middle", tokens.atEOF(), false); | ||
147 | ensure_equals("wants eof", tokens.wantEOF(), true); | ||
148 | ensure_equals("is at eof at end", tokens.atEOF(), true); | ||
149 | } | ||
150 | |||
151 | template<> template<> | ||
152 | void LLMessageTemplateParserTestObject::test<4>() | ||
153 | // tests variable parsing method | ||
154 | { | ||
155 | LLTemplateTokenizer tokens(std::string("{ Test0 \n\t\n U32 \n\n }")); | ||
156 | LLMessageVariable * var = LLTemplateParser::parseVariable(tokens); | ||
157 | |||
158 | ensure("test0 var parsed", var != 0); | ||
159 | ensure_equals("name of variable", std::string(var->getName()), std::string("Test0")); | ||
160 | ensure_equals("type of variable is U32", var->getType(), MVT_U32); | ||
161 | ensure_equals("size of variable", var->getSize(), 4); | ||
162 | |||
163 | delete var; | ||
164 | |||
165 | std::string message_string("\n\t{ \t Test1 Fixed \n 523 }\n\n"); | ||
166 | tokens = LLTemplateTokenizer(message_string); | ||
167 | var = LLTemplateParser::parseVariable(tokens); | ||
168 | |||
169 | ensure("test1 var parsed", var != 0); | ||
170 | ensure_equals("name of variable", std::string(var->getName()), std::string("Test1")); | ||
171 | ensure_equals("type of variable is Fixed", var->getType(), MVT_FIXED); | ||
172 | ensure_equals("size of variable", var->getSize(), 523); | ||
173 | |||
174 | delete var; | ||
175 | |||
176 | // *NOTE: the parsers call llerrs on invalid input, so we can't really | ||
177 | // test that :-( | ||
178 | } | ||
179 | |||
180 | template<> template<> | ||
181 | void LLMessageTemplateParserTestObject::test<5>() | ||
182 | // tests block parsing method | ||
183 | { | ||
184 | LLTemplateTokenizer tokens("{ BlockA Single { VarX F32 } }"); | ||
185 | LLMessageBlock * block = LLTemplateParser::parseBlock(tokens); | ||
186 | |||
187 | ensure("blockA block parsed", block != 0); | ||
188 | ensure_equals("name of block", std::string(block->mName), std::string("BlockA")); | ||
189 | ensure_equals("type of block is Single", block->mType, MBT_SINGLE); | ||
190 | ensure_equals("total size of block", block->mTotalSize, 4); | ||
191 | ensure_equals("number of block defaults to 1", block->mNumber, 1); | ||
192 | ensure_equals("variable type of VarX is F32", | ||
193 | block->getVariableType(prehash("VarX")), MVT_F32); | ||
194 | ensure_equals("variable size of VarX", | ||
195 | block->getVariableSize(prehash("VarX")), 4); | ||
196 | |||
197 | delete block; | ||
198 | |||
199 | tokens = LLTemplateTokenizer("{ Stuff Variable { Id LLUUID } }"); | ||
200 | block = LLTemplateParser::parseBlock(tokens); | ||
201 | |||
202 | ensure("stuff block parsed", block != 0); | ||
203 | ensure_equals("name of block", std::string(block->mName), std::string("Stuff")); | ||
204 | ensure_equals("type of block is Multiple", block->mType, MBT_VARIABLE); | ||
205 | ensure_equals("total size of block", block->mTotalSize, 16); | ||
206 | ensure_equals("number of block defaults to 1", block->mNumber, 1); | ||
207 | ensure_equals("variable type of Id is LLUUID", | ||
208 | block->getVariableType(prehash("Id")), MVT_LLUUID); | ||
209 | ensure_equals("variable size of Id", | ||
210 | block->getVariableSize(prehash("Id")), 16); | ||
211 | |||
212 | delete block; | ||
213 | |||
214 | tokens = LLTemplateTokenizer("{ Stuff2 Multiple 45 { Shid LLVector3d } }"); | ||
215 | block = LLTemplateParser::parseBlock(tokens); | ||
216 | |||
217 | ensure("stuff2 block parsed", block != 0); | ||
218 | ensure_equals("name of block", std::string(block->mName), std::string("Stuff2")); | ||
219 | ensure_equals("type of block is Multiple", block->mType, MBT_MULTIPLE); | ||
220 | ensure_equals("total size of block", block->mTotalSize, 24); | ||
221 | ensure_equals("number of blocks", block->mNumber, 45); | ||
222 | ensure_equals("variable type of Shid is Vector3d", | ||
223 | block->getVariableType(prehash("Shid")), MVT_LLVector3d); | ||
224 | ensure_equals("variable size of Shid", | ||
225 | block->getVariableSize(prehash("Shid")), 24); | ||
226 | |||
227 | delete block; | ||
228 | } | ||
229 | |||
230 | template<> template<> | ||
231 | void LLMessageTemplateParserTestObject::test<6>() | ||
232 | // tests message parsing method on a simple message | ||
233 | { | ||
234 | std::string message_skel( | ||
235 | "{\n" | ||
236 | "TestMessage Low 1 NotTrusted Zerocoded\n" | ||
237 | "// comment \n" | ||
238 | " {\n" | ||
239 | "TestBlock1 Single\n" | ||
240 | " { Test1 U32 }\n" | ||
241 | " }\n" | ||
242 | " {\n" | ||
243 | " NeighborBlock Multiple 4\n" | ||
244 | " { Test0 U32 }\n" | ||
245 | " { Test1 U32 }\n" | ||
246 | " { Test2 U32 }\n" | ||
247 | " }\n" | ||
248 | "}"); | ||
249 | LLTemplateTokenizer tokens(message_skel); | ||
250 | LLMessageTemplate * message = LLTemplateParser::parseMessage(tokens); | ||
251 | |||
252 | ensure("simple message parsed", message != 0); | ||
253 | ensure_equals("name of message", std::string(message->mName), std::string("TestMessage")); | ||
254 | ensure_equals("frequency is Low", message->mFrequency, MFT_LOW); | ||
255 | ensure_equals("trust is untrusted", message->mTrust, MT_NOTRUST); | ||
256 | ensure_equals("message number", message->mMessageNumber, (U32)((255 << 24) | (255 << 16) | 1)); | ||
257 | ensure_equals("message encoding is zerocoded", message->mEncoding, ME_ZEROCODED); | ||
258 | ensure_equals("message deprecation is notdeprecated", message->mDeprecation, MD_NOTDEPRECATED); | ||
259 | |||
260 | LLMessageBlock * block = message->getBlock(prehash("NonexistantBlock")); | ||
261 | ensure("Nonexistant block does not exist", block == 0); | ||
262 | |||
263 | delete message; | ||
264 | } | ||
265 | |||
266 | template<> template<> | ||
267 | void LLMessageTemplateParserTestObject::test<7>() | ||
268 | // tests message parsing method on a deprecated message | ||
269 | { | ||
270 | std::string message_skel( | ||
271 | "{\n" | ||
272 | "TestMessageDeprecated High 34 Trusted Unencoded Deprecated\n" | ||
273 | " {\n" | ||
274 | "TestBlock2 Single\n" | ||
275 | " { Test2 S32 }\n" | ||
276 | " }\n" | ||
277 | "}"); | ||
278 | LLTemplateTokenizer tokens(message_skel); | ||
279 | LLMessageTemplate * message = LLTemplateParser::parseMessage(tokens); | ||
280 | |||
281 | ensure("deprecated message parsed", message != 0); | ||
282 | ensure_equals("name of message", std::string(message->mName), std::string("TestMessageDeprecated")); | ||
283 | ensure_equals("frequency is High", message->mFrequency, MFT_HIGH); | ||
284 | ensure_equals("trust is trusted", message->mTrust, MT_TRUST); | ||
285 | ensure_equals("message number", message->mMessageNumber, (U32)34); | ||
286 | ensure_equals("message encoding is unencoded", message->mEncoding, ME_UNENCODED); | ||
287 | ensure_equals("message deprecation is deprecated", message->mDeprecation, MD_DEPRECATED); | ||
288 | |||
289 | delete message; | ||
290 | } | ||
291 | |||
292 | void LLMessageTemplateParserTestObject::test<8>() | ||
293 | // tests message parsing on RezMultipleAttachmentsFromInv, a possibly-faulty message | ||
294 | { | ||
295 | std::string message_skel( | ||
296 | "{\n\ | ||
297 | RezMultipleAttachmentsFromInv Low 452 NotTrusted Zerocoded\n\ | ||
298 | {\n\ | ||
299 | AgentData Single\n\ | ||
300 | { AgentID LLUUID }\n\ | ||
301 | { SessionID LLUUID }\n\ | ||
302 | } \n\ | ||
303 | {\n\ | ||
304 | HeaderData Single\n\ | ||
305 | { CompoundMsgID LLUUID } // All messages a single \"compound msg\" must have the same id\n\ | ||
306 | { TotalObjects U8 }\n\ | ||
307 | { FirstDetachAll BOOL }\n\ | ||
308 | }\n\ | ||
309 | {\n\ | ||
310 | ObjectData Variable // 1 to 4 of these per packet\n\ | ||
311 | { ItemID LLUUID }\n\ | ||
312 | { OwnerID LLUUID }\n\ | ||
313 | { AttachmentPt U8 } // 0 for default\n\ | ||
314 | { ItemFlags U32 }\n\ | ||
315 | { GroupMask U32 }\n\ | ||
316 | { EveryoneMask U32 }\n\ | ||
317 | { NextOwnerMask U32 }\n\ | ||
318 | { Name Variable 1 }\n\ | ||
319 | { Description Variable 1 }\n\ | ||
320 | }\n\ | ||
321 | }\n\ | ||
322 | "); | ||
323 | LLTemplateTokenizer tokens(message_skel); | ||
324 | LLMessageTemplate * message = LLTemplateParser::parseMessage(tokens); | ||
325 | |||
326 | ensure("RezMultipleAttachmentsFromInv message parsed", message != 0); | ||
327 | ensure_equals("name of message", message->mName, prehash("RezMultipleAttachmentsFromInv")); | ||
328 | ensure_equals("frequency is low", message->mFrequency, MFT_LOW); | ||
329 | ensure_equals("trust is not trusted", message->mTrust, MT_NOTRUST); | ||
330 | ensure_equals("message number", message->mMessageNumber, (U32)((255 << 24) | (255 << 16) | 452)); | ||
331 | ensure_equals("message encoding is zerocoded", message->mEncoding, ME_ZEROCODED); | ||
332 | |||
333 | ensure_block_attributes( | ||
334 | "RMAFI", message, "AgentData", MBT_SINGLE, 1, 16+16); | ||
335 | LLMessageBlock * block = message->getBlock(prehash("AgentData")); | ||
336 | ensure_variable_attributes("RMAFI", | ||
337 | block, "AgentID", MVT_LLUUID, 16); | ||
338 | ensure_variable_attributes("RMAFI", | ||
339 | block, "SessionID", MVT_LLUUID, 16); | ||
340 | |||
341 | ensure_block_attributes( | ||
342 | "RMAFI", message, "HeaderData", MBT_SINGLE, 1, 16+1+1); | ||
343 | block = message->getBlock(prehash("HeaderData")); | ||
344 | ensure_variable_attributes( | ||
345 | "RMAFI", block, "CompoundMsgID", MVT_LLUUID, 16); | ||
346 | ensure_variable_attributes( | ||
347 | "RMAFI", block, "TotalObjects", MVT_U8, 1); | ||
348 | ensure_variable_attributes( | ||
349 | "RMAFI", block, "FirstDetachAll", MVT_BOOL, 1); | ||
350 | |||
351 | |||
352 | ensure_block_attributes( | ||
353 | "RMAFI", message, "ObjectData", MBT_VARIABLE, 1, -1); | ||
354 | block = message->getBlock(prehash("ObjectData")); | ||
355 | ensure_variable_attributes("RMAFI", block, "ItemID", MVT_LLUUID, 16); | ||
356 | ensure_variable_attributes("RMAFI", block, "OwnerID", MVT_LLUUID, 16); | ||
357 | ensure_variable_attributes("RMAFI", block, "AttachmentPt", MVT_U8, 1); | ||
358 | ensure_variable_attributes("RMAFI", block, "ItemFlags", MVT_U32, 4); | ||
359 | ensure_variable_attributes("RMAFI", block, "GroupMask", MVT_U32, 4); | ||
360 | ensure_variable_attributes("RMAFI", block, "EveryoneMask", MVT_U32, 4); | ||
361 | ensure_variable_attributes("RMAFI", block, "NextOwnerMask", MVT_U32, 4); | ||
362 | ensure_variable_attributes("RMAFI", block, "Name", MVT_VARIABLE, 1); | ||
363 | ensure_variable_attributes("RMAFI", block, "Description", MVT_VARIABLE, 1); | ||
364 | |||
365 | delete message; | ||
366 | } | ||
367 | |||
368 | |||
369 | |||
370 | } | ||