OpenShot Library | libopenshot-audio
0.2.0
juce_CachedValue.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
CachedValueTests :
public
UnitTest
33
{
34
public
:
35
CachedValueTests
() : UnitTest (
"CachedValues"
,
"Values"
) {}
36
37
void
runTest()
override
38
{
39
beginTest (
"default constructor"
);
40
{
41
CachedValue<String>
cv
;
42
expect (
cv
.isUsingDefault());
43
expect (
cv
.get() == String());
44
}
45
46
beginTest (
"without default value"
);
47
{
48
ValueTree
t
(
"root"
);
49
t
.setProperty (
"testkey"
,
"testvalue"
,
nullptr
);
50
51
CachedValue<String>
cv
(
t
,
"testkey"
,
nullptr
);
52
53
expect (!
cv
.isUsingDefault());
54
expect (
cv
.get() ==
"testvalue"
);
55
56
cv
.resetToDefault();
57
58
expect (
cv
.isUsingDefault());
59
expect (
cv
.get() == String());
60
}
61
62
beginTest (
"with default value"
);
63
{
64
ValueTree
t
(
"root"
);
65
t
.setProperty (
"testkey"
,
"testvalue"
,
nullptr
);
66
67
CachedValue<String>
cv
(
t
,
"testkey"
,
nullptr
,
"defaultvalue"
);
68
69
expect (!
cv
.isUsingDefault());
70
expect (
cv
.get() ==
"testvalue"
);
71
72
cv
.resetToDefault();
73
74
expect (
cv
.isUsingDefault());
75
expect (
cv
.get() ==
"defaultvalue"
);
76
}
77
78
beginTest (
"with default value (int)"
);
79
{
80
ValueTree
t
(
"root"
);
81
t
.setProperty (
"testkey"
, 23,
nullptr
);
82
83
CachedValue<int>
cv
(
t
,
"testkey"
,
nullptr
, 34);
84
85
expect (!
cv
.isUsingDefault());
86
expect (
cv
== 23);
87
expectEquals (
cv
.get(), 23);
88
89
cv
.resetToDefault();
90
91
expect (
cv
.isUsingDefault());
92
expect (
cv
== 34);
93
}
94
95
beginTest (
"with void value"
);
96
{
97
ValueTree
t
(
"root"
);
98
t
.setProperty (
"testkey"
, var(),
nullptr
);
99
100
CachedValue<String>
cv
(
t
,
"testkey"
,
nullptr
,
"defaultvalue"
);
101
102
expect (!
cv
.isUsingDefault());
103
expect (
cv
==
""
);
104
expectEquals (
cv
.get(), String());
105
}
106
107
beginTest (
"with non-existent value"
);
108
{
109
ValueTree
t
(
"root"
);
110
111
CachedValue<String>
cv
(
t
,
"testkey"
,
nullptr
,
"defaultvalue"
);
112
113
expect (
cv
.isUsingDefault());
114
expect (
cv
==
"defaultvalue"
);
115
expect (
cv
.get() ==
"defaultvalue"
);
116
}
117
118
beginTest (
"with value changing"
);
119
{
120
ValueTree
t
(
"root"
);
121
t
.setProperty (
"testkey"
,
"oldvalue"
,
nullptr
);
122
123
CachedValue<String>
cv
(
t
,
"testkey"
,
nullptr
,
"defaultvalue"
);
124
expect (
cv
==
"oldvalue"
);
125
126
t
.setProperty (
"testkey"
,
"newvalue"
,
nullptr
);
127
expect (
cv
!=
"oldvalue"
);
128
expect (
cv
==
"newvalue"
);
129
}
130
131
beginTest (
"set value"
);
132
{
133
ValueTree
t
(
"root"
);
134
t
.setProperty (
"testkey"
, 23,
nullptr
);
135
136
CachedValue<int>
cv
(
t
,
"testkey"
,
nullptr
, 45);
137
cv
= 34;
138
139
expectEquals ((
int
)
t
[
"testkey"
], 34);
140
141
cv
.resetToDefault();
142
expect (
cv
== 45);
143
expectEquals (
cv
.get(), 45);
144
145
expect (
t
[
"testkey"
] == var());
146
}
147
}
148
};
149
150
static
CachedValueTests cachedValueTests;
151
152
#endif
153
154
}
// namespace juce
juce::Array::Array
Array()=default
Creates an empty array.
juce_data_structures
values
juce_CachedValue.cpp
Generated on Fri Sep 20 2024 04:11:05 for OpenShot Library | libopenshot-audio by
1.9.8