1 #include "tests/utils.h"
3 #include "audiographer/type_utils.h"
5 using namespace AudioGrapher;
7 class TypeUtilsTest : public CppUnit::TestFixture
9 CPPUNIT_TEST_SUITE (TypeUtilsTest);
10 CPPUNIT_TEST (testZeroFillPod);
11 CPPUNIT_TEST (testZeroFillNonPod);
12 CPPUNIT_TEST (testCopy);
13 CPPUNIT_TEST (testMoveBackward);
14 CPPUNIT_TEST (testMoveForward);
15 CPPUNIT_TEST_SUITE_END ();
28 void testZeroFillPod()
32 TypeUtils<float>::zero_fill (buf, frames);
34 for (unsigned i = 0; i < frames; ++i) {
35 CPPUNIT_ASSERT_EQUAL (zero, buf[i]);
39 void testZeroFillNonPod()
41 /* does not compile on OS X Lion
43 NonPodType buf[frames];
44 TypeUtils<NonPodType>::zero_fill (buf, frames);
46 for (unsigned i = 0; i < frames; ++i) {
47 CPPUNIT_ASSERT (zero == buf[i]);
52 void testMoveBackward()
54 int seq[8] = { 0, 1, 2, 3,
57 TypeUtils<int>::move (&seq[4], &seq[2], 4);
59 for (int i = 2; i < 2 + 4; ++i) {
60 CPPUNIT_ASSERT_EQUAL (i + 2, seq[i]);
64 void testMoveForward()
66 int seq[8] = { 0, 1, 2, 3,
69 TypeUtils<int>::move (&seq[2], &seq[4], 4);
71 for (int i = 4; i < 4 + 4; ++i) {
72 CPPUNIT_ASSERT_EQUAL (i - 2, seq[i]);
78 int const seq1[4] = { 1, 2, 3, 4 };
79 int const seq2[4] = { 5, 6, 7, 8 };
80 int seq3[8] = { 0, 0, 0, 0,
83 TypeUtils<int>::copy (seq1, seq3, 4);
84 for (int i = 0; i < 4; ++i) {
85 CPPUNIT_ASSERT_EQUAL (seq1[i], seq3[i]);
88 for (int i = 4; i < 8; ++i) {
89 CPPUNIT_ASSERT_EQUAL (0, seq3[i]);
92 TypeUtils<int>::copy (seq2, &seq3[4], 4);
93 for (int i = 0; i < 4; ++i) {
94 CPPUNIT_ASSERT_EQUAL (seq1[i], seq3[i]);
96 for (int i = 0; i < 4; ++i) {
97 CPPUNIT_ASSERT_EQUAL (seq2[i], seq3[4 + i]);
104 NonPodType() : data (42) {}
105 bool operator== (NonPodType const & other) const
106 { return data == other.data; }
113 CPPUNIT_TEST_SUITE_REGISTRATION (TypeUtilsTest);