File: t_load.cc

package info (click to toggle)
kcemu 0.5.1%2Bdfsg-2
  • links: PTS
  • area: contrib
  • in suites: squeeze
  • size: 14,504 kB
  • ctags: 8,989
  • sloc: cpp: 48,501; ansic: 26,963; sh: 4,875; makefile: 1,760; asm: 376; yacc: 291; xml: 64; sed: 16
file content (140 lines) | stat: -rw-r--r-- 3,688 bytes parent folder | download | duplicates (6)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 *  KCemu -- The emulator for the KC85 homecomputer series and much more.
 *  Copyright (C) 1997-2010 Torsten Paul
 *
 *  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.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <stdio.h>
#include <unistd.h>

#include <cppunit/TestCase.h>
#include <cppunit/TestSuite.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestCaller.h>
#include <cppunit/TextTestRunner.h>

#include "libaudio/libaudio.h"

using namespace std;

class LibAudioTest : public CppUnit::TestCase { 
private:

public: 
  void setUp();
  void tearDown();

  void testOpenNull(void);
  void testOpenNotExisting(void);
  void testOpenEmpty(void);
  void testOpenShort(void);
  void testOpenRandom(void);
};

void
LibAudioTest::setUp(void)
{
  libaudio_init(LIBAUDIO_TYPE_ALL & ~LIBAUDIO_TYPE_MP3);
}

void
LibAudioTest::tearDown(void)
{
}

void
LibAudioTest::testOpenNull(void)
{
  cout << "LibAudioTest::testOpenNull()" << endl;
  libaudio_prop_t *prop = libaudio_open(NULL);
  CPPUNIT_ASSERT(prop == NULL);
}

void
LibAudioTest::testOpenNotExisting(void)
{
  cout << "LibAudioTest::testOpenNotExisting()" << endl;
  libaudio_prop_t *prop = libaudio_open("data/notexisting.wav");
  CPPUNIT_ASSERT(prop == NULL);
}

void
LibAudioTest::testOpenEmpty(void)
{
  cout << "LibAudioTest::testOpenEmpty()" << endl;
  libaudio_prop_t *prop = libaudio_open("data/empty.wav");
  CPPUNIT_ASSERT(prop == NULL);
}

void
LibAudioTest::testOpenShort(void)
{
  FILE *f;
  int a, b, ret;
  unsigned char c;
  libaudio_prop_t *prop;
  const char *filename = "data/short.wav";

  cout << "LibAudioTest::testOpenShort()" << endl;
  for (a = 1;a < 1024;a++)
    {
      f = fopen(filename, "wb");
      CPPUNIT_ASSERT(f != NULL);
      for (b = 0;b < a;b++)
	{
	  c = b & 0xff;
	  ret = fwrite(&c, 1, 1, f);
	  CPPUNIT_ASSERT(ret == 1);
	}
      fclose(f);
      cout << ".." << a << endl;
      prop = libaudio_open(filename);
      CPPUNIT_ASSERT(prop != NULL);
      ret = unlink(filename);
      CPPUNIT_ASSERT(ret == 0);
    }
}

void
LibAudioTest::testOpenRandom(void)
{
  cout << "LibAudioTest::testOpenRandom()" << endl;
  libaudio_prop_t *prop = libaudio_open("data/random.wav");
  CPPUNIT_ASSERT(prop == NULL);
}

int EF_DISABLE_BANNER = 1;
int EF_PROTECT_FREE = 0;
int EF_FREE_WIPES = 1;
int EF_ALLOW_MALLOC_0 = 1;

int
main(void)
{
  CppUnit::TestResult result;
  CppUnit::TextTestRunner runner;

  CppUnit::TestSuite *suite = new CppUnit::TestSuite();
  suite->addTest(new CppUnit::TestCaller<LibAudioTest>("testOpenNull", &LibAudioTest::testOpenNull));
  suite->addTest(new CppUnit::TestCaller<LibAudioTest>("testOpenNotExisting", &LibAudioTest::testOpenNotExisting));
  suite->addTest(new CppUnit::TestCaller<LibAudioTest>("testOpenEmpty", &LibAudioTest::testOpenEmpty));
  suite->addTest(new CppUnit::TestCaller<LibAudioTest>("testOpenShort", &LibAudioTest::testOpenShort));
  suite->addTest(new CppUnit::TestCaller<LibAudioTest>("testOpenRandom", &LibAudioTest::testOpenRandom));
  runner.addTest(suite);
  runner.run();

  return 0;
}