示例#1
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" );
}
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 );
}
示例#3
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::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 );
}
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 );
}