PageRenderTime 86ms CodeModel.GetById 41ms app.highlight 41ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/tests/llslurl_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 260 lines | 186 code | 34 blank | 40 comment | 15 complexity | 6bd68a1f39734eb1e3bf60aa175493b4 MD5 | raw file
  1/** 
  2 * @file llsecapi_test.cpp
  3 * @author Roxie
  4 * @date 2009-02-10
  5 * @brief Test the sec api functionality
  6 *
  7 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28#include "../llviewerprecompiledheaders.h"
 29#include "../llviewernetwork.h"
 30#include "../test/lltut.h"
 31#include "../llslurl.h"
 32#include "../../llxml/llcontrol.h"
 33#include "llsdserialize.h"
 34//----------------------------------------------------------------------------               
 35// Mock objects for the dependencies of the code we're testing                               
 36
 37LLControlGroup::LLControlGroup(const std::string& name)
 38: LLInstanceTracker<LLControlGroup, std::string>(name) {}
 39LLControlGroup::~LLControlGroup() {}
 40BOOL LLControlGroup::declareString(const std::string& name,
 41                                   const std::string& initial_val,
 42                                   const std::string& comment,
 43                                   BOOL persist) {return TRUE;}
 44void LLControlGroup::setString(const std::string& name, const std::string& val){}
 45
 46std::string gCmdLineLoginURI;
 47std::string gCmdLineGridChoice;
 48std::string gCmdLineHelperURI;
 49std::string gLoginPage;
 50std::string gCurrentGrid;
 51std::string LLControlGroup::getString(const std::string& name)
 52{
 53	if (name == "CmdLineGridChoice")
 54		return gCmdLineGridChoice;
 55	else if (name == "CmdLineHelperURI")
 56		return gCmdLineHelperURI;
 57	else if (name == "LoginPage")
 58		return gLoginPage;
 59	else if (name == "CurrentGrid")
 60		return gCurrentGrid;
 61	return "";
 62}
 63
 64LLSD LLControlGroup::getLLSD(const std::string& name)
 65{
 66	if (name == "CmdLineLoginURI")
 67	{
 68		if(!gCmdLineLoginURI.empty())
 69		{
 70			return LLSD(gCmdLineLoginURI);
 71		}
 72	}
 73	return LLSD();
 74}
 75
 76LLPointer<LLControlVariable> LLControlGroup::getControl(const std::string& name)
 77{
 78	ctrl_name_table_t::iterator iter = mNameTable.find(name);
 79	return iter == mNameTable.end() ? LLPointer<LLControlVariable>() : iter->second;
 80}
 81
 82LLControlGroup gSavedSettings("test");
 83
 84// -------------------------------------------------------------------------------------------
 85// TUT
 86// -------------------------------------------------------------------------------------------
 87namespace tut
 88{
 89	// Test wrapper declaration : wrapping nothing for the moment
 90	struct slurlTest
 91	{
 92		slurlTest()
 93		{	
 94			LLGridManager::getInstance()->initialize(std::string(""));
 95		}
 96		~slurlTest()
 97		{
 98		}
 99	};
100	
101	// Tut templating thingamagic: test group, object and test instance
102	typedef test_group<slurlTest> slurlTestFactory;
103	typedef slurlTestFactory::object slurlTestObject;
104	tut::slurlTestFactory tut_test("LLSlurl");
105	
106	// ---------------------------------------------------------------------------------------
107	// Test functions 
108	// ---------------------------------------------------------------------------------------
109	// construction from slurl string
110	template<> template<>
111	void slurlTestObject::test<1>()
112	{
113		LLGridManager::getInstance()->setGridChoice("util.agni.lindenlab.com");
114		
115		LLSLURL slurl = LLSLURL("");
116		ensure_equals("null slurl", (int)slurl.getType(), LLSLURL::LAST_LOCATION);
117		
118		slurl = LLSLURL("http://slurl.com/secondlife/myregion");
119		ensure_equals("slurl.com slurl, region only - type", slurl.getType(), LLSLURL::LOCATION);
120		ensure_equals("slurl.com slurl, region only", slurl.getSLURLString(), 
121					  "http://maps.secondlife.com/secondlife/myregion/128/128/0");
122		
123		slurl = LLSLURL("http://maps.secondlife.com/secondlife/myregion/1/2/3");
124		ensure_equals("maps.secondlife.com slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
125		ensure_equals("maps.secondlife.com slurl, region + coords", slurl.getSLURLString(), 
126					  "http://maps.secondlife.com/secondlife/myregion/1/2/3");
127
128		slurl = LLSLURL("secondlife://myregion");
129		ensure_equals("secondlife: slurl, region only - type", slurl.getType(), LLSLURL::LOCATION);
130		ensure_equals("secondlife: slurl, region only", slurl.getSLURLString(), 
131					  "http://maps.secondlife.com/secondlife/myregion/128/128/0");
132		
133		slurl = LLSLURL("secondlife://myregion/1/2/3");
134		ensure_equals("secondlife: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
135		ensure_equals("secondlife slurl, region + coords", slurl.getSLURLString(), 
136					  "http://maps.secondlife.com/secondlife/myregion/1/2/3");
137		
138		slurl = LLSLURL("/myregion");
139		ensure_equals("/region slurl, region- type", slurl.getType(), LLSLURL::LOCATION);
140		ensure_equals("/region slurl, region ", slurl.getSLURLString(), 
141					  "http://maps.secondlife.com/secondlife/myregion/128/128/0");
142		
143		slurl = LLSLURL("/myregion/1/2/3");
144		ensure_equals("/: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
145		ensure_equals("/ slurl, region + coords", slurl.getSLURLString(), 
146					  "http://maps.secondlife.com/secondlife/myregion/1/2/3");	
147		
148		slurl = LLSLURL("my region/1/2/3");
149		ensure_equals(" slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
150		ensure_equals(" slurl, region + coords", slurl.getSLURLString(), 
151					  "http://maps.secondlife.com/secondlife/my%20region/1/2/3");	
152		
153		LLGridManager::getInstance()->setGridChoice("my.grid.com");		
154		slurl = LLSLURL("https://my.grid.com/region/my%20region/1/2/3");
155		ensure_equals("grid slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
156		ensure_equals("grid slurl, region + coords", slurl.getSLURLString(), 
157					  "https://my.grid.com/region/my%20region/1/2/3");	
158		
159		slurl = LLSLURL("https://my.grid.com/region/my region");
160		ensure_equals("grid slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
161		ensure_equals("grid slurl, region + coords", slurl.getSLURLString(), 
162					  "https://my.grid.com/region/my%20region/128/128/0");
163		
164		LLGridManager::getInstance()->setGridChoice("foo.bar.com");		
165		slurl = LLSLURL("/myregion/1/2/3");
166		ensure_equals("/: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
167		ensure_equals("/ slurl, region + coords", slurl.getSLURLString(), 
168					  "https://foo.bar.com/region/myregion/1/2/3");		
169		
170		slurl = LLSLURL("myregion/1/2/3");
171		ensure_equals(": slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
172		ensure_equals(" slurl, region + coords", slurl.getSLURLString(), 
173					  "https://foo.bar.com/region/myregion/1/2/3");		
174		
175		slurl = LLSLURL(LLSLURL::SIM_LOCATION_HOME);
176		ensure_equals("home", slurl.getType(), LLSLURL::HOME_LOCATION);
177
178		slurl = LLSLURL(LLSLURL::SIM_LOCATION_LAST);
179		ensure_equals("last", slurl.getType(), LLSLURL::LAST_LOCATION);
180		
181		slurl = LLSLURL("secondlife:///app/foo/bar?12345");
182		ensure_equals("app", slurl.getType(), LLSLURL::APP);		
183		ensure_equals("appcmd", slurl.getAppCmd(), "foo");
184		ensure_equals("apppath", slurl.getAppPath().size(), 1);
185		ensure_equals("apppath2", slurl.getAppPath()[0].asString(), "bar");
186		ensure_equals("appquery", slurl.getAppQuery(), "12345");
187		ensure_equals("grid1", "foo.bar.com", slurl.getGrid());
188	
189		slurl = LLSLURL("secondlife://Aditi/app/foo/bar?12345");
190		ensure_equals("app", slurl.getType(), LLSLURL::APP);		
191		ensure_equals("appcmd", slurl.getAppCmd(), "foo");
192		ensure_equals("apppath", slurl.getAppPath().size(), 1);
193		ensure_equals("apppath2", slurl.getAppPath()[0].asString(), "bar");
194		ensure_equals("appquery", slurl.getAppQuery(), "12345");
195		ensure_equals("grid2", "util.aditi.lindenlab.com", slurl.getGrid());		
196
197		LLGridManager::getInstance()->setGridChoice("foo.bar.com");			
198		slurl = LLSLURL("secondlife:///secondlife/myregion/1/2/3");
199		ensure_equals("/: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
200		ensure_equals("location", slurl.getType(), LLSLURL::LOCATION);
201		ensure_equals("region" , "myregion", slurl.getRegion());
202		ensure_equals("grid3", "util.agni.lindenlab.com", slurl.getGrid());
203				
204		slurl = LLSLURL("secondlife://Aditi/secondlife/myregion/1/2/3");
205		ensure_equals("/: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
206		ensure_equals("location", slurl.getType(), LLSLURL::LOCATION);
207		ensure_equals("region" , "myregion", slurl.getRegion());
208		ensure_equals("grid4", "util.aditi.lindenlab.com", slurl.getGrid());		
209		
210		LLGridManager::getInstance()->setGridChoice("my.grid.com");
211		slurl = LLSLURL("https://my.grid.com/app/foo/bar?12345");
212		ensure_equals("app", slurl.getType(), LLSLURL::APP);		
213		ensure_equals("appcmd", slurl.getAppCmd(), "foo");
214		ensure_equals("apppath", slurl.getAppPath().size(), 1);
215		ensure_equals("apppath2", slurl.getAppPath()[0].asString(), "bar");
216		ensure_equals("appquery", slurl.getAppQuery(), "12345");	
217		
218	}
219	
220	// construction from grid/region/vector combos
221	template<> template<>
222	void slurlTestObject::test<2>()
223	{
224		LLSLURL slurl = LLSLURL("mygrid.com", "my region");
225		ensure_equals("grid/region - type", slurl.getType(), LLSLURL::LOCATION);
226		ensure_equals("grid/region", slurl.getSLURLString(), 
227					  "https://mygrid.com/region/my%20region/128/128/0");	
228		
229		slurl = LLSLURL("mygrid.com", "my region", LLVector3(1,2,3));
230		ensure_equals("grid/region/vector - type", slurl.getType(), LLSLURL::LOCATION);
231		ensure_equals(" grid/region/vector", slurl.getSLURLString(), 
232					  "https://mygrid.com/region/my%20region/1/2/3");			
233
234		LLGridManager::getInstance()->setGridChoice("foo.bar.com.bar");			
235		slurl = LLSLURL("my region", LLVector3(1,2,3));
236		ensure_equals("grid/region/vector - type", slurl.getType(), LLSLURL::LOCATION);
237		ensure_equals(" grid/region/vector", slurl.getSLURLString(), 
238					  "https://foo.bar.com.bar/region/my%20region/1/2/3");	
239		
240		LLGridManager::getInstance()->setGridChoice("util.agni.lindenlab.com");	
241		slurl = LLSLURL("my region", LLVector3(1,2,3));
242		ensure_equals("default grid/region/vector - type", slurl.getType(), LLSLURL::LOCATION);
243		ensure_equals(" default grid/region/vector", slurl.getSLURLString(), 
244					  "http://maps.secondlife.com/secondlife/my%20region/1/2/3");	
245		
246	}
247	// Accessors
248	template<> template<>
249	void slurlTestObject::test<3>()
250	{
251		LLGridManager::getInstance()->setGridChoice("my.grid.com");		
252		LLSLURL slurl = LLSLURL("https://my.grid.com/region/my%20region/1/2/3");
253		ensure_equals("login string", slurl.getLoginString(), "uri:my region&amp;1&amp;2&amp;3");
254		ensure_equals("location string", slurl.getLocationString(), "my region/1/2/3");
255		ensure_equals("grid", slurl.getGrid(), "my.grid.com");
256		ensure_equals("region", slurl.getRegion(), "my region");
257		ensure_equals("position", slurl.getPosition(), LLVector3(1, 2, 3));
258		
259	}
260}