PageRenderTime 20ms CodeModel.GetById 11ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/tests/llregionpresenceverifier_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 108 lines | 64 code | 15 blank | 29 comment | 0 complexity | a871022c21ed8635946fae6dfaf93f3e 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 "linden_common.h"
 28
 29#include "../test/lltut.h"
 30#include "llregionpresenceverifier.h"
 31#include "llcurl_stub.cpp"
 32#include "llhost.cpp"
 33#include "net.cpp"
 34#include "lltesthttpclientadapter.cpp"
 35
 36class LLTestResponse : public LLRegionPresenceVerifier::Response
 37{
 38public:
 39
 40	virtual bool checkValidity(const LLSD& content) const
 41	{
 42		return true;
 43	}
 44
 45	virtual void onRegionVerified(const LLSD& region_details)
 46	{
 47	}
 48
 49	virtual void onRegionVerificationFailed()
 50	{
 51	}
 52	
 53	virtual LLHTTPClientInterface& getHttpClient()
 54	{
 55		return mHttpInterface;
 56	}
 57
 58	LLTestHTTPClientAdapter mHttpInterface;
 59};
 60
 61namespace tut
 62{
 63	struct LLRegionPresenceVerifierData
 64	{
 65		LLRegionPresenceVerifierData() :
 66			mResponse(new LLTestResponse()),
 67			mResponder("", LLRegionPresenceVerifier::ResponsePtr(mResponse),
 68					   LLSD(), 3)
 69		{
 70		}
 71		
 72		LLTestResponse* mResponse;
 73		LLRegionPresenceVerifier::VerifiedDestinationResponder mResponder;
 74	};
 75
 76	typedef test_group<LLRegionPresenceVerifierData> factory;
 77	typedef factory::object object;
 78}
 79
 80namespace
 81{
 82	tut::factory tf("LLRegionPresenceVerifier");
 83}
 84
 85namespace tut
 86{
 87	// Test that VerifiedDestinationResponder does retry
 88    // on error when shouldRetry returns true.
 89	template<> template<>
 90	void object::test<1>()
 91	{
 92		mResponder.error(500, "Internal server error");
 93		ensure_equals(mResponse->mHttpInterface.mGetUrl.size(), 1);
 94	}
 95
 96	// Test that VerifiedDestinationResponder only retries
 97	// on error until shouldRetry returns false.
 98	template<> template<>
 99	void object::test<2>()
100	{
101		mResponder.error(500, "Internal server error");
102		mResponder.error(500, "Internal server error");
103		mResponder.error(500, "Internal server error");
104		mResponder.error(500, "Internal server error");
105		ensure_equals(mResponse->mHttpInterface.mGetUrl.size(), 3);
106	}
107}
108