PageRenderTime 34ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/tests/llsdmessage_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 158 lines | 104 code | 8 blank | 46 comment | 2 complexity | e33fa23aa9be34a5780c312c19f7f3d4 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llsdmessage_test.cpp
  3. * @author Nat Goodspeed
  4. * @date 2008-12-22
  5. * @brief Test of llsdmessage.h
  6. *
  7. * $LicenseInfo:firstyear=2008&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. #if LL_WINDOWS
  29. #pragma warning (disable : 4675) // "resolved by ADL" -- just as I want!
  30. #endif
  31. // Precompiled header
  32. #include "linden_common.h"
  33. // associated header
  34. #include "llsdmessage.h"
  35. // STL headers
  36. #include <iostream>
  37. // std headers
  38. #include <stdexcept>
  39. #include <typeinfo>
  40. // external library headers
  41. // other Linden headers
  42. #include "../test/lltut.h"
  43. #include "llsdserialize.h"
  44. #include "llevents.h"
  45. #include "stringize.h"
  46. #include "llhost.h"
  47. #include "tests/networkio.h"
  48. #include "tests/commtest.h"
  49. /*****************************************************************************
  50. * TUT
  51. *****************************************************************************/
  52. namespace tut
  53. {
  54. struct llsdmessage_data: public commtest_data
  55. {
  56. LLEventPump& httpPump;
  57. llsdmessage_data():
  58. httpPump(pumps.obtain("LLHTTPClient"))
  59. {
  60. LLCurl::initClass();
  61. LLSDMessage::link();
  62. }
  63. };
  64. typedef test_group<llsdmessage_data> llsdmessage_group;
  65. typedef llsdmessage_group::object llsdmessage_object;
  66. llsdmessage_group llsdmgr("llsdmessage");
  67. template<> template<>
  68. void llsdmessage_object::test<1>()
  69. {
  70. bool threw = false;
  71. // This should fail...
  72. try
  73. {
  74. LLSDMessage localListener;
  75. }
  76. catch (const LLEventPump::DupPumpName&)
  77. {
  78. threw = true;
  79. }
  80. catch (const std::runtime_error& ex)
  81. {
  82. // This clause is because on Linux, on the viewer side, for this
  83. // one test program (though not others!), the
  84. // LLEventPump::DupPumpName exception isn't caught by the clause
  85. // above. Warn the user...
  86. std::cerr << "Failed to catch " << typeid(ex).name() << std::endl;
  87. // But if the expected exception was thrown, allow the test to
  88. // succeed anyway. Not sure how else to handle this odd case.
  89. if (std::string(typeid(ex).name()) == typeid(LLEventPump::DupPumpName).name())
  90. {
  91. threw = true;
  92. }
  93. else
  94. {
  95. // We don't even recognize this exception. Let it propagate
  96. // out to TUT to fail the test.
  97. throw;
  98. }
  99. }
  100. catch (...)
  101. {
  102. std::cerr << "Utterly failed to catch expected exception!" << std::endl;
  103. // This case is full of fail. We HAVE to address it.
  104. throw;
  105. }
  106. ensure("second LLSDMessage should throw", threw);
  107. }
  108. template<> template<>
  109. void llsdmessage_object::test<2>()
  110. {
  111. LLSD request, body;
  112. body["data"] = "yes";
  113. request["payload"] = body;
  114. request["reply"] = replyPump.getName();
  115. request["error"] = errorPump.getName();
  116. bool threw = false;
  117. try
  118. {
  119. httpPump.post(request);
  120. }
  121. catch (const LLSDMessage::ArgError&)
  122. {
  123. threw = true;
  124. }
  125. ensure("missing URL", threw);
  126. }
  127. template<> template<>
  128. void llsdmessage_object::test<3>()
  129. {
  130. LLSD request, body;
  131. body["data"] = "yes";
  132. request["url"] = server + "got-message";
  133. request["payload"] = body;
  134. request["reply"] = replyPump.getName();
  135. request["error"] = errorPump.getName();
  136. httpPump.post(request);
  137. ensure("got response", netio.pump());
  138. ensure("success response", success);
  139. ensure_equals(result.asString(), "success");
  140. body["status"] = 499;
  141. body["reason"] = "custom error message";
  142. request["url"] = server + "fail";
  143. request["payload"] = body;
  144. httpPump.post(request);
  145. ensure("got response", netio.pump());
  146. ensure("failure response", ! success);
  147. ensure_equals(result["status"].asInteger(), body["status"].asInteger());
  148. ensure_equals(result["reason"].asString(), body["reason"].asString());
  149. }
  150. } // namespace tut