VST3: fetch midi mappings all at once, use it for note/sound-off
[carla.git] / source / modules / juce_data_structures / values / juce_CachedValue.cpp
blobc056a8614aff49cc1787350d6aafd78b81ac8729
1 /*
2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
23 ==============================================================================
26 namespace juce
29 #if JUCE_UNIT_TESTS
31 class CachedValueTests : public UnitTest
33 public:
34 CachedValueTests()
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");
49 ValueTree t ("root");
50 t.setProperty ("testkey", "testvalue", nullptr);
52 CachedValue<String> cv (t, "testkey", nullptr);
54 expect (! cv.isUsingDefault());
55 expect (cv.get() == "testvalue");
57 cv.resetToDefault();
59 expect (cv.isUsingDefault());
60 expect (cv.get() == String());
63 beginTest ("with default value");
65 ValueTree t ("root");
66 t.setProperty ("testkey", "testvalue", nullptr);
68 CachedValue<String> cv (t, "testkey", nullptr, "defaultvalue");
70 expect (! cv.isUsingDefault());
71 expect (cv.get() == "testvalue");
73 cv.resetToDefault();
75 expect (cv.isUsingDefault());
76 expect (cv.get() == "defaultvalue");
79 beginTest ("with default value (int)");
81 ValueTree t ("root");
82 t.setProperty ("testkey", 23, nullptr);
84 CachedValue<int> cv (t, "testkey", nullptr, 34);
86 expect (! cv.isUsingDefault());
87 expect (cv == 23);
88 expectEquals (cv.get(), 23);
90 cv.resetToDefault();
92 expect (cv.isUsingDefault());
93 expect (cv == 34);
96 beginTest ("with void value");
98 ValueTree t ("root");
99 t.setProperty ("testkey", var(), nullptr);
101 CachedValue<String> cv (t, "testkey", nullptr, "defaultvalue");
103 expect (! cv.isUsingDefault());
104 expect (cv == "");
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);
138 cv = 34;
140 expectEquals ((int) t["testkey"], 34);
142 cv.resetToDefault();
143 expect (cv == 45);
144 expectEquals (cv.get(), 45);
146 expect (t["testkey"] == var());
151 static CachedValueTests cachedValueTests;
153 #endif
155 } // namespace juce