/indra/llmessage/tests/lltrustedmessageservice_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 140 lines · 89 code · 19 blank · 32 comment · 0 complexity · 1944ce92fdaad628e2c5e2b9fdefba82 MD5 · raw file

  1. /**
  2. * @file lltrustedmessageservice_test.cpp
  3. * @brief LLTrustedMessageService unit tests
  4. *
  5. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "lltrustedmessageservice.h"
  27. #include "../test/lltut.h"
  28. #include "llhost.cpp" // LLHost is a value type for test purposes.
  29. #include "net.cpp" // Needed by LLHost.
  30. #include "message.h"
  31. #include "llmessageconfig.h"
  32. LLMessageSystem* gMessageSystem = NULL;
  33. LLMessageConfig::SenderTrust
  34. LLMessageConfig::getSenderTrustedness(const std::string& msg_name)
  35. {
  36. return LLMessageConfig::NOT_SET;
  37. }
  38. void LLMessageSystem::receivedMessageFromTrustedSender()
  39. {
  40. }
  41. bool LLMessageSystem::isTrustedSender(const LLHost& host) const
  42. {
  43. return false;
  44. }
  45. bool LLMessageSystem::isTrustedMessage(const std::string& name) const
  46. {
  47. return false;
  48. }
  49. bool messageDispatched = false;
  50. bool messageDispatchedAsBinary = false;
  51. LLSD lastLLSD;
  52. std::string lastMessageName;
  53. void LLMessageSystem::dispatch(const std::string& msg_name,
  54. const LLSD& message,
  55. LLHTTPNode::ResponsePtr responsep)
  56. {
  57. messageDispatched = true;
  58. lastLLSD = message;
  59. lastMessageName = msg_name;
  60. }
  61. void LLMessageSystem::dispatchTemplate(const std::string& msg_name,
  62. const LLSD& message,
  63. LLHTTPNode::ResponsePtr responsep)
  64. {
  65. lastLLSD = message;
  66. lastMessageName = msg_name;
  67. messageDispatchedAsBinary = true;
  68. }
  69. namespace tut
  70. {
  71. struct LLTrustedMessageServiceData
  72. {
  73. LLTrustedMessageServiceData()
  74. {
  75. LLSD emptyLLSD;
  76. lastLLSD = emptyLLSD;
  77. lastMessageName = "uninitialised message name";
  78. messageDispatched = false;
  79. messageDispatchedAsBinary = false;
  80. }
  81. };
  82. typedef test_group<LLTrustedMessageServiceData> factory;
  83. typedef factory::object object;
  84. }
  85. namespace
  86. {
  87. tut::factory tf("LLTrustedMessageServiceData");
  88. }
  89. namespace tut
  90. {
  91. // characterisation tests
  92. // 1) test that messages get forwarded with names etc. as current behaviour (something like LLMessageSystem::dispatch(name, data...)
  93. // test llsd messages are sent as normal using LLMessageSystem::dispatch() (eventually)
  94. template<> template<>
  95. void object::test<1>()
  96. {
  97. LLHTTPNode::ResponsePtr response;
  98. LLSD input;
  99. LLSD context;
  100. LLTrustedMessageService adapter;
  101. adapter.post(response, context, input);
  102. // test original ting got called wit nowt, ya get me blood?
  103. ensure_equals(messageDispatched, true);
  104. ensure(lastLLSD.has("body"));
  105. }
  106. // test that llsd wrapped binary-template-data messages are
  107. // sent via LLMessageSystem::binaryDispatch() or similar
  108. template<> template<>
  109. void object::test<2>()
  110. {
  111. LLHTTPNode::ResponsePtr response;
  112. LLSD input;
  113. input["binary-template-data"] = "10001010110"; //make me a message here.
  114. LLSD context;
  115. LLTrustedMessageService adapter;
  116. adapter.post(response, context, input);
  117. ensure("check template-binary-data message was dispatched as binary", messageDispatchedAsBinary);
  118. ensure_equals(lastLLSD["body"]["binary-template-data"].asString(), "10001010110");
  119. // test somit got called with "10001010110" (something like LLMessageSystem::dispatchTemplate(blah))
  120. }
  121. }