]> sigrok.org Git - pulseview.git/blame - test/data/logicsegment.cpp
MainWindow: Made QActions into member variables
[pulseview.git] / test / data / logicsegment.cpp
CommitLineData
4ceab49a 1/*
b3f22de0 2 * This file is part of the PulseView project.
4ceab49a
JH
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
cef18fc6
JH
21#include <extdef.h>
22
8743e7cb
JH
23#include <stdint.h>
24
4ceab49a
JH
25#include <boost/test/unit_test.hpp>
26
f3d66e52 27#include <pv/data/logicsegment.hpp>
4ceab49a 28
f3d66e52 29using pv::data::LogicSegment;
819f4c25 30using std::vector;
51e77110 31
64f4cc49
UH
32// Dummy, remove again when unit tests are fixed.
33BOOST_AUTO_TEST_SUITE(DummyTestSuite)
34BOOST_AUTO_TEST_CASE(DummyTestCase)
35{
36 BOOST_CHECK_EQUAL(1, 1);
37}
38BOOST_AUTO_TEST_SUITE_END()
39
48ecc1fc 40#if 0
f3d66e52 41BOOST_AUTO_TEST_SUITE(LogicSegmentTest)
ecda6ca9 42
f3d66e52 43void push_logic(LogicSegment &s, unsigned int length, uint8_t value)
4ceab49a
JH
44{
45 sr_datafeed_logic logic;
46 logic.unitsize = 1;
47 logic.length = length;
48 logic.data = new uint8_t[length];
49 memset(logic.data, value, length * logic.unitsize);
50 s.append_payload(logic);
51 delete[] (uint8_t*)logic.data;
52}
53
8743e7cb
JH
54BOOST_AUTO_TEST_CASE(Pow2)
55{
f3d66e52
JH
56 BOOST_CHECK_EQUAL(LogicSegment::pow2_ceil(0, 0), 0);
57 BOOST_CHECK_EQUAL(LogicSegment::pow2_ceil(1, 0), 1);
58 BOOST_CHECK_EQUAL(LogicSegment::pow2_ceil(2, 0), 2);
8743e7cb
JH
59
60 BOOST_CHECK_EQUAL(
f3d66e52 61 LogicSegment::pow2_ceil(INT64_MIN, 0), INT64_MIN);
8743e7cb 62 BOOST_CHECK_EQUAL(
f3d66e52 63 LogicSegment::pow2_ceil(INT64_MAX, 0), INT64_MAX);
8743e7cb 64
f3d66e52
JH
65 BOOST_CHECK_EQUAL(LogicSegment::pow2_ceil(0, 1), 0);
66 BOOST_CHECK_EQUAL(LogicSegment::pow2_ceil(1, 1), 2);
67 BOOST_CHECK_EQUAL(LogicSegment::pow2_ceil(2, 1), 2);
68 BOOST_CHECK_EQUAL(LogicSegment::pow2_ceil(3, 1), 4);
8743e7cb
JH
69}
70
ecda6ca9 71BOOST_AUTO_TEST_CASE(Basic)
4ceab49a 72{
f3d66e52 73 // Create an empty LogicSegment object
4ceab49a
JH
74 sr_datafeed_logic logic;
75 logic.length = 0;
76 logic.unitsize = 1;
77 logic.data = NULL;
78
f3d66e52 79 LogicSegment s(logic);
4ceab49a 80
f3d66e52 81 //----- Test LogicSegment::push_logic -----//
0b02e057 82
4ceab49a 83 BOOST_CHECK(s.get_sample_count() == 0);
f3d66e52 84 for (unsigned int i = 0; i < LogicSegment::ScaleStepCount; i++)
4ceab49a 85 {
f3d66e52 86 const LogicSegment::MipMapLevel &m = s.mip_map_[i];
4ceab49a
JH
87 BOOST_CHECK_EQUAL(m.length, 0);
88 BOOST_CHECK_EQUAL(m.data_length, 0);
89 BOOST_CHECK(m.data == NULL);
90 }
91
92 // Push 8 samples of all zeros
93 push_logic(s, 8, 0);
94
95 BOOST_CHECK(s.get_sample_count() == 8);
96
97 // There should not be enough samples to have a single mip map sample
f3d66e52 98 for (unsigned int i = 0; i < LogicSegment::ScaleStepCount; i++)
4ceab49a 99 {
f3d66e52 100 const LogicSegment::MipMapLevel &m = s.mip_map_[i];
4ceab49a
JH
101 BOOST_CHECK_EQUAL(m.length, 0);
102 BOOST_CHECK_EQUAL(m.data_length, 0);
103 BOOST_CHECK(m.data == NULL);
104 }
105
106 // Push 8 samples of 0x11s to bring the total up to 16
107 push_logic(s, 8, 0x11);
108
109 // There should now be enough data for exactly one sample
110 // in mip map level 0, and that sample should be 0
f3d66e52 111 const LogicSegment::MipMapLevel &m0 = s.mip_map_[0];
4ceab49a 112 BOOST_CHECK_EQUAL(m0.length, 1);
f3d66e52 113 BOOST_CHECK_EQUAL(m0.data_length, LogicSegment::MipMapDataUnit);
4ceab49a
JH
114 BOOST_REQUIRE(m0.data != NULL);
115 BOOST_CHECK_EQUAL(((uint8_t*)m0.data)[0], 0x11);
116
117 // The higher levels should still be empty
f3d66e52 118 for (unsigned int i = 1; i < LogicSegment::ScaleStepCount; i++)
4ceab49a 119 {
f3d66e52 120 const LogicSegment::MipMapLevel &m = s.mip_map_[i];
4ceab49a
JH
121 BOOST_CHECK_EQUAL(m.length, 0);
122 BOOST_CHECK_EQUAL(m.data_length, 0);
123 BOOST_CHECK(m.data == NULL);
124 }
125
126 // Push 240 samples of all zeros to bring the total up to 256
127 push_logic(s, 240, 0);
128
129 BOOST_CHECK_EQUAL(m0.length, 16);
f3d66e52 130 BOOST_CHECK_EQUAL(m0.data_length, LogicSegment::MipMapDataUnit);
4ceab49a
JH
131
132 BOOST_CHECK_EQUAL(((uint8_t*)m0.data)[1], 0x11);
333d5bbc 133 for (unsigned int i = 2; i < m0.length; i++)
4ceab49a
JH
134 BOOST_CHECK_EQUAL(((uint8_t*)m0.data)[i], 0);
135
f3d66e52 136 const LogicSegment::MipMapLevel &m1 = s.mip_map_[1];
4ceab49a 137 BOOST_CHECK_EQUAL(m1.length, 1);
f3d66e52 138 BOOST_CHECK_EQUAL(m1.data_length, LogicSegment::MipMapDataUnit);
4ceab49a
JH
139 BOOST_REQUIRE(m1.data != NULL);
140 BOOST_CHECK_EQUAL(((uint8_t*)m1.data)[0], 0x11);
0b02e057 141
f3d66e52 142 //----- Test LogicSegment::get_subsampled_edges -----//
0b02e057
JH
143
144 // Test a full view at full zoom.
f3d66e52 145 vector<LogicSegment::EdgePair> edges;
0b02e057
JH
146 s.get_subsampled_edges(edges, 0, 255, 1, 0);
147 BOOST_REQUIRE_EQUAL(edges.size(), 4);
148
149 BOOST_CHECK_EQUAL(edges[0].first, 0);
150 BOOST_CHECK_EQUAL(edges[1].first, 8);
151 BOOST_CHECK_EQUAL(edges[2].first, 16);
175d6573 152 BOOST_CHECK_EQUAL(edges[3].first, 256);
0b02e057
JH
153
154 // Test a subset at high zoom
155 edges.clear();
156 s.get_subsampled_edges(edges, 6, 17, 0.05f, 0);
157 BOOST_REQUIRE_EQUAL(edges.size(), 4);
158
159 BOOST_CHECK_EQUAL(edges[0].first, 6);
160 BOOST_CHECK_EQUAL(edges[1].first, 8);
161 BOOST_CHECK_EQUAL(edges[2].first, 16);
175d6573 162 BOOST_CHECK_EQUAL(edges[3].first, 18);
4ceab49a 163}
ecda6ca9
JH
164
165BOOST_AUTO_TEST_CASE(LargeData)
166{
167 uint8_t prev_sample;
38f5609e 168 const unsigned int Length = 1000000;
ecda6ca9
JH
169
170 sr_datafeed_logic logic;
171 logic.unitsize = 1;
172 logic.length = Length;
173 logic.data = new uint8_t[Length];
174 uint8_t *data = (uint8_t*)logic.data;
175
333d5bbc 176 for (unsigned int i = 0; i < Length; i++)
ecda6ca9
JH
177 *data++ = (uint8_t)(i >> 8);
178
f3d66e52 179 LogicSegment s(logic);
ecda6ca9
JH
180 delete[] (uint8_t*)logic.data;
181
182 BOOST_CHECK(s.get_sample_count() == Length);
183
184 // Check mip map level 0
8dbbc7f0
JH
185 BOOST_CHECK_EQUAL(s.mip_map_[0].length, 62500);
186 BOOST_CHECK_EQUAL(s.mip_map_[0].data_length,
f3d66e52 187 LogicSegment::MipMapDataUnit);
8dbbc7f0 188 BOOST_REQUIRE(s.mip_map_[0].data != NULL);
ecda6ca9
JH
189
190 prev_sample = 0;
8dbbc7f0 191 for (unsigned int i = 0; i < s.mip_map_[0].length;)
ecda6ca9
JH
192 {
193 BOOST_TEST_MESSAGE("Testing mip_map[0].data[" << i << "]");
194
195 const uint8_t sample = (uint8_t)((i*16) >> 8);
b2bcbe51 196 BOOST_CHECK_EQUAL(s.get_subsample(0, i++) & 0xFF,
ecda6ca9
JH
197 prev_sample ^ sample);
198 prev_sample = sample;
199
8dbbc7f0 200 for (int j = 1; i < s.mip_map_[0].length && j < 16; j++)
ecda6ca9
JH
201 {
202 BOOST_TEST_MESSAGE("Testing mip_map[0].data[" << i << "]");
b2bcbe51 203 BOOST_CHECK_EQUAL(s.get_subsample(0, i++) & 0xFF, 0);
ecda6ca9
JH
204 }
205 }
206
207 // Check mip map level 1
8dbbc7f0
JH
208 BOOST_CHECK_EQUAL(s.mip_map_[1].length, 3906);
209 BOOST_CHECK_EQUAL(s.mip_map_[1].data_length,
f3d66e52 210 LogicSegment::MipMapDataUnit);
8dbbc7f0 211 BOOST_REQUIRE(s.mip_map_[1].data != NULL);
ecda6ca9
JH
212
213 prev_sample = 0;
8dbbc7f0 214 for (unsigned int i = 0; i < s.mip_map_[1].length; i++)
ecda6ca9
JH
215 {
216 BOOST_TEST_MESSAGE("Testing mip_map[1].data[" << i << "]");
217
218 const uint8_t sample = i;
219 const uint8_t expected = sample ^ prev_sample;
220 prev_sample = i;
221
b2bcbe51 222 BOOST_CHECK_EQUAL(s.get_subsample(1, i) & 0xFF, expected);
ecda6ca9
JH
223 }
224
225 // Check mip map level 2
8dbbc7f0
JH
226 BOOST_CHECK_EQUAL(s.mip_map_[2].length, 244);
227 BOOST_CHECK_EQUAL(s.mip_map_[2].data_length,
f3d66e52 228 LogicSegment::MipMapDataUnit);
8dbbc7f0 229 BOOST_REQUIRE(s.mip_map_[2].data != NULL);
ecda6ca9
JH
230
231 prev_sample = 0;
8dbbc7f0 232 for (unsigned int i = 0; i < s.mip_map_[2].length; i++)
ecda6ca9
JH
233 {
234 BOOST_TEST_MESSAGE("Testing mip_map[2].data[" << i << "]");
235
236 const uint8_t sample = i << 4;
237 const uint8_t expected = (sample ^ prev_sample) | 0x0F;
238 prev_sample = sample;
239
b2bcbe51 240 BOOST_CHECK_EQUAL(s.get_subsample(2, i) & 0xFF, expected);
ecda6ca9
JH
241 }
242
243 // Check mip map level 3
8dbbc7f0
JH
244 BOOST_CHECK_EQUAL(s.mip_map_[3].length, 15);
245 BOOST_CHECK_EQUAL(s.mip_map_[3].data_length,
f3d66e52 246 LogicSegment::MipMapDataUnit);
8dbbc7f0 247 BOOST_REQUIRE(s.mip_map_[3].data != NULL);
ecda6ca9 248
8dbbc7f0
JH
249 for (unsigned int i = 0; i < s.mip_map_[3].length; i++)
250 BOOST_CHECK_EQUAL(*((uint8_t*)s.mip_map_[3].data + i),
ecda6ca9
JH
251 0xFF);
252
253 // Check the higher levels
f3d66e52 254 for (unsigned int i = 4; i < LogicSegment::ScaleStepCount; i++)
ecda6ca9 255 {
f3d66e52 256 const LogicSegment::MipMapLevel &m = s.mip_map_[i];
ecda6ca9
JH
257 BOOST_CHECK_EQUAL(m.length, 0);
258 BOOST_CHECK_EQUAL(m.data_length, 0);
259 BOOST_CHECK(m.data == NULL);
260 }
261
f3d66e52 262 //----- Test LogicSegment::get_subsampled_edges -----//
ac7aa636 263 // Check in normal case
f3d66e52 264 vector<LogicSegment::EdgePair> edges;
ecda6ca9 265 s.get_subsampled_edges(edges, 0, Length-1, 1, 7);
ecda6ca9 266
39f6e56e
JH
267 BOOST_CHECK_EQUAL(edges.size(), 32);
268
333d5bbc 269 for (unsigned int i = 0; i < edges.size() - 1; i++)
ecda6ca9 270 {
39f6e56e
JH
271 BOOST_CHECK_EQUAL(edges[i].first, i * 32768);
272 BOOST_CHECK_EQUAL(edges[i].second, i & 1);
ecda6ca9
JH
273 }
274
175d6573 275 BOOST_CHECK_EQUAL(edges[31].first, 1000000);
ac7aa636
JH
276
277 // Check in very low zoom case
278 edges.clear();
279 s.get_subsampled_edges(edges, 0, Length-1, 50e6f, 7);
280
281 BOOST_CHECK_EQUAL(edges.size(), 2);
ecda6ca9
JH
282}
283
3db297c4
JH
284BOOST_AUTO_TEST_CASE(Pulses)
285{
286 const int Cycles = 3;
287 const int Period = 64;
288 const int Length = Cycles * Period;
289
f3d66e52 290 vector<LogicSegment::EdgePair> edges;
3db297c4 291
f3d66e52 292 //----- Create a LogicSegment -----//
3db297c4
JH
293 sr_datafeed_logic logic;
294 logic.unitsize = 1;
295 logic.length = Length;
296 logic.data = (uint64_t*)new uint8_t[Length];
297 uint8_t *p = (uint8_t*)logic.data;
298
333d5bbc 299 for (int i = 0; i < Cycles; i++) {
3db297c4 300 *p++ = 0xFF;
333d5bbc 301 for (int j = 1; j < Period; j++)
3db297c4
JH
302 *p++ = 0x00;
303 }
304
f3d66e52 305 LogicSegment s(logic);
821f23af 306 delete[] (uint8_t*)logic.data;
3db297c4
JH
307
308 //----- Check the mip-map -----//
309 // Check mip map level 0
8dbbc7f0
JH
310 BOOST_CHECK_EQUAL(s.mip_map_[0].length, 12);
311 BOOST_CHECK_EQUAL(s.mip_map_[0].data_length,
f3d66e52 312 LogicSegment::MipMapDataUnit);
8dbbc7f0 313 BOOST_REQUIRE(s.mip_map_[0].data != NULL);
3db297c4 314
8dbbc7f0 315 for (unsigned int i = 0; i < s.mip_map_[0].length;) {
3db297c4
JH
316 BOOST_TEST_MESSAGE("Testing mip_map[0].data[" << i << "]");
317 BOOST_CHECK_EQUAL(s.get_subsample(0, i++) & 0xFF, 0xFF);
318
333d5bbc 319 for (int j = 1;
8dbbc7f0 320 i < s.mip_map_[0].length &&
f3d66e52 321 j < Period/LogicSegment::MipMapScaleFactor; j++) {
3db297c4
JH
322 BOOST_TEST_MESSAGE(
323 "Testing mip_map[0].data[" << i << "]");
324 BOOST_CHECK_EQUAL(s.get_subsample(0, i++) & 0xFF, 0x00);
325 }
326 }
327
328 // Check the higher levels are all inactive
f3d66e52
JH
329 for (unsigned int i = 1; i < LogicSegment::ScaleStepCount; i++) {
330 const LogicSegment::MipMapLevel &m = s.mip_map_[i];
3db297c4
JH
331 BOOST_CHECK_EQUAL(m.length, 0);
332 BOOST_CHECK_EQUAL(m.data_length, 0);
333 BOOST_CHECK(m.data == NULL);
334 }
335
336 //----- Test get_subsampled_edges at reduced scale -----//
337 s.get_subsampled_edges(edges, 0, Length-1, 16.0f, 2);
7d0d64f9 338 BOOST_REQUIRE_EQUAL(edges.size(), Cycles + 2);
3db297c4 339
7d0d64f9 340 BOOST_CHECK_EQUAL(0, false);
333d5bbc 341 for (unsigned int i = 1; i < edges.size(); i++)
3db297c4
JH
342 BOOST_CHECK_EQUAL(edges[i].second, false);
343}
344
910b16ec
JH
345BOOST_AUTO_TEST_CASE(LongPulses)
346{
347 const int Cycles = 3;
348 const int Period = 64;
349 const int PulseWidth = 16;
350 const int Length = Cycles * Period;
351
352 int j;
f3d66e52 353 vector<LogicSegment::EdgePair> edges;
910b16ec 354
f3d66e52 355 //----- Create a LogicSegment -----//
910b16ec 356 sr_datafeed_logic logic;
4f767cf7 357 logic.unitsize = 8;
37fdce0a 358 logic.length = Length * 8;
4f767cf7
JH
359 logic.data = (uint64_t*)new uint64_t[Length];
360 uint64_t *p = (uint64_t*)logic.data;
910b16ec 361
333d5bbc
UH
362 for (int i = 0; i < Cycles; i++) {
363 for (j = 0; j < PulseWidth; j++)
4f767cf7 364 *p++ = ~0;
333d5bbc 365 for (; j < Period; j++)
4f767cf7 366 *p++ = 0;
910b16ec
JH
367 }
368
f3d66e52 369 LogicSegment s(logic);
ba3c4dae 370 delete[] (uint64_t*)logic.data;
910b16ec
JH
371
372 //----- Check the mip-map -----//
373 // Check mip map level 0
8dbbc7f0
JH
374 BOOST_CHECK_EQUAL(s.mip_map_[0].length, 12);
375 BOOST_CHECK_EQUAL(s.mip_map_[0].data_length,
f3d66e52 376 LogicSegment::MipMapDataUnit);
8dbbc7f0 377 BOOST_REQUIRE(s.mip_map_[0].data != NULL);
910b16ec 378
8dbbc7f0
JH
379 for (unsigned int i = 0; i < s.mip_map_[0].length;) {
380 for (j = 0; i < s.mip_map_[0].length && j < 2; j++) {
910b16ec
JH
381 BOOST_TEST_MESSAGE(
382 "Testing mip_map[0].data[" << i << "]");
4f767cf7 383 BOOST_CHECK_EQUAL(s.get_subsample(0, i++), ~0);
910b16ec
JH
384 }
385
8dbbc7f0 386 for (; i < s.mip_map_[0].length &&
f3d66e52 387 j < Period/LogicSegment::MipMapScaleFactor; j++) {
910b16ec
JH
388 BOOST_TEST_MESSAGE(
389 "Testing mip_map[0].data[" << i << "]");
4f767cf7 390 BOOST_CHECK_EQUAL(s.get_subsample(0, i++), 0);
910b16ec
JH
391 }
392 }
393
394 // Check the higher levels are all inactive
f3d66e52
JH
395 for (unsigned int i = 1; i < LogicSegment::ScaleStepCount; i++) {
396 const LogicSegment::MipMapLevel &m = s.mip_map_[i];
910b16ec
JH
397 BOOST_CHECK_EQUAL(m.length, 0);
398 BOOST_CHECK_EQUAL(m.data_length, 0);
399 BOOST_CHECK(m.data == NULL);
400 }
401
402 //----- Test get_subsampled_edges at a full scale -----//
403 s.get_subsampled_edges(edges, 0, Length-1, 16.0f, 2);
404 BOOST_REQUIRE_EQUAL(edges.size(), Cycles * 2 + 1);
405
333d5bbc 406 for (int i = 0; i < Cycles; i++) {
910b16ec
JH
407 BOOST_CHECK_EQUAL(edges[i*2].first, i * Period);
408 BOOST_CHECK_EQUAL(edges[i*2].second, true);
409 BOOST_CHECK_EQUAL(edges[i*2+1].first, i * Period + PulseWidth);
410 BOOST_CHECK_EQUAL(edges[i*2+1].second, false);
411 }
412
175d6573 413 BOOST_CHECK_EQUAL(edges.back().first, Length);
910b16ec
JH
414 BOOST_CHECK_EQUAL(edges.back().second, false);
415
416 //----- Test get_subsampled_edges at a simplified scale -----//
417 edges.clear();
418 s.get_subsampled_edges(edges, 0, Length-1, 17.0f, 2);
419
7d0d64f9
JH
420 BOOST_CHECK_EQUAL(edges[0].first, 0);
421 BOOST_CHECK_EQUAL(edges[0].second, true);
422 BOOST_CHECK_EQUAL(edges[1].first, 16);
423 BOOST_CHECK_EQUAL(edges[1].second, false);
424
333d5bbc 425 for (int i = 1; i < Cycles; i++) {
7d0d64f9
JH
426 BOOST_CHECK_EQUAL(edges[i+1].first, i * Period);
427 BOOST_CHECK_EQUAL(edges[i+1].second, false);
910b16ec
JH
428 }
429
175d6573 430 BOOST_CHECK_EQUAL(edges.back().first, Length);
910b16ec
JH
431 BOOST_CHECK_EQUAL(edges.back().second, false);
432}
433
a126c277
JH
434BOOST_AUTO_TEST_CASE(LisaMUsbHid)
435{
436 /* This test was created from the beginning of the USB_DM signal in
437 * sigrok-dumps-usb/lisa_m_usbhid/lisa_m_usbhid.sr
438 */
439
440 const int Edges[] = {
441 7028, 7033, 7036, 7041, 7044, 7049, 7053, 7066, 7073, 7079,
442 7086, 7095, 7103, 7108, 7111, 7116, 7119, 7124, 7136, 7141,
443 7148, 7162, 7500
444 };
445 const int Length = Edges[countof(Edges) - 1];
446
447 bool state = false;
448 int lastEdgePos = 0;
449
f3d66e52 450 //----- Create a LogicSegment -----//
a126c277
JH
451 sr_datafeed_logic logic;
452 logic.unitsize = 1;
453 logic.length = Length;
454 logic.data = new uint8_t[Length];
455 uint8_t *data = (uint8_t*)logic.data;
456
333d5bbc 457 for (unsigned int i = 0; i < countof(Edges); i++) {
a126c277
JH
458 const int edgePos = Edges[i];
459 memset(&data[lastEdgePos], state ? 0x02 : 0,
460 edgePos - lastEdgePos - 1);
461
462 lastEdgePos = edgePos;
463 state = !state;
464 }
465
f3d66e52 466 LogicSegment s(logic);
a126c277
JH
467 delete[] (uint64_t*)logic.data;
468
f3d66e52 469 vector<LogicSegment::EdgePair> edges;
a126c277
JH
470
471
472 /* The trailing edge of the pulse train is falling in the source data.
473 * Check this is always true at different scales
474 */
475
476 edges.clear();
477 s.get_subsampled_edges(edges, 0, Length-1, 33.333332f, 1);
478 BOOST_CHECK_EQUAL(edges[edges.size() - 2].second, false);
479}
480
6092d96f 481/*
6ac6242b 482 * This test checks the rendering of wide data (more than 8 channels)
6092d96f 483 * Probe signals are either all-high, or all-low, but are interleaved such that
6ac6242b 484 * they would toggle during every sample if treated like 8 channels.
6092d96f
AG
485 * The packet contains a large number of samples, so the mipmap generation kicks
486 * in.
487 *
488 * The signals should not toggle (have exactly two edges: the start and end)
489 */
490BOOST_AUTO_TEST_CASE(WideData)
491{
492 const int Length = 512<<10;
493 uint16_t *data = new uint16_t[Length];
494
495 sr_datafeed_logic logic;
496 logic.unitsize = sizeof(data[0]);
497 logic.length = Length * sizeof(data[0]);
498 logic.data = data;
499
9ba4ca35 500 for (int i = 0; i < Length; i++)
6092d96f
AG
501 data[i] = 0x0FF0;
502
f3d66e52 503 LogicSegment s(logic);
6092d96f 504
f3d66e52 505 vector<LogicSegment::EdgePair> edges;
6092d96f
AG
506
507 edges.clear();
508 s.get_subsampled_edges(edges, 0, Length-1, 1, 0);
509 BOOST_CHECK_EQUAL(edges.size(), 2);
510
511 edges.clear();
512 s.get_subsampled_edges(edges, 0, Length-1, 1, 8);
513 BOOST_CHECK_EQUAL(edges.size(), 2);
514
515 // Cleanup
516 delete [] data;
517}
a126c277 518
c6013ca7
JH
519/*
520 * This test is a replica of sixteen.sr attached to Bug #33.
521 */
522BOOST_AUTO_TEST_CASE(Sixteen)
523{
524 const int Length = 8;
525 uint16_t data[Length];
526
527 sr_datafeed_logic logic;
528 logic.unitsize = sizeof(data[0]);
529 logic.length = Length * sizeof(data[0]);
530 logic.data = data;
531
9ba4ca35 532 for (int i = 0; i < Length; i++)
c6013ca7
JH
533 data[i] = 0xFFFE;
534
f3d66e52 535 LogicSegment s(logic);
c6013ca7 536
f3d66e52 537 vector<LogicSegment::EdgePair> edges;
c6013ca7
JH
538 s.get_subsampled_edges(edges, 0, 2, 0.0004, 1);
539
540 BOOST_CHECK_EQUAL(edges.size(), 2);
541}
542
ecda6ca9 543BOOST_AUTO_TEST_SUITE_END()
48ecc1fc 544#endif