PageRenderTime 26ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/test/mock_http_client.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 83 lines | 50 code | 7 blank | 26 comment | 0 complexity | 71e8617414dcb615394a06bf68e56fb5 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file mock_http_client.cpp
  3. * @brief Framework for testing HTTP requests
  4. *
  5. * $LicenseInfo:firstyear=2007&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 "linden_common.h"
  27. #include "llsdhttpserver.h"
  28. #include "lliohttpserver.h"
  29. namespace tut
  30. {
  31. class SuccessNode : public LLHTTPNode
  32. {
  33. public:
  34. void get(ResponsePtr r, const LLSD& context) const
  35. {
  36. LLSD result;
  37. result["state"] = "complete";
  38. result["test"] = "test";
  39. r->result(result);
  40. }
  41. void post(ResponsePtr r, const LLSD& context, const LLSD& input) const
  42. {
  43. LLSD result;
  44. result["state"] = "complete";
  45. result["test"] = "test";
  46. r->result(result);
  47. }
  48. };
  49. class ErrorNode : public LLHTTPNode
  50. {
  51. public:
  52. void get(ResponsePtr r, const LLSD& context) const
  53. { r->status(599, "Intentional error"); }
  54. void post(ResponsePtr r, const LLSD& context, const LLSD& input) const
  55. { r->status(input["status"], input["reason"]); }
  56. };
  57. class TimeOutNode : public LLHTTPNode
  58. {
  59. public:
  60. void get(ResponsePtr r, const LLSD& context) const
  61. {
  62. /* do nothing, the request will eventually time out */
  63. }
  64. };
  65. LLSD storage;
  66. class LLSDStorageNode : public LLHTTPNode
  67. {
  68. public:
  69. LLSD get() const{ return storage; }
  70. LLSD put(const LLSD& value) const{ storage = value; return LLSD(); }
  71. };
  72. LLHTTPRegistration<LLSDStorageNode> gStorageNode("/test/storage");
  73. LLHTTPRegistration<SuccessNode> gSuccessNode("/test/success");
  74. LLHTTPRegistration<ErrorNode> gErrorNode("/test/error");
  75. LLHTTPRegistration<TimeOutNode> gTimeOutNode("/test/timeout");
  76. }