| 1 | 
#include "utils/PropertyMapTestCase.hpp" | 
| 2 | 
#include <iostream> | 
| 3 | 
#include <algorithm> | 
| 4 | 
// Registers the fixture into the 'registry' | 
| 5 | 
CPPUNIT_TEST_SUITE_REGISTRATION( PropertyMapTestCase ); | 
| 6 | 
 | 
| 7 | 
 | 
| 8 | 
void PropertyMapTestCase::testPropertyMap(){ | 
| 9 | 
    PropertyMap props; | 
| 10 | 
 | 
| 11 | 
    //test addProperty | 
| 12 | 
    BoolGenericData* b0 = new BoolGenericData("BoolData"); | 
| 13 | 
    b0->setData(false); | 
| 14 | 
    props.addProperty(b0); | 
| 15 | 
    CPPUNIT_ASSERT(props.getPropertyByName("BoolData") == b0); | 
| 16 | 
     | 
| 17 | 
    BoolGenericData* b1 = new BoolGenericData("BoolData"); | 
| 18 | 
    b1->setData(true); | 
| 19 | 
    props.addProperty(b1); | 
| 20 | 
    CPPUNIT_ASSERT(props.getPropertyByName("BoolData") == b1); | 
| 21 | 
 | 
| 22 | 
 | 
| 23 | 
    IntGenericData* i1 = new IntGenericData("IntData"); | 
| 24 | 
    i1->setData(89); | 
| 25 | 
    props.addProperty(i1); | 
| 26 | 
     | 
| 27 | 
    FloatGenericData* f1 = new FloatGenericData("FloatData"); | 
| 28 | 
    f1->setData(49.328); | 
| 29 | 
    props.addProperty(f1); | 
| 30 | 
 | 
| 31 | 
    DoubleGenericData* d1 = new DoubleGenericData("DoubleData"); | 
| 32 | 
    d1->setData(95.1933432); | 
| 33 | 
    props.addProperty(d1); | 
| 34 | 
 | 
| 35 | 
    StringGenericData* s1 = new StringGenericData("StringData"); | 
| 36 | 
    s1->setData("Hello"); | 
| 37 | 
    props.addProperty(s1); | 
| 38 | 
 | 
| 39 | 
 | 
| 40 | 
    IntVectorGenericData* iv1 = new IntVectorGenericData("IntVector"); | 
| 41 | 
    iv1->push_back(2); | 
| 42 | 
    iv1->push_back(1); | 
| 43 | 
    iv1->push_back(324); | 
| 44 | 
    props.addProperty(iv1); | 
| 45 | 
 | 
| 46 | 
    //test getPropertyNames | 
| 47 | 
    std::vector<std::string> propNames = props.getPropertyNames(); | 
| 48 | 
 | 
| 49 | 
 | 
| 50 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "BoolData") != propNames.end()); | 
| 51 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "IntData") != propNames.end()); | 
| 52 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "FloatData") != propNames.end()); | 
| 53 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "DoubleData") != propNames.end()); | 
| 54 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "StringData") != propNames.end()); | 
| 55 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "IntVector") != propNames.end()); | 
| 56 | 
 | 
| 57 | 
    //test getProperties     | 
| 58 | 
    std::vector<GenericData*> propPointers = props.getProperties();     | 
| 59 | 
    CPPUNIT_ASSERT(std::find(propPointers.begin(), propPointers.end(), b1) != propPointers.end()); | 
| 60 | 
    CPPUNIT_ASSERT(std::find(propPointers.begin(), propPointers.end(), i1) != propPointers.end()); | 
| 61 | 
    CPPUNIT_ASSERT(std::find(propPointers.begin(), propPointers.end(), f1) != propPointers.end()); | 
| 62 | 
    CPPUNIT_ASSERT(std::find(propPointers.begin(), propPointers.end(), d1) != propPointers.end()); | 
| 63 | 
    CPPUNIT_ASSERT(std::find(propPointers.begin(), propPointers.end(), s1) != propPointers.end()); | 
| 64 | 
    CPPUNIT_ASSERT(std::find(propPointers.begin(), propPointers.end(), iv1) != propPointers.end()); | 
| 65 | 
 | 
| 66 | 
    //test getPropertyByName | 
| 67 | 
    CPPUNIT_ASSERT(props.getPropertyByName("BoolData") == b1); | 
| 68 | 
    CPPUNIT_ASSERT(props.getPropertyByName("IntData") == i1); | 
| 69 | 
    CPPUNIT_ASSERT(props.getPropertyByName("FloatData") == f1); | 
| 70 | 
    CPPUNIT_ASSERT(props.getPropertyByName("DoubleData") == d1); | 
| 71 | 
    CPPUNIT_ASSERT(props.getPropertyByName("StringData") == s1); | 
| 72 | 
    CPPUNIT_ASSERT(props.getPropertyByName("IntVector") == iv1); | 
| 73 | 
 | 
| 74 | 
    CPPUNIT_ASSERT(b1->getData() == true); | 
| 75 | 
    CPPUNIT_ASSERT(i1->getData() == 89); | 
| 76 | 
    CPPUNIT_ASSERT_DOUBLES_EQUAL(f1->getData(), 49.328, 0.000001); | 
| 77 | 
    CPPUNIT_ASSERT_DOUBLES_EQUAL(d1->getData(), 95.1933432, 0.000001);    | 
| 78 | 
    CPPUNIT_ASSERT(s1->getData() == "Hello"); | 
| 79 | 
    CPPUNIT_ASSERT_EQUAL((*iv1)[0], 2); | 
| 80 | 
    CPPUNIT_ASSERT_EQUAL((*iv1)[1], 1); | 
| 81 | 
    CPPUNIT_ASSERT_EQUAL((*iv1)[2], 324);         | 
| 82 | 
 | 
| 83 | 
    //test removeProperty | 
| 84 | 
    props.removeProperty("DoubleData"); | 
| 85 | 
    props.removeProperty("FloatData"); | 
| 86 | 
    props.removeProperty("IntVector"); | 
| 87 | 
    propNames = props.getPropertyNames(); | 
| 88 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "BoolData") != propNames.end()); | 
| 89 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "IntData") != propNames.end()); | 
| 90 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "FloatData") == propNames.end()); | 
| 91 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "DoubleData") == propNames.end()); | 
| 92 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "StringData") != propNames.end()); | 
| 93 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "IntVector") == propNames.end()); | 
| 94 | 
 | 
| 95 | 
    //test clearProperties | 
| 96 | 
    props.clearProperties(); | 
| 97 | 
    propNames = props.getPropertyNames(); | 
| 98 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "BoolData") == propNames.end()); | 
| 99 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "IntData") == propNames.end()); | 
| 100 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "FloatData") == propNames.end()); | 
| 101 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "DoubleData") == propNames.end()); | 
| 102 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "StringData") == propNames.end()); | 
| 103 | 
    CPPUNIT_ASSERT(std::find(propNames.begin(), propNames.end(), "IntVector") == propNames.end());     | 
| 104 | 
 | 
| 105 | 
} |