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-2016 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.hpp"
25 #include "ifd.hpp"
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;
40  or_error err = unpack.unpack_be12to16((uint8_t*)unpacked, 40, packed,
41  sizeof(packed), s);
42  BOOST_CHECK(s = size_t(sizeof(unpacked)));
43  BOOST_CHECK(err == OR_ERROR_NONE);
44  for (size_t i = 0; i < 2; ++i) {
45  BOOST_CHECK(unpacked[10 * i + 0] == 0x0123);
46  BOOST_CHECK(unpacked[10 * i + 1] == 0x0456);
47  BOOST_CHECK(unpacked[10 * i + 2] == 0x0789);
48  BOOST_CHECK(unpacked[10 * i + 3] == 0x00AB);
49  BOOST_CHECK(unpacked[10 * i + 4] == 0x0CDE);
50  BOOST_CHECK(unpacked[10 * i + 5] == 0x0F12);
51  BOOST_CHECK(unpacked[10 * i + 6] == 0x0345);
52  BOOST_CHECK(unpacked[10 * i + 7] == 0x0678);
53  BOOST_CHECK(unpacked[10 * i + 8] == 0x090A);
54  BOOST_CHECK(unpacked[10 * i + 9] == 0x0BCD);
55  }
56  return 0;
57 }
58 
59 int test_unpack2()
60 {
61  const uint8_t packed[3] = {0x12, 0x34, 0x56};
62  uint16_t unpacked[2];
63 
65  OpenRaw::Internals::IFD::COMPRESS_NONE);
66 
67  size_t s;
68  or_error err = unpack.unpack_be12to16((uint8_t*)unpacked, 4, packed,
69  sizeof(packed), s);
70  BOOST_CHECK(s == size_t(sizeof(unpacked)));
71  BOOST_CHECK(err == OR_ERROR_NONE);
72  BOOST_CHECK(unpacked[0] == 0x0123);
73  BOOST_CHECK(unpacked[1] == 0x0456);
74  return 0;
75 }
76 
77 int test_main( int /*argc*/, char * /*argv*/[] )
78 {
79  test_unpack();
80  test_unpack2();
81  return 0;
82 }