-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestMIDIParser.cs
57 lines (49 loc) · 1.74 KB
/
TestMIDIParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using MIDI_To_Sheet_Music_Converter.MIDI_Format;
using MIDI_To_Sheet_Music_Converter.Util;
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
namespace MIDI_To_Sheet_Music_Converter
{
public class Tests
{
ushort ToUShortHigh(uint source) => (ushort)(source >> 16);
ushort ToUShortLow(uint source) => (ushort)(source & 0xffff);
byte[] ToMidiHeaderBytes(uint chunkId, uint chunkSize, ushort formatType, ushort trackCount, ushort timeDivision)
{
return new List<ushort> {
ToUShortHigh(chunkId),
ToUShortLow(chunkId),
ToUShortHigh(chunkSize),
ToUShortLow(chunkSize),
formatType,
trackCount,
timeDivision
}.SelectMany(Bits.ParseBig.GetBytes).ToArray();
}
[SetUp] public void Setup() { }
[Test]
public void ValidMIDIHeaderParsed()
{
uint chunkId = 0x4D_54_68_64;
uint chunkSize = 0x00_00_00_06;
ushort formatType = 0x00_00;
ushort trackCount = 0x00_01;
ushort timeDivision = 0x00_80;
byte[] headerBytes = ToMidiHeaderBytes(chunkId, chunkSize, formatType, trackCount, timeDivision);
(ReportMessage report, HeaderChunk parsed) = HeaderChunk.FromBytes(headerBytes);
Assert.IsFalse(report.IsError, "Header chunk parsing error: '{0}'", report.Message);
Assert.AreEqual(new HeaderChunk(0, 1, 128), parsed);
}
[Test]
public void MIDILoadedFromFile()
{
Assert.Pass();
}
[Test]
public void MIDILoadedFromEmptyFile()
{
Assert.Pass();
}
}
}