comparison TestDefaults.cpp @ 34:a2d9aed55a2a

Check that a reset call does not change parameter values
author Chris Cannam
date Mon, 16 Dec 2013 13:28:28 +0000
parents b1bc4d045a4b
children 7d4c98c696a5
comparison
equal deleted inserted replaced
33:005ac7a3d827 34:a2d9aed55a2a
55 Tester::TestRegistrar<TestDefaultProgram> 55 Tester::TestRegistrar<TestDefaultProgram>
56 TestDefaultProgram::m_registrar("E1 Inconsistent default program"); 56 TestDefaultProgram::m_registrar("E1 Inconsistent default program");
57 57
58 Tester::TestRegistrar<TestDefaultParameters> 58 Tester::TestRegistrar<TestDefaultParameters>
59 TestDefaultParameters::m_registrar("E2 Inconsistent default parameters"); 59 TestDefaultParameters::m_registrar("E2 Inconsistent default parameters");
60
61 Tester::TestRegistrar<TestParametersOnReset>
62 TestParametersOnReset::m_registrar("E3 Parameter retention through reset");
60 63
61 static const size_t _step = 1000; 64 static const size_t _step = 1000;
62 65
63 Test::Results 66 Test::Results
64 TestDefaultProgram::test(string key, Options options) 67 TestDefaultProgram::test(string key, Options options)
166 r.push_back(success()); 169 r.push_back(success());
167 } 170 }
168 171
169 return r; 172 return r;
170 } 173 }
174
175 Test::Results
176 TestParametersOnReset::test(string key, Options options)
177 {
178 Plugin::FeatureSet f[2];
179 int rate = 44100;
180 Results r;
181 float **data = 0;
182 size_t channels = 0;
183 size_t count = 100;
184
185 for (int run = 0; run < 2; ++run) {
186 auto_ptr<Plugin> p(load(key, rate));
187 if (p->getParameterDescriptors().empty()) return r;
188
189 // Set all parameters to non-default values
190 Plugin::ParameterList pl = p->getParameterDescriptors();
191 for (int i = 0; i < (int)pl.size(); ++i) {
192 if (pl[i].defaultValue == pl[i].minValue) {
193 p->setParameter(pl[i].identifier, pl[i].maxValue);
194 } else {
195 p->setParameter(pl[i].identifier, pl[i].minValue);
196 }
197 }
198
199 if (!initAdapted(p.get(), channels, _step, _step, r)) return r;
200
201 // First run: construct, set params, init, process
202 // Second run: construct, set params, init, reset, process
203 // We expect these to produce the same results
204 if (run == 1) p->reset();
205
206 if (!data) data = createTestAudio(channels, _step, count);
207 for (size_t i = 0; i < count; ++i) {
208 #ifdef __GNUC__
209 float *ptr[channels];
210 #else
211 float **ptr = (float **)alloca(channels * sizeof(float));
212 #endif
213 size_t idx = i * _step;
214 for (size_t c = 0; c < channels; ++c) ptr[c] = data[c] + idx;
215 RealTime timestamp = RealTime::frame2RealTime(idx, rate);
216 Plugin::FeatureSet fs = p->process(ptr, timestamp);
217 appendFeatures(f[run], fs);
218 }
219 Plugin::FeatureSet fs = p->getRemainingFeatures();
220 appendFeatures(f[run], fs);
221 }
222 if (data) destroyTestAudio(data, channels);
223
224 if (!(f[0] == f[1])) {
225 string message = "Call to reset after setting parameters, but before processing, changes the results (parameter values not retained through reset?)";
226 Result res;
227 if (options & NonDeterministic) res = note(message);
228 else res = error(message);
229 if (options & Verbose) dump(res, f[0], f[1]);
230 r.push_back(res);
231 } else {
232 r.push_back(success());
233 }
234
235 return r;
236 }