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 / Test.cpp @ 1:d7ef749300ed

History | View | Annotate | Download (5.05 KB)

1
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2

    
3
/*
4
    Vamp Plugin Fuzz Tester
5
    Chris Cannam, cannam@all-day-breakfast.com
6
    Centre for Digital Music, Queen Mary, University of London.
7
    Copyright 2009 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 "Test.h"
41

    
42
#include <vamp-hostsdk/PluginLoader.h>
43

    
44
using namespace Vamp;
45
using namespace Vamp::HostExt;
46

    
47
#include <cmath>
48

    
49
Test::Test() { }
50
Test::~Test() { }
51

    
52
Plugin *
53
Test::load(std::string key, float rate)
54
{
55
    return PluginLoader::getInstance()->loadPlugin
56
        (key, rate, PluginLoader::ADAPT_ALL);
57
}
58

    
59
float **
60
Test::createBlock(size_t channels, size_t blocksize)
61
{
62
    float **b = new float *[channels];
63
    for (size_t c = 0; c < channels; ++c) {
64
        b[c] = new float[blocksize];
65
    }
66
    return b;
67
}
68

    
69
void
70
Test::destroyBlock(float **blocks, size_t channels)
71
{
72
    for (size_t c = 0; c < channels; ++c) {
73
        delete[] blocks[c];
74
    }
75
    delete[] blocks;
76
}
77

    
78
bool
79
Test::initDefaults(Plugin *p, size_t &channels, size_t &step, size_t &block,
80
                   Results &r)
81
{
82
    channels = p->getMinChannelCount();
83
    block = p->getPreferredBlockSize();
84
    step = p->getPreferredStepSize();
85
    if (block == 0) block = 1024;
86
    if (step == 0) {
87
        if (p->getInputDomain() == Plugin::FrequencyDomain) step = block/2;
88
        else step = block;
89
    }
90
    if (!p->initialise(channels, step, block)) {
91
        r.push_back(error("initialisation with default values failed"));
92
        return false;
93
    }
94
    return true;
95
}
96

    
97
void
98
Test::appendFeatures(Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
99
{
100
    for (Plugin::FeatureSet::const_iterator i = b.begin(); i != b.end(); ++i) {
101
        int output = i->first;
102
        const Plugin::FeatureList &fl = i->second;
103
        Plugin::FeatureList &target = a[output];
104
        for (Plugin::FeatureList::const_iterator j = fl.begin(); j != fl.end(); ++j) {
105
            target.push_back(*j);
106
        }
107
    }
108
}
109

    
110
bool
111
Test::allFeaturesValid(const Plugin::FeatureSet &b)
112
{
113
    for (Plugin::FeatureSet::const_iterator i = b.begin(); i != b.end(); ++i) {
114
        for (int j = 0; j < (int)i->second.size(); ++j) {
115
            if (i->second[j].values.empty()) continue;
116
            for (int k = 0; k < (int)i->second[j].values.size(); ++k) {
117
                if (isnan(i->second[j].values[k]) ||
118
                    isinf(i->second[j].values[k])) {
119
                    return false;
120
                }
121
            }
122
        }
123
    }
124
    return true;
125
}
126

    
127
bool
128
operator==(const Plugin::FeatureSet &a, const Plugin::FeatureSet &b)
129
{
130
    if (a.size() != b.size()) return false;
131
    for (Plugin::FeatureSet::const_iterator ai = a.begin();
132
         ai != a.end(); ++ai) {
133
        int output = ai->first;
134
        Plugin::FeatureSet::const_iterator bi = b.find(output);
135
        if (bi == b.end()) return false;
136
        if (!(ai->second == bi->second)) return false;
137
    }
138
    return true;
139
}
140

    
141
bool
142
operator==(const Plugin::FeatureList &a, const Plugin::FeatureList &b)
143
{
144
    if (a.size() != b.size()) return false;
145
    for (int i = 0; i < (int)a.size(); ++i) {
146
        if (!(a[i] == b[i])) return false;
147
    }
148
    return true;
149
}
150

    
151
bool
152
operator==(const Plugin::Feature &a, const Plugin::Feature &b)
153
{
154
    if (a.hasTimestamp != b.hasTimestamp) return false;
155
    if (a.hasTimestamp && (a.timestamp != b.timestamp)) return false;
156
    if (a.hasDuration != b.hasDuration) return false;
157
    if (a.hasDuration && (a.duration != b.duration)) return false;
158
    if (a.values != b.values) return false;
159
    if (a.label != b.label) return false;
160
    return true;
161
}
162