1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
#include <cppunit/extensions/HelperMacros.h>
#include "cppUnitHelper.hxx"
#include "ProcessingFactory.hxx"
namespace CLAMTest
{
class ProcessingFactoryTest;
CPPUNIT_TEST_SUITE_REGISTRATION( ProcessingFactoryTest );
class ProcessingFactoryTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( ProcessingFactoryTest );
CPPUNIT_TEST( testGetKeys_empty );
CPPUNIT_TEST( testGetKeys_twoElements );
CPPUNIT_TEST( testGetSetOfValues_empty );
CPPUNIT_TEST( testGetSetOfValues_twoElements );
CPPUNIT_TEST( testGetValuesFromAttribute_empty );
CPPUNIT_TEST( testGetValuesFromAttribute_twoElements );
CPPUNIT_TEST( testGetPairsFromKey_empty );
CPPUNIT_TEST( testGetPairsFromKey_twoElements );
// CPPUNIT_TEST( testAddAttribute_nonExistingKey );
// CPPUNIT_TEST( testGetValueFor_nonExistingKey );
// CPPUNIT_TEST( testGetValueFor_nonExistingAttribute );
// CPPUNIT_TEST( testGetValueFor_existingAttribute );
CPPUNIT_TEST_SUITE_END();
protected:
class DummyCreator : public CLAM::Factory<CLAM::Processing>::Creator
{
CLAM::Processing* Create()
{
return 0;
}
};
CLAM::ProcessingFactory factory;
public:
void setUp()
{
}
void tearDown()
{
factory.Clear();
}
// Tests definition :
protected:
void testGetKeys_empty()
{
CLAM::ProcessingFactory::Keys result = factory.GetKeys("category","");
CPPUNIT_ASSERT_EQUAL(size_t(0), result.size() );
}
void testGetKeys_twoElements()
{
factory.AddCreator("first", new DummyCreator());
factory.AddCreator("second", new DummyCreator());
factory.AddAttribute("first", "category", "spectral");
factory.AddAttribute("second", "category", "time-domain");
CLAM::ProcessingFactory::Keys result = factory.GetKeys("category", "spectral");
CPPUNIT_ASSERT_EQUAL(size_t(1), result.size() );
CPPUNIT_ASSERT_EQUAL(std::string("first"), result.front() );
}
void testGetSetOfValues_empty()
{
factory.AddCreator("non-existing", new DummyCreator());
CLAM::ProcessingFactory::Values result = factory.GetSetOfValues("non-existing");
CPPUNIT_ASSERT_EQUAL(size_t(0), result.size());
}
void testGetSetOfValues_twoElements()
{
factory.AddCreator("first", new DummyCreator());
factory.AddCreator("second", new DummyCreator());
factory.AddAttribute("first", "category", "spectral");
factory.AddAttribute("second", "category", "time-domain");
CLAM::ProcessingFactory::Values result = factory.GetSetOfValues("category");
CPPUNIT_ASSERT_EQUAL(size_t(2), result.size());
CPPUNIT_ASSERT_EQUAL(std::string("spectral"), result.front());
CPPUNIT_ASSERT_EQUAL(std::string("time-domain"), result.back());
}
void testGetValuesFromAttribute_empty()
{
factory.AddCreator("key", new DummyCreator());
CLAM::ProcessingFactory::Values result = factory.GetValuesFromAttribute("key","category");
CPPUNIT_ASSERT_EQUAL(size_t(0), result.size());
}
void testGetValuesFromAttribute_twoElements()
{
factory.AddCreator("first", new DummyCreator());
factory.AddAttribute("first", "category", "spectral");
factory.AddAttribute("first", "category", "time-domain");
factory.AddAttribute("first", "description", "short description");
CLAM::ProcessingFactory::Values result = factory.GetValuesFromAttribute("first","category");
CPPUNIT_ASSERT_EQUAL(size_t(2), result.size());
CPPUNIT_ASSERT_EQUAL(std::string("spectral"), result.front());
CPPUNIT_ASSERT_EQUAL(std::string("time-domain"), result.back());
}
void testGetPairsFromKey_empty()
{
factory.AddCreator("key", new DummyCreator());
CLAM::ProcessingFactory::Pairs result = factory.GetPairsFromKey("key");
CPPUNIT_ASSERT_EQUAL(size_t(0), result.size());
}
void testGetPairsFromKey_twoElements()
{
factory.AddCreator("first", new DummyCreator());
factory.AddAttribute("first", "category", "spectral");
factory.AddAttribute("first", "category", "time-domain");
CLAM::ProcessingFactory::Pairs result = factory.GetPairsFromKey("first");
CPPUNIT_ASSERT_EQUAL(size_t(2), result.size());
CPPUNIT_ASSERT_EQUAL(std::string("spectral"), result.front().value);
CPPUNIT_ASSERT_EQUAL(std::string("time-domain"), result.back().value);
}
/* void testAddAttribute_nonExistingKey()
{
CLAM::ProcessingFactory factory;
try
{
factory.AddAttribute("non-existing-key", "attr");
}
catch (CLAM::AssertFailedErr& e)
{
CPPUNIT_ASSERT_EQUAL(
std::string("ProcessingFactory::AddAttribute: Adding an attribute with an non existing key "),
std::string(e.what())
);
}
}
void testGetValueFor_nonExistingKey()
{
CLAM::ProcessingFactory factory;
try
{
factory.GetValueFor("non-existing-key", "attr");
}
catch (CLAM::AssertFailedErr& e)
{
CPPUNIT_ASSERT_EQUAL(
std::string("ProcessingFactory::GetValueFor: Retrieving a value of an non existing key "),
std::string(e.what())
);
}
}
void testGetValueFor_nonExistingAttribute()
{
CLAM::ProcessingFactory factory;
factory.AddCreator("first", new DummyCreator());
factory.AddAttribute("first", "category", "spectral");
CPPUNIT_ASSERT_EQUAL( std::string("--undefined--"), factory.GetValueFor("first", "non existing attr") );
}
void testGetValueFor_existingAttribute()
{
CLAM::ProcessingFactory factory;
factory.AddCreator("first", new DummyCreator());
factory.AddAttribute("first", "category", "spectral");
CPPUNIT_ASSERT_EQUAL( std::string("spectral"), factory.GetValueFor("category") );
}
*/
};
} // namespace CLAMTest
|