OpenShot Audio Library | OpenShotAudio  0.6.0
juce_ValueTreePropertyWithDefault_test.cpp
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2022 - Raw Material Software Limited
6 
7  JUCE is an open source library subject to commercial or open-source
8  licensing.
9 
10  By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11  Agreement and JUCE Privacy Policy.
12 
13  End User License Agreement: www.juce.com/juce-7-licence
14  Privacy Policy: www.juce.com/juce-privacy-policy
15 
16  Or: You may also use this code under the terms of the GPL v3 (see
17  www.gnu.org/licenses).
18 
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.
22 
23  ==============================================================================
24 */
25 
26 namespace juce
27 {
28 
29 class ValueTreePropertyWithDefaultTests final : public UnitTest
30 {
31 public:
32  ValueTreePropertyWithDefaultTests()
33  : UnitTest ("ValueTreePropertyWithDefault", UnitTestCategories::values)
34  {}
35 
36  void runTest() override
37  {
38  beginTest ("default constructor");
39  {
40  ValueTreePropertyWithDefault value;
41  expect (value.isUsingDefault());
42  expect (value.get() == var());
43  }
44 
45  beginTest ("missing property");
46  {
47  ValueTree t ("root");
48  ValueTreePropertyWithDefault value (t, "testKey", nullptr, "default");
49 
50  expect (value.isUsingDefault());
51  expectEquals (value.get().toString(), String ("default"));
52  }
53 
54  beginTest ("non-empty property");
55  {
56  ValueTree t ("root");
57  t.setProperty ("testKey", "non-default", nullptr);
58 
59  ValueTreePropertyWithDefault value (t, "testKey", nullptr, "default");
60 
61  expect (! value.isUsingDefault());
62  expectEquals (value.get().toString(), String ("non-default"));
63  }
64 
65  beginTest ("set default");
66  {
67  ValueTree t ("root");
68 
69  ValueTreePropertyWithDefault value (t, "testkey", nullptr);
70  value.setDefault ("default");
71 
72  expect (value.isUsingDefault());
73  expectEquals (value.get().toString(), String ("default"));
74  }
75 
76  beginTest ("set value");
77  {
78  ValueTree t ("root");
79  t.setProperty ("testkey", "testvalue", nullptr);
80 
81  ValueTreePropertyWithDefault value (t, "testkey", nullptr, "default");
82  value = "newvalue";
83 
84  expect (! value.isUsingDefault());
85  expectEquals (t["testkey"].toString(), String ("newvalue"));
86 
87  value.resetToDefault();
88 
89  expect (value.isUsingDefault());
90  expect (t["testkey"] == var());
91  }
92  }
93 };
94 
95 static ValueTreePropertyWithDefaultTests valueTreePropertyWithDefaultTests;
96 
97 } // namespace juce
void expectEquals(ValueType actual, ValueType expected, String failureMessage=String())
UnitTest(const String &name, const String &category=String())
void beginTest(const String &testName)
void expect(bool testResult, const String &failureMessage=String())