PageRenderTime 52ms CodeModel.GetById 13ms app.highlight 34ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/test/llservicebuilder_tut.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 173 lines | 126 code | 17 blank | 30 comment | 0 complexity | 9d6a420f66c28397e3b1dc38a959a49f MD5 | raw file
  1/**
  2* @file   llservicebuilder_tut.cpp
  3* @brief  LLServiceBuilder unit tests
  4* @date   March 2007
  5*
  6* $LicenseInfo:firstyear=2006&license=viewerlgpl$
  7* Second Life Viewer Source Code
  8* Copyright (C) 2010, Linden Research, Inc.
  9* 
 10* This library is free software; you can redistribute it and/or
 11* modify it under the terms of the GNU Lesser General Public
 12* License as published by the Free Software Foundation;
 13* version 2.1 of the License only.
 14* 
 15* This library is distributed in the hope that it will be useful,
 16* but WITHOUT ANY WARRANTY; without even the implied warranty of
 17* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18* Lesser General Public License for more details.
 19* 
 20* You should have received a copy of the GNU Lesser General Public
 21* License along with this library; if not, write to the Free Software
 22* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23* 
 24* Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25* $/LicenseInfo$
 26*/
 27
 28#include <tut/tut.hpp>
 29
 30#include "linden_common.h"
 31#include "lltut.h"
 32#include "llsd.h"
 33#include "llservicebuilder.h"
 34
 35namespace tut
 36{
 37
 38	struct ServiceBuilderTestData {
 39		LLServiceBuilder mServiceBuilder;
 40	};
 41
 42	typedef test_group<ServiceBuilderTestData>	ServiceBuilderTestGroup;
 43	typedef ServiceBuilderTestGroup::object	ServiceBuilderTestObject;
 44
 45	ServiceBuilderTestGroup serviceBuilderTestGroup("ServiceBuilder");
 46
 47	template<> template<>
 48	void ServiceBuilderTestObject::test<1>()
 49	{
 50		//Simple service build and reply with no mapping
 51		LLSD test_block;
 52		test_block["service-builder"] = "/agent/name";
 53		mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]);
 54		std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest");
 55		ensure_equals("Basic URL Creation", test_url , "/agent/name");
 56	}	
 57
 58	template<> template<>
 59	void ServiceBuilderTestObject::test<2>()
 60	{
 61		//Simple replace test
 62		LLSD test_block;
 63		test_block["service-builder"] = "/agent/{$agent-id}/name";
 64		mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]);	
 65		LLSD data_map;
 66		data_map["agent-id"] = "257c631f-a0c5-4f29-8a9f-9031feaae6c6";
 67		std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest", data_map);
 68		ensure_equals("Replacement URL Creation", test_url , "/agent/257c631f-a0c5-4f29-8a9f-9031feaae6c6/name");
 69	}	
 70
 71	template<> template<>
 72	void ServiceBuilderTestObject::test<3>()
 73	{
 74		//Incorrect service test
 75		LLSD test_block;
 76		test_block["service-builder"] = "/agent/{$agent-id}/name";
 77		mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]);	
 78		std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilder");
 79		ensure_equals("Replacement URL Creation for Non-existant Service", test_url , "");
 80	}
 81
 82	template<> template<>
 83	void ServiceBuilderTestObject::test<4>()
 84	{
 85		//Incorrect service test
 86		LLSD test_block;
 87		test_block["service-builder"] = "/agent/{$agent-id}/name";
 88		mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]);
 89		LLSD data_map;
 90		data_map["agent_id"] = "257c631f-a0c5-4f29-8a9f-9031feaae6c6";
 91		std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest", data_map);
 92		ensure_equals("Replacement URL Creation for Non-existant Service", test_url , "/agent/{$agent-id}/name");
 93	}
 94
 95	template<> template<>
 96	void ServiceBuilderTestObject::test<5>()
 97	{
 98		LLSD test_block;
 99		test_block["service-builder"] = "/proc/{$proc}{%params}";
100		mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]);	
101		LLSD data_map;
102		data_map["proc"] = "do/something/useful";
103		data_map["params"]["estate_id"] = 1;
104		data_map["params"]["query"] = "public";
105		std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest", data_map);
106		ensure_equals(
107			"two part URL Creation",
108			test_url ,
109			"/proc/do/something/useful?estate_id=1&query=public");
110	}
111
112	template<> template<>
113	void ServiceBuilderTestObject::test<6>()
114	{
115		LLSD test_block;
116		test_block["service-builder"] = "Which way to the {${$baz}}?";
117		mServiceBuilder.createServiceDefinition(
118			"ServiceBuilderTest",
119			test_block["service-builder"]);	
120
121		LLSD data_map;
122		data_map["foo"] = "bar";
123		data_map["baz"] = "foo";
124		std::string test_url = mServiceBuilder.buildServiceURI(
125			"ServiceBuilderTest",
126			data_map);
127		ensure_equals(
128			"recursive url creation",
129			test_url ,
130			"Which way to the bar?");
131	}
132
133	template<> template<>
134	void ServiceBuilderTestObject::test<7>()
135	{
136		LLSD test_block;
137		test_block["service-builder"] = "Which way to the {$foo}?";
138		mServiceBuilder.createServiceDefinition(
139			"ServiceBuilderTest",
140			test_block["service-builder"]);	
141
142		LLSD data_map;
143		data_map["baz"] = "foo";
144		std::string test_url = mServiceBuilder.buildServiceURI(
145			"ServiceBuilderTest",
146			data_map);
147		ensure_equals(
148			"fails to do replacement",
149			test_url ,
150			"Which way to the {$foo}?");
151	}
152
153	template<> template<>
154	void ServiceBuilderTestObject::test<8>()
155	{
156		LLSD test_block;
157		test_block["service-builder"] = "/proc/{$proc}{%params}";
158		mServiceBuilder.createServiceDefinition(
159			"ServiceBuilderTest",
160			test_block["service-builder"]);	
161		LLSD data_map;
162		data_map["proc"] = "do/something/useful";
163		data_map["params"] = LLSD();
164		std::string test_url = mServiceBuilder.buildServiceURI(
165			"ServiceBuilderTest",
166			data_map);
167		ensure_equals(
168			"strip params",
169			test_url ,
170			"/proc/do/something/useful");
171	}
172}
173