Skip to content

Commit b8f2189

Browse files
committed
More unit tests
1 parent 57b226e commit b8f2189

3 files changed

Lines changed: 216 additions & 0 deletions

File tree

tests/yup_audio_processors.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@
2121

2222
#include "yup_audio_processors/yup_AudioParameter.cpp"
2323
#include "yup_audio_processors/yup_AudioProcessContext.cpp"
24+
#include "yup_audio_processors/yup_ParameterChangeBuffer.cpp"
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
==============================================================================
3+
4+
This file is part of the YUP library.
5+
Copyright (c) 2026 - kunitoki@gmail.com
6+
7+
YUP is an open source library subject to open-source licensing.
8+
9+
The code included in this file is provided under the terms of the ISC license
10+
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
11+
to use, copy, modify, and/or distribute this software for any purpose with or
12+
without fee is hereby granted provided that the above copyright notice and
13+
this permission notice appear in all copies.
14+
15+
YUP IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
16+
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
17+
DISCLAIMED.
18+
19+
==============================================================================
20+
*/
21+
22+
#include <gtest/gtest.h>
23+
24+
#include <yup_audio_processors/yup_audio_processors.h>
25+
26+
using namespace yup;
27+
28+
TEST (ParameterChangeBufferTests, AddsAndClearsReservedChanges)
29+
{
30+
ParameterChangeBuffer changes;
31+
32+
EXPECT_TRUE (changes.isEmpty());
33+
EXPECT_EQ (0, changes.getNumChanges());
34+
35+
changes.reserve (2);
36+
37+
EXPECT_TRUE (changes.addChange (3, 0.25f, 12));
38+
EXPECT_TRUE (changes.addChange (4, 0.5f, 24));
39+
40+
EXPECT_FALSE (changes.isEmpty());
41+
EXPECT_EQ (2, changes.getNumChanges());
42+
43+
ASSERT_NE (changes.begin(), changes.end());
44+
EXPECT_EQ (3, changes.begin()->parameterIndex);
45+
EXPECT_FLOAT_EQ (0.25f, changes.begin()->normalizedValue);
46+
EXPECT_EQ (12, changes.begin()->sampleOffset);
47+
48+
changes.clear();
49+
50+
EXPECT_TRUE (changes.isEmpty());
51+
EXPECT_EQ (0, changes.getNumChanges());
52+
}
53+
54+
TEST (ParameterChangeBufferTests, SortOrdersChangesBySampleOffset)
55+
{
56+
ParameterChangeBuffer changes;
57+
changes.reserve (4);
58+
59+
EXPECT_TRUE (changes.addChange (1, 0.3f, 24));
60+
EXPECT_TRUE (changes.addChange (2, 0.4f, 4));
61+
EXPECT_TRUE (changes.addChange (1, 0.2f, 12));
62+
63+
changes.sort();
64+
65+
ASSERT_EQ (3, changes.getNumChanges());
66+
67+
const auto* change = changes.begin();
68+
EXPECT_EQ (4, change[0].sampleOffset);
69+
EXPECT_EQ (12, change[1].sampleOffset);
70+
EXPECT_EQ (24, change[2].sampleOffset);
71+
}
72+
73+
TEST (ParameterChangeBufferTests, FindsNextChangeAtOrAfterSamplePosition)
74+
{
75+
ParameterChangeBuffer changes;
76+
changes.reserve (3);
77+
78+
EXPECT_TRUE (changes.addChange (1, 0.1f, 3));
79+
EXPECT_TRUE (changes.addChange (1, 0.2f, 9));
80+
EXPECT_TRUE (changes.addChange (1, 0.3f, 14));
81+
changes.sort();
82+
83+
EXPECT_EQ (3, changes.findNextSamplePosition (0)->sampleOffset);
84+
EXPECT_EQ (3, changes.findNextSamplePosition (3)->sampleOffset);
85+
EXPECT_EQ (9, changes.findNextSamplePosition (4)->sampleOffset);
86+
EXPECT_EQ (14, changes.findNextSamplePosition (14)->sampleOffset);
87+
EXPECT_EQ (changes.end(), changes.findNextSamplePosition (15));
88+
}
89+
90+
TEST (AudioParameterHandleTests, AdvanceToSampleAppliesOnlyMatchingParameterChanges)
91+
{
92+
auto parameter = AudioParameterBuilder()
93+
.withID ("gain")
94+
.withName ("Gain")
95+
.withRange (0.0f, 100.0f)
96+
.withDefault (10.0f)
97+
.build();
98+
99+
parameter->setIndexInContainer (2);
100+
101+
AudioParameterHandle handle (*parameter, 48000.0);
102+
103+
ParameterChangeBuffer changes;
104+
changes.reserve (4);
105+
EXPECT_TRUE (changes.addChange (1, 0.5f, 0));
106+
EXPECT_TRUE (changes.addChange (2, 0.25f, 4));
107+
EXPECT_TRUE (changes.addChange (2, 0.75f, 8));
108+
changes.sort();
109+
110+
handle.prepareBlock (changes, parameter->getIndexInContainer());
111+
112+
EXPECT_FALSE (handle.advanceToSample (3));
113+
EXPECT_FLOAT_EQ (10.0f, parameter->getValue());
114+
115+
EXPECT_TRUE (handle.advanceToSample (4));
116+
EXPECT_FLOAT_EQ (25.0f, parameter->getValue());
117+
EXPECT_FLOAT_EQ (25.0f, handle.getCurrentValue());
118+
119+
EXPECT_FALSE (handle.advanceToSample (7));
120+
EXPECT_FLOAT_EQ (25.0f, parameter->getValue());
121+
122+
EXPECT_TRUE (handle.advanceToSample (8));
123+
EXPECT_FLOAT_EQ (75.0f, parameter->getValue());
124+
EXPECT_FLOAT_EQ (75.0f, handle.getCurrentValue());
125+
126+
EXPECT_FALSE (handle.advanceToSample (8));
127+
}
128+
129+
TEST (AudioParameterHandleTests, PrepareBlockRestartsAutomationIteration)
130+
{
131+
auto parameter = AudioParameterBuilder()
132+
.withID ("mix")
133+
.withName ("Mix")
134+
.withRange (0.0f, 1.0f)
135+
.withDefault (0.0f)
136+
.build();
137+
138+
parameter->setIndexInContainer (0);
139+
140+
AudioParameterHandle handle (*parameter, 48000.0);
141+
142+
ParameterChangeBuffer changes;
143+
changes.reserve (1);
144+
EXPECT_TRUE (changes.addChange (0, 1.0f, 2));
145+
146+
handle.prepareBlock (changes, parameter->getIndexInContainer());
147+
EXPECT_TRUE (handle.advanceToSample (2));
148+
EXPECT_FLOAT_EQ (1.0f, parameter->getValue());
149+
150+
parameter->setValue (0.0f);
151+
152+
handle.prepareBlock (changes, parameter->getIndexInContainer());
153+
EXPECT_TRUE (handle.advanceToSample (2));
154+
EXPECT_FLOAT_EQ (1.0f, parameter->getValue());
155+
}

tests/yup_gui/yup_ApplicationTheme.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,28 @@ TEST_F (ApplicationThemeTest, SetColorOverwritesExistingColor)
107107
EXPECT_EQ (result.value(), second);
108108
}
109109

110+
TEST_F (ApplicationThemeTest, ComponentColorOverridesRegisteredColor)
111+
{
112+
auto c = Component ("testComponent");
113+
114+
const Identifier id ("accentColor");
115+
const Color themeColor = Color::fromRGBA (1, 2, 3, 255);
116+
const Color componentColor = Color::fromRGBA (4, 5, 6, 255);
117+
118+
theme->setColor (id, themeColor);
119+
c.setColor (id, componentColor);
120+
121+
auto result = ApplicationTheme::findComponentColor (c, id);
122+
ASSERT_TRUE (result.has_value());
123+
EXPECT_EQ (result.value(), componentColor);
124+
125+
c.setColor (id, std::nullopt);
126+
127+
result = ApplicationTheme::findComponentColor (c, id);
128+
ASSERT_TRUE (result.has_value());
129+
EXPECT_EQ (result.value(), themeColor);
130+
}
131+
110132
TEST_F (ApplicationThemeTest, FindColorUnregisteredIdDoesNotAffectOtherIds)
111133
{
112134
auto c = Component ("testComponent");
@@ -156,6 +178,44 @@ TEST_F (ApplicationThemeTest, SetMetricOverwritesExistingValue)
156178
EXPECT_FLOAT_EQ (result.value(), 3.5f);
157179
}
158180

181+
TEST_F (ApplicationThemeTest, SetMetricsRegistersMultipleValues)
182+
{
183+
auto c = Component ("testComponent");
184+
185+
const Identifier idA ("smallSpacing");
186+
const Identifier idB ("largeSpacing");
187+
188+
theme->setMetrics ({ { idA, 4.0f }, { idB, 12.0f } });
189+
190+
auto resultA = ApplicationTheme::findComponentMetric (c, idA);
191+
auto resultB = ApplicationTheme::findComponentMetric (c, idB);
192+
193+
ASSERT_TRUE (resultA.has_value());
194+
EXPECT_FLOAT_EQ (resultA.value(), 4.0f);
195+
ASSERT_TRUE (resultB.has_value());
196+
EXPECT_FLOAT_EQ (resultB.value(), 12.0f);
197+
}
198+
199+
TEST_F (ApplicationThemeTest, ComponentMetricOverridesRegisteredMetric)
200+
{
201+
auto c = Component ("testComponent");
202+
203+
const Identifier id ("cornerRadius");
204+
205+
theme->setMetric (id, 8.0f);
206+
c.setMetric (id, 12.0f);
207+
208+
auto result = ApplicationTheme::findComponentMetric (c, id);
209+
ASSERT_TRUE (result.has_value());
210+
EXPECT_FLOAT_EQ (result.value(), 12.0f);
211+
212+
c.setMetric (id, std::nullopt);
213+
214+
result = ApplicationTheme::findComponentMetric (c, id);
215+
ASSERT_TRUE (result.has_value());
216+
EXPECT_FLOAT_EQ (result.value(), 8.0f);
217+
}
218+
159219
TEST_F (ApplicationThemeTest, FindMetricUnregisteredIdDoesNotAffectOtherIds)
160220
{
161221
auto c = Component ("testComponent");

0 commit comments

Comments
 (0)