Skip to content

Commit ebb4df1

Browse files
committed
More missing tests
1 parent 375aa0a commit ebb4df1

File tree

4 files changed

+239
-0
lines changed

4 files changed

+239
-0
lines changed

tests/yup_audio_basics/yup_UMPJitterReductionTimestamps.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,19 @@ TEST (JitterReductionTimestampTests, JitterTimestampMessage)
9595
EXPECT_EQ (tsMsg.getByte3(), 0x7bu);
9696
EXPECT_EQ (tsMsg.getByte4(), 0x7cu);
9797
}
98+
99+
TEST (JitterReductionTimestampTests, JitterClockFollowerScheduling)
100+
{
101+
JitterClockFollower follower;
102+
follower.reset();
103+
104+
const auto now = JitterClockFollower::SystemClock::now();
105+
const auto offset = std::chrono::milliseconds (5);
106+
follower.setSecurityOffset (offset);
107+
108+
follower.processClock (now, JitterTimestamp { 0 });
109+
const auto scheduled = follower.scheduleMessage (now, JitterTimestamp { 0 });
110+
111+
EXPECT_GE (scheduled, now + offset);
112+
EXPECT_EQ (follower.getSecurityOffset(), offset);
113+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
==============================================================================
3+
4+
This file is part of the YUP library.
5+
Copyright (c) 2025 - [email protected]
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 <yup_audio_basics/yup_audio_basics.h>
23+
24+
#include <gtest/gtest.h>
25+
26+
using namespace yup;
27+
using namespace yup::ump;
28+
29+
TEST (UMPKeyboardStateTests, ProcessesMidi1NoteOnOff)
30+
{
31+
UMPKeyboardState state (ump::PacketProtocol::MIDI_1_0);
32+
state.setGroup (0);
33+
34+
const auto noteOn = makeMidi1NoteOnMessage (0, 0, 60, Velocity { uint7_t { 100 } });
35+
state.processNextUMPPacket (View (noteOn.data));
36+
EXPECT_TRUE (state.isNoteOn (1, 60));
37+
38+
const auto noteOff = makeMidi1NoteOffMessage (0, 0, 60, Velocity { uint7_t { 64 } });
39+
state.processNextUMPPacket (View (noteOff.data));
40+
EXPECT_FALSE (state.isNoteOn (1, 60));
41+
}
42+
43+
TEST (UMPKeyboardStateTests, ProcessesMidi2NoteOnOff)
44+
{
45+
UMPKeyboardState state (ump::PacketProtocol::MIDI_2_0);
46+
state.setGroup (0);
47+
48+
const auto noteOn = makeMidi2NoteOnMessage (0, 1, 64, Velocity { uint16_t { 0x9000 } });
49+
state.processNextUMPPacket (View (noteOn.data));
50+
EXPECT_TRUE (state.isNoteOn (2, 64));
51+
52+
const auto noteOff = makeMidi2NoteOffMessage (0, 1, 64, Velocity { uint16_t { 0x4000 } });
53+
state.processNextUMPPacket (View (noteOff.data));
54+
EXPECT_FALSE (state.isNoteOn (2, 64));
55+
}
56+
57+
TEST (UMPKeyboardStateTests, FiltersByGroup)
58+
{
59+
UMPKeyboardState state;
60+
state.setGroup (1);
61+
62+
const auto noteOn = makeMidi1NoteOnMessage (0, 0, 60, Velocity { uint7_t { 100 } });
63+
state.processNextUMPPacket (View (noteOn.data));
64+
EXPECT_FALSE (state.isNoteOn (1, 60));
65+
}
66+
67+
TEST (UMPKeyboardStateTests, AllNotesOffController)
68+
{
69+
UMPKeyboardState state (ump::PacketProtocol::MIDI_1_0);
70+
state.setGroup (0);
71+
72+
const auto noteOn = makeMidi1NoteOnMessage (0, 0, 60, Velocity { uint7_t { 100 } });
73+
state.processNextUMPPacket (View (noteOn.data));
74+
EXPECT_TRUE (state.isNoteOn (1, 60));
75+
76+
const auto allNotesOff = makeMidi1ControlChangeMessage (0, 0, 123, ControllerValue { uint7_t { 0 } });
77+
state.processNextUMPPacket (View (allNotesOff.data));
78+
EXPECT_FALSE (state.isNoteOn (1, 60));
79+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
==============================================================================
3+
4+
This file is part of the YUP library.
5+
Copyright (c) 2025 - [email protected]
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 <yup_audio_basics/yup_audio_basics.h>
23+
24+
#include <gtest/gtest.h>
25+
26+
using namespace yup;
27+
using namespace yup::ump;
28+
29+
TEST (UMPPacketBufferTests, AddEventOrdersBySamplePosition)
30+
{
31+
UMPPacketBuffer buffer;
32+
33+
const UniversalPacket p1 { 0x40000000u, 0x12345678u };
34+
const UniversalPacket p2 { 0x20000000u };
35+
36+
EXPECT_TRUE (buffer.addEvent (p1.data, p1.getSize(), 10));
37+
EXPECT_TRUE (buffer.addEvent (p2.data, p2.getSize(), 5));
38+
39+
EXPECT_EQ (buffer.getNumEvents(), 2);
40+
EXPECT_EQ (buffer.getFirstEventTime(), 5);
41+
EXPECT_EQ (buffer.getLastEventTime(), 10);
42+
43+
auto it = buffer.begin();
44+
const auto first = *it;
45+
EXPECT_EQ (first.samplePosition, 5);
46+
EXPECT_EQ (first.numWords, 1);
47+
EXPECT_EQ (first.getView()[0], p2.data[0]);
48+
49+
++it;
50+
const auto second = *it;
51+
EXPECT_EQ (second.samplePosition, 10);
52+
EXPECT_EQ (second.numWords, 2);
53+
EXPECT_EQ (second.getView()[0], p1.data[0]);
54+
EXPECT_EQ (second.getView()[1], p1.data[1]);
55+
}
56+
57+
TEST (UMPPacketBufferTests, ConstructorAddsSinglePacket)
58+
{
59+
const UniversalPacket packet { 0x40000000u, 0xabcdef01u };
60+
UMPPacketBuffer buffer { View (packet.data) };
61+
62+
EXPECT_EQ (buffer.getNumEvents(), 1);
63+
EXPECT_EQ (buffer.getFirstEventTime(), 0);
64+
65+
const auto meta = *buffer.begin();
66+
EXPECT_EQ (meta.samplePosition, 0);
67+
EXPECT_EQ (meta.numWords, 2);
68+
EXPECT_EQ (meta.getView()[0], packet.data[0]);
69+
EXPECT_EQ (meta.getView()[1], packet.data[1]);
70+
}
71+
72+
TEST (UMPPacketBufferTests, FindNextSamplePosition)
73+
{
74+
UMPPacketBuffer buffer;
75+
76+
const UniversalPacket p1 { 0x20000000u };
77+
const UniversalPacket p2 { 0x40000000u, 0x11111111u };
78+
const UniversalPacket p3 { 0x40000000u, 0x22222222u };
79+
80+
buffer.addEvent (p1.data, p1.getSize(), 2);
81+
buffer.addEvent (p2.data, p2.getSize(), 8);
82+
buffer.addEvent (p3.data, p3.getSize(), 12);
83+
84+
auto it = buffer.findNextSamplePosition (9);
85+
ASSERT_NE (it, buffer.end());
86+
EXPECT_EQ ((*it).samplePosition, 12);
87+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
==============================================================================
3+
4+
This file is part of the YUP library.
5+
Copyright (c) 2025 - [email protected]
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_devices/yup_audio_devices.h>
25+
26+
using namespace yup;
27+
using namespace yup::ump;
28+
29+
TEST (UMPPacketCollectorTests, CollectsPacketsIntoBlocks)
30+
{
31+
UMPPacketCollector collector (PacketProtocol::MIDI_1_0, 0);
32+
collector.reset (1000.0);
33+
34+
const auto packet = makeMidi1NoteOnMessage (0, 0, 60, Velocity { uint7_t { 100 } });
35+
const auto timeStamp = Time::getMillisecondCounterHiRes() * 0.001 + 0.005;
36+
collector.addPacketToQueue (View (packet.data), timeStamp);
37+
38+
UMPPacketBuffer buffer;
39+
collector.removeNextBlockOfPackets (buffer, 64);
40+
41+
EXPECT_FALSE (buffer.isEmpty());
42+
EXPECT_EQ (buffer.getNumEvents(), 1);
43+
}
44+
45+
TEST (UMPPacketCollectorTests, HandlesKeyboardStateCallbacks)
46+
{
47+
UMPPacketCollector collector (PacketProtocol::MIDI_2_0, 1);
48+
collector.reset (1000.0);
49+
50+
collector.handleNoteOn (nullptr, 1, 64, 0.5f);
51+
52+
UMPPacketBuffer buffer;
53+
collector.removeNextBlockOfPackets (buffer, 64);
54+
55+
EXPECT_FALSE (buffer.isEmpty());
56+
EXPECT_EQ (buffer.getNumEvents(), 1);
57+
}

0 commit comments

Comments
 (0)