PageRenderTime 58ms CodeModel.GetById 23ms 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
Possible License(s): LGPL-2.1
  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. #include <tut/tut.hpp>
  28. #include "linden_common.h"
  29. #include "lltut.h"
  30. #include "llsd.h"
  31. #include "llservicebuilder.h"
  32. namespace tut
  33. {
  34. struct ServiceBuilderTestData {
  35. LLServiceBuilder mServiceBuilder;
  36. };
  37. typedef test_group<ServiceBuilderTestData> ServiceBuilderTestGroup;
  38. typedef ServiceBuilderTestGroup::object ServiceBuilderTestObject;
  39. ServiceBuilderTestGroup serviceBuilderTestGroup("ServiceBuilder");
  40. template<> template<>
  41. void ServiceBuilderTestObject::test<1>()
  42. {
  43. //Simple service build and reply with no mapping
  44. LLSD test_block;
  45. test_block["service-builder"] = "/agent/name";
  46. mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]);
  47. std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest");
  48. ensure_equals("Basic URL Creation", test_url , "/agent/name");
  49. }
  50. template<> template<>
  51. void ServiceBuilderTestObject::test<2>()
  52. {
  53. //Simple replace test
  54. LLSD test_block;
  55. test_block["service-builder"] = "/agent/{$agent-id}/name";
  56. mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]);
  57. LLSD data_map;
  58. data_map["agent-id"] = "257c631f-a0c5-4f29-8a9f-9031feaae6c6";
  59. std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest", data_map);
  60. ensure_equals("Replacement URL Creation", test_url , "/agent/257c631f-a0c5-4f29-8a9f-9031feaae6c6/name");
  61. }
  62. template<> template<>
  63. void ServiceBuilderTestObject::test<3>()
  64. {
  65. //Incorrect service test
  66. LLSD test_block;
  67. test_block["service-builder"] = "/agent/{$agent-id}/name";
  68. mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]);
  69. std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilder");
  70. ensure_equals("Replacement URL Creation for Non-existant Service", test_url , "");
  71. }
  72. template<> template<>
  73. void ServiceBuilderTestObject::test<4>()
  74. {
  75. //Incorrect service test
  76. LLSD test_block;
  77. test_block["service-builder"] = "/agent/{$agent-id}/name";
  78. mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]);
  79. LLSD data_map;
  80. data_map["agent_id"] = "257c631f-a0c5-4f29-8a9f-9031feaae6c6";
  81. std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest", data_map);
  82. ensure_equals("Replacement URL Creation for Non-existant Service", test_url , "/agent/{$agent-id}/name");
  83. }
  84. template<> template<>
  85. void ServiceBuilderTestObject::test<5>()
  86. {
  87. LLSD test_block;
  88. test_block["service-builder"] = "/proc/{$proc}{%params}";
  89. mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]);
  90. LLSD data_map;
  91. data_map["proc"] = "do/something/useful";
  92. data_map["params"]["estate_id"] = 1;
  93. data_map["params"]["query"] = "public";
  94. std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest", data_map);
  95. ensure_equals(
  96. "two part URL Creation",
  97. test_url ,
  98. "/proc/do/something/useful?estate_id=1&query=public");
  99. }
  100. template<> template<>
  101. void ServiceBuilderTestObject::test<6>()
  102. {
  103. LLSD test_block;
  104. test_block["service-builder"] = "Which way to the {${$baz}}?";
  105. mServiceBuilder.createServiceDefinition(
  106. "ServiceBuilderTest",
  107. test_block["service-builder"]);
  108. LLSD data_map;
  109. data_map["foo"] = "bar";
  110. data_map["baz"] = "foo";
  111. std::string test_url = mServiceBuilder.buildServiceURI(
  112. "ServiceBuilderTest",
  113. data_map);
  114. ensure_equals(
  115. "recursive url creation",
  116. test_url ,
  117. "Which way to the bar?");
  118. }
  119. template<> template<>
  120. void ServiceBuilderTestObject::test<7>()
  121. {
  122. LLSD test_block;
  123. test_block["service-builder"] = "Which way to the {$foo}?";
  124. mServiceBuilder.createServiceDefinition(
  125. "ServiceBuilderTest",
  126. test_block["service-builder"]);
  127. LLSD data_map;
  128. data_map["baz"] = "foo";
  129. std::string test_url = mServiceBuilder.buildServiceURI(
  130. "ServiceBuilderTest",
  131. data_map);
  132. ensure_equals(
  133. "fails to do replacement",
  134. test_url ,
  135. "Which way to the {$foo}?");
  136. }
  137. template<> template<>
  138. void ServiceBuilderTestObject::test<8>()
  139. {
  140. LLSD test_block;
  141. test_block["service-builder"] = "/proc/{$proc}{%params}";
  142. mServiceBuilder.createServiceDefinition(
  143. "ServiceBuilderTest",
  144. test_block["service-builder"]);
  145. LLSD data_map;
  146. data_map["proc"] = "do/something/useful";
  147. data_map["params"] = LLSD();
  148. std::string test_url = mServiceBuilder.buildServiceURI(
  149. "ServiceBuilderTest",
  150. data_map);
  151. ensure_equals(
  152. "strip params",
  153. test_url ,
  154. "/proc/do/something/useful");
  155. }
  156. }