1+ //
2+ // Created by andrew on 3/05/24.
3+ //
4+
5+ #include " include/bytestreamToUMP.h"
6+ #include < cstdio>
7+
8+ #include " umpToMIDI2Protocol.h"
9+
10+ bytestreamToUMP BS2UMP;
11+
12+
13+ int testPassed = 0 ;
14+ int testFailed = 0 ;
15+
16+ void passFail (uint32_t v1, uint32_t v2)
17+ {
18+ if (v1 == v2)
19+ {
20+ printf (" ." );
21+ testPassed++;
22+ }else
23+ {
24+ printf (" fail %#08x != %#08x " , v1, v2);
25+ testFailed++;
26+ }
27+ }
28+
29+ void testRun_bsToUmp (const char * heading, uint8_t *bytes, int btyelength, uint32_t * testCheck, int outlength)
30+ {
31+ va_list args;
32+ vprintf (heading, args);
33+
34+ int testCounter = 0 ;
35+
36+ for (int i=0 ; i<btyelength; i++){
37+ if (bytes[i] == 0xFF ){
38+ BS2UMP.dumpSysex7State (false );
39+ }else {
40+ BS2UMP.bytestreamParse (bytes[i]);
41+ }
42+ while (BS2UMP.availableUMP ()){
43+ uint32_t ump = BS2UMP.readUMP ();
44+ // ump contains a ump 32 bit value. UMP messages that have 64bit will produce 2 UMP words
45+ passFail (ump, testCheck[testCounter++]);
46+
47+ }
48+ }
49+ printf (" length :" );passFail (outlength, testCounter);
50+ printf (" \n " );
51+ }
52+
53+
54+
55+
56+
57+ void testRun_umpToump (const char * heading, uint32_t * in, int inlength, uint32_t * out)
58+ {
59+ va_list args;
60+ vprintf (heading, args);
61+ for (int i=0 ; i<inlength; i++){
62+ passFail (in[i], out[i]);
63+ }
64+ printf (" \n " );
65+ }
66+
67+ int main (){
68+ printf (" Starting Tests...\n " );
69+
70+ // ******** ByteSteam to UMP ***************
71+ printf (" ByteSteam to UMP \n " );
72+ uint8_t bytes1[] = {0xf0 , 0x11 ,0x22 ,0x33 , 0xf0 , 0x44 , 0x55 , 0xf7 };
73+ uint32_t tests1[] = {0x30131122 , 0x33000000 , 0x30024455 , 0x00000000 };
74+
75+ testRun_bsToUmp (" Bad Sysex 1: " , bytes1, 8 , tests1,4 );
76+
77+ printf (" ByteSteam to UMP \n " );
78+ uint8_t bytes2[] = {0xf0 , 0x10 ,0x11 ,0x12 , 0x13 , 0x14 , 0x15 , 0x16 , 0x17 , 0xFF /* this forces a dump*/ , 0x18 , 0x19 , 0x1A , 0xf7 };
79+ uint32_t tests2[] = {0x30161011 , 0x12131415 , 0x30221617 , 0x00000000 ,0x30331819 , 0x1A000000 };
80+
81+ testRun_bsToUmp (" Sysex w/Dump: " , bytes2, 14 , tests2,6 );
82+
83+ uint8_t bytes4[] = {0xF0 , 0x7E , 0x7F , 0x0D , 0x70 , 0x02 , 0x4B , 0x60 , 0x7A , 0x73 , 0x7F , 0x7F , 0x7F , 0x7F , 0x7D ,
84+ 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x03 , 0x00 , 0x00 , 0x00 , 0x10 , 0x00 , 0x00 , 0x00 , 0xF7 };
85+ uint32_t tests4[] = {
86+ 0x30167e7f , 0x0d70024b ,
87+ 0x3026607a , 0x737f7f7f ,
88+ 0x30267f7d , 0x00000000 ,
89+ 0x30260100 ,0x00000300 ,
90+ 0x30360000 ,0x10000000
91+ };
92+ testRun_bsToUmp (" Test 4 Sysex : " , bytes4, 32 , tests4,10 );
93+
94+
95+
96+ uint8_t bytesSyesex[] = {
97+ 0xf0 , 0x0a , 0x0b , 0x0c , 0x0d , 0x0e , 0x0f , 0x1a , 0x1b , 0x1c , 0x1d , 0x1e ,0x1d , 0x1f , 0xf7 ,
98+ 0xf0 , 0x2a , 0x2b , 0x2c , 0x2d , 0x2f , 0x3a , 0x3b ,
99+ 0xf8 ,
100+ 0x3c , 0x3d , 0x3e , 0x3f , 0xf7 ,
101+ 0xf0 , 0x4a , 0x4b , 0x4c , 0x4d , 0x4f , 0xf7 ,
102+
103+ 0xf0 , 0x5a , 0x5b ,
104+ 0xf8 ,
105+ 0x5c , 0x5d , 0xf7 ,
106+ 0xf0 , 0x6a , 0x6b , 0x6c , 0xf7 ,
107+ 0xf0 , 0x7a , 0x7b , 0xf7 ,
108+ 0xf8 ,
109+ 0xf0 , 0x0a , 0x0b , 0x0c , 0x0d , 0x0e , 0x0f ,
110+ 0xf8 ,
111+ 0x1a , 0x1b , 0x1c , 0x1d ,
112+ 0xf8 ,
113+ 0x1e ,0x1d , 0x1f , 0xf7
114+
115+ };
116+
117+ uint32_t testsSysex2[] = {
118+ 0x30160a0b , 0x0c0d0e0f ,
119+ 0x30261a1b , 0x1c1d1e1d ,
120+ 0x30311f00 , 0x000000 ,
121+ 0x30162a2b , 0x2c2d2f3a ,
122+ 0x10f80000 ,
123+ 0x30353b3c , 0x3d3e3f00 ,
124+ 0x30054a4b , 0x4c4d4f00 ,
125+ 0x10f80000 ,
126+ 0x30045a5b , 0x5c5d0000 ,
127+ 0x30036a6b , 0x6c000000 ,
128+ 0x30027a7b , 0x00000000 ,
129+ 0x10f80000 ,
130+ 0x10f80000 , // This is slightly out of order because otherwise of the way the parser handles end of sysex
131+ 0x30160a0b , 0x0c0d0e0f ,
132+ 0x10f80000 ,
133+ 0x30261a1b , 0x1c1d1e1d ,
134+ 0x30311f00 , 0x000000
135+ };
136+
137+ testRun_bsToUmp (" Test 11 sysex 2 w/Timing Clock : " , bytesSyesex, 70 , testsSysex2,29 );
138+
139+
140+
141+ // /****************************
142+ printf (" Tests Passed: %d Failed : %d\n " ,testPassed, testFailed);
143+
144+ }
0 commit comments