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