libopenraw
|
00001 /* -*- tab-width:4; indent-tabs-mode:'t c-file-style:"stroustrup" -*- */ 00002 /* 00003 * Copyright (C) 2008 Novell, Inc. 00004 * Copyright (C) 2009 Hubert Figuiere 00005 * 00006 * This library is free software: you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public License 00008 * as published by the Free Software Foundation, either version 3 of 00009 * the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library. If not, see 00018 * <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 00022 #include <boost/test/minimal.hpp> 00023 00024 #include "unpack.h" 00025 #include "ifd.h" 00026 00027 00028 int test_unpack() 00029 { 00030 const uint8_t packed[32] = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 00031 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0x00, 00032 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF, 00033 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0x00}; 00034 uint16_t unpacked[20]; 00035 00036 OpenRaw::Internals::Unpack 00037 unpack(32, OpenRaw::Internals::IFD::COMPRESS_NIKON_PACK); 00038 00039 size_t s = unpack.unpack_be12to16((uint8_t*)unpacked, packed, 00040 sizeof(packed)); 00041 BOOST_CHECK(s = size_t(sizeof(unpacked))); 00042 for (size_t i = 0; i < 2; ++i) { 00043 BOOST_CHECK(unpacked[10 * i + 0] == 0x0123); 00044 BOOST_CHECK(unpacked[10 * i + 1] == 0x0456); 00045 BOOST_CHECK(unpacked[10 * i + 2] == 0x0789); 00046 BOOST_CHECK(unpacked[10 * i + 3] == 0x00AB); 00047 BOOST_CHECK(unpacked[10 * i + 4] == 0x0CDE); 00048 BOOST_CHECK(unpacked[10 * i + 5] == 0x0F12); 00049 BOOST_CHECK(unpacked[10 * i + 6] == 0x0345); 00050 BOOST_CHECK(unpacked[10 * i + 7] == 0x0678); 00051 BOOST_CHECK(unpacked[10 * i + 8] == 0x090A); 00052 BOOST_CHECK(unpacked[10 * i + 9] == 0x0BCD); 00053 } 00054 return 0; 00055 } 00056 00057 int test_unpack2() 00058 { 00059 const uint8_t packed[3] = {0x12, 0x34, 0x56}; 00060 uint16_t unpacked[2]; 00061 00062 OpenRaw::Internals::Unpack unpack(32, 00063 OpenRaw::Internals::IFD::COMPRESS_NONE); 00064 00065 size_t s = unpack.unpack_be12to16((uint8_t*)unpacked, packed, 00066 sizeof(packed)); 00067 BOOST_CHECK(s == size_t(sizeof(unpacked))); 00068 BOOST_CHECK(unpacked[0] == 0x0123); 00069 BOOST_CHECK(unpacked[1] == 0x0456); 00070 return 0; 00071 } 00072 00073 int test_main( int /*argc*/, char * /*argv*/[] ) 00074 { 00075 test_unpack(); 00076 test_unpack2(); 00077 return 0; 00078 }