1 /*
2 * KCemu -- The emulator for the KC85 homecomputer series and much more.
3 * Copyright (C) 1997-2010 Torsten Paul
4 *
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.
9 *
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.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <stdio.h>
21 #include <unistd.h>
22
23 #include <cppunit/TestCase.h>
24 #include <cppunit/TestSuite.h>
25 #include <cppunit/TestResult.h>
26 #include <cppunit/TestCaller.h>
27 #include <cppunit/TextTestRunner.h>
28
29 #include "libaudio/libaudio.h"
30
31 using namespace std;
32
33 class LibAudioTest : public CppUnit::TestCase {
34 private:
35
36 public:
37 void setUp();
38 void tearDown();
39
40 void testOpenNull(void);
41 void testOpenNotExisting(void);
42 void testOpenEmpty(void);
43 void testOpenShort(void);
44 void testOpenRandom(void);
45 };
46
47 void
setUp(void)48 LibAudioTest::setUp(void)
49 {
50 libaudio_init(LIBAUDIO_TYPE_ALL & ~LIBAUDIO_TYPE_MP3);
51 }
52
53 void
tearDown(void)54 LibAudioTest::tearDown(void)
55 {
56 }
57
58 void
testOpenNull(void)59 LibAudioTest::testOpenNull(void)
60 {
61 cout << "LibAudioTest::testOpenNull()" << endl;
62 libaudio_prop_t *prop = libaudio_open(NULL);
63 CPPUNIT_ASSERT(prop == NULL);
64 }
65
66 void
testOpenNotExisting(void)67 LibAudioTest::testOpenNotExisting(void)
68 {
69 cout << "LibAudioTest::testOpenNotExisting()" << endl;
70 libaudio_prop_t *prop = libaudio_open("data/notexisting.wav");
71 CPPUNIT_ASSERT(prop == NULL);
72 }
73
74 void
testOpenEmpty(void)75 LibAudioTest::testOpenEmpty(void)
76 {
77 cout << "LibAudioTest::testOpenEmpty()" << endl;
78 libaudio_prop_t *prop = libaudio_open("data/empty.wav");
79 CPPUNIT_ASSERT(prop == NULL);
80 }
81
82 void
testOpenShort(void)83 LibAudioTest::testOpenShort(void)
84 {
85 FILE *f;
86 int a, b, ret;
87 unsigned char c;
88 libaudio_prop_t *prop;
89 const char *filename = "data/short.wav";
90
91 cout << "LibAudioTest::testOpenShort()" << endl;
92 for (a = 1;a < 1024;a++)
93 {
94 f = fopen(filename, "wb");
95 CPPUNIT_ASSERT(f != NULL);
96 for (b = 0;b < a;b++)
97 {
98 c = b & 0xff;
99 ret = fwrite(&c, 1, 1, f);
100 CPPUNIT_ASSERT(ret == 1);
101 }
102 fclose(f);
103 cout << ".." << a << endl;
104 prop = libaudio_open(filename);
105 CPPUNIT_ASSERT(prop != NULL);
106 ret = unlink(filename);
107 CPPUNIT_ASSERT(ret == 0);
108 }
109 }
110
111 void
testOpenRandom(void)112 LibAudioTest::testOpenRandom(void)
113 {
114 cout << "LibAudioTest::testOpenRandom()" << endl;
115 libaudio_prop_t *prop = libaudio_open("data/random.wav");
116 CPPUNIT_ASSERT(prop == NULL);
117 }
118
119 int EF_DISABLE_BANNER = 1;
120 int EF_PROTECT_FREE = 0;
121 int EF_FREE_WIPES = 1;
122 int EF_ALLOW_MALLOC_0 = 1;
123
124 int
main(void)125 main(void)
126 {
127 CppUnit::TestResult result;
128 CppUnit::TextTestRunner runner;
129
130 CppUnit::TestSuite *suite = new CppUnit::TestSuite();
131 suite->addTest(new CppUnit::TestCaller<LibAudioTest>("testOpenNull", &LibAudioTest::testOpenNull));
132 suite->addTest(new CppUnit::TestCaller<LibAudioTest>("testOpenNotExisting", &LibAudioTest::testOpenNotExisting));
133 suite->addTest(new CppUnit::TestCaller<LibAudioTest>("testOpenEmpty", &LibAudioTest::testOpenEmpty));
134 suite->addTest(new CppUnit::TestCaller<LibAudioTest>("testOpenShort", &LibAudioTest::testOpenShort));
135 suite->addTest(new CppUnit::TestCaller<LibAudioTest>("testOpenRandom", &LibAudioTest::testOpenRandom));
136 runner.addTest(suite);
137 runner.run();
138
139 return 0;
140 }
141