Commit 19fe7893 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Midi note on tests

parent e4ea397b
#include <stdio.h>
#include <assert.h>
#include "midi.h"
#include "midi-test.h"
void status_init(void);
void
test_init(void)
{
desc("test status_init()");
status_init();
assert_status(MIDI_NUM_STATUSES, 0, 0);
}
int
main(int argc, char** argv)
void
test_note_on(void)
{
desc("test note on handling");
status_init();
printf("hello world\n");
assert_status(MIDI_NUM_STATUSES, 0, 0);
// fresh note on
midi_parse(0x90);
midi_parse(0x60);
assert_status(MIDI_NOTE_ON, 0, 0);
midi_parse(0x64);
assert_status(MIDI_NOTE_ON, 1, 0x6064);
// running status
midi_parse(0x10);
assert_status(MIDI_NOTE_ON, 0, 0);
midi_parse(0x70);
assert_status(MIDI_NOTE_ON, 1, 0x1070);
// real time garbage
midi_parse(0xf8);
assert_status(MIDI_NOTE_ON, 1, 0x1070);
midi_parse(0x11);
midi_parse(0xf8);
midi_parse(0x25);
assert_status(MIDI_NOTE_ON, 1, 0x1125);
// velocity 0
midi_parse(0x17);
midi_parse(0);
assert_status(MIDI_NOTE_ON, 1, 0x1700);
// new status byte
midi_parse(0x90);
midi_parse(0x60);
midi_parse(0x64);
assert_status(MIDI_NOTE_ON, 1, 0x6064);
// end running status
midi_parse(0xa0); // poly pressure
assert_status(MIDI_NUM_STATUSES, 0, 0);
}
void uart_init(void) { }
int
main(int argc, char** argv)
{
test_init();
test_note_on();
}
uint16_t uart_read(void) { return 0; }
#ifndef midi_test_h
#define midi_test_h
// Access to midi.c internals
void status_init(void);
void midi_parse(uint8_t);
uint8_t midi_available(void);
#define desc(s) printf("TEST: %s\n", s)
#define assert_status(status, avail, data) assert(midi_status() == status); \
assert(!midi_available() == !avail); \
if (avail) assert(midi_data() == data)
// Fake uart functions to let midi.c compile
void uart_init(void) { }
uint16_t uart_read(void) { return 0; }
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment