PageRenderTime 20ms CodeModel.GetById 1ms app.highlight 17ms 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
  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
 27#include "llhttpclientadapter.h"
 28
 29#include "../test/lltut.h"
 30#include "llhttpclient.h"
 31#include "llcurl_stub.cpp"
 32
 33float const HTTP_REQUEST_EXPIRY_SECS = 1.0F;
 34
 35std::vector<std::string> get_urls;
 36std::vector<boost::intrusive_ptr<LLCurl::Responder> > get_responders;
 37void LLHTTPClient::get(const std::string& url, boost::intrusive_ptr<LLCurl::Responder> responder, const LLSD& headers, const F32 timeout)
 38{
 39	get_urls.push_back(url);
 40	get_responders.push_back(responder);
 41}
 42
 43std::vector<std::string> put_urls;
 44std::vector<LLSD> put_body;
 45std::vector<boost::intrusive_ptr<LLCurl::Responder> > put_responders;
 46
 47void LLHTTPClient::put(const std::string& url, const LLSD& body, boost::intrusive_ptr<LLCurl::Responder> responder, const LLSD& headers, const F32 timeout)
 48{
 49	put_urls.push_back(url);
 50	put_responders.push_back(responder);
 51	put_body.push_back(body);
 52
 53}
 54
 55
 56namespace tut
 57{
 58	struct LLHTTPClientAdapterData
 59	{
 60		LLHTTPClientAdapterData()
 61		{
 62			get_urls.clear();
 63			get_responders.clear();
 64			put_urls.clear();
 65			put_responders.clear();
 66			put_body.clear();
 67		}
 68	};
 69
 70	typedef test_group<LLHTTPClientAdapterData> factory;
 71	typedef factory::object object;
 72}
 73
 74namespace
 75{
 76	tut::factory tf("LLHTTPClientAdapterData test");
 77}
 78
 79namespace tut
 80{
 81	// Ensure we can create the object
 82	template<> template<>
 83	void object::test<1>()
 84	{
 85		LLHTTPClientAdapter adapter;
 86	}
 87
 88	// Does the get pass the appropriate arguments to the LLHTTPClient
 89	template<> template<>
 90	void object::test<2>()
 91	{
 92		LLHTTPClientAdapter adapter;
 93
 94		boost::intrusive_ptr<LLCurl::Responder> responder = new LLCurl::Responder();
 95
 96		adapter.get("Made up URL", responder);
 97		ensure_equals(get_urls.size(), 1);
 98		ensure_equals(get_urls[0], "Made up URL");
 99	}
100
101	// Ensure the responder matches the one passed to get
102	template<> template<>
103	void object::test<3>()
104	{
105		LLHTTPClientAdapter adapter;
106		boost::intrusive_ptr<LLCurl::Responder> responder = new LLCurl::Responder();
107
108		adapter.get("Made up URL", responder);
109
110		ensure_equals(get_responders.size(), 1);
111		ensure_equals(get_responders[0].get(), responder.get());
112	}
113	
114	// Ensure the correct url is used in the put
115	template<> template<>
116	void object::test<4>()
117	{
118		LLHTTPClientAdapter adapter;
119
120		boost::intrusive_ptr<LLCurl::Responder> responder = new LLCurl::Responder();
121
122		LLSD body;
123		body["TestBody"] = "Foobar";
124
125		adapter.put("Made up URL", body, responder);
126		ensure_equals(put_urls.size(), 1);
127		ensure_equals(put_urls[0], "Made up URL");
128	}
129
130	// Ensure the correct responder is used by put
131	template<> template<>
132	void object::test<5>()
133	{
134		LLHTTPClientAdapter adapter;
135
136		boost::intrusive_ptr<LLCurl::Responder> responder = new LLCurl::Responder();
137
138		LLSD body;
139		body["TestBody"] = "Foobar";
140
141		adapter.put("Made up URL", body, responder);
142
143		ensure_equals(put_responders.size(), 1);
144		ensure_equals(put_responders[0].get(), responder.get());
145	}
146
147	// Ensure the message body is passed through the put properly
148	template<> template<>
149	void object::test<6>()
150	{
151		LLHTTPClientAdapter adapter;
152
153		boost::intrusive_ptr<LLCurl::Responder> responder = new LLCurl::Responder();
154
155		LLSD body;
156		body["TestBody"] = "Foobar";
157
158		adapter.put("Made up URL", body, responder);
159
160		ensure_equals(put_body.size(), 1);
161		ensure_equals(put_body[0]["TestBody"].asString(), "Foobar");
162	}
163}
164