To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / TestStaticData.cpp @ 42:f1e8e14e9c96

History | View | Annotate | Download (7.35 KB)

1 0:f89128a316e7 cannam
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2
3
/*
4
    Vamp Plugin Tester
5
    Chris Cannam, cannam@all-day-breakfast.com
6
    Centre for Digital Music, Queen Mary, University of London.
7 42:f1e8e14e9c96 Chris
    Copyright 2009-2014 QMUL.
8 0:f89128a316e7 cannam

9
    This program loads a Vamp plugin and tests its susceptibility to a
10
    number of common pitfalls, including handling of extremes of input
11
    data.  If you can think of any additional useful tests that are
12
    easily added, please send them to me.
13

14
    Permission is hereby granted, free of charge, to any person
15
    obtaining a copy of this software and associated documentation
16
    files (the "Software"), to deal in the Software without
17
    restriction, including without limitation the rights to use, copy,
18
    modify, merge, publish, distribute, sublicense, and/or sell copies
19
    of the Software, and to permit persons to whom the Software is
20
    furnished to do so, subject to the following conditions:
21

22
    The above copyright notice and this permission notice shall be
23
    included in all copies or substantial portions of the Software.
24

25
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
29
    ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
30
    CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32

33
    Except as contained in this notice, the names of the Centre for
34
    Digital Music; Queen Mary, University of London; and Chris Cannam
35
    shall not be used in advertising or otherwise to promote the sale,
36
    use or other dealings in this Software without prior written
37
    authorization.
38
*/
39
40
#include "TestStaticData.h"
41
42
#include <vamp-hostsdk/Plugin.h>
43 35:b700f37dc118 Chris
#include <vamp-hostsdk/PluginLoader.h>
44 0:f89128a316e7 cannam
using namespace Vamp;
45 35:b700f37dc118 Chris
using namespace Vamp::HostExt;
46 0:f89128a316e7 cannam
47
#include <memory>
48
using namespace std;
49
50
#include <cmath>
51
52
Tester::TestRegistrar<TestIdentifiers>
53 39:07144cdcbedf Chris
TestIdentifiers::m_registrar("A1", "Invalid identifiers");
54 0:f89128a316e7 cannam
55
Tester::TestRegistrar<TestEmptyFields>
56 39:07144cdcbedf Chris
TestEmptyFields::m_registrar("A2", "Empty metadata fields");
57 0:f89128a316e7 cannam
58
Tester::TestRegistrar<TestValueRanges>
59 39:07144cdcbedf Chris
TestValueRanges::m_registrar("A3", "Inappropriate value extents");
60 0:f89128a316e7 cannam
61 35:b700f37dc118 Chris
Tester::TestRegistrar<TestCategory>
62 39:07144cdcbedf Chris
TestCategory::m_registrar("A3", "Missing category");
63 35:b700f37dc118 Chris
64 0:f89128a316e7 cannam
Test::Results
65 14:e48fdc8de790 cannam
TestIdentifiers::test(string key, Options)
66 0:f89128a316e7 cannam
{
67
    auto_ptr<Plugin> p(load(key));
68
69
    Results r;
70 17:ea8865f488a0 cannam
    r.push_back(testIdentifier(p->getIdentifier(), "Plugin identifier"));
71 0:f89128a316e7 cannam
72
    Plugin::ParameterList params = p->getParameterDescriptors();
73
    for (int i = 0; i < (int)params.size(); ++i) {
74 17:ea8865f488a0 cannam
        r.push_back(testIdentifier(params[i].identifier, "Parameter identifier"));
75 0:f89128a316e7 cannam
    }
76
77
    Plugin::OutputList outputs = p->getOutputDescriptors();
78
    for (int i = 0; i < (int)outputs.size(); ++i) {
79 17:ea8865f488a0 cannam
        r.push_back(testIdentifier(outputs[i].identifier, "Output identifier"));
80 0:f89128a316e7 cannam
    }
81
82
    return r;
83
}
84
85
Test::Result
86
TestIdentifiers::testIdentifier(string identifier, string desc)
87
{
88
    for (int i = 0; i < (int)identifier.length(); ++i) {
89
        char c = identifier[i];
90
        if (c >= 'a' && c <= 'z') continue;
91
        if (c >= 'A' && c <= 'Z') continue;
92
        if (c >= '0' && c <= '9') continue;
93
        if (c == '_' || c == '-') continue;
94
        return error
95
            (desc + " \"" + identifier +
96
             "\" contains invalid character(s); permitted are: [a-zA-Z0-9_-]");
97
    }
98
    return success();
99
}
100
101
Test::Results
102 14:e48fdc8de790 cannam
TestEmptyFields::test(string key, Options)
103 0:f89128a316e7 cannam
{
104
    auto_ptr<Plugin> p(load(key));
105
106
    Results r;
107
108 17:ea8865f488a0 cannam
    r.push_back(testMandatory(p->getName(), "Plugin name"));
109
    r.push_back(testRecommended(p->getDescription(), "Plugin description"));
110
    r.push_back(testRecommended(p->getMaker(), "Plugin maker"));
111
    r.push_back(testRecommended(p->getCopyright(), "Plugin copyright"));
112 0:f89128a316e7 cannam
113
    Plugin::ParameterList params = p->getParameterDescriptors();
114
    for (int i = 0; i < (int)params.size(); ++i) {
115
        r.push_back(testMandatory
116
                    (params[i].name,
117 17:ea8865f488a0 cannam
                     "Plugin parameter \"" + params[i].identifier + "\" name"));
118 0:f89128a316e7 cannam
        r.push_back(testRecommended
119
                    (params[i].description,
120 17:ea8865f488a0 cannam
                     "Plugin parameter \"" + params[i].identifier + "\" description"));
121 0:f89128a316e7 cannam
    }
122
123
    Plugin::OutputList outputs = p->getOutputDescriptors();
124
    for (int i = 0; i < (int)outputs.size(); ++i) {
125
        r.push_back(testMandatory
126
                    (outputs[i].name,
127 17:ea8865f488a0 cannam
                     "Plugin output \"" + outputs[i].identifier + "\" name"));
128 0:f89128a316e7 cannam
        r.push_back(testRecommended
129
                    (outputs[i].description,
130 17:ea8865f488a0 cannam
                     "Plugin output \"" + outputs[i].identifier + "\" description"));
131 0:f89128a316e7 cannam
    }
132
133
    return r;
134
}
135
136
Test::Result
137
TestEmptyFields::testMandatory(string text, string desc)
138
{
139
    if (text == "") {
140
        return error(desc + " is empty");
141
    }
142
    return success();
143
}
144
145
Test::Result
146
TestEmptyFields::testRecommended(string text, string desc)
147
{
148
    if (text == "") {
149
        return warning(desc + " is empty");
150
    }
151
    return success();
152
}
153
154
Test::Results
155 14:e48fdc8de790 cannam
TestValueRanges::test(string key, Options)
156 0:f89128a316e7 cannam
{
157
    auto_ptr<Plugin> p(load(key));
158
159
    Results r;
160
161
    Plugin::ParameterList params = p->getParameterDescriptors();
162
    for (int i = 0; i < (int)params.size(); ++i) {
163
        Plugin::ParameterDescriptor &pd(params[i]);
164 17:ea8865f488a0 cannam
        string pfx("Plugin parameter \"" + pd.identifier + "\"");
165 0:f89128a316e7 cannam
        float min = pd.minValue;
166
        float max = pd.maxValue;
167
        float deft = pd.defaultValue;
168
        if (max <= min) {
169
            r.push_back(error(pfx + " maxValue <= minValue"));
170
        }
171
        if (deft < min || deft > max) {
172
            r.push_back(error(pfx + " defaultValue out of range"));
173
        }
174
        if (pd.isQuantized) {
175
            if (pd.quantizeStep == 0.f) {
176
                r.push_back(error(pfx + " is quantized, but quantize step is zero"));
177
            } else {
178
179
                float epsilon = 0.00001f;
180
                int qty = int((max - min) / pd.quantizeStep + 0.5);
181
                float target = min + pd.quantizeStep * qty;
182
                if (fabsf(max - target) > epsilon) {
183
                    r.push_back(warning(pfx + " value range is not a multiple of quantize step"));
184
                }
185
186
                if (!pd.valueNames.empty()) {
187
                    if ((int)pd.valueNames.size() < qty+1) {
188
                        r.push_back(warning(pfx + " has fewer value names than quantize steps"));
189
                    } else if ((int)pd.valueNames.size() > qty+1) {
190
                        r.push_back(warning(pfx + " has more value names than quantize steps"));
191
                    }
192
                }
193
194
                qty = int((deft - min) / pd.quantizeStep + 0.5);
195
                target = min + pd.quantizeStep * qty;
196
                if (fabsf(deft - target) > epsilon) {
197
                    r.push_back(warning(pfx + " default value is not a multiple of quantize step beyond minimum"));
198
                }
199
            }
200
        }
201
    }
202
203
    return r;
204
}
205
206 35:b700f37dc118 Chris
Test::Results
207
TestCategory::test(string key, Options)
208
{
209
    PluginLoader::PluginCategoryHierarchy hierarchy =
210
        PluginLoader::getInstance()->getPluginCategory(key);
211
212
    Results r;
213 0:f89128a316e7 cannam
214 35:b700f37dc118 Chris
    if (hierarchy.empty()) {
215
        r.push_back(warning("Plugin category missing or cannot be loaded (no .cat file?)"));
216
    }
217
218
    return r;
219
}