PageRenderTime 27ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/tests/llhttpclientadapter_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 164 lines | 100 code | 33 blank | 31 comment | 0 complexity | 5c153dd968fd85795479a2523a8328d4 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file
  3. * @brief
  4. *
  5. * $LicenseInfo:firstyear=2008&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 "llhttpclientadapter.h"
  27. #include "../test/lltut.h"
  28. #include "llhttpclient.h"
  29. #include "llcurl_stub.cpp"
  30. float const HTTP_REQUEST_EXPIRY_SECS = 1.0F;
  31. std::vector<std::string> get_urls;
  32. std::vector<boost::intrusive_ptr<LLCurl::Responder> > get_responders;
  33. void LLHTTPClient::get(const std::string& url, boost::intrusive_ptr<LLCurl::Responder> responder, const LLSD& headers, const F32 timeout)
  34. {
  35. get_urls.push_back(url);
  36. get_responders.push_back(responder);
  37. }
  38. std::vector<std::string> put_urls;
  39. std::vector<LLSD> put_body;
  40. std::vector<boost::intrusive_ptr<LLCurl::Responder> > put_responders;
  41. void LLHTTPClient::put(const std::string& url, const LLSD& body, boost::intrusive_ptr<LLCurl::Responder> responder, const LLSD& headers, const F32 timeout)
  42. {
  43. put_urls.push_back(url);
  44. put_responders.push_back(responder);
  45. put_body.push_back(body);
  46. }
  47. namespace tut
  48. {
  49. struct LLHTTPClientAdapterData
  50. {
  51. LLHTTPClientAdapterData()
  52. {
  53. get_urls.clear();
  54. get_responders.clear();
  55. put_urls.clear();
  56. put_responders.clear();
  57. put_body.clear();
  58. }
  59. };
  60. typedef test_group<LLHTTPClientAdapterData> factory;
  61. typedef factory::object object;
  62. }
  63. namespace
  64. {
  65. tut::factory tf("LLHTTPClientAdapterData test");
  66. }
  67. namespace tut
  68. {
  69. // Ensure we can create the object
  70. template<> template<>
  71. void object::test<1>()
  72. {
  73. LLHTTPClientAdapter adapter;
  74. }
  75. // Does the get pass the appropriate arguments to the LLHTTPClient
  76. template<> template<>
  77. void object::test<2>()
  78. {
  79. LLHTTPClientAdapter adapter;
  80. boost::intrusive_ptr<LLCurl::Responder> responder = new LLCurl::Responder();
  81. adapter.get("Made up URL", responder);
  82. ensure_equals(get_urls.size(), 1);
  83. ensure_equals(get_urls[0], "Made up URL");
  84. }
  85. // Ensure the responder matches the one passed to get
  86. template<> template<>
  87. void object::test<3>()
  88. {
  89. LLHTTPClientAdapter adapter;
  90. boost::intrusive_ptr<LLCurl::Responder> responder = new LLCurl::Responder();
  91. adapter.get("Made up URL", responder);
  92. ensure_equals(get_responders.size(), 1);
  93. ensure_equals(get_responders[0].get(), responder.get());
  94. }
  95. // Ensure the correct url is used in the put
  96. template<> template<>
  97. void object::test<4>()
  98. {
  99. LLHTTPClientAdapter adapter;
  100. boost::intrusive_ptr<LLCurl::Responder> responder = new LLCurl::Responder();
  101. LLSD body;
  102. body["TestBody"] = "Foobar";
  103. adapter.put("Made up URL", body, responder);
  104. ensure_equals(put_urls.size(), 1);
  105. ensure_equals(put_urls[0], "Made up URL");
  106. }
  107. // Ensure the correct responder is used by put
  108. template<> template<>
  109. void object::test<5>()
  110. {
  111. LLHTTPClientAdapter adapter;
  112. boost::intrusive_ptr<LLCurl::Responder> responder = new LLCurl::Responder();
  113. LLSD body;
  114. body["TestBody"] = "Foobar";
  115. adapter.put("Made up URL", body, responder);
  116. ensure_equals(put_responders.size(), 1);
  117. ensure_equals(put_responders[0].get(), responder.get());
  118. }
  119. // Ensure the message body is passed through the put properly
  120. template<> template<>
  121. void object::test<6>()
  122. {
  123. LLHTTPClientAdapter adapter;
  124. boost::intrusive_ptr<LLCurl::Responder> responder = new LLCurl::Responder();
  125. LLSD body;
  126. body["TestBody"] = "Foobar";
  127. adapter.put("Made up URL", body, responder);
  128. ensure_equals(put_body.size(), 1);
  129. ensure_equals(put_body[0]["TestBody"].asString(), "Foobar");
  130. }
  131. }