Tooltips for mixer strip width and hide buttons (#4477).
[ardour.git] / libs / audiographer / tests / type_utils_test.cc
1 #include "tests/utils.h"
2
3 #include "audiographer/type_utils.h"
4
5 using namespace AudioGrapher;
6
7 class TypeUtilsTest : public CppUnit::TestFixture
8 {
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 ();
16
17   public:
18         void setUp()
19         {
20                 
21         }
22
23         void tearDown()
24         {
25                 
26         }
27
28         void testZeroFillPod()
29         {
30                 unsigned frames = 10;
31                 float buf[frames];
32                 TypeUtils<float>::zero_fill (buf, frames);
33                 float zero = 0.0;
34                 for (unsigned i = 0; i < frames; ++i) {
35                         CPPUNIT_ASSERT_EQUAL (zero, buf[i]);
36                 }
37         }
38         
39         void testZeroFillNonPod()
40         {
41                 unsigned frames = 10;
42                 NonPodType buf[frames];
43                 TypeUtils<NonPodType>::zero_fill (buf, frames);
44                 NonPodType zero;
45                 for (unsigned i = 0; i < frames; ++i) {
46                         CPPUNIT_ASSERT (zero == buf[i]);
47                 }
48         }
49         
50         void testMoveBackward()
51         {
52                 int seq[8] = { 0, 1, 2, 3,
53                                4, 5, 6, 7 };
54                 
55                 TypeUtils<int>::move (&seq[4], &seq[2], 4);
56                 
57                 for (int i = 2; i < 2 + 4; ++i) {
58                         CPPUNIT_ASSERT_EQUAL (i + 2, seq[i]);
59                 }
60         }
61         
62         void testMoveForward()
63         {
64                 int seq[8] = { 0, 1, 2, 3,
65                                4, 5, 6, 7 };
66                 
67                 TypeUtils<int>::move (&seq[2], &seq[4], 4);
68                 
69                 for (int i = 4; i < 4 + 4; ++i) {
70                         CPPUNIT_ASSERT_EQUAL (i - 2, seq[i]);
71                 }
72         }
73
74         void testCopy()
75         {
76                 int const seq1[4] = { 1, 2, 3, 4 };
77                 int const seq2[4] = { 5, 6, 7, 8 };
78                 int seq3[8] = { 0, 0, 0, 0,
79                                   0, 0, 0, 0 };
80                 
81                 TypeUtils<int>::copy (seq1, seq3, 4);
82                 for (int i = 0; i < 4; ++i) {
83                         CPPUNIT_ASSERT_EQUAL (seq1[i], seq3[i]);
84                 }
85                 
86                 for (int i = 4; i < 8; ++i) {
87                         CPPUNIT_ASSERT_EQUAL (0, seq3[i]);
88                 }
89                 
90                 TypeUtils<int>::copy (seq2, &seq3[4], 4);
91                 for (int i = 0; i < 4; ++i) {
92                         CPPUNIT_ASSERT_EQUAL (seq1[i], seq3[i]);
93                 }
94                 for (int i = 0; i < 4; ++i) {
95                         CPPUNIT_ASSERT_EQUAL (seq2[i], seq3[4 + i]);
96                 }
97         }
98
99   private:
100         
101         struct NonPodType {
102                 NonPodType() : data (42) {}
103                 bool operator== (NonPodType const & other) const
104                         { return data == other.data; }
105                 int data;
106         };
107         
108
109 };
110
111 CPPUNIT_TEST_SUITE_REGISTRATION (TypeUtilsTest);
112