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