PageRenderTime 14ms CodeModel.GetById 2ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/tests/lltexturestatsuploader_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 150 lines | 65 code | 22 blank | 63 comment | 0 complexity | d0e4f7833113f13aefe080e7f71d8202 MD5 | raw file
  1/** 
  2 * @file lltexturestatsuploader_test.cpp
  3 * @author Si
  4 * @date 2009-05-27
  5 *
  6 * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28// Precompiled header: almost always required for newview cpp files
 29#include "../llviewerprecompiledheaders.h"
 30// Class to test
 31#include "../lltexturestatsuploader.h"
 32// Dependencies
 33
 34// Tut header
 35#include "../test/lltut.h"
 36
 37// -------------------------------------------------------------------------------------------
 38// Stubbing: Declarations required to link and run the class being tested
 39// Notes: 
 40// * Add here stubbed implementation of the few classes and methods used in the class to be tested
 41// * Add as little as possible (let the link errors guide you)
 42// * Do not make any assumption as to how those classes or methods work (i.e. don't copy/paste code)
 43// * A simulator for a class can be implemented here. Please comment and document thoroughly.
 44
 45#include "boost/intrusive_ptr.hpp"
 46void boost::intrusive_ptr_add_ref(LLCurl::Responder*){}
 47void boost::intrusive_ptr_release(LLCurl::Responder* p){}
 48const F32 HTTP_REQUEST_EXPIRY_SECS = 0.0f;
 49
 50static std::string most_recent_url;
 51static LLSD most_recent_body;
 52
 53void LLHTTPClient::post(
 54		const std::string& url,
 55		const LLSD& body,
 56		ResponderPtr,
 57		const LLSD& headers,
 58		const F32 timeout)
 59{
 60	// set some sensor code
 61	most_recent_url = url;
 62	most_recent_body = body;
 63	return;
 64}
 65
 66// End Stubbing
 67// -------------------------------------------------------------------------------------------
 68
 69// -------------------------------------------------------------------------------------------
 70// TUT
 71// -------------------------------------------------------------------------------------------
 72
 73namespace tut
 74{
 75	// Test wrapper declarations
 76	struct texturestatsuploader_test
 77	{
 78		// Constructor and destructor of the test wrapper
 79		texturestatsuploader_test()
 80		{
 81			most_recent_url = "some sort of default text that should never match anything the tests are expecting!";
 82			LLSD blank_llsd;
 83			most_recent_body = blank_llsd;
 84		}
 85		~texturestatsuploader_test()
 86		{
 87		}
 88	};
 89
 90	// Tut templating thingamagic: test group, object and test instance
 91	typedef test_group<texturestatsuploader_test> texturestatsuploader_t;
 92	typedef texturestatsuploader_t::object texturestatsuploader_object_t;
 93	tut::texturestatsuploader_t tut_texturestatsuploader("LLTextureStatsUploader");
 94
 95	
 96	// ---------------------------------------------------------------------------------------
 97	// Test functions
 98	// Notes:
 99	// * Test as many as you possibly can without requiring a full blown simulation of everything
100	// * The tests are executed in sequence so the test instance state may change between calls
101	// * Remember that you cannot test private methods with tut
102	// ---------------------------------------------------------------------------------------
103
104	// ---------------------------------------------------------------------------------------
105	// Test the LLTextureInfo
106	// ---------------------------------------------------------------------------------------
107
108
109	// Test instantiation
110	template<> template<>
111	void texturestatsuploader_object_t::test<1>()
112	{
113		LLTextureStatsUploader tsu;
114		llinfos << &tsu << llendl;
115		ensure("have we crashed?", true);
116	}
117
118	// does it call out to the provided url if we ask it to?
119	template<> template<>
120	void texturestatsuploader_object_t::test<2>()
121	{	
122		LLTextureStatsUploader tsu;
123		std::string url = "http://blahblahblah";
124		LLSD texture_stats;
125		tsu.uploadStatsToSimulator(url, texture_stats);
126		ensure_equals("did the right url get called?", most_recent_url, url);
127		ensure_equals("did the right body get sent?", most_recent_body, texture_stats);
128	}
129
130	// does it not call out to the provided url if we send it an ungranted cap?
131	template<> template<>
132	void texturestatsuploader_object_t::test<3>()
133	{	
134		LLTextureStatsUploader tsu;
135
136		// this url left intentionally blank to mirror
137		// not getting a cap in the caller.
138		std::string url_for_ungranted_cap = ""; 
139							  
140		LLSD texture_stats;
141		std::string most_recent_url_before_test = most_recent_url;
142		tsu.uploadStatsToSimulator(url_for_ungranted_cap, texture_stats);
143
144		ensure_equals("hopefully no url got called!", most_recent_url, most_recent_url_before_test);
145	}
146
147	// does it call out if the data is empty?
148	// should it even do that?
149}
150