예제 #1
0
void StringDicSuite::testRm01()
{
    Sample0 dic0;
    StringVec keys;
    StringVec values(1U /*capacity*/, -1 /*growBy*/);
    dic0.vectorize(keys, values);

    StringDic dic1(dic0);

    // First key-value pair.
    String k(keys[0]);
    bool ok = dic1.rm(k.ascii()) && (!dic1.find(k));
    CPPUNIT_ASSERT(ok);

    // Last key-value pair.
    k = keys[keys.numItems() - 1];
    String removedV;
    ok = dic1.rm(k.ascii(), removedV) && (!dic1.find(k)) && (removedV == values[values.numItems() - 1]);
    CPPUNIT_ASSERT(ok);

    // Non-existent key-value pair.
    k = "non-existent";
    ok = (!dic1.rm(k.ascii()));
    CPPUNIT_ASSERT(ok);
    removedV.reset();
    ok = (!dic1.rm(k.ascii(), removedV)) && removedV.empty();
    CPPUNIT_ASSERT(ok);
}
예제 #2
0
//!
//! Reset the vector with given item strings.
//! Return true if successful.
//!
bool MacAddrVec::reset(const StringVec& vec)
{
    int growBy = 0;
    unsigned int capacity = vec.numItems();
    U64Vec tmp(capacity, growBy);

    item_t item;
    for (size_t i = 0, numItems = vec.numItems(); i < numItems; tmp.add(item), ++i)
    {
        if (!item.reset(vec.peek(i).ascii()))
        {
            bool ok = false;
            return ok;
        }
    }

    U64Vec::operator =(tmp);
    bool ok = true;
    return ok;
}