annotate Test.h @ 26:eff1772ba397 vamp-plugin-tester-v1.0-erroneous

* More doc corrections to match error reporting updates in SDK * Don't return success after failing to load a plugin!
author cannam
date Tue, 22 Sep 2009 11:24:31 +0000
parents 3019cb6b538d
children 07144cdcbedf
rev   line source
cannam@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
cannam@0 2
cannam@0 3 /*
cannam@0 4 Vamp Plugin Tester
cannam@0 5 Chris Cannam, cannam@all-day-breakfast.com
cannam@0 6 Centre for Digital Music, Queen Mary, University of London.
cannam@0 7 Copyright 2009 QMUL.
cannam@0 8
cannam@0 9 This program loads a Vamp plugin and tests its susceptibility to a
cannam@0 10 number of common pitfalls, including handling of extremes of input
cannam@0 11 data. If you can think of any additional useful tests that are
cannam@0 12 easily added, please send them to me.
cannam@0 13
cannam@0 14 Permission is hereby granted, free of charge, to any person
cannam@0 15 obtaining a copy of this software and associated documentation
cannam@0 16 files (the "Software"), to deal in the Software without
cannam@0 17 restriction, including without limitation the rights to use, copy,
cannam@0 18 modify, merge, publish, distribute, sublicense, and/or sell copies
cannam@0 19 of the Software, and to permit persons to whom the Software is
cannam@0 20 furnished to do so, subject to the following conditions:
cannam@0 21
cannam@0 22 The above copyright notice and this permission notice shall be
cannam@0 23 included in all copies or substantial portions of the Software.
cannam@0 24
cannam@0 25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
cannam@0 26 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
cannam@0 27 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
cannam@0 28 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
cannam@0 29 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
cannam@0 30 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
cannam@0 31 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
cannam@0 32
cannam@0 33 Except as contained in this notice, the names of the Centre for
cannam@0 34 Digital Music; Queen Mary, University of London; and Chris Cannam
cannam@0 35 shall not be used in advertising or otherwise to promote the sale,
cannam@0 36 use or other dealings in this Software without prior written
cannam@0 37 authorization.
cannam@0 38 */
cannam@0 39
cannam@0 40 #ifndef _TEST_H_
cannam@0 41 #define _TEST_H_
cannam@0 42
cannam@0 43 #include <string>
cannam@0 44
cannam@0 45 #include <vamp-hostsdk/Plugin.h>
cannam@0 46
cannam@0 47 class Test
cannam@0 48 {
cannam@0 49 public:
cannam@0 50 virtual ~Test();
cannam@8 51
cannam@8 52 enum Option {
cannam@8 53 NoOption = 0x0,
cannam@8 54 NonDeterministic = 0x1,
cannam@8 55 Verbose = 0x2
cannam@8 56 };
cannam@8 57 typedef int Options;
cannam@0 58
cannam@0 59 class Result {
cannam@0 60
cannam@0 61 public:
cannam@3 62 enum Code { Success, Note, Warning, Error };
cannam@0 63
cannam@8 64 Result() : m_code(Success) { }
cannam@0 65 Result(Code c, std::string m) : m_code(c), m_message(m) { }
cannam@0 66
cannam@3 67 Code code() const { return m_code; }
cannam@3 68 std::string message() const { return m_message; }
cannam@8 69
cannam@0 70 protected:
cannam@0 71 Code m_code;
cannam@0 72 std::string m_message;
cannam@0 73 };
cannam@0 74
cannam@0 75 static Result success() { return Result(Result::Success, ""); }
cannam@3 76 static Result note(std::string m) { return Result(Result::Note, m); }
cannam@0 77 static Result warning(std::string m) { return Result(Result::Warning, m); }
cannam@0 78 static Result error(std::string m) { return Result(Result::Error, m); }
cannam@0 79
cannam@0 80 typedef std::vector<Result> Results;
cannam@0 81
cannam@0 82 class FailedToLoadPlugin { };
cannam@0 83
cannam@0 84 // may throw FailedToLoadPlugin
cannam@8 85 virtual Results test(std::string key, Options) = 0;
cannam@0 86
cannam@0 87 protected:
cannam@0 88 Test();
cannam@0 89
cannam@0 90 // may throw FailedToLoadPlugin
cannam@0 91 Vamp::Plugin *load(std::string key, float rate = 44100);
cannam@0 92
cannam@1 93 float **createBlock(size_t channels, size_t blocksize);
cannam@1 94 void destroyBlock(float **blocks, size_t channels);
cannam@1 95
cannam@3 96 float **createTestAudio(size_t channels, size_t blocksize, size_t blocks);
cannam@3 97 void destroyTestAudio(float **audio, size_t channels);
cannam@3 98
cannam@4 99 // use plugin's preferred step/block size, return them:
cannam@1 100 bool initDefaults(Vamp::Plugin *, size_t &channels,
cannam@1 101 size_t &step, size_t &block, Results &r);
cannam@1 102
cannam@4 103 // use the given step/block size and an adapter:
cannam@3 104 bool initAdapted(Vamp::Plugin *, size_t &channels,
cannam@3 105 size_t step, size_t block, Results &r);
cannam@3 106
cannam@0 107 void appendFeatures(Vamp::Plugin::FeatureSet &a,
cannam@0 108 const Vamp::Plugin::FeatureSet &b);
cannam@1 109
cannam@1 110 bool allFeaturesValid(const Vamp::Plugin::FeatureSet &); // i.e. no NaN/inf
cannam@3 111
cannam@3 112 void dump(const Vamp::Plugin::FeatureSet &);
cannam@3 113 void dump(const Result &r,
cannam@3 114 const Vamp::Plugin::FeatureSet &,
cannam@3 115 const Vamp::Plugin::FeatureSet &);
cannam@0 116 };
cannam@0 117
cannam@0 118 extern bool operator==(const Vamp::Plugin::FeatureSet &a,
cannam@0 119 const Vamp::Plugin::FeatureSet &b);
cannam@0 120 extern bool operator==(const Vamp::Plugin::FeatureList &a,
cannam@0 121 const Vamp::Plugin::FeatureList &b);
cannam@0 122 extern bool operator==(const Vamp::Plugin::Feature &a,
cannam@0 123 const Vamp::Plugin::Feature &b);
cannam@0 124
cannam@0 125 #endif
cannam@0 126