223
|
1 /* |
|
2 * TestPack.cpp -- test the pack serializer |
|
3 * |
|
4 * Copyright (c) 2013, 2014 David Demelier <markand@malikania.fr> |
|
5 * |
|
6 * Permission to use, copy, modify, and/or distribute this software for any |
|
7 * purpose with or without fee is hereby granted, provided that the above |
|
8 * copyright notice and this permission notice appear in all copies. |
|
9 * |
|
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
17 */ |
|
18 |
|
19 #include <cppunit/TextTestRunner.h> |
|
20 |
|
21 #include <Pack.h> |
|
22 |
|
23 #include "TestPack.h" |
|
24 |
|
25 void TestPack::simpleLittleEndian() |
|
26 { |
|
27 uint8_t u8(1), r8; |
|
28 uint16_t u16(2), r16; |
|
29 uint32_t u32(3), r32; |
|
30 uint64_t u64(4), r64; |
|
31 |
|
32 try { |
|
33 Pack::write("simple-little.bin", Pack::Little, u8, u16, u32, u64); |
|
34 Pack::read("simple-little.bin", Pack::Little, r8, r16, r32, r64); |
|
35 |
|
36 CPPUNIT_ASSERT_EQUAL(r8, u8); |
|
37 CPPUNIT_ASSERT_EQUAL(r16, u16); |
|
38 CPPUNIT_ASSERT_EQUAL(r32, u32); |
|
39 CPPUNIT_ASSERT_EQUAL(r64, u64); |
|
40 } catch (const std::runtime_error &) { } |
|
41 } |
|
42 |
|
43 void TestPack::simpleBigEndian() |
|
44 { |
|
45 uint8_t u8(1), r8; |
|
46 uint16_t u16(2), r16; |
|
47 uint32_t u32(3), r32; |
|
48 uint64_t u64(4), r64; |
|
49 |
|
50 try { |
|
51 Pack::write("simple-big.bin", Pack::Big, u8, u16, u32, u64); |
|
52 Pack::read("simple-big.bin", Pack::Big, r8, r16, r32, r64); |
|
53 |
|
54 CPPUNIT_ASSERT_EQUAL(r8, u8); |
|
55 CPPUNIT_ASSERT_EQUAL(r16, u16); |
|
56 CPPUNIT_ASSERT_EQUAL(r32, u32); |
|
57 CPPUNIT_ASSERT_EQUAL(r64, u64); |
|
58 } catch (const std::runtime_error &) { } |
|
59 } |
|
60 |
|
61 int main() |
|
62 { |
|
63 CppUnit::TextTestRunner runnerText; |
|
64 |
|
65 runnerText.addTest(TestPack::suite()); |
|
66 |
|
67 return runnerText.run("", false) == 1 ? 0 : 1; |
|
68 } |