PageRenderTime 796ms CodeModel.GetById 241ms app.highlight 231ms RepoModel.GetById 172ms app.codeStats 0ms

/indra/llkdu/tests/llimagej2ckdu_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 249 lines | 170 code | 17 blank | 62 comment | 3 complexity | c192693b7b4ca72e76b4f4c171568d65 MD5 | raw file
  1/** 
  2 * @file llimagej2ckdu_test.cpp
  3 * @author Merov Linden
  4 * @date 2010-12-17
  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#include "linden_common.h"
 29// Class to test 
 30#include "llimagej2ckdu.h"
 31#include "llkdumem.h"
 32// Tut header
 33#include "lltut.h"
 34
 35// -------------------------------------------------------------------------------------------
 36// Stubbing: Declarations required to link and run the class being tested
 37// Notes: 
 38// * Add here stubbed implementation of the few classes and methods used in the class to be tested
 39// * Add as little as possible (let the link errors guide you)
 40// * Do not make any assumption as to how those classes or methods work (i.e. don't copy/paste code)
 41// * A simulator for a class can be implemented here. Please comment and document thoroughly.
 42
 43// End Stubbing
 44// -------------------------------------------------------------------------------------------
 45// Stubb the LL Image Classes
 46LLImageRaw::LLImageRaw() { }
 47LLImageRaw::~LLImageRaw() { }
 48U8* LLImageRaw::allocateData(S32 ) { return NULL; }
 49void LLImageRaw::deleteData() { }
 50U8* LLImageRaw::reallocateData(S32 ) { return NULL; }
 51BOOL LLImageRaw::resize(U16, U16, S8) { return TRUE; } // this method always returns TRUE...
 52
 53LLImageBase::LLImageBase()
 54: mData(NULL),
 55mDataSize(0),
 56mWidth(0),
 57mHeight(0),
 58mComponents(0),
 59mBadBufferAllocation(false),
 60mAllowOverSize(false),
 61mMemType(LLMemType::MTYPE_IMAGEBASE)
 62{ }
 63LLImageBase::~LLImageBase() { }
 64U8* LLImageBase::allocateData(S32 ) { return NULL; }
 65void LLImageBase::deleteData() { }
 66void LLImageBase::dump() { }
 67const U8* LLImageBase::getData() const { return NULL; }
 68U8* LLImageBase::getData() { return NULL; }
 69U8* LLImageBase::reallocateData(S32 ) { return NULL; }
 70void LLImageBase::sanityCheck() { }
 71void LLImageBase::setSize(S32 , S32 , S32 ) { }
 72
 73LLImageJ2CImpl::~LLImageJ2CImpl() { }
 74
 75LLImageFormatted::LLImageFormatted(S8 ) { }
 76LLImageFormatted::~LLImageFormatted() { }
 77U8* LLImageFormatted::allocateData(S32 ) { return NULL; }
 78S32 LLImageFormatted::calcDataSize(S32 ) { return 0; }
 79S32 LLImageFormatted::calcDiscardLevelBytes(S32 ) { return 0; }
 80BOOL LLImageFormatted::decodeChannels(LLImageRaw*, F32, S32, S32) { return FALSE; }
 81BOOL LLImageFormatted::copyData(U8 *, S32) { return TRUE; }  // this method always returns TRUE...
 82void LLImageFormatted::deleteData() { }
 83void LLImageFormatted::dump() { }
 84U8* LLImageFormatted::reallocateData(S32 ) { return NULL; }
 85void LLImageFormatted::resetLastError() { }
 86void LLImageFormatted::sanityCheck() { }
 87void LLImageFormatted::setLastError(const std::string& , const std::string& ) { }
 88
 89LLImageJ2C::LLImageJ2C() : LLImageFormatted(IMG_CODEC_J2C) { }
 90LLImageJ2C::~LLImageJ2C() { }
 91S32 LLImageJ2C::calcDataSize(S32 ) { return 0; }
 92S32 LLImageJ2C::calcDiscardLevelBytes(S32 ) { return 0; }
 93S32 LLImageJ2C::calcHeaderSize() { return 0; }
 94BOOL LLImageJ2C::decode(LLImageRaw*, F32) { return FALSE; }
 95BOOL LLImageJ2C::decodeChannels(LLImageRaw*, F32, S32, S32 ) { return FALSE; }
 96void LLImageJ2C::decodeFailed() { }
 97BOOL LLImageJ2C::encode(const LLImageRaw*, F32) { return FALSE; }
 98S8  LLImageJ2C::getRawDiscardLevel() { return 0; }
 99void LLImageJ2C::resetLastError() { }
100void LLImageJ2C::setLastError(const std::string&, const std::string&) { }
101BOOL LLImageJ2C::updateData() { return FALSE; }
102void LLImageJ2C::updateRawDiscardLevel() { }
103
104LLKDUMemIn::LLKDUMemIn(const U8*, const U32, const U16, const U16, const U8, siz_params*) { }
105LLKDUMemIn::~LLKDUMemIn() { }
106bool LLKDUMemIn::get(int, kdu_line_buf&, int) { return false; }
107
108// Stub Kakadu Library calls
109kdu_tile_comp kdu_tile::access_component(int ) { kdu_tile_comp a; return a; }
110void kdu_tile::close(kdu_thread_env* ) { }
111int kdu_tile::get_num_components() { return 0; }
112bool kdu_tile::get_ycc() { return false; }
113void kdu_tile::set_components_of_interest(int , const int* ) { }
114kdu_resolution kdu_tile_comp::access_resolution() { kdu_resolution a; return a; }
115int kdu_tile_comp::get_bit_depth(bool ) { return 8; }
116bool kdu_tile_comp::get_reversible() { return false; }
117kdu_subband kdu_resolution::access_subband(int ) { kdu_subband a; return a; }
118void kdu_resolution::get_dims(kdu_dims& ) { }
119int kdu_resolution::which() { return 0; }
120kdu_decoder::kdu_decoder(kdu_subband , kdu_sample_allocator*, bool , float, int, kdu_thread_env*, kdu_thread_queue*) { }
121kdu_synthesis::kdu_synthesis(kdu_resolution, kdu_sample_allocator*, bool, float, kdu_thread_env*, kdu_thread_queue*) { }
122kdu_params::kdu_params(const char*, bool, bool, bool, bool, bool) { }
123kdu_params::~kdu_params() { }
124void kdu_params::set(const char* , int , int , bool ) { }
125void kdu_params::set(const char* , int , int , int ) { }
126void kdu_params::finalize_all(bool ) { }
127void kdu_params::copy_from(kdu_params*, int, int, int, int, int, bool, bool, bool) { }
128bool kdu_params::parse_string(const char*) { return false; }
129bool kdu_params::get(const char*, int, int, bool&, bool, bool, bool) { return false; }
130bool kdu_params::get(const char*, int, int, float&, bool, bool, bool) { return false; }
131bool kdu_params::get(const char*, int, int, int&, bool, bool, bool) { return false; }
132kdu_params* kdu_params::access_relation(int, int, int, bool) { return NULL; }
133kdu_params* kdu_params::access_cluster(const char*) { return NULL; }
134void kdu_codestream::set_fast() { }
135void kdu_codestream::set_fussy() { }
136void kdu_codestream::get_dims(int, kdu_dims&, bool ) { }
137int kdu_codestream::get_min_dwt_levels() { return 5; }
138void kdu_codestream::change_appearance(bool, bool, bool) { }
139void kdu_codestream::get_tile_dims(kdu_coords, int, kdu_dims&, bool ) { }
140void kdu_codestream::destroy() { }
141void kdu_codestream::collect_timing_stats(int ) { }
142void kdu_codestream::set_max_bytes(kdu_long, bool, bool ) { }
143void kdu_codestream::get_valid_tiles(kdu_dims& ) { }
144void kdu_codestream::create(siz_params*, kdu_compressed_target*, kdu_dims*, int, kdu_long ) { }
145void kdu_codestream::create(kdu_compressed_source*, kdu_thread_env*) { }
146void kdu_codestream::apply_input_restrictions( int, int, int, int, kdu_dims*, kdu_component_access_mode ) { }
147void kdu_codestream::get_subsampling(int , kdu_coords&, bool ) { }
148void kdu_codestream::flush(kdu_long *, int , kdu_uint16 *, bool, bool, double, kdu_thread_env*) { }
149void kdu_codestream::set_resilient(bool ) { }
150int kdu_codestream::get_num_components(bool ) { return 0; }
151siz_params* kdu_codestream::access_siz() { return NULL; }
152kdu_tile kdu_codestream::open_tile(kdu_coords , kdu_thread_env* ) { kdu_tile a; return a; }
153kdu_codestream_comment kdu_codestream::add_comment() { kdu_codestream_comment a; return a; }
154bool kdu_codestream_comment::put_text(const char*) { return false; }
155void kdu_customize_warnings(kdu_message*) { }
156void kdu_customize_errors(kdu_message*) { }
157void kdu_convert_ycc_to_rgb(kdu_line_buf&, kdu_line_buf&, kdu_line_buf&, int) { }
158kdu_long kdu_multi_analysis::create(kdu_codestream, kdu_tile, bool, kdu_roi_image*, bool, int, kdu_thread_env*, kdu_thread_queue*, bool ) { kdu_long a = 0; return a; }
159siz_params::siz_params() : kdu_params(NULL, false, false, false, false, false) { }
160void siz_params::finalize(bool ) { }
161void siz_params::copy_with_xforms(kdu_params*, int, int, bool, bool, bool) { }
162int siz_params::write_marker_segment(kdu_output*, kdu_params*, int) { return 0; }
163bool siz_params::check_marker_segment(kdu_uint16, int, kdu_byte a[], int&) { return false; }
164bool siz_params::read_marker_segment(kdu_uint16, int, kdu_byte a[], int) { return false; }
165
166// -------------------------------------------------------------------------------------------
167// TUT
168// -------------------------------------------------------------------------------------------
169
170namespace tut
171{
172	// Test wrapper declarations
173	struct llimagej2ckdu_test
174	{
175		// Derived test class
176		class LLTestImageJ2CKDU : public LLImageJ2CKDU
177		{
178		public:
179			// Provides public access to some protected methods for testing
180			BOOL callGetMetadata(LLImageJ2C &base) { return getMetadata(base); }
181			BOOL callDecodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, S32 first_channel, S32 max_channel_count)
182			{
183				return decodeImpl(base, raw_image, decode_time, first_channel, max_channel_count);
184			}
185			BOOL callEncodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, const char* comment_text)
186			{
187				return encodeImpl(base, raw_image, comment_text);
188			}
189		};
190		// Instance to be tested
191		LLTestImageJ2CKDU* mImage;
192		
193		// Constructor and destructor of the test wrapper
194		llimagej2ckdu_test()
195		{
196			mImage = new LLTestImageJ2CKDU;
197		}
198		~llimagej2ckdu_test()
199		{
200			delete mImage;
201		}
202	};
203	
204	// Tut templating thingamagic: test group, object and test instance
205	typedef test_group<llimagej2ckdu_test> llimagej2ckdu_t;
206	typedef llimagej2ckdu_t::object llimagej2ckdu_object_t;
207	tut::llimagej2ckdu_t tut_llimagej2ckdu("LLImageJ2CKDU");
208	
209	// ---------------------------------------------------------------------------------------
210	// Test functions
211	// Notes:
212	// * Test as many as you possibly can without requiring a full blown simulation of everything
213	// * The tests are executed in sequence so the test instance state may change between calls
214	// * Remember that you cannot test private methods with tut
215	// ---------------------------------------------------------------------------------------
216
217	// Test 1 : test getMetadata()
218	template<> template<>
219	void llimagej2ckdu_object_t::test<1>()
220	{
221		LLImageJ2C* image = new LLImageJ2C();
222		BOOL res = mImage->callGetMetadata(*image);
223		// Trying to set up a data stream with all NIL values and stubbed KDU will "work" and return TRUE
224		// Note that is linking with KDU, that call will throw an exception and fail, returning FALSE
225		ensure("getMetadata() test failed", res == TRUE);
226	}
227
228	// Test 2 : test decodeImpl()
229	template<> template<>
230	void llimagej2ckdu_object_t::test<2>()
231	{
232		LLImageJ2C* image = new LLImageJ2C();
233		LLImageRaw* raw = new LLImageRaw();
234		BOOL res = mImage->callDecodeImpl(*image, *raw, 0.0, 0, 0);
235		// Decoding returns TRUE whenever there's nothing else to do, including if decoding failed, so we'll get TRUE here
236		ensure("decodeImpl() test failed", res == TRUE);
237	}
238
239	// Test 3 : test encodeImpl()
240	template<> template<>
241	void llimagej2ckdu_object_t::test<3>()
242	{
243		LLImageJ2C* image = new LLImageJ2C();
244		LLImageRaw* raw = new LLImageRaw();
245		BOOL res = mImage->callEncodeImpl(*image, *raw, NULL);
246		// Encoding returns TRUE unless an exception was raised, so we'll get TRUE here though nothing really was done
247		ensure("encodeImpl() test failed", res == TRUE);
248	}
249}