示例#1
0
void SystemTest::test_getenv2() {

    StlMap<std::string, std::string> values = System::getenv();

    CPPUNIT_ASSERT( values.size() != 0 );
    CPPUNIT_ASSERT( values.containsKey( "PATH" ) || values.containsKey( "Path" ) );
    CPPUNIT_ASSERT( !values.containsKey( "PATH_ASDFGHJKL" ) );
}
void StlMapTest::testContainsKey(){

    StlMap<string, bool> boolMap;
    CPPUNIT_ASSERT(boolMap.containsKey("bob") == false);

    boolMap.put( "bob", true );

    CPPUNIT_ASSERT(boolMap.containsKey("bob") == true );
    CPPUNIT_ASSERT(boolMap.containsKey("fred") == false );
}
void StlMapTest::testPut() {

    StlMap<string, bool> boolMap;

    boolMap.put( "fred", true );
    CPPUNIT_ASSERT( boolMap.get("fred") == true );

    boolMap.put( "bob", false );
    CPPUNIT_ASSERT( boolMap.get("bob") == false );
    CPPUNIT_ASSERT( boolMap.get("fred") == true );

    boolMap.put( "bob", true );
    CPPUNIT_ASSERT( boolMap.get("bob") == true );
    CPPUNIT_ASSERT( boolMap.get("fred") == true );
}
示例#4
0
void BrokerIdTest::test2() {

    typedef PointerComparator< BrokerId > COMPARATOR;

    Pointer<BrokerId> myCommand1( new BrokerId );
    Pointer<BrokerId> myCommand2( new BrokerId );
    Pointer<BrokerId> myCommand3( new BrokerId );

    myCommand1->setValue( "A" );
    myCommand2->setValue( "A" );
    myCommand3->setValue( "C" );

    CPPUNIT_ASSERT( myCommand1->compareTo( *myCommand2 ) == 0 );
    CPPUNIT_ASSERT( myCommand1->compareTo( *myCommand3 ) == -1 );

    StlMap< Pointer<BrokerId>, int, COMPARATOR > testMap;

    testMap.put( myCommand3, 0 );
    testMap.put( myCommand1, 0 );
    CPPUNIT_ASSERT( testMap.size() == 2 );

    testMap.put( myCommand2, 0 );
    CPPUNIT_ASSERT( testMap.size() == 2 );

    std::vector< Pointer<BrokerId> > keys = testMap.keySet().toArray();

    CPPUNIT_ASSERT( keys.at( 0 )->getValue() == "A" );
    CPPUNIT_ASSERT( keys.at( 1 )->getValue() == "C" );
}
示例#5
0
void BrokerIdTest::test() {

    BrokerId myCommand2;
    BrokerId myCommand3;
    BrokerId myCommand1;
    CPPUNIT_ASSERT( myCommand1.getDataStructureType() == BrokerId::ID_BROKERID );

    myCommand1.setValue( "A" );
    myCommand2.setValue( "B" );
    myCommand3.setValue( "C" );

    StlMap< BrokerId*, int, BrokerIdComparitor > testMap;

    testMap.put( &myCommand1, 0 );
    testMap.put( &myCommand3, 0 );
    testMap.put( &myCommand2, 0 );

    std::vector<BrokerId*> keys = testMap.keySet().toArray();

    CPPUNIT_ASSERT( keys.at( 0 )->getValue() == "A" );
    CPPUNIT_ASSERT( keys.at( 1 )->getValue() == "B" );
    CPPUNIT_ASSERT( keys.at( 2 )->getValue() == "C" );
}
void StlMapTest::testSize() {

    StlMap<string, bool> boolMap;

    CPPUNIT_ASSERT(boolMap.size() == 0 );
    boolMap.put( "bob", true );
    CPPUNIT_ASSERT(boolMap.size() == 1 );
    boolMap.put( "fred", true );
    CPPUNIT_ASSERT(boolMap.size() == 2 );
}
void StlMapTest::testIsEmpty() {

    StlMap<string, bool> boolMap;
    boolMap.put( "bob", true );
    boolMap.put( "fred", true );

    CPPUNIT_ASSERT(boolMap.isEmpty() == false );
    boolMap.clear();
    CPPUNIT_ASSERT(boolMap.isEmpty() == true );
}
void StlMapTest::testContiansValue() {

    StlMap<string, bool> boolMap;

    boolMap.put( "fred", true );
    boolMap.put( "fred1", false );
    CPPUNIT_ASSERT( boolMap.containsValue(true) == true );
    boolMap.remove( "fred" );
    CPPUNIT_ASSERT( boolMap.containsValue(true) == false );
}
void StlMapTest::testRemove() {
    StlMap<string, bool> boolMap;

    boolMap.put( "fred", true );
    CPPUNIT_ASSERT( boolMap.containsKey("fred") == true );
    CPPUNIT_ASSERT( boolMap.remove( "fred" ) == true );
    CPPUNIT_ASSERT( boolMap.containsKey("fred") == false );

    CPPUNIT_ASSERT_THROW_MESSAGE(
        "Should throw a NoSuchElementException",
        boolMap.remove( "fred" ),
        decaf::lang::exceptions::NoSuchElementException );
}
示例#10
0
void StlMapTest::testGet() {

    StlMap<string, bool> boolMap;

    boolMap.put( "fred", true );
    CPPUNIT_ASSERT( boolMap.get("fred") == true );

    boolMap.put( "bob", false );
    CPPUNIT_ASSERT( boolMap.get("bob") == false );
    CPPUNIT_ASSERT( boolMap.get("fred") == true );

    try{
        boolMap.get( "mike" );
        CPPUNIT_ASSERT(false);
    } catch( decaf::lang::exceptions::NoSuchElementException& e ){
    }
}
示例#11
0
void StlMapTest::testPutAll() {

    StlMap<string, int> destMap;
    StlTestMap<string, int> srcMap;
    StlTestMap<string, int> srcMap2;

    srcMap.put( "A", 1 );
    srcMap.put( "B", 1 );
    srcMap.put( "C", 1 );

    CPPUNIT_ASSERT( srcMap.size() == 3 );
    CPPUNIT_ASSERT( destMap.size() == 0 );

    srcMap.put( "D", 1 );
    srcMap.put( "E", 1 );
    srcMap.put( "F", 1 );

    destMap.putAll( srcMap );
    CPPUNIT_ASSERT( destMap.size() == 6 );
    destMap.putAll( srcMap2 );
    CPPUNIT_ASSERT( destMap.size() == 6 );
}
示例#12
0
void StlMapTest::testCopy() {

    StlMap<string, int> destMap;
    StlTestMap<string, int> srcMap;
    StlMap<string, int> srcMap2;

    CPPUNIT_ASSERT( destMap.size() == 0 );

    srcMap.put( "A", 1 );
    srcMap.put( "B", 2 );
    srcMap.put( "C", 3 );
    srcMap.put( "D", 4 );
    srcMap.put( "E", 5 );
    srcMap.put( "F", 6 );

    destMap.copy( srcMap );
    CPPUNIT_ASSERT( destMap.size() == 6 );
    CPPUNIT_ASSERT( destMap.get( "A" ) == 1 );
    CPPUNIT_ASSERT( destMap.get( "B" ) == 2 );
    CPPUNIT_ASSERT( destMap.get( "C" ) == 3 );
    CPPUNIT_ASSERT( destMap.get( "D" ) == 4 );
    CPPUNIT_ASSERT( destMap.get( "E" ) == 5 );
    CPPUNIT_ASSERT( destMap.get( "F" ) == 6 );

    destMap.copy( srcMap2 );
    CPPUNIT_ASSERT( destMap.size() == 0 );

    srcMap2.put( "A", 1 );
    srcMap2.put( "B", 2 );
    srcMap2.put( "C", 3 );
    srcMap2.put( "D", 4 );
    srcMap2.put( "E", 5 );

    destMap.copy( srcMap2 );
    CPPUNIT_ASSERT( destMap.size() == 5 );
}