32 class CachedValueTests :
public UnitTest
35 CachedValueTests() : UnitTest (
"CachedValues",
"Values") {}
37 void runTest()
override 39 beginTest (
"default constructor");
41 CachedValue<String> cv;
42 expect (cv.isUsingDefault());
43 expect (cv.get() == String());
46 beginTest (
"without default value");
49 t.setProperty (
"testkey",
"testvalue",
nullptr);
51 CachedValue<String> cv (t,
"testkey",
nullptr);
53 expect (! cv.isUsingDefault());
54 expect (cv.get() ==
"testvalue");
58 expect (cv.isUsingDefault());
59 expect (cv.get() == String());
62 beginTest (
"with default value");
65 t.setProperty (
"testkey",
"testvalue",
nullptr);
67 CachedValue<String> cv (t,
"testkey",
nullptr,
"defaultvalue");
69 expect (! cv.isUsingDefault());
70 expect (cv.get() ==
"testvalue");
74 expect (cv.isUsingDefault());
75 expect (cv.get() ==
"defaultvalue");
78 beginTest (
"with default value (int)");
81 t.setProperty (
"testkey", 23,
nullptr);
83 CachedValue<int> cv (t,
"testkey",
nullptr, 34);
85 expect (! cv.isUsingDefault());
87 expectEquals (cv.get(), 23);
91 expect (cv.isUsingDefault());
95 beginTest (
"with void value");
98 t.setProperty (
"testkey", var(),
nullptr);
100 CachedValue<String> cv (t,
"testkey",
nullptr,
"defaultvalue");
102 expect (! cv.isUsingDefault());
104 expectEquals (cv.get(), String());
107 beginTest (
"with non-existent value");
109 ValueTree t (
"root");
111 CachedValue<String> cv (t,
"testkey",
nullptr,
"defaultvalue");
113 expect (cv.isUsingDefault());
114 expect (cv ==
"defaultvalue");
115 expect (cv.get() ==
"defaultvalue");
118 beginTest (
"with value changing");
120 ValueTree t (
"root");
121 t.setProperty (
"testkey",
"oldvalue",
nullptr);
123 CachedValue<String> cv (t,
"testkey",
nullptr,
"defaultvalue");
124 expect (cv ==
"oldvalue");
126 t.setProperty (
"testkey",
"newvalue",
nullptr);
127 expect (cv !=
"oldvalue");
128 expect (cv ==
"newvalue");
131 beginTest (
"set value");
133 ValueTree t (
"root");
134 t.setProperty (
"testkey", 23,
nullptr);
136 CachedValue<int> cv (t,
"testkey",
nullptr, 45);
139 expectEquals ((
int) t[
"testkey"], 34);
143 expectEquals (cv.get(), 45);
145 expect (t[
"testkey"] == var());
150 static CachedValueTests cachedValueTests;