aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/tests/lltemplatemessagedispatcher_test.cpp
diff options
context:
space:
mode:
authorArmin Weatherwax2010-06-14 12:04:49 +0200
committerArmin Weatherwax2010-09-23 15:38:25 +0200
commit35df5441d3e2789663532c948731aff3a1e04728 (patch)
treeac7674289784a5f96106ea507637055a8dada78a /linden/indra/llmessage/tests/lltemplatemessagedispatcher_test.cpp
parentChanged version to Experimental 2010.09.18 (diff)
downloadmeta-impy-35df5441d3e2789663532c948731aff3a1e04728.zip
meta-impy-35df5441d3e2789663532c948731aff3a1e04728.tar.gz
meta-impy-35df5441d3e2789663532c948731aff3a1e04728.tar.bz2
meta-impy-35df5441d3e2789663532c948731aff3a1e04728.tar.xz
llmediaplugins first step
Diffstat (limited to 'linden/indra/llmessage/tests/lltemplatemessagedispatcher_test.cpp')
-rw-r--r--linden/indra/llmessage/tests/lltemplatemessagedispatcher_test.cpp165
1 files changed, 165 insertions, 0 deletions
diff --git a/linden/indra/llmessage/tests/lltemplatemessagedispatcher_test.cpp b/linden/indra/llmessage/tests/lltemplatemessagedispatcher_test.cpp
new file mode 100644
index 0000000..d57f17f
--- /dev/null
+++ b/linden/indra/llmessage/tests/lltemplatemessagedispatcher_test.cpp
@@ -0,0 +1,165 @@
1/**
2 * @file lltrustedmessageservice_test.cpp
3 * @brief LLTrustedMessageService unit tests
4 *
5 * $LicenseInfo:firstyear=2009&license=viewergpl$
6 *
7 * Copyright (c) 2009, 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://secondlifegrid.net/programs/open_source/licensing/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
21 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
22 *
23 * By copying, modifying or distributing this software, you acknowledge
24 * that you have read and understood your obligations described above,
25 * and agree to abide by those obligations.
26 *
27 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
28 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
29 * COMPLETENESS OR PERFORMANCE.
30 * $/LicenseInfo$
31 */
32
33#include "lltemplatemessagedispatcher.h"
34#include "lltut.h"
35
36#include "llhttpnode.h"
37#include "llhost.h"
38#include "message.h"
39#include "llsd.h"
40
41#include "llhost.cpp" // Needed for copy operator
42#include "net.cpp" // Needed by LLHost.
43
44LLMessageSystem * gMessageSystem = NULL;
45
46// sensor test doubles
47bool gClearRecvWasCalled = false;
48void LLMessageSystem::clearReceiveState(void)
49{
50 gClearRecvWasCalled = true;
51}
52
53char gUdpDispatchedData[MAX_BUFFER_SIZE];
54bool gUdpDispatchWasCalled = false;
55BOOL LLTemplateMessageReader::readMessage(const U8* data,class LLHost const &)
56{
57 gUdpDispatchWasCalled = true;
58 strcpy(gUdpDispatchedData, reinterpret_cast<const char*>(data));
59 return true;
60}
61
62BOOL gValidateMessage = FALSE;
63BOOL LLTemplateMessageReader::validateMessage(const U8*, S32 buffer_size, LLHost const &sender, bool trusted)
64{
65 return gValidateMessage;
66}
67
68LLHost host;
69const LLHost& LLMessageSystem::getSender() const
70{
71 return host;
72}
73
74const char* gBinaryTemplateData = "BINARYTEMPLATEDATA";
75void fillVector(std::vector<U8>& vector_data, const char* data)
76{
77 vector_data.resize(strlen(data) + 1);
78 strcpy(reinterpret_cast<char*>(&vector_data[0]), data);
79}
80
81namespace tut
82{
83 static LLTemplateMessageReader::message_template_number_map_t numberMap;
84
85 struct LLTemplateMessageDispatcherData
86 {
87 LLTemplateMessageDispatcherData()
88 {
89 mMessageName = "MessageName";
90 gUdpDispatchWasCalled = false;
91 gClearRecvWasCalled = false;
92 gValidateMessage = FALSE;
93 mMessage["body"]["binary-template-data"] = std::vector<U8>();
94 }
95
96 LLSD mMessage;
97 LLHTTPNode::ResponsePtr mResponsePtr;
98 std::string mMessageName;
99 };
100
101 typedef test_group<LLTemplateMessageDispatcherData> factory;
102 typedef factory::object object;
103}
104
105namespace
106{
107 tut::factory tf("LLTemplateMessageDispatcher test");
108}
109
110namespace tut
111{
112 // does an empty message stop processing?
113 template<> template<>
114 void object::test<1>()
115 {
116 LLTemplateMessageReader* pReader = NULL;
117 LLTemplateMessageDispatcher t(*pReader);
118 t.dispatch(mMessageName, mMessage, mResponsePtr);
119 ensure(! gUdpDispatchWasCalled);
120 ensure(! gClearRecvWasCalled);
121 }
122
123 // does the disaptch invoke the udp send method?
124 template<> template<>
125 void object::test<2>()
126 {
127 LLTemplateMessageReader* pReader = NULL;
128 LLTemplateMessageDispatcher t(*pReader);
129 gValidateMessage = TRUE;
130 std::vector<U8> vector_data;
131 fillVector(vector_data, gBinaryTemplateData);
132 mMessage["body"]["binary-template-data"] = vector_data;
133 t.dispatch(mMessageName, mMessage, mResponsePtr);
134 ensure("udp dispatch was called", gUdpDispatchWasCalled);
135 }
136
137 // what if the message wasn't valid? We would hope the message gets cleared!
138 template<> template<>
139 void object::test<3>()
140 {
141 LLTemplateMessageReader* pReader = NULL;
142 LLTemplateMessageDispatcher t(*pReader);
143 std::vector<U8> vector_data;
144 fillVector(vector_data, gBinaryTemplateData);
145 mMessage["body"]["binary-template-data"] = vector_data;
146 gValidateMessage = FALSE;
147 t.dispatch(mMessageName, mMessage, mResponsePtr);
148 ensure("clear received message was called", gClearRecvWasCalled);
149 }
150
151 // is the binary data passed through correctly?
152 template<> template<>
153 void object::test<4>()
154 {
155 LLTemplateMessageReader* pReader = NULL;
156 LLTemplateMessageDispatcher t(*pReader);
157 gValidateMessage = TRUE;
158 std::vector<U8> vector_data;
159 fillVector(vector_data, gBinaryTemplateData);
160 mMessage["body"]["binary-template-data"] = vector_data;
161 t.dispatch(mMessageName, mMessage, mResponsePtr);
162 ensure("data couriered correctly", strcmp(gBinaryTemplateData, gUdpDispatchedData) == 0);
163 }
164}
165