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

/indra/test/message_tut.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 148 lines | 112 code | 7 blank | 29 comment | 1 complexity | c29b80962b1c09a37884ca1743134d3f MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lldatapacker_tut.cpp
  3. * @date 2007-04
  4. * @brief LLDataPacker test cases.
  5. *
  6. * $LicenseInfo:firstyear=2007&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 "llapr.h"
  31. #include "llmessageconfig.h"
  32. #include "llsdserialize.h"
  33. #include "llversionserver.h"
  34. #include "message.h"
  35. #include "message_prehash.h"
  36. namespace
  37. {
  38. struct Response : public LLHTTPNode::Response
  39. {
  40. virtual void result(const LLSD&) {}
  41. virtual void status(S32 code, const std::string& message)
  42. {
  43. mStatus = code;
  44. }
  45. virtual void extendedResult(S32 code, const std::string& message, const LLSD& headers) { }
  46. S32 mStatus;
  47. };
  48. }
  49. namespace tut
  50. {
  51. struct LLMessageSystemTestData
  52. {
  53. std::string mTestConfigDir;
  54. std::string mSep;
  55. LLMessageSystemTestData()
  56. {
  57. static bool init = false;
  58. if(!init)
  59. {
  60. ll_init_apr();
  61. //init_prehash_data();
  62. init = true;
  63. }
  64. const F32 circuit_heartbeat_interval=5;
  65. const F32 circuit_timeout=100;
  66. // currently test disconnected message system
  67. start_messaging_system("notafile", 13035,
  68. LL_VERSION_MAJOR,
  69. LL_VERSION_MINOR,
  70. LL_VERSION_PATCH,
  71. FALSE,
  72. "notasharedsecret",
  73. NULL,
  74. false,
  75. circuit_heartbeat_interval,
  76. circuit_timeout
  77. );
  78. // generate temp dir
  79. std::ostringstream ostr;
  80. #if LL_WINDOWS
  81. mSep = "\\";
  82. ostr << "C:" << mSep;
  83. #else
  84. mSep = "/";
  85. ostr << mSep << "tmp" << mSep;
  86. #endif
  87. LLUUID random;
  88. random.generate();
  89. ostr << "message-test-" << random;
  90. mTestConfigDir = ostr.str();
  91. LLFile::mkdir(mTestConfigDir);
  92. writeConfigFile(LLSD());
  93. LLMessageConfig::initClass("simulator", ostr.str());
  94. }
  95. ~LLMessageSystemTestData()
  96. {
  97. // not end_messaging_system()
  98. delete gMessageSystem;
  99. gMessageSystem = NULL;
  100. // rm contents of temp dir
  101. std::ostringstream ostr;
  102. ostr << mTestConfigDir << mSep << "message.xml";
  103. int rmfile = LLFile::remove(ostr.str());
  104. ensure_equals("rmfile value", rmfile, 0);
  105. // rm temp dir
  106. int rmdir = LLFile::rmdir(mTestConfigDir);
  107. ensure_equals("rmdir value", rmdir, 0);
  108. }
  109. void writeConfigFile(const LLSD& config)
  110. {
  111. std::ostringstream ostr;
  112. ostr << mTestConfigDir << mSep << "message.xml";
  113. llofstream file(ostr.str());
  114. if (file.is_open())
  115. {
  116. LLSDSerialize::toPrettyXML(config, file);
  117. }
  118. file.close();
  119. }
  120. };
  121. typedef test_group<LLMessageSystemTestData> LLMessageSystemTestGroup;
  122. typedef LLMessageSystemTestGroup::object LLMessageSystemTestObject;
  123. LLMessageSystemTestGroup messageTestGroup("LLMessageSystem");
  124. template<> template<>
  125. void LLMessageSystemTestObject::test<1>()
  126. // dispatch unknown message
  127. {
  128. const char* name = "notamessasge";
  129. const LLSD message;
  130. const LLPointer<Response> response = new Response();
  131. gMessageSystem->dispatch(name, message, response);
  132. ensure_equals(response->mStatus, 404);
  133. }
  134. }