Esempio n. 1
0
void testWeakCache() {
    WeakCache<std::string, CacheTestRef> cache;

    debugAssert(CacheTest::count == 0);
    CacheTestRef x = new CacheTest();
    debugAssert(CacheTest::count == 1);

    cache.set("x", x);
    debugAssert(CacheTest::count == 1);
    CacheTestRef y = new CacheTest();
    CacheTestRef z = new CacheTest();
    debugAssert(CacheTest::count == 3);
    
    cache.set("y", y);
    
    debugAssert(cache["x"] == x);
    debugAssert(cache["y"] == y);
    debugAssert(cache["q"].isNull());
    
    x = NULL;
    debugAssert(CacheTest::count == 2);
    debugAssert(cache["x"].isNull());

    cache.set("y", z);
    y = NULL;
    debugAssert(cache["y"] == z);

    cache.remove("y");
}