OpenShot Audio Library | OpenShotAudio  0.3.1
juce_ValueWithDefault.cpp
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2017 - ROLI Ltd.
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 5 End-User License
11  Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
12  27th April 2017).
13 
14  End User License Agreement: www.juce.com/juce-5-licence
15  Privacy Policy: www.juce.com/juce-5-privacy-policy
16 
17  Or: You may also use this code under the terms of the GPL v3 (see
18  www.gnu.org/licenses).
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 #if JUCE_UNIT_TESTS
31 
32 class ValueWithDefaultTests : public UnitTest
33 {
34 public:
35  ValueWithDefaultTests()
36  : UnitTest ("ValueWithDefault", UnitTestCategories::values)
37  {}
38 
39  void runTest() override
40  {
41  beginTest ("default constructor");
42  {
43  ValueWithDefault vwd;
44  expect (vwd.isUsingDefault());
45  expect (vwd.get() == var());
46  }
47 
48  beginTest ("missing property");
49  {
50  ValueTree t ("root");
51  ValueWithDefault vwd (t, "testKey", nullptr, "default");
52 
53  expect (vwd.isUsingDefault());
54  expectEquals (vwd.get().toString(), String ("default"));
55  }
56 
57  beginTest ("non-empty property");
58  {
59  ValueTree t ("root");
60  t.setProperty ("testKey", "non-default", nullptr);
61 
62  ValueWithDefault vwd (t, "testKey", nullptr, "default");
63 
64  expect (! vwd.isUsingDefault());
65  expectEquals (vwd.get().toString(), String ("non-default"));
66  }
67 
68  beginTest ("set default");
69  {
70  ValueTree t ("root");
71 
72  ValueWithDefault vwd (t, "testkey", nullptr);
73  vwd.setDefault ("default");
74 
75  expect (vwd.isUsingDefault());
76  expectEquals (vwd.get().toString(), String ("default"));
77  }
78 
79  beginTest ("set value");
80  {
81  ValueTree t ("root");
82  t.setProperty ("testkey", "testvalue", nullptr);
83 
84  ValueWithDefault vwd (t, "testkey", nullptr, "default");
85  vwd = "newvalue";
86 
87  expect (! vwd.isUsingDefault());
88  expectEquals (t["testkey"].toString(), String ("newvalue"));
89 
90  vwd.resetToDefault();
91 
92  expect (vwd.isUsingDefault());
93  expect (t["testkey"] == var());
94  }
95  }
96 };
97 
98 static ValueWithDefaultTests valueWithDefaultTests;
99 
100 #endif
101 
102 } // namespace juce