1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
// ------------------------------------------------------------------------
// samplebuffer_test.h: Unit test for SAMPLE_BUFFER
// Copyright (C) 2009 Kai Vehmanen
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// ------------------------------------------------------------------------
#include <string>
#include <cstdio>
#include "kvu_dbc.h"
#include "kvu_inttypes.h"
#include "samplebuffer.h"
#include "samplebuffer_functions.h"
#include "eca-test-case.h"
using namespace std;
/**
* Unit test for SAMPLE_BUFFER
*/
class SAMPLE_BUFFER_TEST : public ECA_TEST_CASE {
protected:
virtual string do_name(void) const { return("SAMPLE_BUFFER"); }
virtual void do_run(void);
public:
virtual ~SAMPLE_BUFFER_TEST(void) { }
private:
};
void SAMPLE_BUFFER_TEST::do_run(void)
{
const int bufsize = 1024;
const int channels = 12;
const SAMPLE_BUFFER::sample_t multiplier = 100.1f;
std::fprintf(stdout, "%s: tests for SAMPLE_BUFFER class\n",
__FILE__);
/* case: multiply_by */
{
std::fprintf(stdout, "%s: multiply_by\n",
__FILE__);
SAMPLE_BUFFER sbuf_orig (bufsize, channels);
SAMPLE_BUFFER sbuf_ref (bufsize, channels);
SAMPLE_BUFFER sbuf_test (bufsize, channels);
SAMPLE_BUFFER_FUNCTIONS::fill_with_random_samples(&sbuf_orig);
sbuf_test.copy_all_content(sbuf_orig);
sbuf_ref.copy_all_content(sbuf_orig);
sbuf_test.multiply_by(multiplier);
sbuf_ref.multiply_by_ref(multiplier);
if (SAMPLE_BUFFER_FUNCTIONS::is_almost_equal(sbuf_ref, sbuf_test) != true) {
ECA_TEST_FAILURE("optimized multiple_by");
}
}
/* case: copy_all_content */
{
std::fprintf(stdout, "%s: copy_all_content\n",
__FILE__);
SAMPLE_BUFFER sbuf_orig (bufsize, channels);
SAMPLE_BUFFER sbuf_ref (bufsize, channels);
SAMPLE_BUFFER sbuf_test (bufsize, channels);
SAMPLE_BUFFER_FUNCTIONS::fill_with_random_samples(&sbuf_orig);
/* note: copy_all_content should modify the destination
* channel and sample counts to match those of
* the source object. */
sbuf_test.number_of_channels(0);
sbuf_test.length_in_samples(1);
sbuf_test.copy_all_content(sbuf_orig);
sbuf_ref.copy_matching_channels(sbuf_orig);
if (SAMPLE_BUFFER_FUNCTIONS::is_almost_equal(sbuf_ref, sbuf_test) != true) {
ECA_TEST_FAILURE("copy_all_content");
}
}
/* case: multiply_by */
{
std::fprintf(stdout, "%s: add_matching_channels\n",
__FILE__);
SAMPLE_BUFFER sbuf_orig (bufsize, channels);
SAMPLE_BUFFER sbuf_ref (bufsize, channels);
SAMPLE_BUFFER sbuf_test (bufsize, channels);
SAMPLE_BUFFER_FUNCTIONS::fill_with_random_samples(&sbuf_orig);
sbuf_test.copy_all_content(sbuf_orig);
sbuf_ref.copy_all_content(sbuf_orig);
sbuf_test.add_matching_channels(sbuf_orig);
sbuf_ref.add_matching_channels_ref(sbuf_orig);
if (SAMPLE_BUFFER_FUNCTIONS::is_almost_equal(sbuf_ref, sbuf_test) != true) {
ECA_TEST_FAILURE("optimized add_matching_channels");
}
}
}
|