PageRenderTime 96ms CodeModel.GetById 14ms app.highlight 75ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/tests/llviewernetwork_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 581 lines | 465 code | 40 blank | 76 comment | 16 complexity | e3d02ee56dba483b13bb56a534b11bcf MD5 | raw file
  1/** 
  2 * @file llviewernetwork_test.cpp
  3 * @author Roxie
  4 * @date 2009-03-9
  5 * @brief Test the viewernetwork 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 "../../llxml/llcontrol.h"
 32#include "llfile.h"
 33
 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
 84const char *gSampleGridFile = "<llsd><map>"
 85"<key>grid1</key><map>"
 86"  <key>favorite</key><integer>1</integer>"
 87"  <key>helper_uri</key><string>https://helper1/helpers/</string>"
 88"  <key>label</key><string>mylabel</string>"
 89"  <key>login_page</key><string>loginpage</string>"
 90"  <key>login_uri</key><array><string>myloginuri</string></array>"
 91"  <key>name</key><string>grid1</string>"
 92"  <key>visible</key><integer>1</integer>"
 93"  <key>credential_type</key><string>agent</string>"
 94"  <key>grid_login_id</key><string>MyGrid</string>"
 95"</map>"
 96"<key>util.agni.lindenlab.com</key><map>"
 97"  <key>favorite</key><integer>1</integer>"
 98"  <key>helper_uri</key><string>https://helper1/helpers/</string>"
 99"  <key>label</key><string>mylabel</string>"
100"  <key>login_page</key><string>loginpage</string>"
101"  <key>login_uri</key><array><string>myloginuri</string></array>"
102"  <key>name</key><string>util.agni.lindenlab.com</string>"
103"</map></map></llsd>";
104// -------------------------------------------------------------------------------------------
105// TUT
106// -------------------------------------------------------------------------------------------
107namespace tut
108{
109  // Test wrapper declaration : wrapping nothing for the moment
110  struct viewerNetworkTest
111	{
112		viewerNetworkTest()
113		{
114			LLFile::remove("grid_test.xml");
115			gCmdLineLoginURI.clear();
116			gCmdLineGridChoice.clear();
117			gCmdLineHelperURI.clear();
118			gLoginPage.clear();
119			gCurrentGrid.clear();			
120		}
121		~viewerNetworkTest()
122		{
123			LLFile::remove("grid_test.xml");
124		}
125	};
126	
127	// Tut templating thingamagic: test group, object and test instance
128	typedef test_group<viewerNetworkTest> viewerNetworkTestFactory;
129	typedef viewerNetworkTestFactory::object viewerNetworkTestObject;
130	tut::viewerNetworkTestFactory tut_test("LLViewerNetwork");
131	
132	// ---------------------------------------------------------------------------------------
133	// Test functions 
134	// ---------------------------------------------------------------------------------------
135	// initialization without a grid file
136	template<> template<>
137	void viewerNetworkTestObject::test<1>()
138	{
139
140		LLGridManager *manager = LLGridManager::getInstance();
141		// grid file doesn't exist
142		manager->initialize("grid_test.xml");
143		// validate that some of the defaults are available.
144		std::map<std::string, std::string> known_grids = manager->getKnownGrids();
145		ensure_equals("Known grids is a string-string map of size 23", known_grids.size(), 23);
146		ensure_equals("Agni has the right name and label", 
147					  known_grids[std::string("util.agni.lindenlab.com")], std::string("Agni"));
148		ensure_equals("None exists", known_grids[""], "None");
149		
150		LLSD grid;
151		LLGridManager::getInstance()->getGridInfo("util.agni.lindenlab.com", grid);
152		ensure("Grid info for agni is a map", grid.isMap());
153		ensure_equals("name is correct for agni", 
154					  grid[GRID_VALUE].asString(), std::string("util.agni.lindenlab.com"));
155		ensure_equals("label is correct for agni", 
156					  grid[GRID_LABEL_VALUE].asString(), std::string("Agni"));
157		ensure("Login URI is an array", 
158			   grid[GRID_LOGIN_URI_VALUE].isArray());
159		ensure_equals("Agni login uri is correct", 
160					  grid[GRID_LOGIN_URI_VALUE][0].asString(), 
161					  std::string("https://login.agni.lindenlab.com/cgi-bin/login.cgi"));
162		ensure_equals("Agni helper uri is correct",
163					  grid[GRID_HELPER_URI_VALUE].asString(), 
164					  std::string("https://secondlife.com/helpers/"));
165		ensure_equals("Agni login page is correct",
166					  grid[GRID_LOGIN_PAGE_VALUE].asString(), 
167					  std::string("http://viewer-login.agni.lindenlab.com/"));
168		ensure("Agni is a favorite",
169			   grid.has(GRID_IS_FAVORITE_VALUE));
170		ensure("Agni is a system grid", 
171			   grid.has(GRID_IS_SYSTEM_GRID_VALUE));
172		ensure("Grid file wasn't greated as it wasn't saved", 
173			   !LLFile::isfile("grid_test.xml"));
174	}
175	
176	// initialization with a grid file
177	template<> template<>
178	void viewerNetworkTestObject::test<2>()
179	{
180		llofstream gridfile("grid_test.xml");
181		gridfile << gSampleGridFile;
182		gridfile.close();
183		
184		LLGridManager::getInstance()->initialize("grid_test.xml");
185		std::map<std::string, std::string> known_grids = LLGridManager::getInstance()->getKnownGrids();
186		ensure_equals("adding a grid via a grid file increases known grid size", 
187					  known_grids.size(), 24);
188		ensure_equals("Agni is still there after we've added a grid via a grid file", 
189					  known_grids["util.agni.lindenlab.com"], std::string("Agni"));
190	
191		
192		// assure Agni doesn't get overwritten
193		LLSD grid;
194		LLGridManager::getInstance()->getGridInfo("util.agni.lindenlab.com", grid);
195
196		ensure_equals("Agni grid label was not modified by grid file", 
197					  grid[GRID_LABEL_VALUE].asString(), std::string("Agni"));
198		
199		ensure_equals("Agni name wasn't modified by grid file",
200					  grid[GRID_VALUE].asString(), std::string("util.agni.lindenlab.com"));
201		ensure("Agni grid URI is still an array after grid file", 
202			   grid[GRID_LOGIN_URI_VALUE].isArray());
203		ensure_equals("Agni login uri still the same after grid file", 
204					  grid[GRID_LOGIN_URI_VALUE][0].asString(),  
205					  std::string("https://login.agni.lindenlab.com/cgi-bin/login.cgi"));
206		ensure_equals("Agni helper uri still the same after grid file", 
207					  grid[GRID_HELPER_URI_VALUE].asString(), 
208					  std::string("https://secondlife.com/helpers/"));
209		ensure_equals("Agni login page the same after grid file", 
210					  grid[GRID_LOGIN_PAGE_VALUE].asString(), 
211					  std::string("http://viewer-login.agni.lindenlab.com/"));
212		ensure("Agni still a favorite after grid file", 
213			   grid.has(GRID_IS_FAVORITE_VALUE));
214		ensure("Agni system grid still set after grid file", 
215			   grid.has(GRID_IS_SYSTEM_GRID_VALUE));
216		
217		ensure_equals("Grid file adds to name<->label map", 
218					  known_grids["grid1"], std::string("mylabel"));
219		LLGridManager::getInstance()->getGridInfo("grid1", grid);
220		ensure_equals("grid file grid name is set",
221					  grid[GRID_VALUE].asString(), std::string("grid1"));
222		ensure_equals("grid file label is set", 
223					  grid[GRID_LABEL_VALUE].asString(), std::string("mylabel"));
224		ensure("grid file login uri is an array",
225			   grid[GRID_LOGIN_URI_VALUE].isArray());
226		ensure_equals("grid file login uri is set",
227					  grid[GRID_LOGIN_URI_VALUE][0].asString(), 
228					  std::string("myloginuri"));
229		ensure_equals("grid file helper uri is set",
230					  grid[GRID_HELPER_URI_VALUE].asString(), 
231					  std::string("https://helper1/helpers/"));
232		ensure_equals("grid file login page is set",
233					  grid[GRID_LOGIN_PAGE_VALUE].asString(), 
234					  std::string("loginpage"));
235		ensure("grid file favorite is set",
236			   grid.has(GRID_IS_FAVORITE_VALUE));
237		ensure("grid file isn't a system grid",
238			   !grid.has(GRID_IS_SYSTEM_GRID_VALUE));		
239		ensure("Grid file still exists after loading", 
240			   LLFile::isfile("grid_test.xml"));
241	}
242	
243	// Initialize via command line
244	
245	template<> template<>
246	void viewerNetworkTestObject::test<3>()
247	{	
248		// USE --grid command line
249		// initialize with a known grid
250		LLSD grid;
251		gCmdLineGridChoice = "Aditi";
252		LLGridManager::getInstance()->initialize("grid_test.xml");
253		// with single login uri specified.
254		std::map<std::string, std::string> known_grids = LLGridManager::getInstance()->getKnownGrids();
255		ensure_equals("Using a known grid via command line doesn't increase number of known grids", 
256					  known_grids.size(), 23);
257		ensure_equals("getGridLabel", LLGridManager::getInstance()->getGridLabel(), std::string("Aditi"));
258		// initialize with a known grid in lowercase
259		gCmdLineGridChoice = "agni";
260		LLGridManager::getInstance()->initialize("grid_test.xml");
261		ensure_equals("getGridLabel", LLGridManager::getInstance()->getGridLabel(), std::string("Agni"));		
262		
263		// now try a command line with a custom grid identifier
264		gCmdLineGridChoice = "mycustomgridchoice";		
265		LLGridManager::getInstance()->initialize("grid_test.xml");
266		known_grids = LLGridManager::getInstance()->getKnownGrids();
267		ensure_equals("adding a command line grid with custom name increases known grid size", 
268					  known_grids.size(), 24);
269		ensure_equals("Custom Command line grid is added to the list of grids", 
270					  known_grids["mycustomgridchoice"], std::string("mycustomgridchoice"));
271		LLGridManager::getInstance()->getGridInfo("mycustomgridchoice", grid);
272		ensure_equals("Custom Command line grid name is set",
273					  grid[GRID_VALUE].asString(), std::string("mycustomgridchoice"));
274		ensure_equals("Custom Command line grid label is set", 
275					  grid[GRID_LABEL_VALUE].asString(), std::string("mycustomgridchoice"));		
276		ensure("Custom Command line grid login uri is an array",
277			   grid[GRID_LOGIN_URI_VALUE].isArray());
278		ensure_equals("Custom Command line grid login uri is set",
279					  grid[GRID_LOGIN_URI_VALUE][0].asString(), 
280					  std::string("https://mycustomgridchoice/cgi-bin/login.cgi"));
281		ensure_equals("Custom Command line grid helper uri is set",
282					  grid[GRID_HELPER_URI_VALUE].asString(), 
283					  std::string("https://mycustomgridchoice/helpers/"));
284		ensure_equals("Custom Command line grid login page is set",
285					  grid[GRID_LOGIN_PAGE_VALUE].asString(), 
286					  std::string("http://mycustomgridchoice/app/login/"));
287	}
288	
289	// validate override of login uri with cmd line
290	template<> template<>
291	void viewerNetworkTestObject::test<4>()
292	{			
293		// Override with loginuri
294		// override known grid
295		LLSD grid;
296		gCmdLineGridChoice = "Aditi";
297		gCmdLineLoginURI = "https://my.login.uri/cgi-bin/login.cgi";		
298		LLGridManager::getInstance()->initialize("grid_test.xml");		
299		std::map<std::string, std::string> known_grids = LLGridManager::getInstance()->getKnownGrids();		
300		ensure_equals("Override known grid login uri: No grids are added", 
301					  known_grids.size(), 23);
302		LLGridManager::getInstance()->getGridInfo(grid);
303		ensure("Override known grid login uri: login uri is an array",
304			   grid[GRID_LOGIN_URI_VALUE].isArray());
305		ensure_equals("Override known grid login uri: Command line grid login uri is set",
306					  grid[GRID_LOGIN_URI_VALUE][0].asString(), 
307					  std::string("https://my.login.uri/cgi-bin/login.cgi"));
308		ensure_equals("Override known grid login uri: helper uri is not changed",
309					  grid[GRID_HELPER_URI_VALUE].asString(), 
310					  std::string("http://aditi-secondlife.webdev.lindenlab.com/helpers/"));
311		ensure_equals("Override known grid login uri: login page is not set",
312					  grid[GRID_LOGIN_PAGE_VALUE].asString(), 
313					  std::string("http://viewer-login.agni.lindenlab.com/"));		
314		
315		// Override with loginuri
316		// override custom grid
317		gCmdLineGridChoice = "mycustomgridchoice";
318		gCmdLineLoginURI = "https://my.login.uri/cgi-bin/login.cgi";		
319		LLGridManager::getInstance()->initialize("grid_test.xml");		
320		known_grids = LLGridManager::getInstance()->getKnownGrids();
321		LLGridManager::getInstance()->getGridInfo(grid);
322		ensure_equals("Override custom grid login uri: Grid is added", 
323					  known_grids.size(), 24);		
324		ensure("Override custom grid login uri: login uri is an array",
325			   grid[GRID_LOGIN_URI_VALUE].isArray());
326		ensure_equals("Override custom grid login uri: login uri is set",
327					  grid[GRID_LOGIN_URI_VALUE][0].asString(), 
328					  std::string("https://my.login.uri/cgi-bin/login.cgi"));
329		ensure_equals("Override custom grid login uri: Helper uri is not set",
330					  grid[GRID_HELPER_URI_VALUE].asString(), 
331					  std::string("https://mycustomgridchoice/helpers/"));
332		ensure_equals("Override custom grid login uri: Login page is not set",
333					  grid[GRID_LOGIN_PAGE_VALUE].asString(), 
334					  std::string("http://mycustomgridchoice/app/login/"));
335	}
336	
337	// validate override of helper uri with cmd line
338	template<> template<>
339	void viewerNetworkTestObject::test<5>()
340	{	
341		// Override with helperuri
342		// override known grid
343		LLSD grid;
344		gCmdLineGridChoice = "Aditi";
345		gCmdLineLoginURI = "";
346		gCmdLineHelperURI = "https://my.helper.uri/mycustomhelpers";		
347		LLGridManager::getInstance()->initialize("grid_test.xml");		
348		std::map<std::string, std::string> known_grids = LLGridManager::getInstance()->getKnownGrids();		
349		ensure_equals("Override known grid helper uri: No grids are added", 
350					  known_grids.size(), 23);
351		LLGridManager::getInstance()->getGridInfo(grid);
352		ensure("Override known known helper uri: login uri is an array",
353			   grid[GRID_LOGIN_URI_VALUE].isArray());
354		ensure_equals("Override known grid helper uri: login uri is not changed",
355					  grid[GRID_LOGIN_URI_VALUE][0].asString(), 
356					  std::string("https://login.aditi.lindenlab.com/cgi-bin/login.cgi"));
357		ensure_equals("Override known grid helper uri: helper uri is changed",
358					  grid[GRID_HELPER_URI_VALUE].asString(), 
359					  std::string("https://my.helper.uri/mycustomhelpers"));
360		ensure_equals("Override known grid helper uri: login page is not changed",
361					  grid[GRID_LOGIN_PAGE_VALUE].asString(), 
362					  std::string("http://viewer-login.agni.lindenlab.com/"));		
363		
364		// Override with helperuri
365		// override custom grid
366		gCmdLineGridChoice = "mycustomgridchoice";
367		gCmdLineHelperURI = "https://my.helper.uri/mycustomhelpers";		
368		LLGridManager::getInstance()->initialize("grid_test.xml");	
369		known_grids = LLGridManager::getInstance()->getKnownGrids();
370		ensure_equals("Override custom grid helper uri: grids is added", 
371					  known_grids.size(), 24);
372		LLGridManager::getInstance()->getGridInfo(grid);
373		ensure("Override custom helper uri: login uri is an array",
374			   grid[GRID_LOGIN_URI_VALUE].isArray());
375		ensure_equals("Override custom grid helper uri: login uri is not changed",
376					  grid[GRID_LOGIN_URI_VALUE][0].asString(), 
377					  std::string("https://mycustomgridchoice/cgi-bin/login.cgi"));
378		ensure_equals("Override custom grid helper uri: helper uri is changed",
379					  grid[GRID_HELPER_URI_VALUE].asString(), 
380					  std::string("https://my.helper.uri/mycustomhelpers"));
381		ensure_equals("Override custom grid helper uri: login page is not changed",
382					  grid[GRID_LOGIN_PAGE_VALUE].asString(), 
383					  std::string("http://mycustomgridchoice/app/login/"));
384	}
385	
386	// validate overriding of login page via cmd line
387	template<> template<>
388	void viewerNetworkTestObject::test<6>()
389	{	
390		// Override with login page
391		// override known grid
392		LLSD grid;
393		gCmdLineGridChoice = "Aditi";
394		gCmdLineHelperURI = "";
395		gLoginPage = "myloginpage";		
396		LLGridManager::getInstance()->initialize("grid_test.xml");		
397		std::map<std::string, std::string> known_grids = LLGridManager::getInstance()->getKnownGrids();				
398		ensure_equals("Override known grid login page: No grids are added", 
399					  known_grids.size(), 23);
400		LLGridManager::getInstance()->getGridInfo(grid);
401		ensure("Override known grid login page: Command line grid login uri is an array",
402			   grid[GRID_LOGIN_URI_VALUE].isArray());
403		ensure_equals("Override known grid login page: login uri is not changed",
404					  grid[GRID_LOGIN_URI_VALUE][0].asString(), 
405					  std::string("https://login.aditi.lindenlab.com/cgi-bin/login.cgi"));
406		ensure_equals("Override known grid login page: helper uri is not changed",
407					  grid[GRID_HELPER_URI_VALUE].asString(), 
408					  std::string("http://aditi-secondlife.webdev.lindenlab.com/helpers/"));
409		ensure_equals("Override known grid login page: login page is changed",
410					  grid[GRID_LOGIN_PAGE_VALUE].asString(), 
411					  std::string("myloginpage"));		
412		
413		// Override with login page
414		// override custom grid
415		gCmdLineGridChoice = "mycustomgridchoice";
416		gLoginPage = "myloginpage";
417		LLGridManager::getInstance()->initialize("grid_test.xml");		
418		known_grids = LLGridManager::getInstance()->getKnownGrids();
419		ensure_equals("Override custom grid login page: grids are added", 
420					  known_grids.size(), 24);
421		LLGridManager::getInstance()->getGridInfo(grid);
422		ensure("Override custom grid login page: Command line grid login uri is an array",
423			   grid[GRID_LOGIN_URI_VALUE].isArray());
424		ensure_equals("Override custom grid login page: login uri is not changed",
425					  grid[GRID_LOGIN_URI_VALUE][0].asString(), 
426					  std::string("https://mycustomgridchoice/cgi-bin/login.cgi"));
427		ensure_equals("Override custom grid login page: helper uri is not changed",
428					  grid[GRID_HELPER_URI_VALUE].asString(), 
429					  std::string("https://mycustomgridchoice/helpers/"));
430		ensure_equals("Override custom grid login page: login page is changed",
431					  grid[GRID_LOGIN_PAGE_VALUE].asString(), 
432					  std::string("myloginpage"));	
433		
434	}
435	
436	// validate grid selection
437	template<> template<>
438	void viewerNetworkTestObject::test<7>()
439	{	
440		LLSD loginURI = LLSD::emptyArray();
441		LLSD grid = LLSD::emptyMap();
442		// adding a grid with simply a name will populate the values.
443		grid[GRID_VALUE] = "myaddedgrid";
444
445		LLGridManager::getInstance()->initialize("grid_test.xml");
446		LLGridManager::getInstance()->addGrid(grid);
447		LLGridManager::getInstance()->setGridChoice("util.agni.lindenlab.com");	
448		ensure_equals("getGridLabel", LLGridManager::getInstance()->getGridLabel(), std::string("Agni"));
449		ensure_equals("getGrid", LLGridManager::getInstance()->getGrid(), 
450					  std::string("util.agni.lindenlab.com"));
451		ensure_equals("getHelperURI", LLGridManager::getInstance()->getHelperURI(), 
452					  std::string("https://secondlife.com/helpers/"));
453		ensure_equals("getLoginPage", LLGridManager::getInstance()->getLoginPage(), 
454					  std::string("http://viewer-login.agni.lindenlab.com/"));
455		ensure_equals("getLoginPage2", LLGridManager::getInstance()->getLoginPage("util.agni.lindenlab.com"), 
456					  std::string("http://viewer-login.agni.lindenlab.com/"));
457		ensure("Is Agni a production grid", LLGridManager::getInstance()->isInProductionGrid());		
458		std::vector<std::string> uris;
459		LLGridManager::getInstance()->getLoginURIs(uris);
460		ensure_equals("getLoginURIs size", uris.size(), 1);
461		ensure_equals("getLoginURIs", uris[0], 
462					  std::string("https://login.agni.lindenlab.com/cgi-bin/login.cgi"));
463		LLGridManager::getInstance()->setGridChoice("myaddedgrid");
464		ensure_equals("getGridLabel", LLGridManager::getInstance()->getGridLabel(), std::string("myaddedgrid"));		
465		ensure("Is myaddedgrid a production grid", !LLGridManager::getInstance()->isInProductionGrid());
466		
467		LLGridManager::getInstance()->setFavorite();
468		LLGridManager::getInstance()->getGridInfo("myaddedgrid", grid);
469		ensure("setting favorite", grid.has(GRID_IS_FAVORITE_VALUE));
470	}
471	
472	// name based grid population
473	template<> template<>
474	void viewerNetworkTestObject::test<8>()
475	{
476		LLGridManager::getInstance()->initialize("grid_test.xml");
477		LLSD grid = LLSD::emptyMap();
478		// adding a grid with simply a name will populate the values.
479		grid[GRID_VALUE] = "myaddedgrid";
480		LLGridManager::getInstance()->addGrid(grid);
481		LLGridManager::getInstance()->getGridInfo("myaddedgrid", grid);
482		
483		ensure_equals("name based grid has name value", 
484					  grid[GRID_VALUE].asString(),
485					  std::string("myaddedgrid"));
486		ensure_equals("name based grid has label value", 
487					  grid[GRID_LABEL_VALUE].asString(),
488					  std::string("myaddedgrid"));
489		ensure_equals("name based grid has name value", 
490					  grid[GRID_HELPER_URI_VALUE].asString(),
491					  std::string("https://myaddedgrid/helpers/"));
492		ensure_equals("name based grid has name value", 
493					  grid[GRID_LOGIN_PAGE_VALUE].asString(),
494					  std::string("http://myaddedgrid/app/login/"));
495		ensure("name based grid has array loginuri", 
496			   grid[GRID_LOGIN_URI_VALUE].isArray());
497		ensure_equals("name based grid has single login uri value",
498			   grid[GRID_LOGIN_URI_VALUE].size(), 1);
499		ensure_equals("Name based grid login uri is correct",
500					  grid[GRID_LOGIN_URI_VALUE][0].asString(),
501					  std::string("https://myaddedgrid/cgi-bin/login.cgi"));
502		ensure("name based grid is not a favorite yet", 
503			   !grid.has(GRID_IS_FAVORITE_VALUE));
504		ensure("name based grid does not have system setting",
505			   !grid.has(GRID_IS_SYSTEM_GRID_VALUE));
506		
507		llofstream gridfile("grid_test.xml");
508		gridfile << gSampleGridFile;
509		gridfile.close();
510	}
511	
512	// persistence of the grid list with an empty gridfile.
513	template<> template<>
514	void viewerNetworkTestObject::test<9>()
515	{
516		// try with initial grid list without a grid file,
517		// without setting the grid to a saveable favorite.
518		LLGridManager::getInstance()->initialize("grid_test.xml");
519		LLSD grid = LLSD::emptyMap();
520		grid[GRID_VALUE] = std::string("mynewgridname");
521		LLGridManager::getInstance()->addGrid(grid);
522		LLGridManager::getInstance()->saveFavorites();
523		ensure("Grid file exists after saving", 
524			   LLFile::isfile("grid_test.xml"));
525		LLGridManager::getInstance()->initialize("grid_test.xml");
526		// should not be there
527		std::map<std::string, std::string> known_grids = LLGridManager::getInstance()->getKnownGrids();
528		ensure("New grid wasn't added to persisted list without being marked a favorite",
529					  known_grids.find(std::string("mynewgridname")) == known_grids.end());
530		
531		// mark a grid a favorite to make sure it's persisted
532		LLGridManager::getInstance()->addGrid(grid);
533		LLGridManager::getInstance()->setGridChoice("mynewgridname");
534		LLGridManager::getInstance()->setFavorite();
535		LLGridManager::getInstance()->saveFavorites();
536		ensure("Grid file exists after saving", 
537			   LLFile::isfile("grid_test.xml"));
538		LLGridManager::getInstance()->initialize("grid_test.xml");
539		// should not be there
540		known_grids = LLGridManager::getInstance()->getKnownGrids();
541		ensure("New grid wasn't added to persisted list after being marked a favorite",
542					  known_grids.find(std::string("mynewgridname")) !=
543					  known_grids.end());
544	}
545	
546	// persistence of the grid file with existing gridfile
547	template<> template<>
548	void viewerNetworkTestObject::test<10>()
549	{
550		
551		llofstream gridfile("grid_test.xml");
552		gridfile << gSampleGridFile;
553		gridfile.close();
554		
555		LLGridManager::getInstance()->initialize("grid_test.xml");
556		LLSD grid = LLSD::emptyMap();
557		grid[GRID_VALUE] = std::string("mynewgridname");
558		LLGridManager::getInstance()->addGrid(grid);
559		LLGridManager::getInstance()->saveFavorites();
560		// validate we didn't lose existing favorites
561		LLGridManager::getInstance()->initialize("grid_test.xml");
562		std::map<std::string, std::string> known_grids = LLGridManager::getInstance()->getKnownGrids();
563		ensure("New grid wasn't added to persisted list after being marked a favorite",
564			   known_grids.find(std::string("grid1")) !=
565			   known_grids.end());
566		
567		// add a grid
568		LLGridManager::getInstance()->addGrid(grid);
569		LLGridManager::getInstance()->setGridChoice("mynewgridname");
570		LLGridManager::getInstance()->setFavorite();
571		LLGridManager::getInstance()->saveFavorites();
572		known_grids = LLGridManager::getInstance()->getKnownGrids();
573		ensure("New grid wasn't added to persisted list after being marked a favorite",
574			   known_grids.find(std::string("grid1")) !=
575			   known_grids.end());
576		known_grids = LLGridManager::getInstance()->getKnownGrids();
577		ensure("New grid wasn't added to persisted list after being marked a favorite",
578			   known_grids.find(std::string("mynewgridname")) !=
579			   known_grids.end());
580	}
581}