PageRenderTime 197ms CodeModel.GetById 190ms app.highlight 4ms RepoModel.GetById 1ms 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
 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
27#include "linden_common.h"
28#include "llsdhttpserver.h"
29#include "lliohttpserver.h"
30
31namespace tut
32{
33	class SuccessNode : public LLHTTPNode
34	{
35	public:
36		void get(ResponsePtr r, const LLSD& context) const
37	   	{ 
38	   		LLSD result;
39			result["state"] = "complete";
40	   		result["test"] = "test";
41	   		r->result(result);
42	   	}
43		void post(ResponsePtr r, const LLSD& context, const LLSD& input) const
44		{
45			LLSD result;
46			result["state"] = "complete";
47			result["test"] = "test";
48			r->result(result);
49		}
50	};
51
52	class ErrorNode : public LLHTTPNode
53	{
54	public:
55		void get(ResponsePtr r, const LLSD& context) const
56			{ r->status(599, "Intentional error"); }
57		void post(ResponsePtr r, const LLSD& context, const LLSD& input) const
58			{ r->status(input["status"], input["reason"]); }
59	};
60
61	class TimeOutNode : public LLHTTPNode
62	{
63	public:
64		void get(ResponsePtr r, const LLSD& context) const
65		{
66            /* do nothing, the request will eventually time out */ 
67		}
68	};
69
70	LLSD storage;
71	
72	class LLSDStorageNode : public LLHTTPNode
73	{
74	public:
75		LLSD get() const{ return storage; }
76		LLSD put(const LLSD& value) const{ storage = value; return LLSD(); }
77	};
78
79	LLHTTPRegistration<LLSDStorageNode> gStorageNode("/test/storage");
80	LLHTTPRegistration<SuccessNode>		gSuccessNode("/test/success");
81	LLHTTPRegistration<ErrorNode>		gErrorNode("/test/error");
82	LLHTTPRegistration<TimeOutNode>		gTimeOutNode("/test/timeout");
83}