Skip to content

Commit 1ad21de

Browse files
committed
Updated unit tests (#211)
1 parent 077a0b4 commit 1ad21de

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// Channel Voice Tests.swift
3+
// MIDIKit • https://github.com/orchetect/MIDIKit
4+
// © 2021-2023 Steffan Andrews • Licensed under MIT License
5+
//
6+
7+
#if shouldTestCurrentPlatform
8+
9+
@testable import MIDIKitCore
10+
import XCTest
11+
12+
final class MIDIEvent_ChannelVoiceTests_Tests: XCTestCase {
13+
// MARK: - Channel Voice Event encoding
14+
15+
func testProgramChange_RawBytes_MIDI1_0() {
16+
XCTAssertEqual(
17+
MIDIEvent.programChange(program: 0x64, bank: .noBankSelect, channel: 10, group: 0).midi1RawBytes(),
18+
[0xCA, 0x64]
19+
)
20+
21+
XCTAssertEqual(
22+
MIDIEvent.programChange(program: 0x64, bank: .bankSelect(msb: 0x10, lsb: 0x00), channel: 10, group: 0).midi1RawBytes(),
23+
[
24+
0xBA, 0x00, 0x10, // Bank Select MSB
25+
0xBA, 0x20, 0x00, // Bank Select LSB
26+
0xCA, 0x64 // Program Change
27+
]
28+
)
29+
30+
XCTAssertEqual(
31+
MIDIEvent.programChange(program: 0x64, bank: .bankSelect(msb: 0x10, lsb: 0x01), channel: 10, group: 0).midi1RawBytes(),
32+
[
33+
0xBA, 0x00, 0x10, // Bank Select MSB
34+
0xBA, 0x20, 0x01, // Bank Select LSB
35+
0xCA, 0x64 // Program Change
36+
]
37+
)
38+
}
39+
40+
// TODO: Add unit tests for other Channel Voice events
41+
}
42+
43+
#endif

Tests/MIDIKitIOTests/Parser/MIDI1Parser Tests.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,21 @@ final class MIDI1Parser_Tests: XCTestCase {
5757

5858
// program change
5959
XCTAssertEqual(
60-
parsedEvents(bytes: [0xCA, 0x20]),
61-
[.programChange(program: 32, channel: 10, group: 0)]
60+
parsedEvents(bytes: [0xCA, 0x40]),
61+
[.programChange(program: 64, channel: 10, group: 0)]
62+
)
63+
// MIDI1Parser does not wait for trailing program change event in order to bundle them in a `.programChange` event.
64+
// It is more idiomatic to MIDI 2.0 than MIDI 1.0.
65+
// TODO: It could be implemented as an optional parser feature in future, similar to MIDI2Parser's RPN/NRPN bundling ability.
66+
XCTAssertEqual(
67+
parsedEvents(bytes: [0xBA, 0x00, 0x10,
68+
0xBA, 0x20, 0x01,
69+
0xCA, 0x40]),
70+
[
71+
.cc(0, value: .midi1(0x10), channel: 10, group: 0x0),
72+
.cc(32, value: .midi1(0x01), channel: 10, group: 0x0),
73+
.programChange(program: 64, /* bank: .bankSelect(msb: 0x10, lsb: 0x01), */ channel: 10, group: 0)
74+
]
6275
)
6376

6477
// channel aftertouch

0 commit comments

Comments
 (0)