1 /*
2 ZynAddSubFX - a software synthesizer
3
4 EffectTest.h - CxxTest for General Effect Stuff
5 Copyright (C) 2015 Mark McCurry
6
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.
11 */
12 #include "test-suite.h"
13 #include <cmath>
14 #include <cstdio>
15 #include "../Misc/Allocator.h"
16 #include "../Misc/Stereo.h"
17 #include "../Effects/EffectMgr.h"
18 #include "../Effects/Reverb.h"
19 #include "../Effects/Echo.h"
20 #include "../globals.h"
21 using namespace zyn;
22
23 SYNTH_T *synth;
24
25 class EffectTest
26 {
27 public:
setUp()28 void setUp() {
29 synth = new SYNTH_T;
30 alloc = new AllocatorClass;
31 mgr = new EffectMgr(*alloc, *synth, true);
32 }
33
tearDown()34 void tearDown() {
35 delete mgr;
36 delete alloc;
37 delete synth;
38 }
39
testInit()40 void testInit() {
41 TS_ASSERT_EQUAL_INT(mgr->nefx, 0);
42 mgr->changeeffect(1);
43 TS_ASSERT_EQUAL_INT(mgr->nefx, 1);
44 assert_ptr_eq(mgr->efx, nullptr,
45 "nothing before init", __LINE__);
46 mgr->init();
47 TS_NON_NULL(mgr->efx);
48 }
49
testClear()50 void testClear() {
51 mgr->changeeffect(1);
52 mgr->init();
53 TS_NON_NULL(mgr->efx);
54 mgr->changeeffect(0);
55 mgr->init();
56 assert_ptr_eq(mgr->efx, nullptr,
57 "nothing after clearing", __LINE__);
58 }
59
testSwap()60 void testSwap() {
61 //Initially the effect is NULL
62 assert_ptr_eq(mgr->efx, nullptr,
63 "initially null", __LINE__);
64
65 //A Reverb is selected
66 mgr->changeeffect(1);
67 mgr->init();
68 TS_NON_NULL(dynamic_cast<Reverb*>(mgr->efx));
69 assert_ptr_eq(dynamic_cast<Echo*>(mgr->efx),
70 nullptr,
71 "not an echo", __LINE__);
72
73 //An Echo is selected
74 mgr->changeeffect(2);
75 mgr->init();
76 assert_ptr_eq(dynamic_cast<Reverb*>(mgr->efx),
77 nullptr,
78 "not a reverb", __LINE__);
79 TS_NON_NULL(dynamic_cast<Echo*>(mgr->efx));
80 }
81
82 private:
83 EffectMgr *mgr;
84 Allocator *alloc;
85 SYNTH_T *synth;
86 };
87
main()88 int main()
89 {
90 EffectTest test;
91 RUN_TEST(testInit);
92 RUN_TEST(testClear);
93 RUN_TEST(testSwap);
94 return test_summary();
95 }
96