PageRenderTime 13ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/tests/lltrustedmessageservice_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 140 lines | 89 code | 19 blank | 32 comment | 0 complexity | 1944ce92fdaad628e2c5e2b9fdefba82 MD5 | raw file
  1/**
  2 * @file lltrustedmessageservice_test.cpp
  3 * @brief LLTrustedMessageService unit tests
  4 *
  5 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "lltrustedmessageservice.h"
 28#include "../test/lltut.h"
 29
 30#include "llhost.cpp" // LLHost is a value type for test purposes.
 31#include "net.cpp" // Needed by LLHost.
 32
 33#include "message.h"
 34#include "llmessageconfig.h"
 35
 36LLMessageSystem* gMessageSystem = NULL;
 37
 38LLMessageConfig::SenderTrust
 39LLMessageConfig::getSenderTrustedness(const std::string& msg_name)
 40{
 41	return LLMessageConfig::NOT_SET;
 42}
 43
 44void LLMessageSystem::receivedMessageFromTrustedSender()
 45{
 46}
 47
 48bool LLMessageSystem::isTrustedSender(const LLHost& host) const
 49{
 50	return false;
 51}
 52
 53bool LLMessageSystem::isTrustedMessage(const std::string& name) const
 54{
 55	return false;
 56}
 57
 58bool messageDispatched = false;
 59bool messageDispatchedAsBinary = false;
 60LLSD lastLLSD;
 61std::string lastMessageName;
 62
 63void LLMessageSystem::dispatch(const std::string& msg_name,
 64							   const LLSD& message,
 65							   LLHTTPNode::ResponsePtr responsep)
 66{
 67	messageDispatched = true;
 68	lastLLSD = message;
 69	lastMessageName = msg_name;
 70}
 71
 72void LLMessageSystem::dispatchTemplate(const std::string& msg_name,
 73						 const LLSD& message,
 74						 LLHTTPNode::ResponsePtr responsep)
 75{
 76	lastLLSD = message;
 77	lastMessageName = msg_name;
 78	messageDispatchedAsBinary = true;
 79}
 80
 81namespace tut
 82{
 83	    struct LLTrustedMessageServiceData
 84		{
 85			LLTrustedMessageServiceData()
 86			{
 87				LLSD emptyLLSD;
 88				lastLLSD = emptyLLSD;
 89				lastMessageName = "uninitialised message name";
 90				messageDispatched = false;
 91				messageDispatchedAsBinary = false;
 92			}
 93		};
 94
 95	typedef test_group<LLTrustedMessageServiceData> factory;
 96	typedef factory::object object;
 97}
 98
 99namespace
100{
101	tut::factory tf("LLTrustedMessageServiceData");
102}
103
104namespace tut
105{
106	// characterisation tests
107
108	// 1) test that messages get forwarded with names etc. as current behaviour (something like LLMessageSystem::dispatch(name, data...)
109
110	// test llsd messages are sent as normal using LLMessageSystem::dispatch() (eventually)
111	template<> template<>
112	void object::test<1>()
113	{
114		LLHTTPNode::ResponsePtr response;
115		LLSD input;
116		LLSD context;
117		LLTrustedMessageService adapter;
118		adapter.post(response, context, input);
119		// test original ting got called wit nowt, ya get me blood?
120		ensure_equals(messageDispatched, true);
121		ensure(lastLLSD.has("body"));
122	}
123
124	// test that llsd wrapped binary-template-data messages are 
125	// sent via LLMessageSystem::binaryDispatch() or similar
126	template<> template<>
127	void object::test<2>()
128	{
129		LLHTTPNode::ResponsePtr response;
130		LLSD input;
131		input["binary-template-data"] = "10001010110"; //make me a message here.
132		LLSD context;
133		LLTrustedMessageService adapter;
134
135		adapter.post(response, context, input);
136		ensure("check template-binary-data message was dispatched as binary", messageDispatchedAsBinary);
137		ensure_equals(lastLLSD["body"]["binary-template-data"].asString(),  "10001010110");
138		// test somit got called with "10001010110" (something like LLMessageSystem::dispatchTemplate(blah))
139	}
140}