Remove Cxxtest dependency
[zynaddsubfx-code.git] / src / Tests / RtAllocTest.cpp
blob44803dd7be98fa1d94ea82b201db98b83ca5d296
1 /*
2 ZynAddSubFX - a software synthesizer
4 RtAllocTest.h - CxxTest for RT Safe Note Allocation
5 Copyright (C) 2014 Mark McCurry
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
14 #include <cxxtest/TestSuite.h>
15 #include <cstdio>
16 #include <malloc.h>
17 #include "../Misc/Part.h"
18 #include "../Misc/Util.h"
19 #include "../Misc/Allocator.h"
20 #include "../Params/Presets.h"
21 #include "../DSP/FFTwrapper.h"
22 #include "../globals.h"
23 SYNTH_T *synth;
25 using namespace std;
27 size_t allocations;
28 size_t allocated_size;
29 void *(*old_malloc_hook)(size_t, const void*);
30 void *hook(size_t size, const void *v)
32 printf("Alloc(%d,%p)\n", size, v);
33 allocated_size += size;
34 allocations++;
35 __malloc_hook = 0;
36 void *res = malloc(size);
37 __malloc_hook = hook;
38 return res;
42 class RtAllocTest:public CxxTest::TestSuite
44 public:
46 Part *part;
47 Microtonal *micro;
48 FFTwrapper *fft;
49 Allocator memory;
50 float *outR, *outL;
52 void setUp() {
53 //First the sensible settings and variables that have to be set:
54 synth = new SYNTH_T;
55 synth->buffersize = 256;
57 outL = NULL;
58 outR = NULL;
59 denormalkillbuf = new float[synth->buffersize];
61 //phew, glad to get thouse out of my way. took me a lot of sweat and gdb to get this far...
62 fft = new FFTwrapper(synth->oscilsize);
63 micro = new Microtonal();
64 part = new Part(memory, micro, fft);
65 part->partoutl = new float[synth->buffersize];
66 part->partoutr = new float[synth->buffersize];
67 //prepare the default settings
70 void tearDown() {
71 delete part;
72 delete micro;
73 delete fft;
74 FFT_cleanup();
75 delete synth;
78 void testDefaults() {
79 old_malloc_hook = __malloc_hook;
80 __malloc_hook = hook;
81 part->NoteOn(82, 101, 0);
82 printf("allocated size = %u\n", allocated_size);
83 printf("allocations = %u\n", allocations);