aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/test/mock_http_client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/test/mock_http_client.cpp')
-rw-r--r--linden/indra/test/mock_http_client.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/linden/indra/test/mock_http_client.cpp b/linden/indra/test/mock_http_client.cpp
new file mode 100644
index 0000000..c24c469
--- /dev/null
+++ b/linden/indra/test/mock_http_client.cpp
@@ -0,0 +1,88 @@
1/**
2 * @file mock_http_client.cpp
3 * @brief Framework for testing HTTP requests
4 *
5 * $LicenseInfo:firstyear=2007&license=viewergpl$
6 *
7 * Copyright (c) 2007-2008, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32#include "linden_common.h"
33#include "llsdhttpserver.h"
34#include "lliohttpserver.h"
35
36namespace tut
37{
38 class SuccessNode : public LLHTTPNode
39 {
40 public:
41 void get(ResponsePtr r, const LLSD& context) const
42 {
43 LLSD result;
44 result["state"] = "complete";
45 result["test"] = "test";
46 r->result(result);
47 }
48 void post(ResponsePtr r, const LLSD& context, const LLSD& input) const
49 {
50 LLSD result;
51 result["state"] = "complete";
52 result["test"] = "test";
53 r->result(result);
54 }
55 };
56
57 class ErrorNode : public LLHTTPNode
58 {
59 public:
60 void get(ResponsePtr r, const LLSD& context) const
61 { r->status(599, "Intentional error"); }
62 void post(ResponsePtr r, const LLSD& context, const LLSD& input) const
63 { r->status(input["status"], input["reason"]); }
64 };
65
66 class TimeOutNode : public LLHTTPNode
67 {
68 public:
69 void get(ResponsePtr r, const LLSD& context) const
70 {
71 /* do nothing, the request will eventually time out */
72 }
73 };
74
75 LLSD storage;
76
77 class LLSDStorageNode : public LLHTTPNode
78 {
79 public:
80 LLSD get() const{ return storage; }
81 LLSD put(const LLSD& value) const{ storage = value; return LLSD(); }
82 };
83
84 LLHTTPRegistration<LLSDStorageNode> gStorageNode("/test/storage");
85 LLHTTPRegistration<SuccessNode> gSuccessNode("/test/success");
86 LLHTTPRegistration<ErrorNode> gErrorNode("/test/error");
87 LLHTTPRegistration<TimeOutNode> gTimeOutNode("/test/timeout");
88}