]>
Commit | Line | Data |
---|---|---|
4ceab49a JH |
1 | /* |
2 | * This file is part of the sigrok project. | |
3 | * | |
4 | * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program 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 | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
21 | #include <boost/test/unit_test.hpp> | |
22 | ||
23 | #include "../logicdatasnapshot.h" | |
24 | ||
25 | void push_logic(LogicDataSnapshot &s, unsigned int length, uint8_t value) | |
26 | { | |
27 | sr_datafeed_logic logic; | |
28 | logic.unitsize = 1; | |
29 | logic.length = length; | |
30 | logic.data = new uint8_t[length]; | |
31 | memset(logic.data, value, length * logic.unitsize); | |
32 | s.append_payload(logic); | |
33 | delete[] (uint8_t*)logic.data; | |
34 | } | |
35 | ||
36 | BOOST_AUTO_TEST_CASE(LogicDataSnapshotTest) | |
37 | { | |
38 | // Create an empty LogicDataSnapshot object | |
39 | sr_datafeed_logic logic; | |
40 | logic.length = 0; | |
41 | logic.unitsize = 1; | |
42 | logic.data = NULL; | |
43 | ||
44 | LogicDataSnapshot s(logic); | |
45 | ||
46 | BOOST_CHECK(s.get_sample_count() == 0); | |
47 | for(int i = 0; i < LogicDataSnapshot::ScaleStepCount; i++) | |
48 | { | |
49 | const LogicDataSnapshot::MipMapLevel &m = s._mip_map[i]; | |
50 | BOOST_CHECK_EQUAL(m.length, 0); | |
51 | BOOST_CHECK_EQUAL(m.data_length, 0); | |
52 | BOOST_CHECK(m.data == NULL); | |
53 | } | |
54 | ||
55 | // Push 8 samples of all zeros | |
56 | push_logic(s, 8, 0); | |
57 | ||
58 | BOOST_CHECK(s.get_sample_count() == 8); | |
59 | ||
60 | // There should not be enough samples to have a single mip map sample | |
61 | for(int i = 0; i < LogicDataSnapshot::ScaleStepCount; i++) | |
62 | { | |
63 | const LogicDataSnapshot::MipMapLevel &m = s._mip_map[i]; | |
64 | BOOST_CHECK_EQUAL(m.length, 0); | |
65 | BOOST_CHECK_EQUAL(m.data_length, 0); | |
66 | BOOST_CHECK(m.data == NULL); | |
67 | } | |
68 | ||
69 | // Push 8 samples of 0x11s to bring the total up to 16 | |
70 | push_logic(s, 8, 0x11); | |
71 | ||
72 | // There should now be enough data for exactly one sample | |
73 | // in mip map level 0, and that sample should be 0 | |
74 | const LogicDataSnapshot::MipMapLevel &m0 = s._mip_map[0]; | |
75 | BOOST_CHECK_EQUAL(m0.length, 1); | |
76 | BOOST_CHECK_EQUAL(m0.data_length, LogicDataSnapshot::MipMapDataUnit); | |
77 | BOOST_REQUIRE(m0.data != NULL); | |
78 | BOOST_CHECK_EQUAL(((uint8_t*)m0.data)[0], 0x11); | |
79 | ||
80 | // The higher levels should still be empty | |
81 | for(int i = 1; i < LogicDataSnapshot::ScaleStepCount; i++) | |
82 | { | |
83 | const LogicDataSnapshot::MipMapLevel &m = s._mip_map[i]; | |
84 | BOOST_CHECK_EQUAL(m.length, 0); | |
85 | BOOST_CHECK_EQUAL(m.data_length, 0); | |
86 | BOOST_CHECK(m.data == NULL); | |
87 | } | |
88 | ||
89 | // Push 240 samples of all zeros to bring the total up to 256 | |
90 | push_logic(s, 240, 0); | |
91 | ||
92 | BOOST_CHECK_EQUAL(m0.length, 16); | |
93 | BOOST_CHECK_EQUAL(m0.data_length, LogicDataSnapshot::MipMapDataUnit); | |
94 | ||
95 | BOOST_CHECK_EQUAL(((uint8_t*)m0.data)[1], 0x11); | |
96 | for(int i = 2; i < m0.length; i++) | |
97 | BOOST_CHECK_EQUAL(((uint8_t*)m0.data)[i], 0); | |
98 | ||
99 | const LogicDataSnapshot::MipMapLevel &m1 = s._mip_map[1]; | |
100 | BOOST_CHECK_EQUAL(m1.length, 1); | |
101 | BOOST_CHECK_EQUAL(m1.data_length, LogicDataSnapshot::MipMapDataUnit); | |
102 | BOOST_REQUIRE(m1.data != NULL); | |
103 | BOOST_CHECK_EQUAL(((uint8_t*)m1.data)[0], 0x11); | |
104 | } |