Mercurial > hg > vamp-plugin-tester
comparison Test.cpp @ 3:0f65bb22172b
* Add basic tests for output numbers, data existence, timestamps &c
author | cannam |
---|---|
date | Tue, 17 Mar 2009 16:38:47 +0000 |
parents | d7ef749300ed |
children | 3019cb6b538d |
comparison
equal
deleted
inserted
replaced
2:c9a4bd247497 | 3:0f65bb22172b |
---|---|
73 delete[] blocks[c]; | 73 delete[] blocks[c]; |
74 } | 74 } |
75 delete[] blocks; | 75 delete[] blocks; |
76 } | 76 } |
77 | 77 |
78 float ** | |
79 Test::createTestAudio(size_t channels, size_t blocksize, size_t blocks) | |
80 { | |
81 float **b = new float *[channels]; | |
82 for (size_t c = 0; c < channels; ++c) { | |
83 b[c] = new float[blocksize * blocks]; | |
84 for (int i = 0; i < int(blocksize * blocks); ++i) { | |
85 b[c][i] = sinf(float(i) / 10.f); | |
86 if (i == 5005 || i == 20002) { | |
87 b[c][i-2] = 0; | |
88 b[c][i-1] = -1; | |
89 b[c][i] = 1; | |
90 } | |
91 } | |
92 } | |
93 return b; | |
94 } | |
95 | |
96 void | |
97 Test::destroyTestAudio(float **b, size_t channels) | |
98 { | |
99 for (size_t c = 0; c < channels; ++c) { | |
100 delete[] b[c]; | |
101 } | |
102 delete[] b; | |
103 } | |
104 | |
78 bool | 105 bool |
79 Test::initDefaults(Plugin *p, size_t &channels, size_t &step, size_t &block, | 106 Test::initDefaults(Plugin *p, size_t &channels, size_t &step, size_t &block, |
80 Results &r) | 107 Results &r) |
81 { | 108 { |
82 channels = p->getMinChannelCount(); | 109 channels = p->getMinChannelCount(); |
87 if (p->getInputDomain() == Plugin::FrequencyDomain) step = block/2; | 114 if (p->getInputDomain() == Plugin::FrequencyDomain) step = block/2; |
88 else step = block; | 115 else step = block; |
89 } | 116 } |
90 if (!p->initialise(channels, step, block)) { | 117 if (!p->initialise(channels, step, block)) { |
91 r.push_back(error("initialisation with default values failed")); | 118 r.push_back(error("initialisation with default values failed")); |
119 return false; | |
120 } | |
121 return true; | |
122 } | |
123 | |
124 bool | |
125 Test::initAdapted(Plugin *p, size_t &channels, size_t step, size_t block, | |
126 Results &r) | |
127 { | |
128 channels = p->getMinChannelCount(); | |
129 if (!p->initialise(channels, step, block)) { | |
130 r.push_back(error("initialisation failed")); | |
92 return false; | 131 return false; |
93 } | 132 } |
94 return true; | 133 return true; |
95 } | 134 } |
96 | 135 |
122 } | 161 } |
123 } | 162 } |
124 return true; | 163 return true; |
125 } | 164 } |
126 | 165 |
166 void | |
167 Test::dump(const Plugin::FeatureSet &fs) | |
168 { | |
169 for (Plugin::FeatureSet::const_iterator fsi = fs.begin(); | |
170 fsi != fs.end(); ++fsi) { | |
171 int output = fsi->first; | |
172 std::cerr << "Output " << output << ":" << std::endl; | |
173 const Plugin::FeatureList &fl = fsi->second; | |
174 for (int i = 0; i < (int)fl.size(); ++i) { | |
175 std::cerr << " Feature " << i << ":" << std::endl; | |
176 const Plugin::Feature &f = fl[i]; | |
177 std::cerr << " Timestamp: " << (f.hasTimestamp ? "(none)" : f.timestamp.toText()) << std::endl; | |
178 std::cerr << " Duration: " << (f.hasDuration ? "(none)" : f.duration.toText()) << std::endl; | |
179 std::cerr << " Label: " << (f.label == "" ? "(none)" : f.label) << std::endl; | |
180 std::cerr << " Value: " << (f.values.empty() ? "(none)" : ""); | |
181 for (int j = 0; j < (int)f.values.size(); ++j) { | |
182 std::cerr << f.values[j] << " "; | |
183 } | |
184 std::cerr << std::endl; | |
185 } | |
186 } | |
187 } | |
188 | |
189 void | |
190 Test::dump(const Result &r, | |
191 const Plugin::FeatureSet &a, | |
192 const Plugin::FeatureSet &b) | |
193 { | |
194 std::cerr << r.message() << std::endl; | |
195 std::cerr << "\nFirst result set:" << std::endl; | |
196 dump(a); | |
197 std::cerr << "\nSecond result set:" << std::endl; | |
198 dump(b); | |
199 std::cerr << std::endl; | |
200 } | |
201 | |
127 bool | 202 bool |
128 operator==(const Plugin::FeatureSet &a, const Plugin::FeatureSet &b) | 203 operator==(const Plugin::FeatureSet &a, const Plugin::FeatureSet &b) |
129 { | 204 { |
130 if (a.size() != b.size()) return false; | 205 if (a.size() != b.size()) return false; |
131 for (Plugin::FeatureSet::const_iterator ai = a.begin(); | 206 for (Plugin::FeatureSet::const_iterator ai = a.begin(); |