PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. LLControlGroup::LLControlGroup(const std::string& name)
  37. : LLInstanceTracker<LLControlGroup, std::string>(name) {}
  38. LLControlGroup::~LLControlGroup() {}
  39. BOOL LLControlGroup::declareString(const std::string& name,
  40. const std::string& initial_val,
  41. const std::string& comment,
  42. BOOL persist) {return TRUE;}
  43. void LLControlGroup::setString(const std::string& name, const std::string& val){}
  44. std::string gCmdLineLoginURI;
  45. std::string gCmdLineGridChoice;
  46. std::string gCmdLineHelperURI;
  47. std::string gLoginPage;
  48. std::string gCurrentGrid;
  49. std::string LLControlGroup::getString(const std::string& name)
  50. {
  51. if (name == "CmdLineGridChoice")
  52. return gCmdLineGridChoice;
  53. else if (name == "CmdLineHelperURI")
  54. return gCmdLineHelperURI;
  55. else if (name == "LoginPage")
  56. return gLoginPage;
  57. else if (name == "CurrentGrid")
  58. return gCurrentGrid;
  59. return "";
  60. }
  61. LLSD LLControlGroup::getLLSD(const std::string& name)
  62. {
  63. if (name == "CmdLineLoginURI")
  64. {
  65. if(!gCmdLineLoginURI.empty())
  66. {
  67. return LLSD(gCmdLineLoginURI);
  68. }
  69. }
  70. return LLSD();
  71. }
  72. LLPointer<LLControlVariable> LLControlGroup::getControl(const std::string& name)
  73. {
  74. ctrl_name_table_t::iterator iter = mNameTable.find(name);
  75. return iter == mNameTable.end() ? LLPointer<LLControlVariable>() : iter->second;
  76. }
  77. LLControlGroup gSavedSettings("test");
  78. // -------------------------------------------------------------------------------------------
  79. // TUT
  80. // -------------------------------------------------------------------------------------------
  81. namespace tut
  82. {
  83. // Test wrapper declaration : wrapping nothing for the moment
  84. struct slurlTest
  85. {
  86. slurlTest()
  87. {
  88. LLGridManager::getInstance()->initialize(std::string(""));
  89. }
  90. ~slurlTest()
  91. {
  92. }
  93. };
  94. // Tut templating thingamagic: test group, object and test instance
  95. typedef test_group<slurlTest> slurlTestFactory;
  96. typedef slurlTestFactory::object slurlTestObject;
  97. tut::slurlTestFactory tut_test("LLSlurl");
  98. // ---------------------------------------------------------------------------------------
  99. // Test functions
  100. // ---------------------------------------------------------------------------------------
  101. // construction from slurl string
  102. template<> template<>
  103. void slurlTestObject::test<1>()
  104. {
  105. LLGridManager::getInstance()->setGridChoice("util.agni.lindenlab.com");
  106. LLSLURL slurl = LLSLURL("");
  107. ensure_equals("null slurl", (int)slurl.getType(), LLSLURL::LAST_LOCATION);
  108. slurl = LLSLURL("http://slurl.com/secondlife/myregion");
  109. ensure_equals("slurl.com slurl, region only - type", slurl.getType(), LLSLURL::LOCATION);
  110. ensure_equals("slurl.com slurl, region only", slurl.getSLURLString(),
  111. "http://maps.secondlife.com/secondlife/myregion/128/128/0");
  112. slurl = LLSLURL("http://maps.secondlife.com/secondlife/myregion/1/2/3");
  113. ensure_equals("maps.secondlife.com slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
  114. ensure_equals("maps.secondlife.com slurl, region + coords", slurl.getSLURLString(),
  115. "http://maps.secondlife.com/secondlife/myregion/1/2/3");
  116. slurl = LLSLURL("secondlife://myregion");
  117. ensure_equals("secondlife: slurl, region only - type", slurl.getType(), LLSLURL::LOCATION);
  118. ensure_equals("secondlife: slurl, region only", slurl.getSLURLString(),
  119. "http://maps.secondlife.com/secondlife/myregion/128/128/0");
  120. slurl = LLSLURL("secondlife://myregion/1/2/3");
  121. ensure_equals("secondlife: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
  122. ensure_equals("secondlife slurl, region + coords", slurl.getSLURLString(),
  123. "http://maps.secondlife.com/secondlife/myregion/1/2/3");
  124. slurl = LLSLURL("/myregion");
  125. ensure_equals("/region slurl, region- type", slurl.getType(), LLSLURL::LOCATION);
  126. ensure_equals("/region slurl, region ", slurl.getSLURLString(),
  127. "http://maps.secondlife.com/secondlife/myregion/128/128/0");
  128. slurl = LLSLURL("/myregion/1/2/3");
  129. ensure_equals("/: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
  130. ensure_equals("/ slurl, region + coords", slurl.getSLURLString(),
  131. "http://maps.secondlife.com/secondlife/myregion/1/2/3");
  132. slurl = LLSLURL("my region/1/2/3");
  133. ensure_equals(" slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
  134. ensure_equals(" slurl, region + coords", slurl.getSLURLString(),
  135. "http://maps.secondlife.com/secondlife/my%20region/1/2/3");
  136. LLGridManager::getInstance()->setGridChoice("my.grid.com");
  137. slurl = LLSLURL("https://my.grid.com/region/my%20region/1/2/3");
  138. ensure_equals("grid slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
  139. ensure_equals("grid slurl, region + coords", slurl.getSLURLString(),
  140. "https://my.grid.com/region/my%20region/1/2/3");
  141. slurl = LLSLURL("https://my.grid.com/region/my region");
  142. ensure_equals("grid slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
  143. ensure_equals("grid slurl, region + coords", slurl.getSLURLString(),
  144. "https://my.grid.com/region/my%20region/128/128/0");
  145. LLGridManager::getInstance()->setGridChoice("foo.bar.com");
  146. slurl = LLSLURL("/myregion/1/2/3");
  147. ensure_equals("/: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
  148. ensure_equals("/ slurl, region + coords", slurl.getSLURLString(),
  149. "https://foo.bar.com/region/myregion/1/2/3");
  150. slurl = LLSLURL("myregion/1/2/3");
  151. ensure_equals(": slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
  152. ensure_equals(" slurl, region + coords", slurl.getSLURLString(),
  153. "https://foo.bar.com/region/myregion/1/2/3");
  154. slurl = LLSLURL(LLSLURL::SIM_LOCATION_HOME);
  155. ensure_equals("home", slurl.getType(), LLSLURL::HOME_LOCATION);
  156. slurl = LLSLURL(LLSLURL::SIM_LOCATION_LAST);
  157. ensure_equals("last", slurl.getType(), LLSLURL::LAST_LOCATION);
  158. slurl = LLSLURL("secondlife:///app/foo/bar?12345");
  159. ensure_equals("app", slurl.getType(), LLSLURL::APP);
  160. ensure_equals("appcmd", slurl.getAppCmd(), "foo");
  161. ensure_equals("apppath", slurl.getAppPath().size(), 1);
  162. ensure_equals("apppath2", slurl.getAppPath()[0].asString(), "bar");
  163. ensure_equals("appquery", slurl.getAppQuery(), "12345");
  164. ensure_equals("grid1", "foo.bar.com", slurl.getGrid());
  165. slurl = LLSLURL("secondlife://Aditi/app/foo/bar?12345");
  166. ensure_equals("app", slurl.getType(), LLSLURL::APP);
  167. ensure_equals("appcmd", slurl.getAppCmd(), "foo");
  168. ensure_equals("apppath", slurl.getAppPath().size(), 1);
  169. ensure_equals("apppath2", slurl.getAppPath()[0].asString(), "bar");
  170. ensure_equals("appquery", slurl.getAppQuery(), "12345");
  171. ensure_equals("grid2", "util.aditi.lindenlab.com", slurl.getGrid());
  172. LLGridManager::getInstance()->setGridChoice("foo.bar.com");
  173. slurl = LLSLURL("secondlife:///secondlife/myregion/1/2/3");
  174. ensure_equals("/: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
  175. ensure_equals("location", slurl.getType(), LLSLURL::LOCATION);
  176. ensure_equals("region" , "myregion", slurl.getRegion());
  177. ensure_equals("grid3", "util.agni.lindenlab.com", slurl.getGrid());
  178. slurl = LLSLURL("secondlife://Aditi/secondlife/myregion/1/2/3");
  179. ensure_equals("/: slurl, region + coords - type", slurl.getType(), LLSLURL::LOCATION);
  180. ensure_equals("location", slurl.getType(), LLSLURL::LOCATION);
  181. ensure_equals("region" , "myregion", slurl.getRegion());
  182. ensure_equals("grid4", "util.aditi.lindenlab.com", slurl.getGrid());
  183. LLGridManager::getInstance()->setGridChoice("my.grid.com");
  184. slurl = LLSLURL("https://my.grid.com/app/foo/bar?12345");
  185. ensure_equals("app", slurl.getType(), LLSLURL::APP);
  186. ensure_equals("appcmd", slurl.getAppCmd(), "foo");
  187. ensure_equals("apppath", slurl.getAppPath().size(), 1);
  188. ensure_equals("apppath2", slurl.getAppPath()[0].asString(), "bar");
  189. ensure_equals("appquery", slurl.getAppQuery(), "12345");
  190. }
  191. // construction from grid/region/vector combos
  192. template<> template<>
  193. void slurlTestObject::test<2>()
  194. {
  195. LLSLURL slurl = LLSLURL("mygrid.com", "my region");
  196. ensure_equals("grid/region - type", slurl.getType(), LLSLURL::LOCATION);
  197. ensure_equals("grid/region", slurl.getSLURLString(),
  198. "https://mygrid.com/region/my%20region/128/128/0");
  199. slurl = LLSLURL("mygrid.com", "my region", LLVector3(1,2,3));
  200. ensure_equals("grid/region/vector - type", slurl.getType(), LLSLURL::LOCATION);
  201. ensure_equals(" grid/region/vector", slurl.getSLURLString(),
  202. "https://mygrid.com/region/my%20region/1/2/3");
  203. LLGridManager::getInstance()->setGridChoice("foo.bar.com.bar");
  204. slurl = LLSLURL("my region", LLVector3(1,2,3));
  205. ensure_equals("grid/region/vector - type", slurl.getType(), LLSLURL::LOCATION);
  206. ensure_equals(" grid/region/vector", slurl.getSLURLString(),
  207. "https://foo.bar.com.bar/region/my%20region/1/2/3");
  208. LLGridManager::getInstance()->setGridChoice("util.agni.lindenlab.com");
  209. slurl = LLSLURL("my region", LLVector3(1,2,3));
  210. ensure_equals("default grid/region/vector - type", slurl.getType(), LLSLURL::LOCATION);
  211. ensure_equals(" default grid/region/vector", slurl.getSLURLString(),
  212. "http://maps.secondlife.com/secondlife/my%20region/1/2/3");
  213. }
  214. // Accessors
  215. template<> template<>
  216. void slurlTestObject::test<3>()
  217. {
  218. LLGridManager::getInstance()->setGridChoice("my.grid.com");
  219. LLSLURL slurl = LLSLURL("https://my.grid.com/region/my%20region/1/2/3");
  220. ensure_equals("login string", slurl.getLoginString(), "uri:my region&amp;1&amp;2&amp;3");
  221. ensure_equals("location string", slurl.getLocationString(), "my region/1/2/3");
  222. ensure_equals("grid", slurl.getGrid(), "my.grid.com");
  223. ensure_equals("region", slurl.getRegion(), "my region");
  224. ensure_equals("position", slurl.getPosition(), LLVector3(1, 2, 3));
  225. }
  226. }