32 class CachedValueTests :
public UnitTest
36 : UnitTest (
"CachedValues", UnitTestCategories::values)
39 void runTest()
override 41 beginTest (
"default constructor");
43 CachedValue<String> cv;
44 expect (cv.isUsingDefault());
45 expect (cv.get() == String());
48 beginTest (
"without default value");
51 t.setProperty (
"testkey",
"testvalue",
nullptr);
53 CachedValue<String> cv (t,
"testkey",
nullptr);
55 expect (! cv.isUsingDefault());
56 expect (cv.get() ==
"testvalue");
60 expect (cv.isUsingDefault());
61 expect (cv.get() == String());
64 beginTest (
"with default value");
67 t.setProperty (
"testkey",
"testvalue",
nullptr);
69 CachedValue<String> cv (t,
"testkey",
nullptr,
"defaultvalue");
71 expect (! cv.isUsingDefault());
72 expect (cv.get() ==
"testvalue");
76 expect (cv.isUsingDefault());
77 expect (cv.get() ==
"defaultvalue");
80 beginTest (
"with default value (int)");
83 t.setProperty (
"testkey", 23,
nullptr);
85 CachedValue<int> cv (t,
"testkey",
nullptr, 34);
87 expect (! cv.isUsingDefault());
89 expectEquals (cv.get(), 23);
93 expect (cv.isUsingDefault());
97 beginTest (
"with void value");
100 t.setProperty (
"testkey", var(),
nullptr);
102 CachedValue<String> cv (t,
"testkey",
nullptr,
"defaultvalue");
104 expect (! cv.isUsingDefault());
106 expectEquals (cv.get(), String());
109 beginTest (
"with non-existent value");
111 ValueTree t (
"root");
113 CachedValue<String> cv (t,
"testkey",
nullptr,
"defaultvalue");
115 expect (cv.isUsingDefault());
116 expect (cv ==
"defaultvalue");
117 expect (cv.get() ==
"defaultvalue");
120 beginTest (
"with value changing");
122 ValueTree t (
"root");
123 t.setProperty (
"testkey",
"oldvalue",
nullptr);
125 CachedValue<String> cv (t,
"testkey",
nullptr,
"defaultvalue");
126 expect (cv ==
"oldvalue");
128 t.setProperty (
"testkey",
"newvalue",
nullptr);
129 expect (cv !=
"oldvalue");
130 expect (cv ==
"newvalue");
133 beginTest (
"set value");
135 ValueTree t (
"root");
136 t.setProperty (
"testkey", 23,
nullptr);
138 CachedValue<int> cv (t,
"testkey",
nullptr, 45);
141 expectEquals ((
int) t[
"testkey"], 34);
145 expectEquals (cv.get(), 45);
147 expect (t[
"testkey"] == var());
152 static CachedValueTests cachedValueTests;