1
// ------------------------------------------------------------------------
2
// samplebuffer_test.h: Unit test for SAMPLE_BUFFER
3
// Copyright (C) 2009 Kai Vehmanen
5
// This program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 2 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
// ------------------------------------------------------------------------
24
#include "kvu_inttypes.h"
26
#include "samplebuffer.h"
27
#include "samplebuffer_functions.h"
28
#include "eca-test-case.h"
33
* Unit test for SAMPLE_BUFFER
35
class SAMPLE_BUFFER_TEST : public ECA_TEST_CASE {
39
virtual string do_name(void) const { return("SAMPLE_BUFFER"); }
40
virtual void do_run(void);
44
virtual ~SAMPLE_BUFFER_TEST(void) { }
50
void SAMPLE_BUFFER_TEST::do_run(void)
52
const int bufsize = 1024;
53
const int channels = 12;
54
const SAMPLE_BUFFER::sample_t multiplier = 100.1f;
56
std::fprintf(stdout, "%s: tests for SAMPLE_BUFFER class\n",
59
/* case: multiply_by */
61
std::fprintf(stdout, "%s: multiply_by\n",
63
SAMPLE_BUFFER sbuf_orig (bufsize, channels);
64
SAMPLE_BUFFER sbuf_ref (bufsize, channels);
65
SAMPLE_BUFFER sbuf_test (bufsize, channels);
67
SAMPLE_BUFFER_FUNCTIONS::fill_with_random_samples(&sbuf_orig);
69
sbuf_test.copy_all_content(sbuf_orig);
70
sbuf_ref.copy_all_content(sbuf_orig);
72
sbuf_test.multiply_by(multiplier);
73
sbuf_ref.multiply_by_ref(multiplier);
75
if (SAMPLE_BUFFER_FUNCTIONS::is_almost_equal(sbuf_ref, sbuf_test) != true) {
76
ECA_TEST_FAILURE("optimized multiple_by");
80
/* case: copy_all_content */
82
std::fprintf(stdout, "%s: copy_all_content\n",
85
SAMPLE_BUFFER sbuf_orig (bufsize, channels);
86
SAMPLE_BUFFER sbuf_ref (bufsize, channels);
87
SAMPLE_BUFFER sbuf_test (bufsize, channels);
89
SAMPLE_BUFFER_FUNCTIONS::fill_with_random_samples(&sbuf_orig);
91
/* note: copy_all_content should modify the destination
92
* channel and sample counts to match those of
93
* the source object. */
94
sbuf_test.number_of_channels(0);
95
sbuf_test.length_in_samples(1);
97
sbuf_test.copy_all_content(sbuf_orig);
98
sbuf_ref.copy_matching_channels(sbuf_orig);
100
if (SAMPLE_BUFFER_FUNCTIONS::is_almost_equal(sbuf_ref, sbuf_test) != true) {
101
ECA_TEST_FAILURE("copy_all_content");
105
/* case: multiply_by */
107
std::fprintf(stdout, "%s: add_matching_channels\n",
109
SAMPLE_BUFFER sbuf_orig (bufsize, channels);
110
SAMPLE_BUFFER sbuf_ref (bufsize, channels);
111
SAMPLE_BUFFER sbuf_test (bufsize, channels);
113
SAMPLE_BUFFER_FUNCTIONS::fill_with_random_samples(&sbuf_orig);
115
sbuf_test.copy_all_content(sbuf_orig);
116
sbuf_ref.copy_all_content(sbuf_orig);
118
sbuf_test.add_matching_channels(sbuf_orig);
119
sbuf_ref.add_matching_channels_ref(sbuf_orig);
121
if (SAMPLE_BUFFER_FUNCTIONS::is_almost_equal(sbuf_ref, sbuf_test) != true) {
122
ECA_TEST_FAILURE("optimized add_matching_channels");