31class CachedValueTests final :
public UnitTest
35 : UnitTest (
"CachedValues", UnitTestCategories::values)
38 void runTest()
override
40 beginTest (
"default constructor");
42 CachedValue<String> cv;
43 expect (cv.isUsingDefault());
44 expect (cv.get() == String());
47 beginTest (
"without default value");
50 t.setProperty (
"testkey",
"testvalue",
nullptr);
52 CachedValue<String> cv (t,
"testkey",
nullptr);
54 expect (! cv.isUsingDefault());
55 expect (cv.get() ==
"testvalue");
59 expect (cv.isUsingDefault());
60 expect (cv.get() == String());
63 beginTest (
"with default value");
66 t.setProperty (
"testkey",
"testvalue",
nullptr);
68 CachedValue<String> cv (t,
"testkey",
nullptr,
"defaultvalue");
70 expect (! cv.isUsingDefault());
71 expect (cv.get() ==
"testvalue");
75 expect (cv.isUsingDefault());
76 expect (cv.get() ==
"defaultvalue");
79 beginTest (
"with default value (int)");
82 t.setProperty (
"testkey", 23,
nullptr);
84 CachedValue<int> cv (t,
"testkey",
nullptr, 34);
86 expect (! cv.isUsingDefault());
88 expectEquals (cv.get(), 23);
92 expect (cv.isUsingDefault());
96 beginTest (
"with void value");
99 t.setProperty (
"testkey", var(),
nullptr);
101 CachedValue<String> cv (t,
"testkey",
nullptr,
"defaultvalue");
103 expect (! cv.isUsingDefault());
105 expectEquals (cv.get(), String());
108 beginTest (
"with non-existent value");
110 ValueTree t (
"root");
112 CachedValue<String> cv (t,
"testkey",
nullptr,
"defaultvalue");
114 expect (cv.isUsingDefault());
115 expect (cv ==
"defaultvalue");
116 expect (cv.get() ==
"defaultvalue");
119 beginTest (
"with value changing");
121 ValueTree t (
"root");
122 t.setProperty (
"testkey",
"oldvalue",
nullptr);
124 CachedValue<String> cv (t,
"testkey",
nullptr,
"defaultvalue");
125 expect (cv ==
"oldvalue");
127 t.setProperty (
"testkey",
"newvalue",
nullptr);
128 expect (cv !=
"oldvalue");
129 expect (cv ==
"newvalue");
132 beginTest (
"set value");
134 ValueTree t (
"root");
135 t.setProperty (
"testkey", 23,
nullptr);
137 CachedValue<int> cv (t,
"testkey",
nullptr, 45);
140 expectEquals ((
int) t[
"testkey"], 34);
144 expectEquals (cv.get(), 45);
146 expect (t[
"testkey"] == var());
151static CachedValueTests cachedValueTests;