PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/indra/test/llmessageconfig_tut.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 236 lines | 181 code | 17 blank | 38 comment | 1 complexity | 03ceaa9bebca87719bf3cbeebe75a514 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llmessageconfig_tut.cpp
  3. * @date March 2007
  4. * @brief LLMessageConfig unit tests
  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 "linden_common.h"
  28. #include "llmessageconfig.h"
  29. #include "lltut.h"
  30. #include "llsdserialize.h"
  31. #include "llfile.h"
  32. #include "lltimer.h"
  33. #include "llframetimer.h"
  34. #include "llsdutil.h"
  35. namespace tut
  36. {
  37. struct LLMessageConfigTestData {
  38. std::string mTestConfigDir;
  39. LLMessageConfigTestData()
  40. {
  41. LLUUID random;
  42. random.generate();
  43. // generate temp dir
  44. std::ostringstream oStr;
  45. #if LL_WINDOWS
  46. oStr << "llmessage-config-test-" << random;
  47. #else
  48. oStr << "/tmp/llmessage-config-test-" << random;
  49. #endif
  50. mTestConfigDir = oStr.str();
  51. LLFile::mkdir(mTestConfigDir);
  52. writeConfigFile(LLSD());
  53. LLMessageConfig::initClass("simulator", mTestConfigDir);
  54. }
  55. ~LLMessageConfigTestData()
  56. {
  57. // rm contents of temp dir
  58. int rmfile = LLFile::remove((mTestConfigDir + "/message.xml"));
  59. ensure_equals("rmfile value", rmfile, 0);
  60. // rm temp dir
  61. int rmdir = LLFile::rmdir(mTestConfigDir);
  62. ensure_equals("rmdir value", rmdir, 0);
  63. }
  64. void writeConfigFile(const LLSD& config)
  65. {
  66. llofstream file((mTestConfigDir + "/message.xml"));
  67. if (file.is_open())
  68. {
  69. LLSDSerialize::toPrettyXML(config, file);
  70. }
  71. file.close();
  72. }
  73. };
  74. typedef test_group<LLMessageConfigTestData> LLMessageConfigTestGroup;
  75. typedef LLMessageConfigTestGroup::object LLMessageConfigTestObject;
  76. LLMessageConfigTestGroup llMessageConfigTestGroup("LLMessageConfig");
  77. template<> template<>
  78. void LLMessageConfigTestObject::test<1>()
  79. // tests server defaults
  80. {
  81. LLSD config;
  82. config["serverDefaults"]["simulator"] = "template";
  83. LLMessageConfig::useConfig(config);
  84. ensure_equals("Ensure server default is not template",
  85. LLMessageConfig::getServerDefaultFlavor(),
  86. LLMessageConfig::TEMPLATE_FLAVOR);
  87. }
  88. template<> template<>
  89. void LLMessageConfigTestObject::test<2>()
  90. // tests message flavors
  91. {
  92. LLSD config;
  93. config["serverDefaults"]["simulator"] = "template";
  94. config["messages"]["msg1"]["flavor"] = "template";
  95. config["messages"]["msg2"]["flavor"] = "llsd";
  96. LLMessageConfig::useConfig(config);
  97. ensure_equals("Ensure msg template flavor",
  98. LLMessageConfig::getMessageFlavor("msg1"),
  99. LLMessageConfig::TEMPLATE_FLAVOR);
  100. ensure_equals("Ensure msg llsd flavor",
  101. LLMessageConfig::getMessageFlavor("msg2"),
  102. LLMessageConfig::LLSD_FLAVOR);
  103. }
  104. template<> template<>
  105. void LLMessageConfigTestObject::test<4>()
  106. // tests message flavor defaults
  107. {
  108. LLSD config;
  109. config["serverDefaults"]["simulator"] = "llsd";
  110. config["messages"]["msg1"]["trusted-sender"] = true;
  111. LLMessageConfig::useConfig(config);
  112. ensure_equals("Ensure missing message gives no flavor",
  113. LLMessageConfig::getMessageFlavor("Test"),
  114. LLMessageConfig::NO_FLAVOR);
  115. ensure_equals("Ensure missing flavor is NO_FLAVOR even with sender trustedness set",
  116. LLMessageConfig::getMessageFlavor("msg1"),
  117. LLMessageConfig::NO_FLAVOR);
  118. ensure_equals("Ensure server default is llsd",
  119. LLMessageConfig::getServerDefaultFlavor(),
  120. LLMessageConfig::LLSD_FLAVOR);
  121. }
  122. template<> template<>
  123. void LLMessageConfigTestObject::test<3>()
  124. // tests trusted/untrusted senders
  125. {
  126. LLSD config;
  127. config["serverDefaults"]["simulator"] = "template";
  128. config["messages"]["msg1"]["flavor"] = "llsd";
  129. config["messages"]["msg1"]["trusted-sender"] = false;
  130. config["messages"]["msg2"]["flavor"] = "llsd";
  131. config["messages"]["msg2"]["trusted-sender"] = true;
  132. LLMessageConfig::useConfig(config);
  133. ensure_equals("Ensure untrusted is untrusted",
  134. LLMessageConfig::getSenderTrustedness("msg1"),
  135. LLMessageConfig::UNTRUSTED);
  136. ensure_equals("Ensure trusted is trusted",
  137. LLMessageConfig::getSenderTrustedness("msg2"),
  138. LLMessageConfig::TRUSTED);
  139. ensure_equals("Ensure missing trustedness is NOT_SET",
  140. LLMessageConfig::getSenderTrustedness("msg3"),
  141. LLMessageConfig::NOT_SET);
  142. }
  143. template<> template<>
  144. void LLMessageConfigTestObject::test<5>()
  145. // tests trusted/untrusted without flag, only flavor
  146. {
  147. LLSD config;
  148. config["serverDefaults"]["simulator"] = "template";
  149. config["messages"]["msg1"]["flavor"] = "llsd";
  150. LLMessageConfig::useConfig(config);
  151. ensure_equals("Ensure msg1 exists, has llsd flavor",
  152. LLMessageConfig::getMessageFlavor("msg1"),
  153. LLMessageConfig::LLSD_FLAVOR);
  154. ensure_equals("Ensure missing trusted is not set",
  155. LLMessageConfig::getSenderTrustedness("msg1"),
  156. LLMessageConfig::NOT_SET);
  157. }
  158. template<> template<>
  159. void LLMessageConfigTestObject::test<6>()
  160. {
  161. LLSD config;
  162. config["capBans"]["MapLayer"] = true;
  163. config["capBans"]["MapLayerGod"] = false;
  164. LLMessageConfig::useConfig(config);
  165. ensure_equals("Ensure cap ban true MapLayer",
  166. LLMessageConfig::isCapBanned("MapLayer"),
  167. true);
  168. ensure_equals("Ensure cap ban false",
  169. LLMessageConfig::isCapBanned("MapLayerGod"),
  170. false);
  171. }
  172. template<> template<>
  173. void LLMessageConfigTestObject::test<7>()
  174. // tests that config changes are picked up/refreshed periodically
  175. {
  176. LLSD config;
  177. config["serverDefaults"]["simulator"] = "llsd";
  178. writeConfigFile(config);
  179. // wait for it to reload after N seconds
  180. ms_sleep(6*1000);
  181. LLFrameTimer::updateFrameTime();
  182. ensure_equals("Ensure reload after 6 seconds",
  183. LLMessageConfig::getServerDefaultFlavor(),
  184. LLMessageConfig::LLSD_FLAVOR);
  185. }
  186. template<> template<>
  187. void LLMessageConfigTestObject::test<8>()
  188. // tests that config changes are picked up/refreshed periodically
  189. {
  190. LLSD config;
  191. config["serverDefaults"]["simulator"] = "template";
  192. config["messages"]["msg1"]["flavor"] = "llsd";
  193. config["messages"]["msg1"]["only-send-latest"] = true;
  194. config["messages"]["msg2"]["flavor"] = "llsd";
  195. config["messages"]["msg2"]["only-send-latest"] = false;
  196. LLMessageConfig::useConfig(config);
  197. ensure_equals("Ensure msg1 exists, sent latest-only",
  198. LLMessageConfig::onlySendLatest("msg1"),
  199. true);
  200. ensure_equals("Ensure msg2 exists, sent latest-only",
  201. LLMessageConfig::onlySendLatest("msg2"),
  202. false);
  203. }
  204. template<> template<>
  205. void LLMessageConfigTestObject::test<9>()
  206. // tests that event queue max is reloaded
  207. {
  208. LLSD config;
  209. config["maxQueuedEvents"] = 200;
  210. LLMessageConfig::useConfig(config);
  211. ensure_equals("Ensure setting maxQueuedEvents",
  212. LLMessageConfig::getMaxQueuedEvents(),
  213. 200);
  214. LLMessageConfig::useConfig(LLSD());
  215. ensure_equals("Ensure default of event queue max 100",
  216. LLMessageConfig::getMaxQueuedEvents(),
  217. 100);
  218. }
  219. }