Пример #1
0
void tst_QCache::axioms_on_key_type()
{
    QCache<KeyType, ValueType> foo;
    foo.setMaxCost(1);
    foo.clear();
    foo.insert(KeyType(123), new ValueType(123));
    foo.object(KeyType(123));
    foo.contains(KeyType(456));
    foo[KeyType(456)];
    foo.remove(KeyType(456));
    foo.remove(KeyType(123));
    foo.take(KeyType(789));
// If this fails, contact the maintaner
    QVERIFY(sizeof(QHash<int, int>) == sizeof(void *));
}
Пример #2
0
void tst_QCache::remove()
{
    QCache<QString, Foo> cache;
    cache.remove(QString());
    cache.remove("alpha");
    QVERIFY(cache.isEmpty());

    cache.insert("alpha", new Foo, 10);
    QCOMPARE(cache.size(), 1);

    cache.insert("beta", new Foo, 20);
    QCOMPARE(cache.size(), 2);

    for (int i = 0; i < 10; ++i) {
        cache.remove("alpha");
        QCOMPARE(cache.size(), 1);
        QCOMPARE(cache.totalCost(), 20);
    }

    cache.setMaxCost(1);
    QCOMPARE(cache.size(), 0);
    cache.remove("beta");
    QCOMPARE(cache.size(), 0);
}
Пример #3
0
void tst_QCache::operator_bracket_bracket()
{
    QCache<int, int> cache;
    cache.insert(1, new int(2));
    QVERIFY(cache[0] == 0);
    QVERIFY(cache[1] != 0);
    QCOMPARE(*cache[1], 2);

    cache.insert(1, new int(4));
    QVERIFY(cache[1] != 0);
    QCOMPARE(*cache[1], 4);

    // check that operator[] doesn't remove the item
    QVERIFY(cache[1] != 0);
    QCOMPARE(*cache[1], 4);

    cache.remove(1);
    QVERIFY(cache[1] == 0);
}
Пример #4
0
void tst_QCache::contains()
{
    QCache<int, int> cache;
    QVERIFY(!cache.contains(0));
    QVERIFY(!cache.contains(1));

    cache.insert(1, new int(1), 1);
    QVERIFY(!cache.contains(0));
    QVERIFY(cache.contains(1));

    cache.remove(0);
    cache.remove(1);
    QVERIFY(!cache.contains(0));
    QVERIFY(!cache.contains(1));

    cache.insert(1, new int(1), 1);
    QVERIFY(!cache.contains(0));
    QVERIFY(cache.contains(1));

    cache.clear();
    QVERIFY(!cache.contains(0));
    QVERIFY(!cache.contains(1));
}
Пример #5
0
void QGLBlurTextureCache::clearBlurTextureInfo(quint64 cacheKey)
{
    cache.remove(cacheKey);
}