diff options
author | Robin Cornelius | 2010-10-10 21:53:54 +0100 |
---|---|---|
committer | Robin Cornelius | 2010-10-10 21:53:54 +0100 |
commit | c0034c520c6e61b64822e276316651ec6912bd98 (patch) | |
tree | 910442027b6a2c1406d80ca93949755b54badf5c /linden/indra/llmessage | |
parent | Use all those cores for compile (diff) | |
parent | Thickbrick Sleaford, Soft Linden: STORM-164 make gcc-4.4 happy about llvosky.h (diff) | |
download | meta-impy-c0034c520c6e61b64822e276316651ec6912bd98.zip meta-impy-c0034c520c6e61b64822e276316651ec6912bd98.tar.gz meta-impy-c0034c520c6e61b64822e276316651ec6912bd98.tar.bz2 meta-impy-c0034c520c6e61b64822e276316651ec6912bd98.tar.xz |
Merge branch 'mccabe-plugins' into plugins_merge
Conflicts:
linden/doc/contributions.txt
linden/indra/cmake/GStreamer.cmake
linden/indra/cmake/LLMedia.cmake
linden/indra/cmake/OPENAL.cmake
linden/indra/llmedia/CMakeLists.txt
linden/indra/llprimitive/material_codes.h
linden/indra/newview/chatbar_as_cmdline.cpp
linden/indra/newview/llappviewer.cpp
linden/indra/newview/llfloatertos.cpp
linden/indra/newview/llstartup.cpp
linden/indra/newview/llviewerwindow.cpp
linden/indra/newview/llvoavatar.cpp
linden/indra/newview/pipeline.cpp
linden/indra/newview/pipeline.h
linden/indra/newview/viewer_manifest.py
linden/install.xml
Diffstat (limited to 'linden/indra/llmessage')
-rw-r--r-- | linden/indra/llmessage/tests/commtest.h | 83 | ||||
-rw-r--r-- | linden/indra/llmessage/tests/llcurl_stub.cpp | 100 | ||||
-rw-r--r-- | linden/indra/llmessage/tests/llhttpclientadapter_test.cpp | 170 | ||||
-rw-r--r-- | linden/indra/llmessage/tests/lltemplatemessagedispatcher_test.cpp | 165 | ||||
-rw-r--r-- | linden/indra/llmessage/tests/lltesthttpclientadapter.cpp | 67 | ||||
-rw-r--r-- | linden/indra/llmessage/tests/lltesthttpclientadapter.h | 63 | ||||
-rw-r--r-- | linden/indra/llmessage/tests/lltestmessagesender.cpp | 44 | ||||
-rw-r--r-- | linden/indra/llmessage/tests/lltestmessagesender.h | 57 | ||||
-rw-r--r-- | linden/indra/llmessage/tests/lltrustedmessageservice_test.cpp | 146 | ||||
-rw-r--r-- | linden/indra/llmessage/tests/networkio.h | 116 | ||||
-rw-r--r-- | linden/indra/llmessage/tests/test_llsdmessage_peer.py | 153 |
11 files changed, 1164 insertions, 0 deletions
diff --git a/linden/indra/llmessage/tests/commtest.h b/linden/indra/llmessage/tests/commtest.h new file mode 100644 index 0000000..cf1461e --- /dev/null +++ b/linden/indra/llmessage/tests/commtest.h | |||
@@ -0,0 +1,83 @@ | |||
1 | /** | ||
2 | * @file commtest.h | ||
3 | * @author Nat Goodspeed | ||
4 | * @date 2009-01-09 | ||
5 | * @brief | ||
6 | * | ||
7 | * $LicenseInfo:firstyear=2009&license=viewergpl$ | ||
8 | * | ||
9 | * Copyright (c) 2009, Linden Research, Inc. | ||
10 | * | ||
11 | * Second Life Viewer Source Code | ||
12 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
13 | * to you under the terms of the GNU General Public License, version 2.0 | ||
14 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
15 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
16 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
17 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
18 | * | ||
19 | * There are special exceptions to the terms and conditions of the GPL as | ||
20 | * it is applied to this Source Code. View the full text of the exception | ||
21 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
22 | * online at | ||
23 | * http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
24 | * | ||
25 | * By copying, modifying or distributing this software, you acknowledge | ||
26 | * that you have read and understood your obligations described above, | ||
27 | * and agree to abide by those obligations. | ||
28 | * | ||
29 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
30 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
31 | * COMPLETENESS OR PERFORMANCE. | ||
32 | * $/LicenseInfo$ | ||
33 | */ | ||
34 | |||
35 | #if ! defined(LL_COMMTEST_H) | ||
36 | #define LL_COMMTEST_H | ||
37 | |||
38 | #include "networkio.h" | ||
39 | #include "llevents.h" | ||
40 | #include "llsd.h" | ||
41 | #include "llhost.h" | ||
42 | #include "stringize.h" | ||
43 | #include <string> | ||
44 | |||
45 | /** | ||
46 | * This struct is shared by a couple of standalone comm tests (ADD_COMM_BUILD_TEST). | ||
47 | */ | ||
48 | struct commtest_data | ||
49 | { | ||
50 | NetworkIO& netio; | ||
51 | LLEventPumps& pumps; | ||
52 | LLEventStream replyPump, errorPump; | ||
53 | LLSD result; | ||
54 | bool success; | ||
55 | LLHost host; | ||
56 | std::string server; | ||
57 | |||
58 | commtest_data(): | ||
59 | netio(NetworkIO::instance()), | ||
60 | pumps(LLEventPumps::instance()), | ||
61 | replyPump("reply"), | ||
62 | errorPump("error"), | ||
63 | success(false), | ||
64 | host("127.0.0.1", 8000), | ||
65 | server(STRINGIZE("http://" << host.getString() << "/")) | ||
66 | { | ||
67 | replyPump.listen("self", boost::bind(&commtest_data::outcome, this, _1, true)); | ||
68 | errorPump.listen("self", boost::bind(&commtest_data::outcome, this, _1, false)); | ||
69 | } | ||
70 | |||
71 | bool outcome(const LLSD& _result, bool _success) | ||
72 | { | ||
73 | // std::cout << "commtest_data::outcome(" << _result << ", " << _success << ")\n"; | ||
74 | result = _result; | ||
75 | success = _success; | ||
76 | // Break the wait loop in NetworkIO::pump(), otherwise devs get | ||
77 | // irritated at making the big monolithic test executable take longer | ||
78 | pumps.obtain("done").post(success); | ||
79 | return false; | ||
80 | } | ||
81 | }; | ||
82 | |||
83 | #endif /* ! defined(LL_COMMTEST_H) */ | ||
diff --git a/linden/indra/llmessage/tests/llcurl_stub.cpp b/linden/indra/llmessage/tests/llcurl_stub.cpp new file mode 100644 index 0000000..c73a565 --- /dev/null +++ b/linden/indra/llmessage/tests/llcurl_stub.cpp | |||
@@ -0,0 +1,100 @@ | |||
1 | /** | ||
2 | * @file llcurl_stub.cpp | ||
3 | * @brief stub class to allow unit testing | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2008&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2008-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 "linden_common.h" | ||
34 | #include "llcurl.h" | ||
35 | |||
36 | LLCurl::Responder::Responder() : mReferenceCount(0) | ||
37 | { | ||
38 | } | ||
39 | |||
40 | void LLCurl::Responder::completed(U32 status, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const &reason, | ||
41 | LLSD const& mContent) | ||
42 | { | ||
43 | if (isGoodStatus(status)) | ||
44 | { | ||
45 | result(mContent); | ||
46 | } | ||
47 | else | ||
48 | { | ||
49 | error(status, reason, mContent); | ||
50 | } | ||
51 | } | ||
52 | |||
53 | void LLCurl::Responder::completedHeader(unsigned, | ||
54 | std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, | ||
55 | LLSD const&) | ||
56 | { | ||
57 | } | ||
58 | |||
59 | void LLCurl::Responder::completedRaw(unsigned, | ||
60 | std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, | ||
61 | LLChannelDescriptors const&, | ||
62 | boost::shared_ptr<LLBufferArray> const&) | ||
63 | { | ||
64 | } | ||
65 | |||
66 | void LLCurl::Responder::error(unsigned, | ||
67 | std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, | ||
68 | LLSD const&) | ||
69 | { | ||
70 | } | ||
71 | |||
72 | LLCurl::Responder::~Responder () | ||
73 | { | ||
74 | } | ||
75 | |||
76 | void LLCurl::Responder::error(unsigned, | ||
77 | std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) | ||
78 | { | ||
79 | } | ||
80 | |||
81 | void LLCurl::Responder::result(LLSD const&) | ||
82 | { | ||
83 | } | ||
84 | |||
85 | namespace boost | ||
86 | { | ||
87 | void intrusive_ptr_add_ref(LLCurl::Responder* p) | ||
88 | { | ||
89 | ++p->mReferenceCount; | ||
90 | } | ||
91 | |||
92 | void intrusive_ptr_release(LLCurl::Responder* p) | ||
93 | { | ||
94 | if(p && 0 == --p->mReferenceCount) | ||
95 | { | ||
96 | delete p; | ||
97 | } | ||
98 | } | ||
99 | }; | ||
100 | |||
diff --git a/linden/indra/llmessage/tests/llhttpclientadapter_test.cpp b/linden/indra/llmessage/tests/llhttpclientadapter_test.cpp new file mode 100644 index 0000000..7065c9d --- /dev/null +++ b/linden/indra/llmessage/tests/llhttpclientadapter_test.cpp | |||
@@ -0,0 +1,170 @@ | |||
1 | /** | ||
2 | * @file | ||
3 | * @brief | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2008&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2008-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 "llhttpclientadapter.h" | ||
34 | |||
35 | #include "../test/lltut.h" | ||
36 | #include "llhttpclient.h" | ||
37 | #include "llcurl_stub.cpp" | ||
38 | |||
39 | float const HTTP_REQUEST_EXPIRY_SECS = 1.0F; | ||
40 | |||
41 | std::vector<std::string> get_urls; | ||
42 | std::vector<boost::intrusive_ptr<LLCurl::Responder> > get_responders; | ||
43 | void LLHTTPClient::get(const std::string& url, boost::intrusive_ptr<LLCurl::Responder> responder, const LLSD& headers, const F32 timeout) | ||
44 | { | ||
45 | get_urls.push_back(url); | ||
46 | get_responders.push_back(responder); | ||
47 | } | ||
48 | |||
49 | std::vector<std::string> put_urls; | ||
50 | std::vector<LLSD> put_body; | ||
51 | std::vector<boost::intrusive_ptr<LLCurl::Responder> > put_responders; | ||
52 | |||
53 | void LLHTTPClient::put(const std::string& url, const LLSD& body, boost::intrusive_ptr<LLCurl::Responder> responder, const LLSD& headers, const F32 timeout) | ||
54 | { | ||
55 | put_urls.push_back(url); | ||
56 | put_responders.push_back(responder); | ||
57 | put_body.push_back(body); | ||
58 | |||
59 | } | ||
60 | |||
61 | |||
62 | namespace tut | ||
63 | { | ||
64 | struct LLHTTPClientAdapterData | ||
65 | { | ||
66 | LLHTTPClientAdapterData() | ||
67 | { | ||
68 | get_urls.clear(); | ||
69 | get_responders.clear(); | ||
70 | put_urls.clear(); | ||
71 | put_responders.clear(); | ||
72 | put_body.clear(); | ||
73 | } | ||
74 | }; | ||
75 | |||
76 | typedef test_group<LLHTTPClientAdapterData> factory; | ||
77 | typedef factory::object object; | ||
78 | } | ||
79 | |||
80 | namespace | ||
81 | { | ||
82 | tut::factory tf("LLHTTPClientAdapterData test"); | ||
83 | } | ||
84 | |||
85 | namespace tut | ||
86 | { | ||
87 | // Ensure we can create the object | ||
88 | template<> template<> | ||
89 | void object::test<1>() | ||
90 | { | ||
91 | LLHTTPClientAdapter adapter; | ||
92 | } | ||
93 | |||
94 | // Does the get pass the appropriate arguments to the LLHTTPClient | ||
95 | template<> template<> | ||
96 | void object::test<2>() | ||
97 | { | ||
98 | LLHTTPClientAdapter adapter; | ||
99 | |||
100 | boost::intrusive_ptr<LLCurl::Responder> responder = new LLCurl::Responder(); | ||
101 | |||
102 | adapter.get("Made up URL", responder); | ||
103 | ensure_equals(get_urls.size(), 1); | ||
104 | ensure_equals(get_urls[0], "Made up URL"); | ||
105 | } | ||
106 | |||
107 | // Ensure the responder matches the one passed to get | ||
108 | template<> template<> | ||
109 | void object::test<3>() | ||
110 | { | ||
111 | LLHTTPClientAdapter adapter; | ||
112 | boost::intrusive_ptr<LLCurl::Responder> responder = new LLCurl::Responder(); | ||
113 | |||
114 | adapter.get("Made up URL", responder); | ||
115 | |||
116 | ensure_equals(get_responders.size(), 1); | ||
117 | ensure_equals(get_responders[0].get(), responder.get()); | ||
118 | } | ||
119 | |||
120 | // Ensure the correct url is used in the put | ||
121 | template<> template<> | ||
122 | void object::test<4>() | ||
123 | { | ||
124 | LLHTTPClientAdapter adapter; | ||
125 | |||
126 | boost::intrusive_ptr<LLCurl::Responder> responder = new LLCurl::Responder(); | ||
127 | |||
128 | LLSD body; | ||
129 | body["TestBody"] = "Foobar"; | ||
130 | |||
131 | adapter.put("Made up URL", body, responder); | ||
132 | ensure_equals(put_urls.size(), 1); | ||
133 | ensure_equals(put_urls[0], "Made up URL"); | ||
134 | } | ||
135 | |||
136 | // Ensure the correct responder is used by put | ||
137 | template<> template<> | ||
138 | void object::test<5>() | ||
139 | { | ||
140 | LLHTTPClientAdapter adapter; | ||
141 | |||
142 | boost::intrusive_ptr<LLCurl::Responder> responder = new LLCurl::Responder(); | ||
143 | |||
144 | LLSD body; | ||
145 | body["TestBody"] = "Foobar"; | ||
146 | |||
147 | adapter.put("Made up URL", body, responder); | ||
148 | |||
149 | ensure_equals(put_responders.size(), 1); | ||
150 | ensure_equals(put_responders[0].get(), responder.get()); | ||
151 | } | ||
152 | |||
153 | // Ensure the message body is passed through the put properly | ||
154 | template<> template<> | ||
155 | void object::test<6>() | ||
156 | { | ||
157 | LLHTTPClientAdapter adapter; | ||
158 | |||
159 | boost::intrusive_ptr<LLCurl::Responder> responder = new LLCurl::Responder(); | ||
160 | |||
161 | LLSD body; | ||
162 | body["TestBody"] = "Foobar"; | ||
163 | |||
164 | adapter.put("Made up URL", body, responder); | ||
165 | |||
166 | ensure_equals(put_body.size(), 1); | ||
167 | ensure_equals(put_body[0]["TestBody"].asString(), "Foobar"); | ||
168 | } | ||
169 | } | ||
170 | |||
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 | |||
44 | LLMessageSystem * gMessageSystem = NULL; | ||
45 | |||
46 | // sensor test doubles | ||
47 | bool gClearRecvWasCalled = false; | ||
48 | void LLMessageSystem::clearReceiveState(void) | ||
49 | { | ||
50 | gClearRecvWasCalled = true; | ||
51 | } | ||
52 | |||
53 | char gUdpDispatchedData[MAX_BUFFER_SIZE]; | ||
54 | bool gUdpDispatchWasCalled = false; | ||
55 | BOOL 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 | |||
62 | BOOL gValidateMessage = FALSE; | ||
63 | BOOL LLTemplateMessageReader::validateMessage(const U8*, S32 buffer_size, LLHost const &sender, bool trusted) | ||
64 | { | ||
65 | return gValidateMessage; | ||
66 | } | ||
67 | |||
68 | LLHost host; | ||
69 | const LLHost& LLMessageSystem::getSender() const | ||
70 | { | ||
71 | return host; | ||
72 | } | ||
73 | |||
74 | const char* gBinaryTemplateData = "BINARYTEMPLATEDATA"; | ||
75 | void 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 | |||
81 | namespace 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 | |||
105 | namespace | ||
106 | { | ||
107 | tut::factory tf("LLTemplateMessageDispatcher test"); | ||
108 | } | ||
109 | |||
110 | namespace 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 | |||
diff --git a/linden/indra/llmessage/tests/lltesthttpclientadapter.cpp b/linden/indra/llmessage/tests/lltesthttpclientadapter.cpp new file mode 100644 index 0000000..6361f1c --- /dev/null +++ b/linden/indra/llmessage/tests/lltesthttpclientadapter.cpp | |||
@@ -0,0 +1,67 @@ | |||
1 | /** | ||
2 | * @file | ||
3 | * @brief | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2008&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2008-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 | #include "lltesthttpclientadapter.h" | ||
33 | |||
34 | LLTestHTTPClientAdapter::LLTestHTTPClientAdapter() | ||
35 | { | ||
36 | } | ||
37 | |||
38 | LLTestHTTPClientAdapter::~LLTestHTTPClientAdapter() | ||
39 | { | ||
40 | } | ||
41 | |||
42 | void LLTestHTTPClientAdapter::get(const std::string& url, LLCurl::ResponderPtr responder) | ||
43 | { | ||
44 | mGetUrl.push_back(url); | ||
45 | mGetResponder.push_back(responder); | ||
46 | } | ||
47 | |||
48 | void LLTestHTTPClientAdapter::put(const std::string& url, const LLSD& body, LLCurl::ResponderPtr responder) | ||
49 | { | ||
50 | mPutUrl.push_back(url); | ||
51 | mPutBody.push_back(body); | ||
52 | mPutResponder.push_back(responder); | ||
53 | } | ||
54 | |||
55 | U32 LLTestHTTPClientAdapter::putCalls() const | ||
56 | { | ||
57 | return mPutUrl.size(); | ||
58 | } | ||
59 | |||
60 | void LLTestHTTPClientAdapter::get(const std::string& url, LLCurl::ResponderPtr responder, const LLSD& headers) | ||
61 | { | ||
62 | mGetUrl.push_back(url); | ||
63 | mGetHeaders.push_back(headers); | ||
64 | mGetResponder.push_back(responder); | ||
65 | } | ||
66 | |||
67 | |||
diff --git a/linden/indra/llmessage/tests/lltesthttpclientadapter.h b/linden/indra/llmessage/tests/lltesthttpclientadapter.h new file mode 100644 index 0000000..ac2afa8 --- /dev/null +++ b/linden/indra/llmessage/tests/lltesthttpclientadapter.h | |||
@@ -0,0 +1,63 @@ | |||
1 | /** | ||
2 | * @file | ||
3 | * @brief | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2008&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2008-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 | /* Macro Definitions */ | ||
34 | #ifndef LL_LLTESTHTTPCLIENTADAPTER_H | ||
35 | #define LL_LLTESTHTTPCLIENTADAPTER_H | ||
36 | |||
37 | |||
38 | #include "linden_common.h" | ||
39 | #include "llhttpclientinterface.h" | ||
40 | |||
41 | class LLTestHTTPClientAdapter : public LLHTTPClientInterface | ||
42 | { | ||
43 | public: | ||
44 | LLTestHTTPClientAdapter(); | ||
45 | virtual ~LLTestHTTPClientAdapter(); | ||
46 | virtual void get(const std::string& url, LLCurl::ResponderPtr responder); | ||
47 | virtual void get(const std::string& url, LLCurl::ResponderPtr responder, const LLSD& headers); | ||
48 | |||
49 | virtual void put(const std::string& url, const LLSD& body, LLCurl::ResponderPtr responder); | ||
50 | U32 putCalls() const; | ||
51 | |||
52 | std::vector<LLSD> mPutBody; | ||
53 | std::vector<LLSD> mGetHeaders; | ||
54 | std::vector<std::string> mPutUrl; | ||
55 | std::vector<std::string> mGetUrl; | ||
56 | std::vector<LLCurl::ResponderPtr> mPutResponder; | ||
57 | std::vector<LLCurl::ResponderPtr> mGetResponder; | ||
58 | }; | ||
59 | |||
60 | |||
61 | |||
62 | #endif //LL_LLSIMULATORPRESENCESENDER_H | ||
63 | |||
diff --git a/linden/indra/llmessage/tests/lltestmessagesender.cpp b/linden/indra/llmessage/tests/lltestmessagesender.cpp new file mode 100644 index 0000000..5e8a87f --- /dev/null +++ b/linden/indra/llmessage/tests/lltestmessagesender.cpp | |||
@@ -0,0 +1,44 @@ | |||
1 | /** | ||
2 | * @file | ||
3 | * @brief | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2008&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2008-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 | #include "lltestmessagesender.h" | ||
33 | |||
34 | LLTestMessageSender::~LLTestMessageSender() | ||
35 | { | ||
36 | } | ||
37 | |||
38 | |||
39 | S32 LLTestMessageSender::sendMessage(const LLHost& host, LLStoredMessagePtr message) | ||
40 | { | ||
41 | mSendHosts.push_back(host); | ||
42 | mSendMessages.push_back(message); | ||
43 | return 0; | ||
44 | } | ||
diff --git a/linden/indra/llmessage/tests/lltestmessagesender.h b/linden/indra/llmessage/tests/lltestmessagesender.h new file mode 100644 index 0000000..f57210e --- /dev/null +++ b/linden/indra/llmessage/tests/lltestmessagesender.h | |||
@@ -0,0 +1,57 @@ | |||
1 | /** | ||
2 | * @file | ||
3 | * @brief | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2008&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2008-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 | /* Macro Definitions */ | ||
34 | #ifndef LL_LLTESTMESSAGESENDER_H | ||
35 | #define LL_LLTESTMESSAGESENDER_H | ||
36 | |||
37 | |||
38 | #include "linden_common.h" | ||
39 | #include "llmessagesenderinterface.h" | ||
40 | #include <vector> | ||
41 | |||
42 | |||
43 | |||
44 | class LLTestMessageSender : public LLMessageSenderInterface | ||
45 | { | ||
46 | public: | ||
47 | virtual ~LLTestMessageSender(); | ||
48 | virtual S32 sendMessage(const LLHost& host, LLStoredMessagePtr message); | ||
49 | |||
50 | std::vector<LLHost> mSendHosts; | ||
51 | std::vector<LLStoredMessagePtr> mSendMessages; | ||
52 | }; | ||
53 | |||
54 | |||
55 | |||
56 | #endif //LL_LLTESTMESSAGESENDER_H | ||
57 | |||
diff --git a/linden/indra/llmessage/tests/lltrustedmessageservice_test.cpp b/linden/indra/llmessage/tests/lltrustedmessageservice_test.cpp new file mode 100644 index 0000000..0a3da4b --- /dev/null +++ b/linden/indra/llmessage/tests/lltrustedmessageservice_test.cpp | |||
@@ -0,0 +1,146 @@ | |||
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 "lltrustedmessageservice.h" | ||
34 | #include "../test/lltut.h" | ||
35 | |||
36 | #include "llhost.cpp" // LLHost is a value type for test purposes. | ||
37 | #include "net.cpp" // Needed by LLHost. | ||
38 | |||
39 | #include "message.h" | ||
40 | #include "llmessageconfig.h" | ||
41 | |||
42 | LLMessageSystem* gMessageSystem = NULL; | ||
43 | |||
44 | LLMessageConfig::SenderTrust | ||
45 | LLMessageConfig::getSenderTrustedness(const std::string& msg_name) | ||
46 | { | ||
47 | return LLMessageConfig::NOT_SET; | ||
48 | } | ||
49 | |||
50 | void LLMessageSystem::receivedMessageFromTrustedSender() | ||
51 | { | ||
52 | } | ||
53 | |||
54 | bool LLMessageSystem::isTrustedSender(const LLHost& host) const | ||
55 | { | ||
56 | return false; | ||
57 | } | ||
58 | |||
59 | bool LLMessageSystem::isTrustedMessage(const std::string& name) const | ||
60 | { | ||
61 | return false; | ||
62 | } | ||
63 | |||
64 | bool messageDispatched = false; | ||
65 | bool messageDispatchedAsBinary = false; | ||
66 | LLSD lastLLSD; | ||
67 | std::string lastMessageName; | ||
68 | |||
69 | void LLMessageSystem::dispatch(const std::string& msg_name, | ||
70 | const LLSD& message, | ||
71 | LLHTTPNode::ResponsePtr responsep) | ||
72 | { | ||
73 | messageDispatched = true; | ||
74 | lastLLSD = message; | ||
75 | lastMessageName = msg_name; | ||
76 | } | ||
77 | |||
78 | void LLMessageSystem::dispatchTemplate(const std::string& msg_name, | ||
79 | const LLSD& message, | ||
80 | LLHTTPNode::ResponsePtr responsep) | ||
81 | { | ||
82 | lastLLSD = message; | ||
83 | lastMessageName = msg_name; | ||
84 | messageDispatchedAsBinary = true; | ||
85 | } | ||
86 | |||
87 | namespace tut | ||
88 | { | ||
89 | struct LLTrustedMessageServiceData | ||
90 | { | ||
91 | LLTrustedMessageServiceData() | ||
92 | { | ||
93 | LLSD emptyLLSD; | ||
94 | lastLLSD = emptyLLSD; | ||
95 | lastMessageName = "uninitialised message name"; | ||
96 | messageDispatched = false; | ||
97 | messageDispatchedAsBinary = false; | ||
98 | } | ||
99 | }; | ||
100 | |||
101 | typedef test_group<LLTrustedMessageServiceData> factory; | ||
102 | typedef factory::object object; | ||
103 | } | ||
104 | |||
105 | namespace | ||
106 | { | ||
107 | tut::factory tf("LLTrustedMessageServiceData test"); | ||
108 | } | ||
109 | |||
110 | namespace tut | ||
111 | { | ||
112 | // characterisation tests | ||
113 | |||
114 | // 1) test that messages get forwarded with names etc. as current behaviour (something like LLMessageSystem::dispatch(name, data...) | ||
115 | |||
116 | // test llsd messages are sent as normal using LLMessageSystem::dispatch() (eventually) | ||
117 | template<> template<> | ||
118 | void object::test<1>() | ||
119 | { | ||
120 | LLHTTPNode::ResponsePtr response; | ||
121 | LLSD input; | ||
122 | LLSD context; | ||
123 | LLTrustedMessageService adapter; | ||
124 | adapter.post(response, context, input); | ||
125 | // test original ting got called wit nowt, ya get me blood? | ||
126 | ensure_equals(messageDispatched, true); | ||
127 | ensure(lastLLSD.has("body")); | ||
128 | } | ||
129 | |||
130 | // test that llsd wrapped binary-template-data messages are | ||
131 | // sent via LLMessageSystem::binaryDispatch() or similar | ||
132 | template<> template<> | ||
133 | void object::test<2>() | ||
134 | { | ||
135 | LLHTTPNode::ResponsePtr response; | ||
136 | LLSD input; | ||
137 | input["binary-template-data"] = "10001010110"; //make me a message here. | ||
138 | LLSD context; | ||
139 | LLTrustedMessageService adapter; | ||
140 | |||
141 | adapter.post(response, context, input); | ||
142 | ensure("check template-binary-data message was dispatched as binary", messageDispatchedAsBinary); | ||
143 | ensure_equals(lastLLSD["body"]["binary-template-data"].asString(), "10001010110"); | ||
144 | // test somit got called with "10001010110" (something like LLMessageSystem::dispatchTemplate(blah)) | ||
145 | } | ||
146 | } | ||
diff --git a/linden/indra/llmessage/tests/networkio.h b/linden/indra/llmessage/tests/networkio.h new file mode 100644 index 0000000..0ebe369 --- /dev/null +++ b/linden/indra/llmessage/tests/networkio.h | |||
@@ -0,0 +1,116 @@ | |||
1 | /** | ||
2 | * @file networkio.h | ||
3 | * @author Nat Goodspeed | ||
4 | * @date 2009-01-09 | ||
5 | * @brief | ||
6 | * | ||
7 | * $LicenseInfo:firstyear=2009&license=viewergpl$ | ||
8 | * | ||
9 | * Copyright (c) 2009, Linden Research, Inc. | ||
10 | * | ||
11 | * Second Life Viewer Source Code | ||
12 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
13 | * to you under the terms of the GNU General Public License, version 2.0 | ||
14 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
15 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
16 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
17 | * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
18 | * | ||
19 | * There are special exceptions to the terms and conditions of the GPL as | ||
20 | * it is applied to this Source Code. View the full text of the exception | ||
21 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
22 | * online at | ||
23 | * http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
24 | * | ||
25 | * By copying, modifying or distributing this software, you acknowledge | ||
26 | * that you have read and understood your obligations described above, | ||
27 | * and agree to abide by those obligations. | ||
28 | * | ||
29 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
30 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
31 | * COMPLETENESS OR PERFORMANCE. | ||
32 | * $/LicenseInfo$ | ||
33 | */ | ||
34 | |||
35 | #if ! defined(LL_NETWORKIO_H) | ||
36 | #define LL_NETWORKIO_H | ||
37 | |||
38 | #include "llmemory.h" // LLSingleton | ||
39 | #include "llapr.h" | ||
40 | #include "llares.h" | ||
41 | #include "llpumpio.h" | ||
42 | #include "llhttpclient.h" | ||
43 | |||
44 | /***************************************************************************** | ||
45 | * NetworkIO | ||
46 | *****************************************************************************/ | ||
47 | // Doing this initialization in a class constructor makes sense. But we don't | ||
48 | // want to redo it for each different test. Nor do we want to do it at static- | ||
49 | // init time. Use the lazy, on-demand initialization we get from LLSingleton. | ||
50 | class NetworkIO: public LLSingleton<NetworkIO> | ||
51 | { | ||
52 | public: | ||
53 | NetworkIO(): | ||
54 | mServicePump(NULL), | ||
55 | mDone(false) | ||
56 | { | ||
57 | ll_init_apr(); | ||
58 | if (! gAPRPoolp) | ||
59 | { | ||
60 | throw std::runtime_error("Can't initialize APR"); | ||
61 | } | ||
62 | |||
63 | // Create IO Pump to use for HTTP Requests. | ||
64 | mServicePump = new LLPumpIO(gAPRPoolp); | ||
65 | LLHTTPClient::setPump(*mServicePump); | ||
66 | if (ll_init_ares() == NULL || !gAres->isInitialized()) | ||
67 | { | ||
68 | throw std::runtime_error("Can't start DNS resolver"); | ||
69 | } | ||
70 | |||
71 | // You can interrupt pump() without waiting the full timeout duration | ||
72 | // by posting an event to the LLEventPump named "done". | ||
73 | LLEventPumps::instance().obtain("done").listen("self", | ||
74 | boost::bind(&NetworkIO::done, this, _1)); | ||
75 | } | ||
76 | |||
77 | bool pump(F32 timeout=10) | ||
78 | { | ||
79 | // Reset the done flag so we don't pop out prematurely | ||
80 | mDone = false; | ||
81 | // Evidently the IO structures underlying LLHTTPClient need to be | ||
82 | // "pumped". Do some stuff normally performed in the viewer's main | ||
83 | // loop. | ||
84 | LLTimer timer; | ||
85 | while (timer.getElapsedTimeF32() < timeout) | ||
86 | { | ||
87 | if (mDone) | ||
88 | { | ||
89 | // std::cout << "NetworkIO::pump(" << timeout << "): breaking loop after " | ||
90 | // << timer.getElapsedTimeF32() << " seconds\n"; | ||
91 | return true; | ||
92 | } | ||
93 | pumpOnce(); | ||
94 | } | ||
95 | return false; | ||
96 | } | ||
97 | |||
98 | void pumpOnce() | ||
99 | { | ||
100 | gAres->process(); | ||
101 | mServicePump->pump(); | ||
102 | mServicePump->callback(); | ||
103 | } | ||
104 | |||
105 | bool done(const LLSD&) | ||
106 | { | ||
107 | mDone = true; | ||
108 | return false; | ||
109 | } | ||
110 | |||
111 | private: | ||
112 | LLPumpIO* mServicePump; | ||
113 | bool mDone; | ||
114 | }; | ||
115 | |||
116 | #endif /* ! defined(LL_NETWORKIO_H) */ | ||
diff --git a/linden/indra/llmessage/tests/test_llsdmessage_peer.py b/linden/indra/llmessage/tests/test_llsdmessage_peer.py new file mode 100644 index 0000000..655169d --- /dev/null +++ b/linden/indra/llmessage/tests/test_llsdmessage_peer.py | |||
@@ -0,0 +1,153 @@ | |||
1 | #!/usr/bin/python | ||
2 | """\ | ||
3 | @file test_llsdmessage_peer.py | ||
4 | @author Nat Goodspeed | ||
5 | @date 2008-10-09 | ||
6 | @brief This script asynchronously runs the executable (with args) specified on | ||
7 | the command line, returning its result code. While that executable is | ||
8 | running, we provide dummy local services for use by C++ tests. | ||
9 | |||
10 | $LicenseInfo:firstyear=2008&license=viewergpl$ | ||
11 | |||
12 | Copyright (c) 2008-2009, Linden Research, Inc. | ||
13 | |||
14 | Second Life Viewer Source Code | ||
15 | The source code in this file ("Source Code") is provided by Linden Lab | ||
16 | to you under the terms of the GNU General Public License, version 2.0 | ||
17 | ("GPL"), unless you have obtained a separate licensing agreement | ||
18 | ("Other License"), formally executed by you and Linden Lab. Terms of | ||
19 | the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
20 | online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
21 | |||
22 | There are special exceptions to the terms and conditions of the GPL as | ||
23 | it is applied to this Source Code. View the full text of the exception | ||
24 | in the file doc/FLOSS-exception.txt in this software distribution, or | ||
25 | online at | ||
26 | http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
27 | |||
28 | By copying, modifying or distributing this software, you acknowledge | ||
29 | that you have read and understood your obligations described above, | ||
30 | and agree to abide by those obligations. | ||
31 | |||
32 | ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
33 | WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
34 | COMPLETENESS OR PERFORMANCE. | ||
35 | $/LicenseInfo$ | ||
36 | """ | ||
37 | |||
38 | import os | ||
39 | import sys | ||
40 | from threading import Thread | ||
41 | from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler | ||
42 | mydir = os.path.dirname(__file__) # expected to be .../indra/llmessage/tests/ | ||
43 | sys.path.insert(0, os.path.join(mydir, os.pardir, os.pardir, "lib", "python")) | ||
44 | from indra.util.fastest_elementtree import parse as xml_parse | ||
45 | from indra.base import llsd | ||
46 | |||
47 | def debug(*args): | ||
48 | sys.stdout.writelines(args) | ||
49 | sys.stdout.flush() | ||
50 | # comment out the line below to enable debug output | ||
51 | debug = lambda *args: None | ||
52 | |||
53 | class TestHTTPRequestHandler(BaseHTTPRequestHandler): | ||
54 | """This subclass of BaseHTTPRequestHandler is to receive and echo | ||
55 | LLSD-flavored messages sent by the C++ LLHTTPClient. | ||
56 | """ | ||
57 | def read(self): | ||
58 | # The following logic is adapted from the library module | ||
59 | # SimpleXMLRPCServer.py. | ||
60 | # Get arguments by reading body of request. | ||
61 | # We read this in chunks to avoid straining | ||
62 | # socket.read(); around the 10 or 15Mb mark, some platforms | ||
63 | # begin to have problems (bug #792570). | ||
64 | try: | ||
65 | size_remaining = int(self.headers["content-length"]) | ||
66 | except (KeyError, ValueError): | ||
67 | return "" | ||
68 | max_chunk_size = 10*1024*1024 | ||
69 | L = [] | ||
70 | while size_remaining: | ||
71 | chunk_size = min(size_remaining, max_chunk_size) | ||
72 | chunk = self.rfile.read(chunk_size) | ||
73 | L.append(chunk) | ||
74 | size_remaining -= len(chunk) | ||
75 | return ''.join(L) | ||
76 | # end of swiped read() logic | ||
77 | |||
78 | def read_xml(self): | ||
79 | # This approach reads the entire POST data into memory first | ||
80 | return llsd.parse(self.read()) | ||
81 | ## # This approach attempts to stream in the LLSD XML from self.rfile, | ||
82 | ## # assuming that the underlying XML parser reads its input file | ||
83 | ## # incrementally. Unfortunately I haven't been able to make it work. | ||
84 | ## tree = xml_parse(self.rfile) | ||
85 | ## debug("Finished raw parse\n") | ||
86 | ## debug("parsed XML tree %s\n" % tree) | ||
87 | ## debug("parsed root node %s\n" % tree.getroot()) | ||
88 | ## debug("root node tag %s\n" % tree.getroot().tag) | ||
89 | ## return llsd.to_python(tree.getroot()) | ||
90 | |||
91 | def do_GET(self): | ||
92 | # Of course, don't attempt to read data. | ||
93 | self.answer(dict(reply="success", status=500, | ||
94 | reason="Your GET operation requested failure")) | ||
95 | |||
96 | def do_POST(self): | ||
97 | # Read the provided POST data. | ||
98 | self.answer(self.read_xml()) | ||
99 | |||
100 | def answer(self, data): | ||
101 | if "fail" not in self.path: | ||
102 | response = llsd.format_xml(data.get("reply", llsd.LLSD("success"))) | ||
103 | self.send_response(200) | ||
104 | self.send_header("Content-type", "application/llsd+xml") | ||
105 | self.send_header("Content-Length", str(len(response))) | ||
106 | self.end_headers() | ||
107 | self.wfile.write(response) | ||
108 | else: # fail requested | ||
109 | status = data.get("status", 500) | ||
110 | reason = data.get("reason", | ||
111 | self.responses.get(status, | ||
112 | ("fail requested", | ||
113 | "Your request specified failure status %s " | ||
114 | "without providing a reason" % status))[1]) | ||
115 | self.send_error(status, reason) | ||
116 | |||
117 | def log_request(self, code, size=None): | ||
118 | # For present purposes, we don't want the request splattered onto | ||
119 | # stderr, as it would upset devs watching the test run | ||
120 | pass | ||
121 | |||
122 | def log_error(self, format, *args): | ||
123 | # Suppress error output as well | ||
124 | pass | ||
125 | |||
126 | class TestHTTPServer(Thread): | ||
127 | def run(self): | ||
128 | httpd = HTTPServer(('127.0.0.1', 8000), TestHTTPRequestHandler) | ||
129 | debug("Starting HTTP server...\n") | ||
130 | httpd.serve_forever() | ||
131 | |||
132 | def main(*args): | ||
133 | # Start HTTP server thread. Note that this and all other comm server | ||
134 | # threads should be daemon threads: we'll let them run "forever," | ||
135 | # confident that the whole process will terminate when the main thread | ||
136 | # terminates, which will be when the test executable child process | ||
137 | # terminates. | ||
138 | httpThread = TestHTTPServer(name="httpd") | ||
139 | httpThread.setDaemon(True) | ||
140 | httpThread.start() | ||
141 | # choice of os.spawnv(): | ||
142 | # - [v vs. l] pass a list of args vs. individual arguments, | ||
143 | # - [no p] don't use the PATH because we specifically want to invoke the | ||
144 | # executable passed as our first arg, | ||
145 | # - [no e] child should inherit this process's environment. | ||
146 | debug("Running %s...\n" % (" ".join(args))) | ||
147 | sys.stdout.flush() | ||
148 | rc = os.spawnv(os.P_WAIT, args[0], args) | ||
149 | debug("%s returned %s\n" % (args[0], rc)) | ||
150 | return rc | ||
151 | |||
152 | if __name__ == "__main__": | ||
153 | sys.exit(main(*sys.argv[1:])) | ||