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 @ 54:314eea778b80

History | View | Annotate | Download (7.66 KB)

1
/* -*- 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
    Copyright 2009-2014 QMUL.
8

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
#include <vamp-hostsdk/PluginLoader.h>
44
using namespace Vamp;
45
using namespace Vamp::HostExt;
46

    
47
#include <memory>
48
using namespace std;
49

    
50
#include <cmath>
51

    
52
Tester::TestRegistrar<TestIdentifiers>
53
TestIdentifiers::m_registrar("A1", "Invalid identifiers");
54

    
55
Tester::TestRegistrar<TestEmptyFields>
56
TestEmptyFields::m_registrar("A2", "Empty metadata fields");
57

    
58
Tester::TestRegistrar<TestValueRanges>
59
TestValueRanges::m_registrar("A3", "Inappropriate value extents");
60

    
61
Tester::TestRegistrar<TestCategory>
62
TestCategory::m_registrar("A3", "Missing category");
63

    
64
Test::Results
65
TestIdentifiers::test(string key, Options)
66
{
67
    auto_ptr<Plugin> p(load(key));
68
    
69
    Results r;
70
    r.push_back(testIdentifier(p->getIdentifier(), "Plugin identifier"));
71

    
72
    Plugin::ParameterList params = p->getParameterDescriptors();
73
    for (int i = 0; i < (int)params.size(); ++i) {
74
        r.push_back(testIdentifier(params[i].identifier, "Parameter identifier"));
75
    }
76

    
77
    Plugin::OutputList outputs = p->getOutputDescriptors();
78
    for (int i = 0; i < (int)outputs.size(); ++i) {
79
        r.push_back(testIdentifier(outputs[i].identifier, "Output identifier"));
80
    }
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
TestEmptyFields::test(string key, Options)
103
{
104
    auto_ptr<Plugin> p(load(key));
105

    
106
    Results r;
107

    
108
    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
    
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
                     "Plugin parameter \"" + params[i].identifier + "\" name"));
118
        r.push_back(testRecommended
119
                    (params[i].description,
120
                     "Plugin parameter \"" + params[i].identifier + "\" description"));
121
    }
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
                     "Plugin output \"" + outputs[i].identifier + "\" name"));
128
        r.push_back(testRecommended
129
                    (outputs[i].description,
130
                     "Plugin output \"" + outputs[i].identifier + "\" description"));
131
    }
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
    } else if (text == "Licence information not available." ||
151
               text == "VamPy Plugin." ||
152
               text == "Not given. (Hint: Implement getDescription method.)" ||
153
               text == "VamPy Plugin (Noname)") {
154
        return warning(desc + " is missing (returns VamPy boilerplate text)");
155
    }
156
    return success();
157
}
158

    
159
Test::Results
160
TestValueRanges::test(string key, Options)
161
{
162
    auto_ptr<Plugin> p(load(key));
163

    
164
    Results r;
165

    
166
    Plugin::ParameterList params = p->getParameterDescriptors();
167
    for (int i = 0; i < (int)params.size(); ++i) {
168
        Plugin::ParameterDescriptor &pd(params[i]);
169
        string pfx("Plugin parameter \"" + pd.identifier + "\"");
170
        float min = pd.minValue;
171
        float max = pd.maxValue;
172
        float deft = pd.defaultValue;
173
        if (max <= min) {
174
            r.push_back(error(pfx + " maxValue <= minValue"));
175
        }
176
        if (deft < min || deft > max) {
177
            r.push_back(error(pfx + " defaultValue out of range"));
178
        }
179
        if (pd.isQuantized) {
180
            if (pd.quantizeStep == 0.f) {
181
                r.push_back(error(pfx + " is quantized, but quantize step is zero"));
182
            } else {
183

    
184
                float epsilon = 0.00001f;
185
                int qty = int((max - min) / pd.quantizeStep + 0.5);
186
                float target = min + pd.quantizeStep * qty;
187
                if (fabsf(max - target) > epsilon) {
188
                    r.push_back(warning(pfx + " value range is not a multiple of quantize step"));
189
                }
190

    
191
                if (!pd.valueNames.empty()) {
192
                    if ((int)pd.valueNames.size() < qty+1) {
193
                        r.push_back(warning(pfx + " has fewer value names than quantize steps"));
194
                    } else if ((int)pd.valueNames.size() > qty+1) {
195
                        r.push_back(warning(pfx + " has more value names than quantize steps"));
196
                    }
197
                }
198

    
199
                qty = int((deft - min) / pd.quantizeStep + 0.5);
200
                target = min + pd.quantizeStep * qty;
201
                if (fabsf(deft - target) > epsilon) {
202
                    r.push_back(warning(pfx + " default value is not a multiple of quantize step beyond minimum"));
203
                }
204
            }
205
        }
206
    }
207

    
208
    return r;
209
}
210

    
211
Test::Results
212
TestCategory::test(string key, Options)
213
{
214
    PluginLoader::PluginCategoryHierarchy hierarchy =
215
        PluginLoader::getInstance()->getPluginCategory(key);
216
    
217
    Results r;
218

    
219
    if (hierarchy.empty()) {
220
        r.push_back(warning("Plugin category missing or cannot be loaded (no .cat file?)"));
221
    }
222

    
223
    return r;
224
}
225