File indexing completed on 2024-12-22 04:09:28
0001 /* 0002 * SPDX-FileCopyrightText: 2023 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "KisValueCacheTest.h" 0008 0009 #include "simpletest.h" 0010 0011 #include "KisValueCache.h" 0012 0013 void KisValueCacheTest::test() 0014 { 0015 struct Initializer 0016 { 0017 Initializer(int *sourceValue) : m_sourceValue(sourceValue) {} 0018 int initialize() { return *m_sourceValue; } 0019 0020 private: 0021 int *m_sourceValue {nullptr}; 0022 }; 0023 0024 int sourceValue = 1; 0025 0026 KisValueCache<Initializer> cache(&sourceValue); 0027 0028 QVERIFY(!cache.isValid()); 0029 0030 QCOMPARE(cache.value(), 1); 0031 QVERIFY(cache.isValid()); 0032 0033 sourceValue = 2; 0034 0035 QCOMPARE(cache.value(), 1); 0036 0037 cache.clear(); 0038 QVERIFY(!cache.isValid()); 0039 0040 QCOMPARE(cache.value(), 2); 0041 } 0042 0043 SIMPLE_TEST_MAIN(KisValueCacheTest);