]> sigrok.org Git - pulseview.git/blame - test/data/analogsegment.cpp
Replace non-ASCII characters
[pulseview.git] / test / data / analogsegment.cpp
CommitLineData
340bc0a4
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2013 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
efdec55a 17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
340bc0a4
JH
18 */
19
83b1c8d2 20#if 0
340bc0a4
JH
21#include <extdef.h>
22
eb8269e3 23#include <cstdint>
340bc0a4
JH
24
25#include <boost/test/unit_test.hpp>
26
f3d66e52 27#include <pv/data/analogsegment.hpp>
340bc0a4 28
f3d66e52 29using pv::data::AnalogSegment;
340bc0a4 30
f3d66e52 31BOOST_AUTO_TEST_SUITE(AnalogSegmentTest)
340bc0a4 32
f3d66e52 33void push_analog(AnalogSegment &s, unsigned int num_samples,
340bc0a4
JH
34 float value)
35{
1c4a9ec1
JH
36 float *const data = new float[num_samples];
37 for (unsigned int i = 0; i < num_samples; i++)
38 data[i] = value;
340bc0a4 39
1c4a9ec1
JH
40 s.append_interleaved_samples(data, num_samples, 1);
41 delete[] data;
340bc0a4
JH
42}
43
44BOOST_AUTO_TEST_CASE(Basic)
45{
f3d66e52
JH
46 // Create an empty AnalogSegment object
47 AnalogSegment s;
340bc0a4 48
f3d66e52 49 //----- Test AnalogSegment::push_analog -----//
340bc0a4
JH
50
51 BOOST_CHECK(s.get_sample_count() == 0);
f3d66e52 52 for (unsigned int i = 0; i < AnalogSegment::ScaleStepCount; i++)
340bc0a4 53 {
f3d66e52 54 const AnalogSegment::Envelope &m = s.envelope_levels_[i];
340bc0a4
JH
55 BOOST_CHECK_EQUAL(m.length, 0);
56 BOOST_CHECK_EQUAL(m.data_length, 0);
4c60462b 57 BOOST_CHECK(m.samples == nullptr);
340bc0a4
JH
58 }
59
60 // Push 8 samples of all zeros
61 push_analog(s, 8, 0.0f);
62
63 BOOST_CHECK(s.get_sample_count() == 8);
64
65 // There should not be enough samples to have a single mip map sample
f3d66e52 66 for (unsigned int i = 0; i < AnalogSegment::ScaleStepCount; i++)
340bc0a4 67 {
f3d66e52 68 const AnalogSegment::Envelope &m = s.envelope_levels_[i];
340bc0a4
JH
69 BOOST_CHECK_EQUAL(m.length, 0);
70 BOOST_CHECK_EQUAL(m.data_length, 0);
4c60462b 71 BOOST_CHECK(m.samples == nullptr);
340bc0a4
JH
72 }
73
74 // Push 8 samples of 1.0s to bring the total up to 16
75 push_analog(s, 8, 1.0f);
76
77 // There should now be enough data for exactly one sample
78 // in mip map level 0, and that sample should be 0
f3d66e52 79 const AnalogSegment::Envelope &e0 = s.envelope_levels_[0];
340bc0a4 80 BOOST_CHECK_EQUAL(e0.length, 1);
f3d66e52 81 BOOST_CHECK_EQUAL(e0.data_length, AnalogSegment::EnvelopeDataUnit);
4c60462b 82 BOOST_REQUIRE(e0.samples != nullptr);
340bc0a4
JH
83 BOOST_CHECK_EQUAL(e0.samples[0].min, 0.0f);
84 BOOST_CHECK_EQUAL(e0.samples[0].max, 1.0f);
85
86 // The higher levels should still be empty
f3d66e52 87 for (unsigned int i = 1; i < AnalogSegment::ScaleStepCount; i++)
340bc0a4 88 {
f3d66e52 89 const AnalogSegment::Envelope &m = s.envelope_levels_[i];
340bc0a4
JH
90 BOOST_CHECK_EQUAL(m.length, 0);
91 BOOST_CHECK_EQUAL(m.data_length, 0);
4c60462b 92 BOOST_CHECK(m.samples == nullptr);
340bc0a4
JH
93 }
94
95 // Push 240 samples of all zeros to bring the total up to 256
96 push_analog(s, 240, -1.0f);
97
98 BOOST_CHECK_EQUAL(e0.length, 16);
f3d66e52 99 BOOST_CHECK_EQUAL(e0.data_length, AnalogSegment::EnvelopeDataUnit);
340bc0a4
JH
100
101 for (unsigned int i = 1; i < e0.length; i++) {
102 BOOST_CHECK_EQUAL(e0.samples[i].min, -1.0f);
103 BOOST_CHECK_EQUAL(e0.samples[i].max, -1.0f);
104 }
105
f3d66e52 106 const AnalogSegment::Envelope &e1 = s.envelope_levels_[1];
340bc0a4 107 BOOST_CHECK_EQUAL(e1.length, 1);
f3d66e52 108 BOOST_CHECK_EQUAL(e1.data_length, AnalogSegment::EnvelopeDataUnit);
4c60462b 109 BOOST_REQUIRE(e1.samples != nullptr);
340bc0a4
JH
110 BOOST_CHECK_EQUAL(e1.samples[0].min, -1.0f);
111 BOOST_CHECK_EQUAL(e1.samples[0].max, 1.0f);
112}
113
114BOOST_AUTO_TEST_SUITE_END()
48ecc1fc 115#endif