PageRenderTime 24ms CodeModel.GetById 1ms app.highlight 18ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/test/llassetuploadqueue_tut.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 195 lines | 144 code | 25 blank | 26 comment | 0 complexity | 1ce9461aada894a045defbc25787054c MD5 | raw file
  1/** 
  2 * @file asset_upload_queue_tut.cpp
  3 * @brief Tests for newview/llassetuploadqueue.cpp
  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 "lltut.h"
 29
 30#include "mock_http_client.h"
 31#include "../newview/llassetuploadqueue.cpp"
 32
 33// Mock implementation.
 34LLAssetUploadResponder::LLAssetUploadResponder(const LLSD& post_data,
 35											   const LLUUID& vfile_id,
 36											   LLAssetType::EType asset_type)
 37{
 38}
 39
 40LLAssetUploadResponder::LLAssetUploadResponder(const LLSD& post_data, const std::string& file_name)
 41{
 42}
 43
 44LLAssetUploadResponder::~LLAssetUploadResponder()
 45{
 46}
 47
 48void LLAssetUploadResponder::error(U32 statusNum, const std::string& reason)
 49{
 50}
 51
 52void LLAssetUploadResponder::result(const LLSD& content)
 53{
 54}
 55
 56void LLAssetUploadResponder::uploadUpload(const LLSD& content)
 57{
 58}
 59
 60void LLAssetUploadResponder::uploadComplete(const LLSD& content)
 61{
 62}
 63
 64void LLAssetUploadResponder::uploadFailure(const LLSD& content)
 65{
 66}
 67
 68LLUpdateTaskInventoryResponder::LLUpdateTaskInventoryResponder(const LLSD& post_data,
 69															   const LLUUID& vfile_id,
 70															   LLAssetType::EType asset_type) :
 71	LLAssetUploadResponder(post_data, vfile_id, asset_type)
 72{
 73}
 74
 75LLUpdateTaskInventoryResponder::LLUpdateTaskInventoryResponder(const LLSD& post_data,
 76															   const std::string& file_name) :
 77	LLAssetUploadResponder(post_data, file_name)
 78{
 79}
 80
 81LLUpdateTaskInventoryResponder::LLUpdateTaskInventoryResponder(const LLSD& post_data,
 82															   const std::string& file_name,
 83															   const LLUUID& queue_id) :
 84	LLAssetUploadResponder(post_data, file_name)
 85{
 86}
 87
 88void LLUpdateTaskInventoryResponder::uploadComplete(const LLSD& content)
 89{
 90}
 91
 92namespace tut
 93{
 94	class asset_upload_queue_test_data : public MockHttpClient {};
 95	typedef test_group<asset_upload_queue_test_data> asset_upload_queue_test;
 96	typedef asset_upload_queue_test::object asset_upload_queue_object;
 97	tut::asset_upload_queue_test asset_upload_queue("asset_upload_queue");
 98
 99	void queue(LLAssetUploadQueue& q, const std::string& filename)
100	{
101		LLUUID task_id;
102		LLUUID item_id;
103		BOOL is_running = FALSE; 
104		BOOL is_target_mono = TRUE; 
105		LLUUID queue_id;
106		q.queue(filename, task_id, item_id, is_running, is_target_mono, queue_id);
107	}
108
109	class LLTestSupplier : public LLAssetUploadQueueSupplier
110	{
111	public:
112
113		void set(LLAssetUploadQueue* queue) {mQueue = queue;}
114		
115		virtual LLAssetUploadQueue* get() const
116			{
117				return mQueue;
118			}
119
120	private:
121		LLAssetUploadQueue* mQueue;  
122	};
123
124	template<> template<>
125	void asset_upload_queue_object::test<1>()
126	{
127		setupTheServer();
128		reset();
129		LLTestSupplier* supplier = new LLTestSupplier();
130		LLAssetUploadQueue q("http://localhost:8888/test/success", supplier);
131		supplier->set(&q);
132		queue(q, "foo.bar");
133		ensure("upload queue not empty before request", q.isEmpty());
134		runThePump(10);
135		ensure("upload queue not empty after request", q.isEmpty());
136	}
137
138	template<> template<>
139	void asset_upload_queue_object::test<2>()
140	{
141		reset();
142		LLTestSupplier* supplier = new LLTestSupplier();
143		LLAssetUploadQueue q("http://localhost:8888/test/error", supplier);
144		supplier->set(&q);
145		queue(q, "foo.bar");
146		ensure("upload queue not empty before request", q.isEmpty());
147		runThePump(10);
148		ensure("upload queue not empty after request", q.isEmpty());
149	}
150
151	template<> template<>
152	void asset_upload_queue_object::test<3>()
153	{
154		reset();
155		LLTestSupplier* supplier = new LLTestSupplier();
156		LLAssetUploadQueue q("http://localhost:8888/test/timeout", supplier);
157		supplier->set(&q);
158		queue(q, "foo.bar");
159		ensure("upload queue not empty before request", q.isEmpty());
160		runThePump(10);
161		ensure("upload queue not empty after request", q.isEmpty());
162	}
163
164	template<> template<>
165	void asset_upload_queue_object::test<4>()
166	{
167		reset();
168		LLTestSupplier* supplier = new LLTestSupplier();
169		LLAssetUploadQueue q("http://localhost:8888/test/success", supplier);
170		supplier->set(&q);
171		queue(q, "foo.bar");
172		queue(q, "baz.bar");
173		ensure("upload queue empty before request", !q.isEmpty());
174		runThePump(10);
175		ensure("upload queue not empty before request", q.isEmpty());
176		runThePump(10);
177		ensure("upload queue not empty after request", q.isEmpty());
178	}
179
180	template<> template<>
181	void asset_upload_queue_object::test<5>()
182	{
183		reset();
184		LLTestSupplier* supplier = new LLTestSupplier();
185		LLAssetUploadQueue q("http://localhost:8888/test/success", supplier);
186		supplier->set(&q);
187		queue(q, "foo.bar");
188		runThePump(10);
189		ensure("upload queue not empty before request", q.isEmpty());
190		queue(q, "baz.bar");
191		ensure("upload queue not empty after request", q.isEmpty());
192		runThePump(10);
193		killServer();
194	}
195}