]> sigrok.org Git - pulseview.git/blame - test/data/analogsegment.cpp
MainWindow: Made QActions into member variables
[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
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 <extdef.h>
22
340bc0a4
JH
23#include <stdint.h>
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
48ecc1fc 31#if 0
f3d66e52 32BOOST_AUTO_TEST_SUITE(AnalogSegmentTest)
340bc0a4 33
f3d66e52 34void push_analog(AnalogSegment &s, unsigned int num_samples,
340bc0a4
JH
35 float value)
36{
1c4a9ec1
JH
37 float *const data = new float[num_samples];
38 for (unsigned int i = 0; i < num_samples; i++)
39 data[i] = value;
340bc0a4 40
1c4a9ec1
JH
41 s.append_interleaved_samples(data, num_samples, 1);
42 delete[] data;
340bc0a4
JH
43}
44
45BOOST_AUTO_TEST_CASE(Basic)
46{
f3d66e52
JH
47 // Create an empty AnalogSegment object
48 AnalogSegment s;
340bc0a4 49
f3d66e52 50 //----- Test AnalogSegment::push_analog -----//
340bc0a4
JH
51
52 BOOST_CHECK(s.get_sample_count() == 0);
f3d66e52 53 for (unsigned int i = 0; i < AnalogSegment::ScaleStepCount; i++)
340bc0a4 54 {
f3d66e52 55 const AnalogSegment::Envelope &m = s.envelope_levels_[i];
340bc0a4
JH
56 BOOST_CHECK_EQUAL(m.length, 0);
57 BOOST_CHECK_EQUAL(m.data_length, 0);
58 BOOST_CHECK(m.samples == NULL);
59 }
60
61 // Push 8 samples of all zeros
62 push_analog(s, 8, 0.0f);
63
64 BOOST_CHECK(s.get_sample_count() == 8);
65
66 // There should not be enough samples to have a single mip map sample
f3d66e52 67 for (unsigned int i = 0; i < AnalogSegment::ScaleStepCount; i++)
340bc0a4 68 {
f3d66e52 69 const AnalogSegment::Envelope &m = s.envelope_levels_[i];
340bc0a4
JH
70 BOOST_CHECK_EQUAL(m.length, 0);
71 BOOST_CHECK_EQUAL(m.data_length, 0);
72 BOOST_CHECK(m.samples == NULL);
73 }
74
75 // Push 8 samples of 1.0s to bring the total up to 16
76 push_analog(s, 8, 1.0f);
77
78 // There should now be enough data for exactly one sample
79 // in mip map level 0, and that sample should be 0
f3d66e52 80 const AnalogSegment::Envelope &e0 = s.envelope_levels_[0];
340bc0a4 81 BOOST_CHECK_EQUAL(e0.length, 1);
f3d66e52 82 BOOST_CHECK_EQUAL(e0.data_length, AnalogSegment::EnvelopeDataUnit);
340bc0a4
JH
83 BOOST_REQUIRE(e0.samples != NULL);
84 BOOST_CHECK_EQUAL(e0.samples[0].min, 0.0f);
85 BOOST_CHECK_EQUAL(e0.samples[0].max, 1.0f);
86
87 // The higher levels should still be empty
f3d66e52 88 for (unsigned int i = 1; i < AnalogSegment::ScaleStepCount; i++)
340bc0a4 89 {
f3d66e52 90 const AnalogSegment::Envelope &m = s.envelope_levels_[i];
340bc0a4
JH
91 BOOST_CHECK_EQUAL(m.length, 0);
92 BOOST_CHECK_EQUAL(m.data_length, 0);
93 BOOST_CHECK(m.samples == NULL);
94 }
95
96 // Push 240 samples of all zeros to bring the total up to 256
97 push_analog(s, 240, -1.0f);
98
99 BOOST_CHECK_EQUAL(e0.length, 16);
f3d66e52 100 BOOST_CHECK_EQUAL(e0.data_length, AnalogSegment::EnvelopeDataUnit);
340bc0a4
JH
101
102 for (unsigned int i = 1; i < e0.length; i++) {
103 BOOST_CHECK_EQUAL(e0.samples[i].min, -1.0f);
104 BOOST_CHECK_EQUAL(e0.samples[i].max, -1.0f);
105 }
106
f3d66e52 107 const AnalogSegment::Envelope &e1 = s.envelope_levels_[1];
340bc0a4 108 BOOST_CHECK_EQUAL(e1.length, 1);
f3d66e52 109 BOOST_CHECK_EQUAL(e1.data_length, AnalogSegment::EnvelopeDataUnit);
340bc0a4
JH
110 BOOST_REQUIRE(e1.samples != NULL);
111 BOOST_CHECK_EQUAL(e1.samples[0].min, -1.0f);
112 BOOST_CHECK_EQUAL(e1.samples[0].max, 1.0f);
113}
114
115BOOST_AUTO_TEST_SUITE_END()
48ecc1fc 116#endif