LMMS
Loading...
Searching...
No Matches
PluginTest.h
Go to the documentation of this file.
1/*
2 ZynAddSubFX - a software synthesizer
3
4 PluginTest.h - CxxTest for embedding zyn
5 Copyright (C) 2013-2013 Mark McCurry
6 Authors: Mark McCurry
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of version 2 of the GNU General Public License
10 as published by the Free Software Foundation.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License (version 2 or later) for more details.
16
17 You should have received a copy of the GNU General Public License (version 2)
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21*/
22#include <cxxtest/TestSuite.h>
23#include <cmath>
24#include <cstdlib>
25#include <iostream>
26#include <fstream>
27#include <string>
28#include "../Misc/Master.h"
29#include "../Misc/Util.h"
30#include "../globals.h"
32
33using namespace std;
34
35char *instance_name=(char*)"";
36
37class PluginTest:public CxxTest::TestSuite
38{
39 public:
40 void setUp() {
41 synth = new SYNTH_T;
42 synth->buffersize = 256;
43 synth->samplerate = 48000;
44 synth->alias();
45
46 outL = new float[1024];
47 for(int i = 0; i < synth->buffersize; ++i)
48 outL[i] = 0.0f;
49 outR = new float[1024];
50 for(int i = 0; i < synth->buffersize; ++i)
51 outR[i] = 0.0f;
52
53 //next the bad global variables that for some reason have not been properly placed in some
54 //initialization routine, but rather exist as cryptic oneliners in main.cpp:
55 denormalkillbuf = new float[synth->buffersize];
56 for(int i = 0; i < synth->buffersize; ++i)
57 denormalkillbuf[i] = 0;
58
59 for(int i = 0; i < 16; ++i)
60 master[i] = new Master();
61 }
62
63 void tearDown() {
64 for(int i = 0; i < 16; ++i)
65 delete master[i];
66
67 delete[] outL;
68 delete[] outR;
69 delete synth;
70 }
71
72
73 void testInit() {
74
75 for(int x=0; x<100; ++x)
76 for(int i=0; i<16; ++i)
77 master[i]->GetAudioOutSamples(rand()%1025,
78 synth->samplerate, outL, outR);
79 }
80
81 void testPanic()
82 {
83 master[0]->setController(0, 0x64, 0);
84 master[0]->noteOn(0,64,64);
85 master[0]->AudioOut(outL, outR);
86
87 float sum = 0.0f;
88 for(int i = 0; i < synth->buffersize; ++i)
89 sum += fabs(outL[i]);
90
91 TS_ASSERT_LESS_THAN(0.1f, sum);
92 }
93
94 string loadfile(string fname) const
95 {
96 std::ifstream t(fname.c_str());
97 std::string str((std::istreambuf_iterator<char>(t)),
98 std::istreambuf_iterator<char>());
99 return str;
100 }
101
102
103 void testLoadSave(void)
104 {
105 const string fname = string(SOURCE_DIR) + "/guitar-adnote.xmz";
106 const string fdata = string("\n") + loadfile(fname);
107 char *result = NULL;
108 master[0]->putalldata((char*)fdata.c_str(), fdata.length());
109 int res = master[0]->getalldata(&result);
110
111 TS_ASSERT_EQUALS(fdata.length()+1, res);
112 TS_ASSERT(fdata == result);
113 }
114
115
116 private:
117 float *outR, *outL;
119};
#define NULL
Definition CarlaBridgeFormat.cpp:30
SYNTH_T * synth
Definition LocalZynAddSubFx.cpp:47
SYNTH_T * synth
Definition PluginTest.h:31
float * denormalkillbuf
Definition Util.cpp:46
Definition Master.h:55
Definition PluginTest.h:38
string loadfile(string fname) const
Definition PluginTest.h:94
float * outR
Definition PluginTest.h:117
float * outL
Definition PluginTest.h:117
Master * master[16]
Definition PluginTest.h:118
void testPanic()
Definition PluginTest.h:81
void tearDown()
Definition PluginTest.h:63
void testInit()
Definition PluginTest.h:73
void testLoadSave(void)
Definition PluginTest.h:103
void setUp()
Definition PluginTest.h:40
struct huft * t
Definition inflate.c:943
register unsigned i
Definition inflate.c:1575
unsigned x[BMAX+1]
Definition inflate.c:1586
Definition juce_Uuid.h:141
char * instance_name
Definition main.cpp:88
Definition globals.h:204
int result
Definition process.c:1455
#define SOURCE_DIR
Definition zynaddsubfx-src.cpp:21