libopenraw
testunpack.cpp
1 /* -*- tab-width:4; indent-tabs-mode:'t c-file-style:"stroustrup" -*- */
2 /*
3  * Copyright (C) 2008 Novell, Inc.
4  * Copyright (C) 2009 Hubert Figuiere
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 #include <boost/test/minimal.hpp>
23 
24 #include "unpack.h"
25 #include "ifd.h"
26 
27 
28 int test_unpack()
29 {
30  const uint8_t packed[32] = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF,
31  0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0x00,
32  0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF,
33  0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0x00};
34  uint16_t unpacked[20];
35 
37  unpack(32, OpenRaw::Internals::IFD::COMPRESS_NIKON_PACK);
38 
39  size_t s = unpack.unpack_be12to16((uint8_t*)unpacked, packed,
40  sizeof(packed));
41  BOOST_CHECK(s = size_t(sizeof(unpacked)));
42  for (size_t i = 0; i < 2; ++i) {
43  BOOST_CHECK(unpacked[10 * i + 0] == 0x0123);
44  BOOST_CHECK(unpacked[10 * i + 1] == 0x0456);
45  BOOST_CHECK(unpacked[10 * i + 2] == 0x0789);
46  BOOST_CHECK(unpacked[10 * i + 3] == 0x00AB);
47  BOOST_CHECK(unpacked[10 * i + 4] == 0x0CDE);
48  BOOST_CHECK(unpacked[10 * i + 5] == 0x0F12);
49  BOOST_CHECK(unpacked[10 * i + 6] == 0x0345);
50  BOOST_CHECK(unpacked[10 * i + 7] == 0x0678);
51  BOOST_CHECK(unpacked[10 * i + 8] == 0x090A);
52  BOOST_CHECK(unpacked[10 * i + 9] == 0x0BCD);
53  }
54  return 0;
55 }
56 
57 int test_unpack2()
58 {
59  const uint8_t packed[3] = {0x12, 0x34, 0x56};
60  uint16_t unpacked[2];
61 
63  OpenRaw::Internals::IFD::COMPRESS_NONE);
64 
65  size_t s = unpack.unpack_be12to16((uint8_t*)unpacked, packed,
66  sizeof(packed));
67  BOOST_CHECK(s == size_t(sizeof(unpacked)));
68  BOOST_CHECK(unpacked[0] == 0x0123);
69  BOOST_CHECK(unpacked[1] == 0x0456);
70  return 0;
71 }
72 
73 int test_main( int /*argc*/, char * /*argv*/[] )
74 {
75  test_unpack();
76  test_unpack2();
77  return 0;
78 }