llservicebuilder_tut.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:6k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /**
  2. * @file   llservicebuilder_tut.cpp
  3. * @brief  LLServiceBuilder unit tests
  4. * @date   March 2007
  5. *
  6. * $LicenseInfo:firstyear=2006&license=viewergpl$
  7. * Copyright (c) 2006-2010, Linden Research, Inc.
  8. * Second Life Viewer Source Code
  9. * The source code in this file ("Source Code") is provided by Linden Lab
  10. * to you under the terms of the GNU General Public License, version 2.0
  11. * ("GPL"), unless you have obtained a separate licensing agreement
  12. * ("Other License"), formally executed by you and Linden Lab.  Terms of
  13. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  14. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  15. * There are special exceptions to the terms and conditions of the GPL as
  16. * it is applied to this Source Code. View the full text of the exception
  17. * in the file doc/FLOSS-exception.txt in this software distribution, or
  18. * online at
  19. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  20. * By copying, modifying or distributing this software, you acknowledge
  21. * that you have read and understood your obligations described above,
  22. * and agree to abide by those obligations.
  23. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  24. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  25. * COMPLETENESS OR PERFORMANCE.
  26. * $/LicenseInfo$
  27. */
  28. #include <tut/tut.hpp>
  29. #include "linden_common.h"
  30. #include "lltut.h"
  31. #include "llsd.h"
  32. #include "llservicebuilder.h"
  33. namespace tut
  34. {
  35. struct ServiceBuilderTestData {
  36. LLServiceBuilder mServiceBuilder;
  37. };
  38. typedef test_group<ServiceBuilderTestData> ServiceBuilderTestGroup;
  39. typedef ServiceBuilderTestGroup::object ServiceBuilderTestObject;
  40. ServiceBuilderTestGroup serviceBuilderTestGroup("ServiceBuilder");
  41. template<> template<>
  42. void ServiceBuilderTestObject::test<1>()
  43. {
  44. //Simple service build and reply with no mapping
  45. LLSD test_block;
  46. test_block["service-builder"] = "/agent/name";
  47. mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]);
  48. std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest");
  49. ensure_equals("Basic URL Creation", test_url , "/agent/name");
  50. }
  51. template<> template<>
  52. void ServiceBuilderTestObject::test<2>()
  53. {
  54. //Simple replace test
  55. LLSD test_block;
  56. test_block["service-builder"] = "/agent/{$agent-id}/name";
  57. mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]);
  58. LLSD data_map;
  59. data_map["agent-id"] = "257c631f-a0c5-4f29-8a9f-9031feaae6c6";
  60. std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest", data_map);
  61. ensure_equals("Replacement URL Creation", test_url , "/agent/257c631f-a0c5-4f29-8a9f-9031feaae6c6/name");
  62. }
  63. template<> template<>
  64. void ServiceBuilderTestObject::test<3>()
  65. {
  66. //Incorrect service test
  67. LLSD test_block;
  68. test_block["service-builder"] = "/agent/{$agent-id}/name";
  69. mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]);
  70. std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilder");
  71. ensure_equals("Replacement URL Creation for Non-existant Service", test_url , "");
  72. }
  73. template<> template<>
  74. void ServiceBuilderTestObject::test<4>()
  75. {
  76. //Incorrect service test
  77. LLSD test_block;
  78. test_block["service-builder"] = "/agent/{$agent-id}/name";
  79. mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]);
  80. LLSD data_map;
  81. data_map["agent_id"] = "257c631f-a0c5-4f29-8a9f-9031feaae6c6";
  82. std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest", data_map);
  83. ensure_equals("Replacement URL Creation for Non-existant Service", test_url , "/agent/{$agent-id}/name");
  84. }
  85. template<> template<>
  86. void ServiceBuilderTestObject::test<5>()
  87. {
  88. LLSD test_block;
  89. test_block["service-builder"] = "/proc/{$proc}{%params}";
  90. mServiceBuilder.createServiceDefinition("ServiceBuilderTest", test_block["service-builder"]);
  91. LLSD data_map;
  92. data_map["proc"] = "do/something/useful";
  93. data_map["params"]["estate_id"] = 1;
  94. data_map["params"]["query"] = "public";
  95. std::string test_url = mServiceBuilder.buildServiceURI("ServiceBuilderTest", data_map);
  96. ensure_equals(
  97. "two part URL Creation",
  98. test_url ,
  99. "/proc/do/something/useful?estate_id=1&query=public");
  100. }
  101. template<> template<>
  102. void ServiceBuilderTestObject::test<6>()
  103. {
  104. LLSD test_block;
  105. test_block["service-builder"] = "Which way to the {${$baz}}?";
  106. mServiceBuilder.createServiceDefinition(
  107. "ServiceBuilderTest",
  108. test_block["service-builder"]);
  109. LLSD data_map;
  110. data_map["foo"] = "bar";
  111. data_map["baz"] = "foo";
  112. std::string test_url = mServiceBuilder.buildServiceURI(
  113. "ServiceBuilderTest",
  114. data_map);
  115. ensure_equals(
  116. "recursive url creation",
  117. test_url ,
  118. "Which way to the bar?");
  119. }
  120. template<> template<>
  121. void ServiceBuilderTestObject::test<7>()
  122. {
  123. LLSD test_block;
  124. test_block["service-builder"] = "Which way to the {$foo}?";
  125. mServiceBuilder.createServiceDefinition(
  126. "ServiceBuilderTest",
  127. test_block["service-builder"]);
  128. LLSD data_map;
  129. data_map["baz"] = "foo";
  130. std::string test_url = mServiceBuilder.buildServiceURI(
  131. "ServiceBuilderTest",
  132. data_map);
  133. ensure_equals(
  134. "fails to do replacement",
  135. test_url ,
  136. "Which way to the {$foo}?");
  137. }
  138. template<> template<>
  139. void ServiceBuilderTestObject::test<8>()
  140. {
  141. LLSD test_block;
  142. test_block["service-builder"] = "/proc/{$proc}{%params}";
  143. mServiceBuilder.createServiceDefinition(
  144. "ServiceBuilderTest",
  145. test_block["service-builder"]);
  146. LLSD data_map;
  147. data_map["proc"] = "do/something/useful";
  148. data_map["params"] = LLSD();
  149. std::string test_url = mServiceBuilder.buildServiceURI(
  150. "ServiceBuilderTest",
  151. data_map);
  152. ensure_equals(
  153. "strip params",
  154. test_url ,
  155. "/proc/do/something/useful");
  156. }
  157. }