From 79149b818fab1c09d36c8b6a9e62fc396ea03892 Mon Sep 17 00:00:00 2001 From: Robert Hargreaves Date: Sun, 8 Sep 2024 21:49:20 +0100 Subject: [PATCH] Fixes issue of tests not rebuilding correctly after modification --- tests/Makefile | 22 +++--- tests/system/main.c | 2 +- tests/system/test_e2e.c | 45 ++++++------ tests/system/test_e2e.h | 23 ++++++ tests/unit/main.c | 38 +++++----- tests/unit/test_applemidi.c | 44 ++++++------ tests/unit/test_applemidi.h | 22 ++++++ tests/unit/test_buffer.c | 18 ++--- tests/unit/test_buffer.h | 10 +++ tests/unit/test_comm.c | 20 +++--- tests/unit/test_comm.h | 11 +++ tests/unit/test_comm_demo.c | 18 ++--- tests/unit/test_comm_demo.h | 10 +++ tests/unit/test_comm_megawifi.c | 10 +-- tests/unit/test_comm_megawifi.h | 6 ++ tests/unit/test_log.c | 15 ++-- tests/unit/test_log.h | 8 +++ tests/unit/test_midi_dac.c | 13 ++-- tests/unit/test_midi_dac.h | 8 +++ tests/unit/test_midi_dynamic.c | 58 +++++++-------- tests/unit/test_midi_dynamic.h | 31 ++++++++ tests/unit/test_midi_finetune.c | 7 +- tests/unit/test_midi_finetune.h | 5 ++ tests/unit/test_midi_fm.c | 99 ++++++++++++------------- tests/unit/test_midi_fm.h | 51 +++++++++++++ tests/unit/test_midi_polyphony.c | 17 ++--- tests/unit/test_midi_polyphony.h | 10 +++ tests/unit/test_midi_portamento.c | 37 +++++----- tests/unit/test_midi_portamento.h | 20 ++++++ tests/unit/test_midi_psg.c | 52 +++++++------- tests/unit/test_midi_psg.h | 29 ++++++++ tests/unit/test_midi_receiver.c | 38 +++++----- tests/unit/test_midi_receiver.h | 20 ++++++ tests/unit/test_midi_sysex.c | 35 ++++----- tests/unit/test_midi_sysex.h | 19 +++++ tests/unit/test_note_priority.c | 10 +-- tests/unit/test_note_priority.h | 6 ++ tests/unit/test_pitchcents.c | 23 +++--- tests/unit/test_pitchcents.h | 13 ++++ tests/unit/test_scheduler.c | 19 ++--- tests/unit/test_scheduler.h | 11 +++ tests/unit/test_synth.c | 115 ++++++++++++++---------------- tests/unit/test_synth.h | 54 ++++++++++++++ 43 files changed, 742 insertions(+), 380 deletions(-) create mode 100644 tests/system/test_e2e.h create mode 100644 tests/unit/test_applemidi.h create mode 100644 tests/unit/test_buffer.h create mode 100644 tests/unit/test_comm.h create mode 100644 tests/unit/test_comm_demo.h create mode 100644 tests/unit/test_comm_megawifi.h create mode 100644 tests/unit/test_log.h create mode 100644 tests/unit/test_midi_dac.h create mode 100644 tests/unit/test_midi_dynamic.h create mode 100644 tests/unit/test_midi_finetune.h create mode 100644 tests/unit/test_midi_fm.h create mode 100644 tests/unit/test_midi_polyphony.h create mode 100644 tests/unit/test_midi_portamento.h create mode 100644 tests/unit/test_midi_psg.h create mode 100644 tests/unit/test_midi_receiver.h create mode 100644 tests/unit/test_midi_sysex.h create mode 100644 tests/unit/test_note_priority.h create mode 100644 tests/unit/test_pitchcents.h create mode 100644 tests/unit/test_scheduler.h create mode 100644 tests/unit/test_synth.h diff --git a/tests/Makefile b/tests/Makefile index d87896a..1f46df7 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -205,14 +205,13 @@ LDFLAGS+=$(foreach MOCK,$(MD_MOCKS),-Wl,--wrap=$(MOCK)) SYSTEM_TEST_LDFLAGS=$(LDFLAGS) UNIT_TEST_LDFLAGS=$(LDFLAGS) $(foreach MOCK,$(MOCKS),-Wl,--wrap=$(MOCK)) -SRC=$(wildcard ../src/*.c) -SRC+=$(wildcard ../src/*/*.c) +SRC=$(wildcard ../src/*.c ../src/*/*.c) SRC:=$(filter-out ../src/boot/rom_head.c,$(SRC)) SRC:=$(filter-out ../src/main.c,$(SRC)) COMMON_TEST_SRC=$(wildcard *.c) -UNIT_TEST_SRC+=$(wildcard unit/*.c) -SYSTEM_TEST_SRC+=$(wildcard system/*.c) +UNIT_TEST_SRC=$(wildcard unit/*.c) +SYSTEM_TEST_SRC=$(wildcard system/*.c) SRC_OBJ=$(patsubst ../src/%.c,obj/%.o,$(SRC)) COMMON_TEST_OBJ=$(patsubst %.c,obj/%.o,$(COMMON_TEST_SRC)) @@ -228,6 +227,7 @@ UNIT_TESTS_TARGET=$(BIN_DIR)/unit_tests SYSTEM_TESTS_TARGET=$(BIN_DIR)/system_tests all: unit system +.PHONY: all unit: $(UNIT_TESTS_TARGET) $(GDB) ./$(UNIT_TESTS_TARGET) @@ -237,22 +237,24 @@ system: $(SYSTEM_TESTS_TARGET) $(GDB) ./$(SYSTEM_TESTS_TARGET) .PHONY: system -$(SRC_OBJ): | $(OBJ_DIR) $(CMOCKA_DIR) - $(OBJ_DIR): mkdir -p $(dir $@) $(OBJ_DIR)/%.o: %.c mkdir -p $(dir $@) - $(CC) $(CFLAGS) -c $< -o $@ + $(CC) $(CFLAGS) -MMD -c $< -o $@ + +$(OBJ_DIR)/%.o: %.c + mkdir -p $(dir $@) + $(CC) $(CFLAGS) -MMD -c $< -o $@ $(UNIT_TESTS_TARGET): $(SRC_OBJ) $(UNIT_TEST_OBJ) $(COMMON_TEST_OBJ) mkdir -p $(dir $@) - $(CC) -o $@ $^ $(UNIT_TEST_LDFLAGS) + $(CC) -MMD -o $@ $^ $(UNIT_TEST_LDFLAGS) $(SYSTEM_TESTS_TARGET): $(SRC_OBJ) $(SYSTEM_TEST_OBJ) $(COMMON_TEST_OBJ) mkdir -p $(dir $@) - $(CC) -o $@ $^ $(SYSTEM_TEST_LDFLAGS) + $(CC) -MMD -o $@ $^ $(SYSTEM_TEST_LDFLAGS) $(CMOCKA_DIR): mkdir -p $@ @@ -262,6 +264,8 @@ $(CMOCKA_DIR): clean-target: rm -rf $(UNIT_TESTS_TARGET) $(SYSTEM_TESTS_TARGET) $(OBJ_DIR) +.PHONY: clean-target clean: clean-target rm -rf $(CMOCKA_DIR) +.PHONY: clean diff --git a/tests/system/main.c b/tests/system/main.c index 5dad151..5a41404 100644 --- a/tests/system/main.c +++ b/tests/system/main.c @@ -1,5 +1,5 @@ #include "cmocka_inc.h" -#include "test_e2e.c" +#include "test_e2e.h" #define e2e_test(test) cmocka_unit_test_setup(test, test_e2e_setup) diff --git a/tests/system/test_e2e.c b/tests/system/test_e2e.c index 1fe61d9..4b64e79 100644 --- a/tests/system/test_e2e.c +++ b/tests/system/test_e2e.c @@ -1,4 +1,4 @@ -#include "cmocka_inc.h" +#include "test_e2e.h" #include "asserts.h" #include "comm/comm.h" #include "envelopes.h" @@ -30,7 +30,7 @@ static const u8 TEST_MIDI_CHANNEL_11 = 10; static const u8 TEST_VOLUME_MAX = 127; static const u8 TEST_VELOCITY_MAX = 127; -static int test_e2e_setup(void** state) +int test_e2e_setup(void** state) { wraps_disable_checks(); scheduler_init(); @@ -42,7 +42,7 @@ static int test_e2e_setup(void** state) return 0; } -static void test_midi_note_on_event_sent_to_ym2612(void** state) +void test_midi_note_on_event_sent_to_ym2612(void** state) { stub_everdrive_as_present(); stub_usb_receive_note_on(TEST_MIDI_CHANNEL_1, 48, 127); @@ -52,7 +52,7 @@ static void test_midi_note_on_event_sent_to_ym2612(void** state) midi_receiver_read(); } -static void test_polyphonic_midi_sent_to_separate_ym2612_channels(void** state) +void test_polyphonic_midi_sent_to_separate_ym2612_channels(void** state) { stub_everdrive_as_present(); stub_usb_receive_cc(TEST_MIDI_CHANNEL_1, TEST_CC_POLYPHONIC, TEST_POLYPHONIC_ON); @@ -72,7 +72,7 @@ static void test_polyphonic_midi_sent_to_separate_ym2612_channels(void** state) midi_receiver_read(); } -static void test_psg_audible_if_note_on_event_triggered(void** state) +void test_psg_audible_if_note_on_event_triggered(void** state) { stub_everdrive_as_present(); stub_usb_receive_note_on(TEST_MIDI_CHANNEL_PSG_1, 60, TEST_VELOCITY_MAX); @@ -83,15 +83,14 @@ static void test_psg_audible_if_note_on_event_triggered(void** state) midi_receiver_read(); } -static void test_psg_not_audible_if_midi_channel_volume_set_and_there_is_no_note_on_event( - void** state) +void test_psg_not_audible_if_midi_channel_volume_set_and_there_is_no_note_on_event(void** state) { stub_everdrive_as_present(); stub_usb_receive_cc(TEST_MIDI_CHANNEL_PSG_1, TEST_CC_VOLUME, TEST_VOLUME_MAX); midi_receiver_read(); } -static void test_general_midi_reset_sysex_stops_all_notes(void** state) +void test_general_midi_reset_sysex_stops_all_notes(void** state) { stub_everdrive_as_present(); @@ -137,7 +136,7 @@ static void remapChannel(u8 midiChannel, u8 deviceChannel) } } -static void test_remap_midi_channel_1_to_psg_channel_1() +void test_remap_midi_channel_1_to_psg_channel_1() { stub_everdrive_as_present(); @@ -159,7 +158,7 @@ static void test_remap_midi_channel_1_to_psg_channel_1() midi_receiver_read(); } -static void test_set_device_for_midi_channel_1_to_psg() +void test_set_device_for_midi_channel_1_to_psg() { stub_everdrive_as_present(); stub_usb_receive_cc(TEST_MIDI_CHANNEL_1, TEST_CC_POLYPHONIC, TEST_POLYPHONIC_ON); @@ -176,7 +175,7 @@ static void test_set_device_for_midi_channel_1_to_psg() midi_receiver_read(); } -static void test_pong_received_after_ping_sent() +void test_pong_received_after_ping_sent() { const u8 sysExPingSequence[] = { SYSEX_START, SYSEX_MANU_EXTENDED, SYSEX_MANU_REGION, SYSEX_MANU_ID, SYSEX_COMMAND_PING, SYSEX_END }; @@ -197,7 +196,7 @@ static void test_pong_received_after_ping_sent() midi_receiver_read(); } -static void test_loads_psg_envelope() +void test_loads_psg_envelope() { const u8 sysExPingSequence[] = { SYSEX_START, SYSEX_MANU_EXTENDED, SYSEX_MANU_REGION, SYSEX_MANU_ID, SYSEX_COMMAND_LOAD_PSG_ENVELOPE, 0x06, 0x06, SYSEX_END }; @@ -216,7 +215,7 @@ static void test_loads_psg_envelope() midi_receiver_read(); } -static void test_enables_ch3_special_mode(void** state) +void test_enables_ch3_special_mode(void** state) { stub_everdrive_as_present(); stub_usb_receive_cc(TEST_MIDI_CHANNEL_1, TEST_CC_SPECIAL_MODE, TEST_SPECIAL_MODE_ON); @@ -224,7 +223,7 @@ static void test_enables_ch3_special_mode(void** state) midi_receiver_read(); } -static void test_sets_separate_ch3_operator_frequencies(void** state) +void test_sets_separate_ch3_operator_frequencies(void** state) { stub_everdrive_as_present(); stub_usb_receive_cc(TEST_MIDI_CHANNEL_1, TEST_CC_SPECIAL_MODE, TEST_SPECIAL_MODE_ON); @@ -248,7 +247,7 @@ static void test_sets_separate_ch3_operator_frequencies(void** state) } } -static void test_pitch_bends_ch3_special_mode_operators(void** state) +void test_pitch_bends_ch3_special_mode_operators(void** state) { stub_everdrive_as_present(); stub_usb_receive_cc(TEST_MIDI_CHANNEL_1, TEST_CC_SPECIAL_MODE, TEST_SPECIAL_MODE_ON); @@ -271,7 +270,7 @@ static void test_pitch_bends_ch3_special_mode_operators(void** state) midi_receiver_read(); } -static void test_write_directly_to_ym2612_regs_via_sysex(void** state) +void test_write_directly_to_ym2612_regs_via_sysex(void** state) { stub_everdrive_as_present(); @@ -283,7 +282,7 @@ static void test_write_directly_to_ym2612_regs_via_sysex(void** state) midi_receiver_read(); } -static void test_plays_pcm_sample(void** state) +void test_plays_pcm_sample(void** state) { stub_everdrive_as_present(); stub_usb_receive_cc(TEST_MIDI_CHANNEL_1, TEST_CC_ENABLE_DAC, 127); @@ -299,7 +298,7 @@ static void test_plays_pcm_sample(void** state) midi_receiver_read(); } -static void test_midi_last_note_played_priority_respected_on_fm(void** state) +void test_midi_last_note_played_priority_respected_on_fm(void** state) { stub_everdrive_as_present(); stub_usb_receive_note_on(TEST_MIDI_CHANNEL_1, 48, 127); @@ -321,7 +320,7 @@ static void test_midi_last_note_played_priority_respected_on_fm(void** state) midi_receiver_read(); } -static void test_midi_last_note_played_remembers_velocity_on_fm(void** state) +void test_midi_last_note_played_remembers_velocity_on_fm(void** state) { stub_everdrive_as_present(); stub_usb_receive_note_on(TEST_MIDI_CHANNEL_1, 48, 100); @@ -347,7 +346,7 @@ static void test_midi_last_note_played_remembers_velocity_on_fm(void** state) midi_receiver_read(); } -static void test_midi_last_note_played_cleared_when_released_on_fm(void** state) +void test_midi_last_note_played_cleared_when_released_on_fm(void** state) { stub_everdrive_as_present(); stub_usb_receive_note_on(TEST_MIDI_CHANNEL_1, 48, 127); @@ -370,7 +369,7 @@ static void test_midi_last_note_played_cleared_when_released_on_fm(void** state) midi_receiver_read(); } -static void test_midi_changing_program_retains_pan(void** state) +void test_midi_changing_program_retains_pan(void** state) { stub_everdrive_as_present(); @@ -414,7 +413,7 @@ static void test_midi_changing_program_retains_pan(void** state) midi_receiver_read(); } -static void test_midi_changing_program_retains_volume(void** state) +void test_midi_changing_program_retains_volume(void** state) { stub_everdrive_as_present(); @@ -461,7 +460,7 @@ static void test_midi_changing_program_retains_volume(void** state) midi_receiver_read(); } -static void test_midi_portamento_glides_note(void** state) +void test_midi_portamento_glides_note(void** state) { stub_everdrive_as_present(); diff --git a/tests/system/test_e2e.h b/tests/system/test_e2e.h new file mode 100644 index 0000000..27e933a --- /dev/null +++ b/tests/system/test_e2e.h @@ -0,0 +1,23 @@ +#include "cmocka_inc.h" + +int test_e2e_setup(void** state); +void test_midi_note_on_event_sent_to_ym2612(void** state); +void test_polyphonic_midi_sent_to_separate_ym2612_channels(void** state); +void test_psg_audible_if_note_on_event_triggered(void** state); +void test_psg_not_audible_if_midi_channel_volume_set_and_there_is_no_note_on_event(void** state); +void test_general_midi_reset_sysex_stops_all_notes(void** state); +void test_remap_midi_channel_1_to_psg_channel_1(); +void test_set_device_for_midi_channel_1_to_psg(); +void test_pong_received_after_ping_sent(); +void test_loads_psg_envelope(); +void test_enables_ch3_special_mode(void** state); +void test_sets_separate_ch3_operator_frequencies(void** state); +void test_write_directly_to_ym2612_regs_via_sysex(void** state); +void test_plays_pcm_sample(void** state); +void test_midi_last_note_played_priority_respected_on_fm(void** state); +void test_midi_last_note_played_remembers_velocity_on_fm(void** state); +void test_midi_last_note_played_cleared_when_released_on_fm(void** state); +void test_midi_changing_program_retains_pan(void** state); +void test_midi_changing_program_retains_volume(void** state); +void test_midi_portamento_glides_note(void** state); +void test_pitch_bends_ch3_special_mode_operators(void** state); diff --git a/tests/unit/main.c b/tests/unit/main.c index e3114e2..3f1b8e3 100644 --- a/tests/unit/main.c +++ b/tests/unit/main.c @@ -1,24 +1,24 @@ #include "cmocka_inc.h" -#include "test_applemidi.c" -#include "test_comm.c" -#include "test_comm_megawifi.c" -#include "test_comm_demo.c" -#include "test_log.c" +#include "test_applemidi.h" +#include "test_buffer.h" +#include "test_comm.h" +#include "test_comm_megawifi.h" +#include "test_comm_demo.h" +#include "test_log.h" #include "test_midi.h" -#include "test_midi_dynamic.c" -#include "test_midi_fm.c" -#include "test_midi_polyphony.c" -#include "test_midi_psg.c" -#include "test_midi_receiver.c" -#include "test_midi_sysex.c" -#include "test_midi_dac.c" -#include "test_scheduler.c" -#include "test_synth.c" -#include "test_buffer.c" -#include "test_note_priority.c" -#include "test_midi_portamento.c" -#include "test_pitchcents.c" -#include "test_midi_finetune.c" +#include "test_midi_dac.h" +#include "test_midi_dynamic.h" +#include "test_midi_finetune.h" +#include "test_midi_fm.h" +#include "test_midi_polyphony.h" +#include "test_midi_portamento.h" +#include "test_midi_psg.h" +#include "test_midi_receiver.h" +#include "test_midi_sysex.h" +#include "test_scheduler.h" +#include "test_synth.h" +#include "test_note_priority.h" +#include "test_pitchcents.h" #define midi_test(test) cmocka_unit_test_setup(test, test_midi_setup) #define midi_pcm_test(test) cmocka_unit_test_setup(test, test_midi_setup) diff --git a/tests/unit/test_applemidi.c b/tests/unit/test_applemidi.c index e7fb021..571aedb 100644 --- a/tests/unit/test_applemidi.c +++ b/tests/unit/test_applemidi.c @@ -1,12 +1,11 @@ -#include "cmocka_inc.h" -#include "comm/applemidi.h" +#include "test_applemidi.h" -static int test_applemidi_setup(UNUSED void** state) +int test_applemidi_setup(UNUSED void** state) { return 0; } -static void test_applemidi_parses_rtpmidi_packet_with_single_midi_event(UNUSED void** state) +void test_applemidi_parses_rtpmidi_packet_with_single_midi_event(UNUSED void** state) { char rtp_packet[1024] = { /* V P X CC M PT */ 0x80, 0x61, /* sequence number */ 0x8c, 0x24, /* timestamp */ 0x00, 0x58, 0xbb, 0x40, /* SSRC */ 0xac, 0x67, 0xe1, 0x08, @@ -22,7 +21,7 @@ static void test_applemidi_parses_rtpmidi_packet_with_single_midi_event(UNUSED v assert_int_equal(err, MW_ERR_NONE); } -static void test_applemidi_parses_rtpmidi_packet_with_single_2_byte_midi_event(UNUSED void** state) +void test_applemidi_parses_rtpmidi_packet_with_single_2_byte_midi_event(UNUSED void** state) { const u8 statuses[] = { 0xC0, 0xD0, 0xF1, 0xF3 }; @@ -42,8 +41,7 @@ static void test_applemidi_parses_rtpmidi_packet_with_single_2_byte_midi_event(U } } -static void test_applemidi_parses_rtpmidi_packet_with_multiple_2_byte_midi_events( - UNUSED void** state) +void test_applemidi_parses_rtpmidi_packet_with_multiple_2_byte_midi_events(UNUSED void** state) { const u8 statuses[] = { 0xC0, 0xD0, 0xF1, 0xF3 }; @@ -65,8 +63,7 @@ static void test_applemidi_parses_rtpmidi_packet_with_multiple_2_byte_midi_event } } -static void test_applemidi_parses_rtpmidi_packet_with_single_midi_event_long_header( - UNUSED void** state) +void test_applemidi_parses_rtpmidi_packet_with_single_midi_event_long_header(UNUSED void** state) { char rtp_packet[1024] = { /* V P X CC M PT */ 0x80, 0x61, /* sequence number */ 0x8c, 0x24, @@ -83,7 +80,7 @@ static void test_applemidi_parses_rtpmidi_packet_with_single_midi_event_long_hea assert_int_equal(err, MW_ERR_NONE); } -static void test_applemidi_parses_rtpmidi_packet_with_two_midi_events(UNUSED void** state) +void test_applemidi_parses_rtpmidi_packet_with_two_midi_events(UNUSED void** state) { char rtp_packet[1024] = { /* V P X CC M PT */ 0x80, 0x61, /* sequence number */ 0x8c, 0x24, /* timestamp */ 0x00, 0x58, 0xbb, 0x40, /* SSRC */ 0xac, 0x67, 0xe1, 0x08, @@ -103,7 +100,7 @@ static void test_applemidi_parses_rtpmidi_packet_with_two_midi_events(UNUSED voi assert_int_equal(err, MW_ERR_NONE); } -static void test_applemidi_parses_rtpmidi_packet_with_multiple_midi_events(UNUSED void** state) +void test_applemidi_parses_rtpmidi_packet_with_multiple_midi_events(UNUSED void** state) { char rtp_packet[1024] = { /* V P X CC M PT */ 0x80, 0x61, /* sequence number */ 0x8c, 0x24, /* timestamp */ 0x00, 0x58, 0xbb, 0x40, /* SSRC */ 0xac, 0x67, 0xe1, 0x08, @@ -127,7 +124,7 @@ static void test_applemidi_parses_rtpmidi_packet_with_multiple_midi_events(UNUSE assert_int_equal(err, MW_ERR_NONE); } -static void test_applemidi_parses_rtpmidi_packet_with_sysex(UNUSED void** state) +void test_applemidi_parses_rtpmidi_packet_with_sysex(UNUSED void** state) { char rtpPacket[1024] = { /* V P X CC M PT */ 0x80, 0x61, /* sequence number */ 0x8c, 0x24, @@ -146,7 +143,7 @@ static void test_applemidi_parses_rtpmidi_packet_with_sysex(UNUSED void** state) assert_int_equal(err, MW_ERR_NONE); } -static void test_applemidi_parses_rtpmidi_packet_with_sysex_ending_with_F0(UNUSED void** state) +void test_applemidi_parses_rtpmidi_packet_with_sysex_ending_with_F0(UNUSED void** state) { char rtpPacket[1024] = { /* V P X CC M PT */ 0x80, 0x61, /* sequence number */ 0x8c, 0x24, @@ -165,7 +162,7 @@ static void test_applemidi_parses_rtpmidi_packet_with_sysex_ending_with_F0(UNUSE assert_int_equal(err, MW_ERR_NONE); } -static void test_applemidi_parses_rtpmidi_packet_with_sysex_with_0xF7_at_end(UNUSED void** state) +void test_applemidi_parses_rtpmidi_packet_with_sysex_with_0xF7_at_end(UNUSED void** state) { char rtpPacket[1024] = { /* V P X CC M PT */ 0x80, 0x61, /* sequence number */ 0x8c, 0x24, @@ -184,8 +181,7 @@ static void test_applemidi_parses_rtpmidi_packet_with_sysex_with_0xF7_at_end(UNU assert_int_equal(err, MW_ERR_NONE); } -static void test_applemidi_parses_rtpmidi_packet_with_multiple_different_midi_events( - UNUSED void** state) +void test_applemidi_parses_rtpmidi_packet_with_multiple_different_midi_events(UNUSED void** state) { char rtp_packet[1024] = { /* V P X CC M PT */ 0x80, 0x61, /* sequence number */ 0x8c, 0x24, /* timestamp */ 0x00, 0x58, 0xbb, 0x40, /* SSRC */ 0xac, 0x67, 0xe1, 0x08, @@ -210,7 +206,7 @@ static void test_applemidi_parses_rtpmidi_packet_with_multiple_different_midi_ev assert_int_equal(err, MW_ERR_NONE); } -static void test_applemidi_parses_rtpmidi_packet_with_system_reset(UNUSED void** state) +void test_applemidi_parses_rtpmidi_packet_with_system_reset(UNUSED void** state) { char rtp_packet[1024] = { /* V P X CC M PT */ 0x80, 0x61, /* sequence number */ 0x8c, 0x24, /* timestamp */ 0x00, 0x58, 0xbb, 0x40, /* SSRC */ 0xac, 0x67, 0xe1, 0x08, @@ -223,7 +219,7 @@ static void test_applemidi_parses_rtpmidi_packet_with_system_reset(UNUSED void** assert_int_equal(err, MW_ERR_NONE); } -static void test_applemidi_parses_notes_sysex_cc_in_one_packet(UNUSED void** state) +void test_applemidi_parses_notes_sysex_cc_in_one_packet(UNUSED void** state) { char rtp_packet[] = { /* V P X CC M PT */ 0x80, 0x61, /* sequence number */ 0xe0, 0x19, /* timestamp */ 0x03, 0x31, 0xdd, 0x6d, /* SSRC */ 0x09, @@ -270,7 +266,7 @@ static void test_applemidi_parses_notes_sysex_cc_in_one_packet(UNUSED void** sta assert_int_equal(err, MW_ERR_NONE); } -static void test_applemidi_ignores_middle_sysex_segments(UNUSED void** state) +void test_applemidi_ignores_middle_sysex_segments(UNUSED void** state) { const u8 endings[] = { 0xF0, 0xF7 }; const u8 cmd_length = 11; @@ -295,7 +291,7 @@ static void test_applemidi_ignores_middle_sysex_segments(UNUSED void** state) } } -static void test_applemidi_processes_multiple_sysex_segments(UNUSED void** state) +void test_applemidi_processes_multiple_sysex_segments(UNUSED void** state) { const u8 cmd_length = 12; char rtp_packet[] = { /* V P X CC M PT */ 0x80, 0x61, @@ -315,7 +311,7 @@ static void test_applemidi_processes_multiple_sysex_segments(UNUSED void** state assert_int_equal(err, MW_ERR_NONE); } -static void test_applemidi_processes_ccs(UNUSED void** state) +void test_applemidi_processes_ccs(UNUSED void** state) { char rtp_packet[] = { /* V P X CC M PT */ 0x80, 0x61, /* sequence number */ 0xf3, 0x86, /* timestamp */ 0x08, 0xbe, 0x9f, 0x2b, /* SSRC */ 0x09, @@ -350,7 +346,7 @@ static void test_applemidi_processes_ccs(UNUSED void** state) assert_int_equal(err, MW_ERR_NONE); } -static void test_applemidi_sets_last_sequence_number(UNUSED void** state) +void test_applemidi_sets_last_sequence_number(UNUSED void** state) { char rtp_packet[1024] = { /* V P X CC M PT */ 0x80, 0x61, /* sequence number */ 0x8c, 0x24, @@ -370,7 +366,7 @@ static void test_applemidi_sets_last_sequence_number(UNUSED void** state) assert_int_equal(seqNum, 0x8c24); } -static void test_applemidi_sends_receiver_feedback(UNUSED void** state) +void test_applemidi_sends_receiver_feedback(UNUSED void** state) { char rtp_packet[1024] = { /* V P X CC M PT */ 0x80, 0x61, /* sequence number */ 0x00, 0x01, @@ -398,7 +394,7 @@ static void test_applemidi_sends_receiver_feedback(UNUSED void** state) assert_int_equal(err, MW_ERR_NONE); } -static void test_applemidi_does_not_read_beyond_length(UNUSED void** state) +void test_applemidi_does_not_read_beyond_length(UNUSED void** state) { u8 length = 4; char rtp_packet[1024] = { /* V P X CC M PT */ 0x80, 0x61, diff --git a/tests/unit/test_applemidi.h b/tests/unit/test_applemidi.h new file mode 100644 index 0000000..f9d4233 --- /dev/null +++ b/tests/unit/test_applemidi.h @@ -0,0 +1,22 @@ +#include "cmocka_inc.h" +#include "comm/applemidi.h" + +int test_applemidi_setup(UNUSED void** state); +void test_applemidi_parses_rtpmidi_packet_with_single_midi_event(UNUSED void** state); +void test_applemidi_parses_rtpmidi_packet_with_single_2_byte_midi_event(UNUSED void** state); +void test_applemidi_parses_rtpmidi_packet_with_multiple_2_byte_midi_events(UNUSED void** state); +void test_applemidi_parses_rtpmidi_packet_with_single_midi_event_long_header(UNUSED void** state); +void test_applemidi_parses_rtpmidi_packet_with_two_midi_events(UNUSED void** state); +void test_applemidi_parses_rtpmidi_packet_with_multiple_midi_events(UNUSED void** state); +void test_applemidi_parses_rtpmidi_packet_with_sysex(UNUSED void** state); +void test_applemidi_parses_rtpmidi_packet_with_sysex_ending_with_F0(UNUSED void** state); +void test_applemidi_parses_rtpmidi_packet_with_sysex_with_0xF7_at_end(UNUSED void** state); +void test_applemidi_parses_rtpmidi_packet_with_multiple_different_midi_events(UNUSED void** state); +void test_applemidi_parses_rtpmidi_packet_with_system_reset(UNUSED void** state); +void test_applemidi_parses_notes_sysex_cc_in_one_packet(UNUSED void** state); +void test_applemidi_ignores_middle_sysex_segments(UNUSED void** state); +void test_applemidi_processes_multiple_sysex_segments(UNUSED void** state); +void test_applemidi_processes_ccs(UNUSED void** state); +void test_applemidi_sets_last_sequence_number(UNUSED void** state); +void test_applemidi_sends_receiver_feedback(UNUSED void** state); +void test_applemidi_does_not_read_beyond_length(UNUSED void** state); diff --git a/tests/unit/test_buffer.c b/tests/unit/test_buffer.c index ba3a889..5064369 100644 --- a/tests/unit/test_buffer.c +++ b/tests/unit/test_buffer.c @@ -1,13 +1,13 @@ -#include "cmocka_inc.h" +#include "test_buffer.h" #include "comm/buffer.h" -static int test_buffer_setup(UNUSED void** state) +int test_buffer_setup(UNUSED void** state) { buffer_init(); return 0; } -static void test_buffer_reads_and_writes_single_byte(UNUSED void** state) +void test_buffer_reads_and_writes_single_byte(UNUSED void** state) { const u8 expectedData = 0x01; @@ -16,7 +16,7 @@ static void test_buffer_reads_and_writes_single_byte(UNUSED void** state) assert_int_equal(buffer_read(), expectedData); } -static void test_buffer_reads_and_writes_circularly_over_capacity(UNUSED void** state) +void test_buffer_reads_and_writes_circularly_over_capacity(UNUSED void** state) { const u16 chunkSize = BUFFER_SIZE / 2; @@ -43,7 +43,7 @@ static void test_buffer_reads_and_writes_circularly_over_capacity(UNUSED void** }; } -static void test_buffer_available_returns_correct_value(UNUSED void** state) +void test_buffer_available_returns_correct_value(UNUSED void** state) { const u16 chunkSize = BUFFER_SIZE / 2; @@ -66,12 +66,12 @@ static void test_buffer_available_returns_correct_value(UNUSED void** state) assert_int_equal(buffer_available(), chunkSize); } -static void test_buffer_available_returns_correct_value_when_empty(UNUSED void** state) +void test_buffer_available_returns_correct_value_when_empty(UNUSED void** state) { assert_int_equal(buffer_available(), BUFFER_SIZE); } -static void test_buffer_available_returns_correct_value_when_full(UNUSED void** state) +void test_buffer_available_returns_correct_value_when_full(UNUSED void** state) { for (u16 i = 0; i < BUFFER_SIZE; i++) { buffer_write(0x00); @@ -79,7 +79,7 @@ static void test_buffer_available_returns_correct_value_when_full(UNUSED void** assert_int_equal(buffer_available(), 0); } -static void test_buffer_returns_cannot_write_if_full(UNUSED void** state) +void test_buffer_returns_cannot_write_if_full(UNUSED void** state) { for (u16 i = 0; i < BUFFER_SIZE; i++) { buffer_write(0x00); @@ -87,7 +87,7 @@ static void test_buffer_returns_cannot_write_if_full(UNUSED void** state) assert_int_equal(buffer_can_write(), false); } -static void test_buffer_returns_can_write_if_empty(UNUSED void** state) +void test_buffer_returns_can_write_if_empty(UNUSED void** state) { assert_int_equal(buffer_can_write(), true); } diff --git a/tests/unit/test_buffer.h b/tests/unit/test_buffer.h new file mode 100644 index 0000000..1a68d60 --- /dev/null +++ b/tests/unit/test_buffer.h @@ -0,0 +1,10 @@ +#include "cmocka_inc.h" + +int test_buffer_setup(UNUSED void** state); +void test_buffer_reads_and_writes_single_byte(UNUSED void** state); +void test_buffer_reads_and_writes_circularly_over_capacity(UNUSED void** state); +void test_buffer_available_returns_correct_value(UNUSED void** state); +void test_buffer_available_returns_correct_value_when_empty(UNUSED void** state); +void test_buffer_available_returns_correct_value_when_full(UNUSED void** state); +void test_buffer_returns_cannot_write_if_full(UNUSED void** state); +void test_buffer_returns_can_write_if_empty(UNUSED void** state); diff --git a/tests/unit/test_comm.c b/tests/unit/test_comm.c index 12db489..eba2143 100644 --- a/tests/unit/test_comm.c +++ b/tests/unit/test_comm.c @@ -1,10 +1,10 @@ -#include "cmocka_inc.h" +#include "test_comm.h" #include "comm/comm.h" static const u16 MAX_COMM_IDLE = 0x28F; static const u16 MAX_COMM_BUSY = 0x28F; -static int test_comm_setup(UNUSED void** state) +int test_comm_setup(UNUSED void** state) { __real_comm_init(); @@ -20,7 +20,7 @@ static void switch_comm_type_to_everdrive(void) __real_comm_reset_counts(); } -static void test_comm_reads_from_serial_when_ready(UNUSED void** state) +void test_comm_reads_from_serial_when_ready(UNUSED void** state) { will_return(__wrap_comm_everdrive_is_present, false); will_return(__wrap_comm_everdrive_pro_is_present, false); @@ -33,7 +33,7 @@ static void test_comm_reads_from_serial_when_ready(UNUSED void** state) assert_int_equal(read, 50); } -static void test_comm_reads_everdrive_when_ready(UNUSED void** state) +void test_comm_reads_everdrive_when_ready(UNUSED void** state) { will_return(__wrap_comm_everdrive_is_present, true); will_return(__wrap_comm_everdrive_read_ready, 1); @@ -44,7 +44,7 @@ static void test_comm_reads_everdrive_when_ready(UNUSED void** state) assert_int_equal(read, 50); } -static void test_comm_reads_demo_when_ready(UNUSED void** state) +void test_comm_reads_demo_when_ready(UNUSED void** state) { will_return(__wrap_comm_everdrive_is_present, false); will_return(__wrap_comm_everdrive_pro_is_present, false); @@ -61,7 +61,7 @@ static void test_comm_reads_demo_when_ready(UNUSED void** state) assert_int_equal(read, 50); } -static void test_comm_writes_when_ready(UNUSED void** state) +void test_comm_writes_when_ready(UNUSED void** state) { const u8 test_data = 50; @@ -77,7 +77,7 @@ static void test_comm_writes_when_ready(UNUSED void** state) __real_comm_write(test_data); } -static void test_comm_idle_count_is_correct(UNUSED void** state) +void test_comm_idle_count_is_correct(UNUSED void** state) { will_return(__wrap_comm_everdrive_is_present, true); will_return(__wrap_comm_everdrive_read_ready, 1); @@ -95,7 +95,7 @@ static void test_comm_idle_count_is_correct(UNUSED void** state) assert_int_equal(idle, 2); } -static void test_comm_busy_count_is_correct(UNUSED void** state) +void test_comm_busy_count_is_correct(UNUSED void** state) { will_return(__wrap_comm_everdrive_is_present, true); will_return(__wrap_comm_everdrive_read_ready, 1); @@ -115,7 +115,7 @@ static void test_comm_busy_count_is_correct(UNUSED void** state) assert_int_equal(busy, 2); } -static void test_comm_clamps_idle_count(UNUSED void** state) +void test_comm_clamps_idle_count(UNUSED void** state) { switch_comm_type_to_everdrive(); @@ -131,7 +131,7 @@ static void test_comm_clamps_idle_count(UNUSED void** state) assert_int_equal(idle, MAX_COMM_IDLE); } -static void test_comm_clamps_busy_count(UNUSED void** state) +void test_comm_clamps_busy_count(UNUSED void** state) { switch_comm_type_to_everdrive(); diff --git a/tests/unit/test_comm.h b/tests/unit/test_comm.h new file mode 100644 index 0000000..612472b --- /dev/null +++ b/tests/unit/test_comm.h @@ -0,0 +1,11 @@ +#include "cmocka_inc.h" + +int test_comm_setup(UNUSED void** state); +void test_comm_reads_from_serial_when_ready(UNUSED void** state); +void test_comm_reads_everdrive_when_ready(UNUSED void** state); +void test_comm_reads_demo_when_ready(UNUSED void** state); +void test_comm_writes_when_ready(UNUSED void** state); +void test_comm_idle_count_is_correct(UNUSED void** state); +void test_comm_busy_count_is_correct(UNUSED void** state); +void test_comm_clamps_idle_count(UNUSED void** state); +void test_comm_clamps_busy_count(UNUSED void** state); diff --git a/tests/unit/test_comm_demo.c b/tests/unit/test_comm_demo.c index 328c987..cb72fe6 100644 --- a/tests/unit/test_comm_demo.c +++ b/tests/unit/test_comm_demo.c @@ -1,4 +1,4 @@ -#include "cmocka_inc.h" +#include "test_comm_demo.h" #include "comm/comm_demo.h" #include "joy.h" @@ -6,14 +6,14 @@ extern void __real_comm_demo_init(void); -static int test_comm_demo_setup(UNUSED void** state) +int test_comm_demo_setup(UNUSED void** state) { expect_any(__wrap_scheduler_addFrameHandler, onFrame); __real_comm_demo_init(); return 0; } -static void test_comm_demo_is_ready_if_button_a_pressed(UNUSED void** state) +void test_comm_demo_is_ready_if_button_a_pressed(UNUSED void** state) { will_return(__wrap_JOY_readJoypad, BUTTON_A); @@ -22,7 +22,7 @@ static void test_comm_demo_is_ready_if_button_a_pressed(UNUSED void** state) assert_int_equal(read, true); } -static void test_comm_demo_is_not_ready_if_no_button_pressed(UNUSED void** state) +void test_comm_demo_is_not_ready_if_no_button_pressed(UNUSED void** state) { will_return(__wrap_JOY_readJoypad, 0); @@ -75,7 +75,7 @@ static void assert_note_played_and_stopped(u8 pitch, u8 program) } } -static void test_comm_demo_plays_note(UNUSED void** state) +void test_comm_demo_plays_note(UNUSED void** state) { will_return(__wrap_JOY_readJoypad, BUTTON_A); @@ -84,7 +84,7 @@ static void test_comm_demo_plays_note(UNUSED void** state) } } -static void test_comm_demo_increases_pitch(UNUSED void** state) +void test_comm_demo_increases_pitch(UNUSED void** state) { will_return(__wrap_JOY_readJoypad, BUTTON_A); assert_note_played_and_stopped(DEFAULT_PITCH, 0); @@ -93,7 +93,7 @@ static void test_comm_demo_increases_pitch(UNUSED void** state) assert_note_played_and_stopped(DEFAULT_PITCH + 1, 0); } -static void test_comm_demo_decreases_pitch(UNUSED void** state) +void test_comm_demo_decreases_pitch(UNUSED void** state) { will_return(__wrap_JOY_readJoypad, BUTTON_A); assert_note_played_and_stopped(DEFAULT_PITCH, 0); @@ -102,7 +102,7 @@ static void test_comm_demo_decreases_pitch(UNUSED void** state) assert_note_played_and_stopped(DEFAULT_PITCH - 1, 0); } -static void test_comm_demo_increases_program(UNUSED void** state) +void test_comm_demo_increases_program(UNUSED void** state) { will_return(__wrap_JOY_readJoypad, BUTTON_A); assert_note_played_and_stopped(DEFAULT_PITCH, 0); @@ -111,7 +111,7 @@ static void test_comm_demo_increases_program(UNUSED void** state) assert_note_played_and_stopped(DEFAULT_PITCH, 1); } -static void test_comm_demo_decreases_program(UNUSED void** state) +void test_comm_demo_decreases_program(UNUSED void** state) { will_return(__wrap_JOY_readJoypad, BUTTON_A); assert_note_played_and_stopped(DEFAULT_PITCH, 0); diff --git a/tests/unit/test_comm_demo.h b/tests/unit/test_comm_demo.h new file mode 100644 index 0000000..d053da3 --- /dev/null +++ b/tests/unit/test_comm_demo.h @@ -0,0 +1,10 @@ +#include "cmocka_inc.h" + +int test_comm_demo_setup(UNUSED void** state); +void test_comm_demo_is_ready_if_button_a_pressed(UNUSED void** state); +void test_comm_demo_is_not_ready_if_no_button_pressed(UNUSED void** state); +void test_comm_demo_plays_note(UNUSED void** state); +void test_comm_demo_increases_pitch(UNUSED void** state); +void test_comm_demo_decreases_pitch(UNUSED void** state); +void test_comm_demo_increases_program(UNUSED void** state); +void test_comm_demo_decreases_program(UNUSED void** state); diff --git a/tests/unit/test_comm_megawifi.c b/tests/unit/test_comm_megawifi.c index 3738719..071469a 100644 --- a/tests/unit/test_comm_megawifi.c +++ b/tests/unit/test_comm_megawifi.c @@ -1,4 +1,4 @@ -#include "cmocka_inc.h" +#include "test_comm_megawifi.h" #include "comm/applemidi.h" #include "comm/comm_megawifi.h" #include "ext/mw/megawifi.h" @@ -7,7 +7,7 @@ #include "settings.h" #include "comm/ip_util.h" -static int test_comm_megawifi_setup(UNUSED void** state) +int test_comm_megawifi_setup(UNUSED void** state) { log_init(); wraps_enable_logging_checks(); @@ -76,17 +76,17 @@ static void megawifi_init(void) __real_comm_megawifi_init(); } -static void test_comm_megawifi_initialises(UNUSED void** state) +void test_comm_megawifi_initialises(UNUSED void** state) { megawifi_init(); } -static void test_comm_megawifi_reads_midi_message(UNUSED void** state) +void test_comm_megawifi_reads_midi_message(UNUSED void** state) { megawifi_init(); } -static void test_comm_megawifi_logs_if_buffer_full(UNUSED void** state) +void test_comm_megawifi_logs_if_buffer_full(UNUSED void** state) { expect_log_warn("MW: MIDI buffer full!"); diff --git a/tests/unit/test_comm_megawifi.h b/tests/unit/test_comm_megawifi.h new file mode 100644 index 0000000..5fdfaf4 --- /dev/null +++ b/tests/unit/test_comm_megawifi.h @@ -0,0 +1,6 @@ +#include "cmocka_inc.h" + +int test_comm_megawifi_setup(UNUSED void** state); +void test_comm_megawifi_initialises(UNUSED void** state); +void test_comm_megawifi_reads_midi_message(UNUSED void** state); +void test_comm_megawifi_logs_if_buffer_full(UNUSED void** state); diff --git a/tests/unit/test_log.c b/tests/unit/test_log.c index 42e8a83..db943a6 100644 --- a/tests/unit/test_log.c +++ b/tests/unit/test_log.c @@ -1,15 +1,15 @@ -#include "cmocka_inc.h" +#include "test_log.h" #include "log.h" #include "string.h" -static int test_log_setup(UNUSED void** state) +int test_log_setup(UNUSED void** state) { __real_log_init(); return 0; } -static void test_log_info_writes_to_log_buffer(UNUSED void** state) +void test_log_info_writes_to_log_buffer(UNUSED void** state) { __real_log_info("Test Message %u", 1, 0, 0); @@ -19,7 +19,7 @@ static void test_log_info_writes_to_log_buffer(UNUSED void** state) assert_string_equal("Test Message 1", log->msg); } -static void test_log_warn_writes_to_log_buffer(UNUSED void** state) +void test_log_warn_writes_to_log_buffer(UNUSED void** state) { __real_log_warn("Test Message %d", 1); @@ -30,7 +30,7 @@ static void test_log_warn_writes_to_log_buffer(UNUSED void** state) assert_int_equal(log->level, Warn); } -static void test_log_stores_two_logs(UNUSED void** state) +void test_log_stores_two_logs(UNUSED void** state) { __real_log_info("Test Message %d", 1); __real_log_info("Test Message %d", 2); @@ -45,7 +45,7 @@ static void test_log_stores_two_logs(UNUSED void** state) assert_string_equal("Test Message 2", log2->msg); } -static void test_log_stores_multiple_logs_and_overwrites_older(UNUSED void** state) +void test_log_stores_multiple_logs_and_overwrites_older(UNUSED void** state) { for (u8 i = 1; i <= 15; i++) { __real_log_info("Test Message %d", i); @@ -60,8 +60,7 @@ static void test_log_stores_multiple_logs_and_overwrites_older(UNUSED void** sta } } -static void test_log_returns_null_when_no_more_logs_are_available_to_be_dequeued( - UNUSED void** state) +void test_log_returns_null_when_no_more_logs_are_available_to_be_dequeued(UNUSED void** state) { __real_log_info("Test Message %d", 1); diff --git a/tests/unit/test_log.h b/tests/unit/test_log.h new file mode 100644 index 0000000..e212165 --- /dev/null +++ b/tests/unit/test_log.h @@ -0,0 +1,8 @@ +#include "cmocka_inc.h" + +int test_log_setup(UNUSED void** state); +void test_log_info_writes_to_log_buffer(UNUSED void** state); +void test_log_warn_writes_to_log_buffer(UNUSED void** state); +void test_log_stores_two_logs(UNUSED void** state); +void test_log_stores_multiple_logs_and_overwrites_older(UNUSED void** state); +void test_log_returns_null_when_no_more_logs_are_available_to_be_dequeued(UNUSED void** state); diff --git a/tests/unit/test_midi_dac.c b/tests/unit/test_midi_dac.c index 1a287f7..dc97bbd 100644 --- a/tests/unit/test_midi_dac.c +++ b/tests/unit/test_midi_dac.c @@ -1,3 +1,4 @@ +#include "test_midi_dac.h" #include "test_midi.h" #include "snd/sound.h" #include "snd/pcm/snd_pcm.h" @@ -6,7 +7,7 @@ static const u8 noteKey = 39; static const u8 nullNoteKey = 1; static const u8 dacFmChannel = 5; -static int test_midi_dac_setup(UNUSED void** state) +int test_midi_dac_setup(UNUSED void** state) { test_midi_setup(state); @@ -16,21 +17,21 @@ static int test_midi_dac_setup(UNUSED void** state) return 0; } -static void test_midi_enables_dac(UNUSED void** state) +void test_midi_enables_dac(UNUSED void** state) { expect_value(__wrap_synth_enableDac, enable, true); __real_midi_cc(0, 78, 0x7F); } -static void test_midi_disables_dac(UNUSED void** state) +void test_midi_disables_dac(UNUSED void** state) { expect_value(__wrap_synth_enableDac, enable, false); __real_midi_cc(0, 78, 0); } -static void test_midi_dac_plays_note(UNUSED void** state) +void test_midi_dac_plays_note(UNUSED void** state) { expect_any(__wrap_SND_PCM_startPlay, sample); expect_any(__wrap_SND_PCM_startPlay, len); @@ -41,12 +42,12 @@ static void test_midi_dac_plays_note(UNUSED void** state) __real_midi_note_on(dacFmChannel, noteKey, 100); } -static void test_midi_dac_does_not_play_null_sample(UNUSED void** state) +void test_midi_dac_does_not_play_null_sample(UNUSED void** state) { __real_midi_note_on(dacFmChannel, nullNoteKey, 100); } -static void test_midi_dac_stops_note(UNUSED void** state) +void test_midi_dac_stops_note(UNUSED void** state) { expect_any(__wrap_SND_PCM_startPlay, sample); expect_any(__wrap_SND_PCM_startPlay, len); diff --git a/tests/unit/test_midi_dac.h b/tests/unit/test_midi_dac.h new file mode 100644 index 0000000..5e63f7b --- /dev/null +++ b/tests/unit/test_midi_dac.h @@ -0,0 +1,8 @@ +#include "cmocka_inc.h" + +int test_midi_dac_setup(UNUSED void** state); +void test_midi_enables_dac(UNUSED void** state); +void test_midi_disables_dac(UNUSED void** state); +void test_midi_dac_plays_note(UNUSED void** state); +void test_midi_dac_does_not_play_null_sample(UNUSED void** state); +void test_midi_dac_stops_note(UNUSED void** state); diff --git a/tests/unit/test_midi_dynamic.c b/tests/unit/test_midi_dynamic.c index 5eed4ed..66d7009 100644 --- a/tests/unit/test_midi_dynamic.c +++ b/tests/unit/test_midi_dynamic.c @@ -1,3 +1,4 @@ +#include "test_midi_dynamic.h" #include "test_midi.h" #define LENGTH_OF(x) (sizeof(x) / sizeof((x)[0])) @@ -10,7 +11,7 @@ static void setStickToDeviceType(bool enable) __real_midi_sysex(sequence, sizeof(sequence)); } -static int test_dynamic_midi_setup(UNUSED void** state) +int test_dynamic_midi_setup(UNUSED void** state) { test_midi_setup(state); @@ -27,7 +28,7 @@ static int test_dynamic_midi_setup(UNUSED void** state) return 0; } -static void test_midi_dynamic_uses_all_channels(UNUSED void** state) +void test_midi_dynamic_uses_all_channels(UNUSED void** state) { const u8 octave = 4; const u16 freq = 0x284; @@ -51,7 +52,7 @@ static void test_midi_dynamic_uses_all_channels(UNUSED void** state) } } -static void test_midi_routing_switches_to_dynamic_on_gm_reset(UNUSED void** state) +void test_midi_routing_switches_to_dynamic_on_gm_reset(UNUSED void** state) { const u8 sysExGeneralMidiResetSequence[] = { 0x7E, 0x7F, 0x09, 0x01 }; __real_midi_sysex(sysExGeneralMidiResetSequence, sizeof(sysExGeneralMidiResetSequence)); @@ -69,7 +70,7 @@ static void test_midi_routing_switches_to_dynamic_on_gm_reset(UNUSED void** stat __real_midi_note_on(0, 61, MAX_MIDI_VOLUME); } -static void test_midi_dynamic_tries_to_reuse_original_midi_channel_if_available(UNUSED void** state) +void test_midi_dynamic_tries_to_reuse_original_midi_channel_if_available(UNUSED void** state) { const u8 octave = 4; const u16 freq = 0x284; @@ -95,7 +96,7 @@ static void test_midi_dynamic_tries_to_reuse_original_midi_channel_if_available( __real_midi_note_on(REUSE_MIDI_CHANNEL, pitch, MAX_MIDI_VOLUME); } -static void test_midi_dynamic_reuses_mapped_midi_channel_even_if_busy_if_sticking_to_device_type( +void test_midi_dynamic_reuses_mapped_midi_channel_even_if_busy_if_sticking_to_device_type( UNUSED void** state) { setStickToDeviceType(true); @@ -117,12 +118,12 @@ static void test_midi_dynamic_reuses_mapped_midi_channel_even_if_busy_if_stickin __real_midi_note_on(REUSE_MIDI_CHANNEL, MIDI_PITCH_AS6, MAX_MIDI_VOLUME); } -static void test_midi_reports_dynamic_mode_enabled(UNUSED void** state) +void test_midi_reports_dynamic_mode_enabled(UNUSED void** state) { assert_true(__real_midi_dynamic_mode); } -static void test_midi_reports_dynamic_mode_disabled(UNUSED void** state) +void test_midi_reports_dynamic_mode_disabled(UNUSED void** state) { const u8 sequence[] = { SYSEX_MANU_EXTENDED, @@ -137,7 +138,7 @@ static void test_midi_reports_dynamic_mode_disabled(UNUSED void** state) assert_false(__real_midi_dynamic_mode()); } -static void test_midi_exposes_dynamic_mode_mappings(UNUSED void** state) +void test_midi_exposes_dynamic_mode_mappings(UNUSED void** state) { DeviceChannel* mappings = __real_midi_channel_mappings(); for (u8 i = DEV_CHAN_MIN_FM; i < DEV_CHAN_MAX_FM; i++) { @@ -148,7 +149,7 @@ static void test_midi_exposes_dynamic_mode_mappings(UNUSED void** state) } } -static void test_midi_dynamic_enables_percussive_mode_if_needed(UNUSED void** state) +void test_midi_dynamic_enables_percussive_mode_if_needed(UNUSED void** state) { const u8 MIDI_KEY = 30; @@ -169,7 +170,7 @@ static void test_midi_dynamic_enables_percussive_mode_if_needed(UNUSED void** st __real_midi_note_on(GENERAL_MIDI_PERCUSSION_CHANNEL, MIDI_KEY, MAX_MIDI_VOLUME); } -static void test_midi_sets_presets_on_dynamic_channels(UNUSED void** state) +void test_midi_sets_presets_on_dynamic_channels(UNUSED void** state) { expect_value(__wrap_synth_preset, channel, 0); expect_any(__wrap_synth_preset, preset); @@ -190,7 +191,7 @@ static void test_midi_sets_presets_on_dynamic_channels(UNUSED void** state) __real_midi_note_on(0, MIDI_PITCH_AS6, MAX_MIDI_VOLUME); } -static void test_midi_dynamic_does_not_send_percussion_to_psg_channels(UNUSED void** state) +void test_midi_dynamic_does_not_send_percussion_to_psg_channels(UNUSED void** state) { const u8 MIDI_KEY_IN_PSG_RANGE = MIDI_PITCH_AS6; @@ -206,7 +207,7 @@ static void test_midi_dynamic_does_not_send_percussion_to_psg_channels(UNUSED vo __real_midi_note_on(GENERAL_MIDI_PERCUSSION_CHANNEL, MIDI_KEY_IN_PSG_RANGE, MAX_MIDI_VOLUME); } -static void test_midi_sysex_resets_dynamic_mode_state(UNUSED void** state) +void test_midi_sysex_resets_dynamic_mode_state(UNUSED void** state) { const u8 sysExGeneralMidiResetSequence[] = { 0x7E, 0x7F, 0x09, 0x01 }; const u8 octave = 4; @@ -239,7 +240,7 @@ static void test_midi_sysex_resets_dynamic_mode_state(UNUSED void** state) } } -static void test_midi_dynamic_sends_note_off_to_channel_playing_same_pitch(UNUSED void** state) +void test_midi_dynamic_sends_note_off_to_channel_playing_same_pitch(UNUSED void** state) { expect_synth_pitch_any(); expect_synth_volume_any(); @@ -255,7 +256,7 @@ static void test_midi_dynamic_sends_note_off_to_channel_playing_same_pitch(UNUSE __real_midi_note_off(0, MIDI_PITCH_B6); } -static void test_midi_dynamic_limits_percussion_notes(UNUSED void** state) +void test_midi_dynamic_limits_percussion_notes(UNUSED void** state) { const u8 DRUM_KEY = 30; @@ -272,7 +273,7 @@ static void test_midi_dynamic_limits_percussion_notes(UNUSED void** state) __real_midi_note_on(GENERAL_MIDI_PERCUSSION_CHANNEL, DRUM_KEY, MAX_MIDI_VOLUME); } -static void test_midi_dynamic_maintains_volume_on_remapping(UNUSED void** state) +void test_midi_dynamic_maintains_volume_on_remapping(UNUSED void** state) { const u8 midi_vol = 50; const u8 expected_synth_vol = 0x32; @@ -294,7 +295,7 @@ static void test_midi_dynamic_maintains_volume_on_remapping(UNUSED void** state) __real_midi_note_on(0, MIDI_PITCH_B6, MAX_MIDI_VOLUME); } -static void test_midi_dynamic_sets_volume_on_playing_notes(UNUSED void** state) +void test_midi_dynamic_sets_volume_on_playing_notes(UNUSED void** state) { const u8 midi_vol_initial = 50; const u8 midi_vol_next = 75; @@ -323,7 +324,7 @@ static void test_midi_dynamic_sets_volume_on_playing_notes(UNUSED void** state) __real_midi_cc(0, CC_VOLUME, midi_vol_next); } -static void test_midi_dynamic_maintains_pan_on_remapping(UNUSED void** state) +void test_midi_dynamic_maintains_pan_on_remapping(UNUSED void** state) { const u8 midi_pan = 127; const u8 expected_synth_stereo = STEREO_MODE_RIGHT; @@ -348,7 +349,7 @@ static void test_midi_dynamic_maintains_pan_on_remapping(UNUSED void** state) __real_midi_note_on(0, MIDI_PITCH_B6, MAX_MIDI_VOLUME); } -static void test_midi_dynamic_maintains_pitch_bend_on_remapping(UNUSED void** state) +void test_midi_dynamic_maintains_pitch_bend_on_remapping(UNUSED void** state) { const u16 midi_bend = 0x3000; @@ -371,7 +372,7 @@ static void test_midi_dynamic_maintains_pitch_bend_on_remapping(UNUSED void** st __real_midi_note_on(0, MIDI_PITCH_B6, MAX_MIDI_VOLUME); } -static void test_midi_dynamic_resets_mappings_on_cc_121(UNUSED void** state) +void test_midi_dynamic_resets_mappings_on_cc_121(UNUSED void** state) { const u8 midiChannel = 2; @@ -392,7 +393,7 @@ static void test_midi_dynamic_resets_mappings_on_cc_121(UNUSED void** state) } } -static void test_midi_dynamic_all_notes_off_on_cc_123(UNUSED void** state) +void test_midi_dynamic_all_notes_off_on_cc_123(UNUSED void** state) { const u8 midiChannel = 2; @@ -417,7 +418,7 @@ static void test_midi_dynamic_all_notes_off_on_cc_123(UNUSED void** state) } } -static void test_midi_dynamic_sysex_remaps_midi_channel(UNUSED void** state) +void test_midi_dynamic_sysex_remaps_midi_channel(UNUSED void** state) { const u8 MIDI_CHANNEL = 0x01; const u8 DESTINATION_FIRST_PSG_CHANNEL = 0x06; @@ -433,7 +434,7 @@ static void test_midi_dynamic_sysex_remaps_midi_channel(UNUSED void** state) __real_midi_note_on(MIDI_CHANNEL, 60, MAX_MIDI_VOLUME); } -static void test_midi_dynamic_sysex_removes_mapping_of_midi_channel(UNUSED void** state) +void test_midi_dynamic_sysex_removes_mapping_of_midi_channel(UNUSED void** state) { const u8 MIDI_CHANNEL = 0x00; const u8 MIDI_CHANNEL_NO_MAPPING = 0x7F; @@ -463,7 +464,7 @@ static void test_midi_dynamic_sysex_removes_mapping_of_midi_channel(UNUSED void* __real_midi_note_on(MIDI_CHANNEL, 60, MAX_MIDI_VOLUME); } -static void test_midi_dynamic_prefers_psg_for_square_wave_instruments(UNUSED void** state) +void test_midi_dynamic_prefers_psg_for_square_wave_instruments(UNUSED void** state) { const u8 PSG_CHANNEL = 0; const u8 MIDI_CHANNEL = 0; @@ -485,7 +486,7 @@ static void test_midi_dynamic_prefers_psg_for_square_wave_instruments(UNUSED voi } } -static void test_midi_dynamic_sticks_to_assigned_device_type_for_midi_channels(UNUSED void** state) +void test_midi_dynamic_sticks_to_assigned_device_type_for_midi_channels(UNUSED void** state) { setStickToDeviceType(true); @@ -505,8 +506,7 @@ static void test_midi_dynamic_sticks_to_assigned_device_type_for_midi_channels(U __real_midi_note_on(REUSE_MIDI_CHANNEL, MIDI_PITCH_AS6, MAX_MIDI_VOLUME); } -static void test_midi_dynamic_sticks_to_assigned_psg_device_type_for_midi_channels( - UNUSED void** state) +void test_midi_dynamic_sticks_to_assigned_psg_device_type_for_midi_channels(UNUSED void** state) { setStickToDeviceType(true); @@ -526,7 +526,7 @@ static void test_midi_dynamic_sticks_to_assigned_psg_device_type_for_midi_channe __real_midi_note_on(MIDI_CHANNEL, MIDI_PITCH_B6, MAX_MIDI_VOLUME); } -static void test_midi_assign_channel_to_psg_device(UNUSED void** state) +void test_midi_assign_channel_to_psg_device(UNUSED void** state) { const u8 MIDI_CHANNEL = 0; const u8 PSG_CHANNEL = 0; @@ -540,7 +540,7 @@ static void test_midi_assign_channel_to_psg_device(UNUSED void** state) __real_midi_note_on(MIDI_CHANNEL, 60, MAX_MIDI_VOLUME); } -static void test_midi_assign_channel_to_fm_device_only(UNUSED void** state) +void test_midi_assign_channel_to_fm_device_only(UNUSED void** state) { const u8 MIDI_CHANNEL = 0; const u8 DEVICE_SELECT_FM = 32; @@ -560,7 +560,7 @@ static void test_midi_assign_channel_to_fm_device_only(UNUSED void** state) __real_midi_note_on(MIDI_CHANNEL, 60, MAX_MIDI_VOLUME); } -static void test_midi_assign_channel_to_psg_noise(UNUSED void** state) +void test_midi_assign_channel_to_psg_noise(UNUSED void** state) { const u8 MIDI_CHANNEL = 0; const u8 PSG_NOISE_CHANNEL = 3; diff --git a/tests/unit/test_midi_dynamic.h b/tests/unit/test_midi_dynamic.h new file mode 100644 index 0000000..3313518 --- /dev/null +++ b/tests/unit/test_midi_dynamic.h @@ -0,0 +1,31 @@ +#include "cmocka_inc.h" + +int test_dynamic_midi_setup(UNUSED void** state); +void test_midi_dynamic_uses_all_channels(UNUSED void** state); +void test_midi_routing_switches_to_dynamic_on_gm_reset(UNUSED void** state); +void test_midi_dynamic_tries_to_reuse_original_midi_channel_if_available(UNUSED void** state); +void test_midi_dynamic_reuses_mapped_midi_channel_even_if_busy_if_sticking_to_device_type( + UNUSED void** state); +void test_midi_reports_dynamic_mode_enabled(UNUSED void** state); +void test_midi_reports_dynamic_mode_disabled(UNUSED void** state); +void test_midi_exposes_dynamic_mode_mappings(UNUSED void** state); +void test_midi_dynamic_enables_percussive_mode_if_needed(UNUSED void** state); +void test_midi_sets_presets_on_dynamic_channels(UNUSED void** state); +void test_midi_dynamic_does_not_send_percussion_to_psg_channels(UNUSED void** state); +void test_midi_sysex_resets_dynamic_mode_state(UNUSED void** state); +void test_midi_dynamic_sends_note_off_to_channel_playing_same_pitch(UNUSED void** state); +void test_midi_dynamic_limits_percussion_notes(UNUSED void** state); +void test_midi_dynamic_maintains_volume_on_remapping(UNUSED void** state); +void test_midi_dynamic_sets_volume_on_playing_notes(UNUSED void** state); +void test_midi_dynamic_maintains_pan_on_remapping(UNUSED void** state); +void test_midi_dynamic_maintains_pitch_bend_on_remapping(UNUSED void** state); +void test_midi_dynamic_resets_mappings_on_cc_121(UNUSED void** state); +void test_midi_dynamic_all_notes_off_on_cc_123(UNUSED void** state); +void test_midi_dynamic_sysex_remaps_midi_channel(UNUSED void** state); +void test_midi_dynamic_sysex_removes_mapping_of_midi_channel(UNUSED void** state); +void test_midi_dynamic_prefers_psg_for_square_wave_instruments(UNUSED void** state); +void test_midi_dynamic_sticks_to_assigned_device_type_for_midi_channels(UNUSED void** state); +void test_midi_dynamic_sticks_to_assigned_psg_device_type_for_midi_channels(UNUSED void** state); +void test_midi_assign_channel_to_psg_device(UNUSED void** state); +void test_midi_assign_channel_to_fm_device_only(UNUSED void** state); +void test_midi_assign_channel_to_psg_noise(UNUSED void** state); diff --git a/tests/unit/test_midi_finetune.c b/tests/unit/test_midi_finetune.c index 82b8cff..90719bb 100644 --- a/tests/unit/test_midi_finetune.c +++ b/tests/unit/test_midi_finetune.c @@ -1,6 +1,7 @@ +#include "test_midi_finetune.h" #include "test_midi.h" -static void test_midi_finetune_max(UNUSED void** state) +void test_midi_finetune_max(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { debug_message("channel %d\n", chan); @@ -13,7 +14,7 @@ static void test_midi_finetune_max(UNUSED void** state) } } -static void test_midi_finetune_min(UNUSED void** state) +void test_midi_finetune_min(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { debug_message("channel %d\n", chan); @@ -26,7 +27,7 @@ static void test_midi_finetune_min(UNUSED void** state) } } -static void test_midi_finetune_with_pitchbend(UNUSED void** state) +void test_midi_finetune_with_pitchbend(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { debug_message("channel %d\n", chan); diff --git a/tests/unit/test_midi_finetune.h b/tests/unit/test_midi_finetune.h new file mode 100644 index 0000000..b0f0eca --- /dev/null +++ b/tests/unit/test_midi_finetune.h @@ -0,0 +1,5 @@ +#include "cmocka_inc.h" + +void test_midi_finetune_max(UNUSED void** state); +void test_midi_finetune_min(UNUSED void** state); +void test_midi_finetune_with_pitchbend(UNUSED void** state); diff --git a/tests/unit/test_midi_fm.c b/tests/unit/test_midi_fm.c index 36e1007..70421ee 100644 --- a/tests/unit/test_midi_fm.c +++ b/tests/unit/test_midi_fm.c @@ -1,7 +1,8 @@ +#include "test_midi_fm.h" #include "test_midi.h" #include "debug.h" -static void test_midi_triggers_synth_note_on(UNUSED void** state) +void test_midi_triggers_synth_note_on(UNUSED void** state) { for (int chan = 0; chan <= MAX_FM_CHAN; chan++) { expect_synth_pitch(chan, 4, SYNTH_NTSC_C); @@ -11,7 +12,7 @@ static void test_midi_triggers_synth_note_on(UNUSED void** state) } } -static void test_midi_triggers_synth_note_on_with_velocity(UNUSED void** state) +void test_midi_triggers_synth_note_on_with_velocity(UNUSED void** state) { for (int chan = 0; chan <= MAX_FM_CHAN; chan++) { expect_synth_pitch(chan, 4, SYNTH_NTSC_C); @@ -21,7 +22,7 @@ static void test_midi_triggers_synth_note_on_with_velocity(UNUSED void** state) } } -static void test_midi_triggers_synth_note_on_with_velocity_and_channel_volume(UNUSED void** state) +void test_midi_triggers_synth_note_on_with_velocity_and_channel_volume(UNUSED void** state) { for (int chan = 0; chan <= MAX_FM_CHAN; chan++) { expect_synth_volume(chan, MAX_MIDI_VOLUME / 2); @@ -34,7 +35,7 @@ static void test_midi_triggers_synth_note_on_with_velocity_and_channel_volume(UN } } -static void test_midi_changing_volume_during_note_on_respects_velocity(UNUSED void** state) +void test_midi_changing_volume_during_note_on_respects_velocity(UNUSED void** state) { for (int chan = 0; chan <= MAX_FM_CHAN; chan++) { expect_synth_pitch(chan, 4, SYNTH_NTSC_C); @@ -50,7 +51,7 @@ static void test_midi_changing_volume_during_note_on_respects_velocity(UNUSED vo } } -static void test_midi_triggers_synth_note_on_boundary_values(UNUSED void** state) +void test_midi_triggers_synth_note_on_boundary_values(UNUSED void** state) { const u8 keys[] = { 11, 106 }; const u16 expectedFrequencies[] = { 607, SYNTH_NTSC_AS }; @@ -67,7 +68,7 @@ static void test_midi_triggers_synth_note_on_boundary_values(UNUSED void** state } } -static void test_midi_does_not_trigger_synth_note_on_out_of_bound_values(UNUSED void** state) +void test_midi_does_not_trigger_synth_note_on_out_of_bound_values(UNUSED void** state) { const u8 keys[] = { 0, 10, 107, 127 }; @@ -78,7 +79,7 @@ static void test_midi_does_not_trigger_synth_note_on_out_of_bound_values(UNUSED } } -static void test_midi_triggers_synth_note_off(UNUSED void** state) +void test_midi_triggers_synth_note_off(UNUSED void** state) { for (int chan = 0; chan <= MAX_FM_CHAN; chan++) { expect_synth_pitch(chan, 4, SYNTH_NTSC_C); @@ -91,7 +92,7 @@ static void test_midi_triggers_synth_note_off(UNUSED void** state) } } -static void test_midi_triggers_synth_note_off_when_note_on_has_zero_velocity(UNUSED void** state) +void test_midi_triggers_synth_note_off_when_note_on_has_zero_velocity(UNUSED void** state) { for (int chan = 0; chan <= MAX_FM_CHAN; chan++) { expect_synth_pitch(chan, 4, SYNTH_NTSC_C); @@ -104,7 +105,7 @@ static void test_midi_triggers_synth_note_off_when_note_on_has_zero_velocity(UNU } } -static void test_midi_triggers_synth_note_on_2(UNUSED void** state) +void test_midi_triggers_synth_note_on_2(UNUSED void** state) { expect_synth_pitch(0, 6, SYNTH_NTSC_AS); expect_synth_volume_any(); @@ -113,7 +114,7 @@ static void test_midi_triggers_synth_note_on_2(UNUSED void** state) __real_midi_note_on(0, MIDI_PITCH_AS6, MAX_MIDI_VOLUME); } -static void test_midi_channel_volume_sets_volume(UNUSED void** state) +void test_midi_channel_volume_sets_volume(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { expect_synth_volume(chan, 60); @@ -121,7 +122,7 @@ static void test_midi_channel_volume_sets_volume(UNUSED void** state) } } -static void test_midi_pan_sets_synth_stereo_mode_right(UNUSED void** state) +void test_midi_pan_sets_synth_stereo_mode_right(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { expect_value(__wrap_synth_stereo, channel, chan); @@ -131,7 +132,7 @@ static void test_midi_pan_sets_synth_stereo_mode_right(UNUSED void** state) } } -static void test_midi_pan_sets_synth_stereo_mode_left(UNUSED void** state) +void test_midi_pan_sets_synth_stereo_mode_left(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { expect_value(__wrap_synth_stereo, channel, chan); @@ -141,7 +142,7 @@ static void test_midi_pan_sets_synth_stereo_mode_left(UNUSED void** state) } } -static void test_midi_pan_sets_synth_stereo_mode_centre(UNUSED void** state) +void test_midi_pan_sets_synth_stereo_mode_centre(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { expect_value(__wrap_synth_stereo, channel, chan); @@ -156,7 +157,7 @@ static void test_midi_pan_sets_synth_stereo_mode_centre(UNUSED void** state) } } -static void test_midi_sets_fm_algorithm(UNUSED void** state) +void test_midi_sets_fm_algorithm(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { expect_value(__wrap_synth_algorithm, channel, chan); @@ -166,7 +167,7 @@ static void test_midi_sets_fm_algorithm(UNUSED void** state) } } -static void test_midi_sets_fm_feedback(UNUSED void** state) +void test_midi_sets_fm_feedback(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { expect_value(__wrap_synth_feedback, channel, chan); @@ -176,7 +177,7 @@ static void test_midi_sets_fm_feedback(UNUSED void** state) } } -static void test_midi_sets_channel_AMS(UNUSED void** state) +void test_midi_sets_channel_AMS(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { expect_value(__wrap_synth_ams, channel, chan); @@ -186,7 +187,7 @@ static void test_midi_sets_channel_AMS(UNUSED void** state) } } -static void test_midi_sets_channel_FMS(UNUSED void** state) +void test_midi_sets_channel_FMS(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { expect_value(__wrap_synth_fms, channel, chan); @@ -196,7 +197,7 @@ static void test_midi_sets_channel_FMS(UNUSED void** state) } } -static void test_midi_sets_operator_total_level(UNUSED void** state) +void test_midi_sets_operator_total_level(UNUSED void** state) { const u8 expectedValue = 50; for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { @@ -211,7 +212,7 @@ static void test_midi_sets_operator_total_level(UNUSED void** state) } } -static void test_midi_sets_operator_multiple(UNUSED void** state) +void test_midi_sets_operator_multiple(UNUSED void** state) { const u8 expectedValue = 4; @@ -227,7 +228,7 @@ static void test_midi_sets_operator_multiple(UNUSED void** state) } } -static void test_midi_sets_operator_detune(UNUSED void** state) +void test_midi_sets_operator_detune(UNUSED void** state) { const u8 expectedValue = 2; @@ -243,7 +244,7 @@ static void test_midi_sets_operator_detune(UNUSED void** state) } } -static void test_midi_sets_operator_rate_scaling(UNUSED void** state) +void test_midi_sets_operator_rate_scaling(UNUSED void** state) { const u8 expectedValue = 2; @@ -259,7 +260,7 @@ static void test_midi_sets_operator_rate_scaling(UNUSED void** state) } } -static void test_midi_sets_operator_attack_rate(UNUSED void** state) +void test_midi_sets_operator_attack_rate(UNUSED void** state) { const u8 expectedValue = 2; @@ -275,7 +276,7 @@ static void test_midi_sets_operator_attack_rate(UNUSED void** state) } } -static void test_midi_sets_operator_decay_rate(UNUSED void** state) +void test_midi_sets_operator_decay_rate(UNUSED void** state) { const u8 expectedValue = 2; for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { @@ -290,7 +291,7 @@ static void test_midi_sets_operator_decay_rate(UNUSED void** state) } } -static void test_midi_sets_operator_sustain_rate(UNUSED void** state) +void test_midi_sets_operator_sustain_rate(UNUSED void** state) { const u8 expectedValue = 1; @@ -306,7 +307,7 @@ static void test_midi_sets_operator_sustain_rate(UNUSED void** state) } } -static void test_midi_sets_operator_sustain_level(UNUSED void** state) +void test_midi_sets_operator_sustain_level(UNUSED void** state) { const u8 expectedValue = 1; @@ -322,7 +323,7 @@ static void test_midi_sets_operator_sustain_level(UNUSED void** state) } } -static void test_midi_sets_operator_amplitude_modulation(UNUSED void** state) +void test_midi_sets_operator_amplitude_modulation(UNUSED void** state) { const u8 expectedValue = 1; @@ -339,7 +340,7 @@ static void test_midi_sets_operator_amplitude_modulation(UNUSED void** state) } } -static void test_midi_sets_operator_release_rate(UNUSED void** state) +void test_midi_sets_operator_release_rate(UNUSED void** state) { const u8 expectedValue = 1; @@ -355,7 +356,7 @@ static void test_midi_sets_operator_release_rate(UNUSED void** state) } } -static void test_midi_sets_operator_ssg_eg(UNUSED void** state) +void test_midi_sets_operator_ssg_eg(UNUSED void** state) { const u8 expectedValue = 11; @@ -374,7 +375,7 @@ static void test_midi_sets_operator_ssg_eg(UNUSED void** state) } } -static void test_midi_sets_genmdm_stereo_mode(UNUSED void** state) +void test_midi_sets_genmdm_stereo_mode(UNUSED void** state) { const u8 expectedMode = 3; const u8 value = 127; @@ -388,21 +389,21 @@ static void test_midi_sets_genmdm_stereo_mode(UNUSED void** state) } } -static void test_midi_sets_global_LFO_enable(UNUSED void** state) +void test_midi_sets_global_LFO_enable(UNUSED void** state) { expect_value(__wrap_synth_enableLfo, enable, 1); __real_midi_cc(0, 74, 64); } -static void test_midi_sets_global_LFO_frequency(UNUSED void** state) +void test_midi_sets_global_LFO_frequency(UNUSED void** state) { expect_value(__wrap_synth_globalLfoFrequency, freq, 1); __real_midi_cc(0, 1, 16); } -static void test_midi_sets_fm_preset(UNUSED void** state) +void test_midi_sets_fm_preset(UNUSED void** state) { const u8 program = 1; const u8 chan = 0; @@ -418,7 +419,7 @@ static void test_midi_sets_fm_preset(UNUSED void** state) __real_midi_program(chan, program); } -static void test_midi_sets_synth_pitch_bend(UNUSED void** state) +void test_midi_sets_synth_pitch_bend(UNUSED void** state) { for (int chan = 0; chan <= MAX_FM_CHAN; chan++) { expect_synth_pitch(chan, 4, SYNTH_NTSC_C); @@ -431,7 +432,7 @@ static void test_midi_sets_synth_pitch_bend(UNUSED void** state) } } -static void test_midi_sets_synth_pitch_bend_before_note_on(UNUSED void** state) +void test_midi_sets_synth_pitch_bend_before_note_on(UNUSED void** state) { for (int chan = 0; chan <= MAX_FM_CHAN; chan++) { print_message("channel %d\n", chan); @@ -446,7 +447,7 @@ static void test_midi_sets_synth_pitch_bend_before_note_on(UNUSED void** state) } } -static void test_midi_pitch_bends_down_an_octave(UNUSED void** state) +void test_midi_pitch_bends_down_an_octave(UNUSED void** state) { const u8 MIDI_PITCH_B3 = 59; const u16 SYNTH_FREQ_B3 = 0x25f; @@ -463,7 +464,7 @@ static void test_midi_pitch_bends_down_an_octave(UNUSED void** state) } } -static void test_midi_pitch_bends_up_an_octave(UNUSED void** state) +void test_midi_pitch_bends_up_an_octave(UNUSED void** state) { const u8 MIDI_PITCH_B3 = 59; const u16 SYNTH_FREQ_B3 = 0x25f; @@ -480,7 +481,7 @@ static void test_midi_pitch_bends_up_an_octave(UNUSED void** state) } } -static void test_midi_pitch_bends_up_an_octave_upper_freq_limit(UNUSED void** state) +void test_midi_pitch_bends_up_an_octave_upper_freq_limit(UNUSED void** state) { const u8 MIDI_PITCH_AS4 = 70; const u16 SYNTH_FREQ_AS4 = 1146; @@ -497,7 +498,7 @@ static void test_midi_pitch_bends_up_an_octave_upper_freq_limit(UNUSED void** st } } -static void test_midi_persists_pitch_bend_between_notes(UNUSED void** state) +void test_midi_persists_pitch_bend_between_notes(UNUSED void** state) { for (int chan = 0; chan <= MAX_FM_CHAN; chan++) { expect_synth_pitch(chan, 4, SYNTH_NTSC_C); @@ -526,7 +527,7 @@ static void remap_midi_channel(u8 midiChannel, u8 deviceChannel) __real_midi_sysex(sequence, sizeof(sequence) / sizeof(sequence[0])); } -static void test_midi_fm_note_on_percussion_channel_sets_percussion_preset(UNUSED void** state) +void test_midi_fm_note_on_percussion_channel_sets_percussion_preset(UNUSED void** state) { const u8 MIDI_PERCUSSION_CHANNEL = 9; const u8 FM_CHANNEL = 5; @@ -549,7 +550,7 @@ static void test_midi_fm_note_on_percussion_channel_sets_percussion_preset(UNUSE __real_midi_note_on(MIDI_PERCUSSION_CHANNEL, MIDI_KEY, MAX_MIDI_VOLUME); } -static void test_midi_switching_program_retains_pan_setting(UNUSED void** state) +void test_midi_switching_program_retains_pan_setting(UNUSED void** state) { const u8 program = 1; const u8 chan = 0; @@ -568,7 +569,7 @@ static void test_midi_switching_program_retains_pan_setting(UNUSED void** state) __real_midi_program(chan, program); } -static void test_midi_enables_fm_special_mode(UNUSED void** state) +void test_midi_enables_fm_special_mode(UNUSED void** state) { u8 expectedController = 80; u8 expectedValue = 64; @@ -578,7 +579,7 @@ static void test_midi_enables_fm_special_mode(UNUSED void** state) __real_midi_cc(0, expectedController, expectedValue); } -static void test_midi_disables_fm_special_mode(UNUSED void** state) +void test_midi_disables_fm_special_mode(UNUSED void** state) { u8 expectedController = 80; u8 expectedValue = 0; @@ -588,7 +589,7 @@ static void test_midi_disables_fm_special_mode(UNUSED void** state) __real_midi_cc(0, expectedController, expectedValue); } -static void test_midi_sets_pitch_of_special_mode_ch3_operator(UNUSED void** state) +void test_midi_sets_pitch_of_special_mode_ch3_operator(UNUSED void** state) { for (u8 op = 0; op < 3; op++) { int midiChannel = 10 + op; @@ -604,7 +605,7 @@ static void test_midi_sets_pitch_of_special_mode_ch3_operator(UNUSED void** stat } } -static void test_midi_sets_volume_of_special_mode_ch3_operator(UNUSED void** state) +void test_midi_sets_volume_of_special_mode_ch3_operator(UNUSED void** state) { for (u8 op = 0; op < 3; op++) { int midiChannel = 10 + op; @@ -620,7 +621,7 @@ static void test_midi_sets_volume_of_special_mode_ch3_operator(UNUSED void** sta } } -static void test_midi_pitch_bends_special_mode_operator(UNUSED void** state) +void test_midi_pitch_bends_special_mode_operator(UNUSED void** state) { int chan = 10; @@ -637,7 +638,7 @@ static void test_midi_pitch_bends_special_mode_operator(UNUSED void** state) __real_midi_pitch_bend(chan, 0x6000); } -static void test_midi_pitch_bends_special_mode_op_independent_of_other_ops(UNUSED void** state) +void test_midi_pitch_bends_special_mode_op_independent_of_other_ops(UNUSED void** state) { expect_value(__wrap_synth_specialModePitch, op, 0); expect_value(__wrap_synth_specialModePitch, octave, 4); @@ -659,7 +660,7 @@ static void test_midi_pitch_bends_special_mode_op_independent_of_other_ops(UNUSE __real_midi_note_on(11, MIDI_PITCH_C4, MAX_MIDI_VOLUME); } -static void test_midi_persists_pitch_bends_for_special_mode_op_between_notes(UNUSED void** state) +void test_midi_persists_pitch_bends_for_special_mode_op_between_notes(UNUSED void** state) { int chan = 10; @@ -683,7 +684,7 @@ static void test_midi_persists_pitch_bends_for_special_mode_op_between_notes(UNU __real_midi_note_on(chan, MIDI_PITCH_C4, MAX_MIDI_VOLUME); } -static void test_midi_note_priority_respected_for_multiple_notes(UNUSED void** state) +void test_midi_note_priority_respected_for_multiple_notes(UNUSED void** state) { expect_synth_pitch(0, 4, 0x284); expect_synth_volume_any(); @@ -713,7 +714,7 @@ static void test_midi_note_priority_respected_for_multiple_notes(UNUSED void** s #define NOTE_PRIORITY_LENGTH 10 -static void test_midi_drops_note_when_note_priority_stack_full(UNUSED void** state) +void test_midi_drops_note_when_note_priority_stack_full(UNUSED void** state) { const u16 expectedFreqNum[NOTE_PRIORITY_LENGTH] = { 0x25f, 0x284, 0x2a9, 0x2d2, 0x2fd, 0x32a, 0x35a, 0x38e, 0x3c4, 0x3fd }; diff --git a/tests/unit/test_midi_fm.h b/tests/unit/test_midi_fm.h new file mode 100644 index 0000000..9bd11b9 --- /dev/null +++ b/tests/unit/test_midi_fm.h @@ -0,0 +1,51 @@ +#include "cmocka_inc.h" + +void test_midi_triggers_synth_note_on(UNUSED void** state); +void test_midi_triggers_synth_note_on_with_velocity(UNUSED void** state); +void test_midi_triggers_synth_note_on_with_velocity_and_channel_volume(UNUSED void** state); +void test_midi_changing_volume_during_note_on_respects_velocity(UNUSED void** state); +void test_midi_triggers_synth_note_on_boundary_values(UNUSED void** state); +void test_midi_does_not_trigger_synth_note_on_out_of_bound_values(UNUSED void** state); +void test_midi_triggers_synth_note_off(UNUSED void** state); +void test_midi_triggers_synth_note_off_when_note_on_has_zero_velocity(UNUSED void** state); +void test_midi_triggers_synth_note_on_2(UNUSED void** state); +void test_midi_channel_volume_sets_volume(UNUSED void** state); +void test_midi_pan_sets_synth_stereo_mode_right(UNUSED void** state); +void test_midi_pan_sets_synth_stereo_mode_left(UNUSED void** state); +void test_midi_pan_sets_synth_stereo_mode_centre(UNUSED void** state); +void test_midi_sets_fm_algorithm(UNUSED void** state); +void test_midi_sets_fm_feedback(UNUSED void** state); +void test_midi_sets_channel_AMS(UNUSED void** state); +void test_midi_sets_channel_FMS(UNUSED void** state); +void test_midi_sets_operator_total_level(UNUSED void** state); +void test_midi_sets_operator_multiple(UNUSED void** state); +void test_midi_sets_operator_detune(UNUSED void** state); +void test_midi_sets_operator_rate_scaling(UNUSED void** state); +void test_midi_sets_operator_attack_rate(UNUSED void** state); +void test_midi_sets_operator_decay_rate(UNUSED void** state); +void test_midi_sets_operator_sustain_rate(UNUSED void** state); +void test_midi_sets_operator_sustain_level(UNUSED void** state); +void test_midi_sets_operator_amplitude_modulation(UNUSED void** state); +void test_midi_sets_operator_release_rate(UNUSED void** state); +void test_midi_sets_operator_ssg_eg(UNUSED void** state); +void test_midi_sets_genmdm_stereo_mode(UNUSED void** state); +void test_midi_sets_global_LFO_enable(UNUSED void** state); +void test_midi_sets_global_LFO_frequency(UNUSED void** state); +void test_midi_sets_fm_preset(UNUSED void** state); +void test_midi_sets_synth_pitch_bend(UNUSED void** state); +void test_midi_sets_synth_pitch_bend_before_note_on(UNUSED void** state); +void test_midi_pitch_bends_down_an_octave(UNUSED void** state); +void test_midi_pitch_bends_up_an_octave(UNUSED void** state); +void test_midi_pitch_bends_up_an_octave_upper_freq_limit(UNUSED void** state); +void test_midi_persists_pitch_bend_between_notes(UNUSED void** state); +void test_midi_fm_note_on_percussion_channel_sets_percussion_preset(UNUSED void** state); +void test_midi_switching_program_retains_pan_setting(UNUSED void** state); +void test_midi_enables_fm_special_mode(UNUSED void** state); +void test_midi_disables_fm_special_mode(UNUSED void** state); +void test_midi_sets_pitch_of_special_mode_ch3_operator(UNUSED void** state); +void test_midi_sets_volume_of_special_mode_ch3_operator(UNUSED void** state); +void test_midi_pitch_bends_special_mode_operator(UNUSED void** state); +void test_midi_pitch_bends_special_mode_op_independent_of_other_ops(UNUSED void** state); +void test_midi_persists_pitch_bends_for_special_mode_op_between_notes(UNUSED void** state); +void test_midi_note_priority_respected_for_multiple_notes(UNUSED void** state); +void test_midi_drops_note_when_note_priority_stack_full(UNUSED void** state); diff --git a/tests/unit/test_midi_polyphony.c b/tests/unit/test_midi_polyphony.c index 909ae6a..7fb9858 100644 --- a/tests/unit/test_midi_polyphony.c +++ b/tests/unit/test_midi_polyphony.c @@ -1,6 +1,7 @@ +#include "test_midi_polyphony.h" #include "test_midi.h" -static void test_midi_polyphonic_mode_sends_CCs_to_all_FM_channels(UNUSED void** state) +void test_midi_polyphonic_mode_sends_CCs_to_all_FM_channels(UNUSED void** state) { __real_midi_cc(0, CC_GENMDM_POLYPHONIC_MODE, 127); @@ -19,7 +20,7 @@ static void test_midi_polyphonic_mode_sends_CCs_to_all_FM_channels(UNUSED void** __real_midi_cc(0, CC_GENMDM_FM_ALGORITHM, 16); } -static void test_midi_set_overflow_flag_on_polyphony_breach(UNUSED void** state) +void test_midi_set_overflow_flag_on_polyphony_breach(UNUSED void** state) { wraps_enable_logging_checks(); __real_midi_cc(0, CC_GENMDM_POLYPHONIC_MODE, 127); @@ -40,7 +41,7 @@ static void test_midi_set_overflow_flag_on_polyphony_breach(UNUSED void** state) __real_midi_note_on(DEV_CHAN_MAX_PSG + 1, MIDI_PITCH_AS6, 127); } -static void test_midi_polyphonic_mode_uses_multiple_fm_channels(UNUSED void** state) +void test_midi_polyphonic_mode_uses_multiple_fm_channels(UNUSED void** state) { __real_midi_cc(0, CC_GENMDM_POLYPHONIC_MODE, 127); @@ -69,7 +70,7 @@ static void test_midi_polyphonic_mode_uses_multiple_fm_channels(UNUSED void** st __real_midi_cc(0, CC_GENMDM_POLYPHONIC_MODE, 0); } -static void test_midi_polyphonic_mode_note_off_silences_all_matching_pitch(UNUSED void** state) +void test_midi_polyphonic_mode_note_off_silences_all_matching_pitch(UNUSED void** state) { __real_midi_cc(0, CC_GENMDM_POLYPHONIC_MODE, 127); @@ -95,7 +96,7 @@ static void test_midi_polyphonic_mode_note_off_silences_all_matching_pitch(UNUSE __real_midi_cc(0, CC_GENMDM_POLYPHONIC_MODE, 0); } -static void test_midi_sets_all_notes_off_in_polyphonic_mode(UNUSED void** state) +void test_midi_sets_all_notes_off_in_polyphonic_mode(UNUSED void** state) { __real_midi_cc(0, CC_GENMDM_POLYPHONIC_MODE, 64); @@ -127,21 +128,21 @@ static void test_midi_sets_all_notes_off_in_polyphonic_mode(UNUSED void** state) __real_midi_cc(0, CC_GENMDM_POLYPHONIC_MODE, 0); } -static void test_midi_sets_polyphonic_mode(UNUSED void** state) +void test_midi_sets_polyphonic_mode(UNUSED void** state) { __real_midi_cc(0, CC_GENMDM_POLYPHONIC_MODE, 64); assert_true(__real_midi_dynamic_mode()); } -static void test_midi_unsets_polyphonic_mode(UNUSED void** state) +void test_midi_unsets_polyphonic_mode(UNUSED void** state) { __real_midi_cc(0, CC_GENMDM_POLYPHONIC_MODE, 0); assert_false(__real_midi_dynamic_mode()); } -static void test_midi_sets_all_channel_mappings_when_setting_polyphonic_mode(UNUSED void** state) +void test_midi_sets_all_channel_mappings_when_setting_polyphonic_mode(UNUSED void** state) { __real_midi_cc(0, CC_GENMDM_POLYPHONIC_MODE, 64); diff --git a/tests/unit/test_midi_polyphony.h b/tests/unit/test_midi_polyphony.h new file mode 100644 index 0000000..c5ef4f3 --- /dev/null +++ b/tests/unit/test_midi_polyphony.h @@ -0,0 +1,10 @@ +#include "cmocka_inc.h" + +void test_midi_polyphonic_mode_sends_CCs_to_all_FM_channels(UNUSED void** state); +void test_midi_set_overflow_flag_on_polyphony_breach(UNUSED void** state); +void test_midi_polyphonic_mode_uses_multiple_fm_channels(UNUSED void** state); +void test_midi_polyphonic_mode_note_off_silences_all_matching_pitch(UNUSED void** state); +void test_midi_sets_all_notes_off_in_polyphonic_mode(UNUSED void** state); +void test_midi_sets_polyphonic_mode(UNUSED void** state); +void test_midi_unsets_polyphonic_mode(UNUSED void** state); +void test_midi_sets_all_channel_mappings_when_setting_polyphonic_mode(UNUSED void** state); diff --git a/tests/unit/test_midi_portamento.c b/tests/unit/test_midi_portamento.c index 6814118..e970ccf 100644 --- a/tests/unit/test_midi_portamento.c +++ b/tests/unit/test_midi_portamento.c @@ -1,6 +1,7 @@ +#include "test_midi_portamento.h" #include "test_midi.h" -static int test_midi_portamento_setup(UNUSED void** state) +int test_midi_portamento_setup(UNUSED void** state) { test_midi_setup(state); @@ -10,7 +11,7 @@ static int test_midi_portamento_setup(UNUSED void** state) return 0; } -static void test_midi_portamento_glides_note_up(UNUSED void** state) +void test_midi_portamento_glides_note_up(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { debug_message("channel %d\n", chan); @@ -37,7 +38,7 @@ static void test_midi_portamento_glides_note_up(UNUSED void** state) } } -static void test_midi_portamento_glides_note_down(UNUSED void** state) +void test_midi_portamento_glides_note_down(UNUSED void** state) { __real_midi_cc(0, CC_PORTAMENTO_ENABLE, 127); @@ -62,7 +63,7 @@ static void test_midi_portamento_glides_note_down(UNUSED void** state) midi_tick(); } -static void test_midi_portamento_glides_note_up_and_down_on_early_release(UNUSED void** state) +void test_midi_portamento_glides_note_up_and_down_on_early_release(UNUSED void** state) { u8 chan = 0; debug_message("channel %d\n", chan); @@ -95,7 +96,7 @@ static void test_midi_portamento_glides_note_up_and_down_on_early_release(UNUSED midi_tick(); } -static void test_midi_portamento_glide_ignores_unassigned_channels(UNUSED void** state) +void test_midi_portamento_glide_ignores_unassigned_channels(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { debug_message("channel %d\n", chan); @@ -112,7 +113,7 @@ static void test_midi_portamento_glide_ignores_unassigned_channels(UNUSED void** } } -static void test_midi_portamento_glides_note_up_down_and_back_up(UNUSED void** state) +void test_midi_portamento_glides_note_up_down_and_back_up(UNUSED void** state) { u8 chan = 0; debug_message("channel %d\n", chan); @@ -153,7 +154,7 @@ static void test_midi_portamento_glides_note_up_down_and_back_up(UNUSED void** s midi_tick(); } -static void test_midi_portamento_glides_only_if_target_set(UNUSED void** state) +void test_midi_portamento_glides_only_if_target_set(UNUSED void** state) { u8 chan = 0; debug_message("channel %d\n", chan); @@ -168,7 +169,7 @@ static void test_midi_portamento_glides_only_if_target_set(UNUSED void** state) midi_tick(); } -static void test_midi_portamento_glide_ends_after_both_notes_off(UNUSED void** state) +void test_midi_portamento_glide_ends_after_both_notes_off(UNUSED void** state) { u8 chan = 0; debug_message("channel %d\n", chan); @@ -209,7 +210,7 @@ static void test_midi_portamento_glide_ends_after_both_notes_off(UNUSED void** s midi_tick(); } -static void test_midi_portamento_glides_fully_up_and_down(UNUSED void** state) +void test_midi_portamento_glides_fully_up_and_down(UNUSED void** state) { u8 chan = 0; debug_message("channel %d\n", chan); @@ -240,7 +241,7 @@ static void test_midi_portamento_glides_fully_up_and_down(UNUSED void** state) midi_tick(); } -static void test_midi_portamento_synth_note_off_triggered(UNUSED void** state) +void test_midi_portamento_synth_note_off_triggered(UNUSED void** state) { u8 chan = 0; debug_message("channel %d\n", chan); @@ -259,7 +260,7 @@ static void test_midi_portamento_synth_note_off_triggered(UNUSED void** state) midi_tick(); } -static void test_midi_portamento_zeros_any_residual_cents(UNUSED void** state) +void test_midi_portamento_zeros_any_residual_cents(UNUSED void** state) { const u8 chan = 0; debug_message("channel %d\n", chan); @@ -294,7 +295,7 @@ static void test_midi_portamento_zeros_any_residual_cents(UNUSED void** state) midi_tick(); } -static void test_midi_portamento_glides_note_up_for_psg(UNUSED void** state) +void test_midi_portamento_glides_note_up_for_psg(UNUSED void** state) { for (u8 chan = MIN_PSG_CHAN; chan <= MAX_PSG_CHAN; chan++) { debug_message("channel %d\n", chan); @@ -322,7 +323,7 @@ static void test_midi_portamento_glides_note_up_for_psg(UNUSED void** state) } } -static void test_midi_portamento_glides_note_up_with_pitch_bend(UNUSED void** state) +void test_midi_portamento_glides_note_up_with_pitch_bend(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { debug_message("channel %d\n", chan); @@ -353,7 +354,7 @@ static void test_midi_portamento_glides_note_up_with_pitch_bend(UNUSED void** st } } -static void test_midi_portamento_glides_note_down_with_pitch_bend(UNUSED void** state) +void test_midi_portamento_glides_note_down_with_pitch_bend(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { debug_message("channel %d\n", chan); @@ -384,7 +385,7 @@ static void test_midi_portamento_glides_note_down_with_pitch_bend(UNUSED void** } } -static void test_midi_portamento_sets_portamento_time_to_minimum(UNUSED void** state) +void test_midi_portamento_sets_portamento_time_to_minimum(UNUSED void** state) { const u8 chan = 0; __real_midi_cc(chan, CC_PORTAMENTO_ENABLE, 127); @@ -405,7 +406,7 @@ static void test_midi_portamento_sets_portamento_time_to_minimum(UNUSED void** s midi_tick(); } -static void test_midi_portamento_sets_portamento_time_to_maximum(UNUSED void** state) +void test_midi_portamento_sets_portamento_time_to_maximum(UNUSED void** state) { const u8 chan = 0; __real_midi_cc(chan, CC_PORTAMENTO_ENABLE, 127); @@ -424,7 +425,7 @@ static void test_midi_portamento_sets_portamento_time_to_maximum(UNUSED void** s midi_tick(); } -static void test_midi_portamento_default_portamento_time_set(UNUSED void** state) +void test_midi_portamento_default_portamento_time_set(UNUSED void** state) { wraps_disable_checks(); __real_midi_reset(); @@ -443,7 +444,7 @@ static void test_midi_portamento_default_portamento_time_set(UNUSED void** state midi_tick(); } -static void test_midi_portamento_glides_with_fine_tune(UNUSED void** state) +void test_midi_portamento_glides_with_fine_tune(UNUSED void** state) { const u8 chan = 0; __real_midi_cc(chan, CC_PORTAMENTO_ENABLE, 127); diff --git a/tests/unit/test_midi_portamento.h b/tests/unit/test_midi_portamento.h new file mode 100644 index 0000000..892e0c2 --- /dev/null +++ b/tests/unit/test_midi_portamento.h @@ -0,0 +1,20 @@ +#include "cmocka_inc.h" + +int test_midi_portamento_setup(UNUSED void** state); +void test_midi_portamento_glides_note_up(UNUSED void** state); +void test_midi_portamento_glides_note_down(UNUSED void** state); +void test_midi_portamento_glides_note_up_and_down_on_early_release(UNUSED void** state); +void test_midi_portamento_glide_ignores_unassigned_channels(UNUSED void** state); +void test_midi_portamento_glides_note_up_down_and_back_up(UNUSED void** state); +void test_midi_portamento_glides_only_if_target_set(UNUSED void** state); +void test_midi_portamento_glide_ends_after_both_notes_off(UNUSED void** state); +void test_midi_portamento_glides_fully_up_and_down(UNUSED void** state); +void test_midi_portamento_synth_note_off_triggered(UNUSED void** state); +void test_midi_portamento_zeros_any_residual_cents(UNUSED void** state); +void test_midi_portamento_glides_note_up_for_psg(UNUSED void** state); +void test_midi_portamento_glides_note_up_with_pitch_bend(UNUSED void** state); +void test_midi_portamento_glides_note_down_with_pitch_bend(UNUSED void** state); +void test_midi_portamento_sets_portamento_time_to_minimum(UNUSED void** state); +void test_midi_portamento_sets_portamento_time_to_maximum(UNUSED void** state); +void test_midi_portamento_default_portamento_time_set(UNUSED void** state); +void test_midi_portamento_glides_with_fine_tune(UNUSED void** state); diff --git a/tests/unit/test_midi_psg.c b/tests/unit/test_midi_psg.c index 4367fe9..ce5f32d 100644 --- a/tests/unit/test_midi_psg.c +++ b/tests/unit/test_midi_psg.c @@ -1,6 +1,7 @@ +#include "test_midi_psg.h" #include "test_midi.h" -static void test_midi_triggers_psg_note_on(UNUSED void** state) +void test_midi_triggers_psg_note_on(UNUSED void** state) { const u8 midiKeys[] = { 45, 69, 108 }; const u16 tones[] = { 1016, 254, 26 }; @@ -22,7 +23,7 @@ static void test_midi_triggers_psg_note_on(UNUSED void** state) } } -static void test_midi_uses_PAL_tones_if_system_is_in_that_region(UNUSED void** state) +void test_midi_uses_PAL_tones_if_system_is_in_that_region(UNUSED void** state) { u8 chan = MIN_PSG_CHAN; u8 expectedPsgChan = chan - MIN_PSG_CHAN; @@ -37,7 +38,7 @@ static void test_midi_uses_PAL_tones_if_system_is_in_that_region(UNUSED void** s __real_midi_note_on(chan, MIDI_PITCH_C4, MAX_MIDI_VOLUME); } -static void test_midi_triggers_psg_note_on_with_velocity(UNUSED void** state) +void test_midi_triggers_psg_note_on_with_velocity(UNUSED void** state) { u8 chan = MIN_PSG_CHAN; u8 expectedPsgChan = chan - MIN_PSG_CHAN; @@ -48,7 +49,7 @@ static void test_midi_triggers_psg_note_on_with_velocity(UNUSED void** state) __real_midi_note_on(chan, MIDI_PITCH_C4, MAX_MIDI_VOLUME / 2); } -static void test_midi_triggers_psg_note_on_with_velocity_and_channel_volume(UNUSED void** state) +void test_midi_triggers_psg_note_on_with_velocity_and_channel_volume(UNUSED void** state) { u8 chan = MIN_PSG_CHAN; u8 expectedPsgChan = chan - MIN_PSG_CHAN; @@ -61,7 +62,7 @@ static void test_midi_triggers_psg_note_on_with_velocity_and_channel_volume(UNUS __real_midi_note_on(chan, MIDI_PITCH_C4, MAX_MIDI_VOLUME / 2); } -static void test_midi_changing_volume_during_psg_note_on_respects_velocity(UNUSED void** state) +void test_midi_changing_volume_during_psg_note_on_respects_velocity(UNUSED void** state) { u8 chan = MIN_PSG_CHAN; u8 expectedPsgChan = chan - MIN_PSG_CHAN; @@ -76,7 +77,7 @@ static void test_midi_changing_volume_during_psg_note_on_respects_velocity(UNUSE __real_midi_cc(chan, CC_VOLUME, MAX_MIDI_VOLUME / 2); } -static void test_midi_triggers_psg_note_off(UNUSED void** state) +void test_midi_triggers_psg_note_off(UNUSED void** state) { for (u8 chan = MIN_PSG_CHAN; chan <= MAX_PSG_CHAN; chan++) { u8 expectedPsgChan = chan - MIN_PSG_CHAN; @@ -93,7 +94,7 @@ static void test_midi_triggers_psg_note_off(UNUSED void** state) } } -static void test_midi_drops_psg_key_below_45(UNUSED void** state) +void test_midi_drops_psg_key_below_45(UNUSED void** state) { for (u8 chan = MIN_PSG_CHAN; chan <= MAX_PSG_CHAN; chan++) { @@ -102,7 +103,7 @@ static void test_midi_drops_psg_key_below_45(UNUSED void** state) } } -static void test_midi_triggers_psg_note_off_and_volume_change_does_not_cause_psg_channel_to_play( +void test_midi_triggers_psg_note_off_and_volume_change_does_not_cause_psg_channel_to_play( UNUSED void** state) { u8 midiKey = MIDI_PITCH_C4; @@ -120,7 +121,7 @@ static void test_midi_triggers_psg_note_off_and_volume_change_does_not_cause_psg } } -static void test_midi_psg_note_off_only_triggered_if_specific_note_is_on(UNUSED void** state) +void test_midi_psg_note_off_only_triggered_if_specific_note_is_on(UNUSED void** state) { u8 chan = MIN_PSG_CHAN; @@ -134,7 +135,7 @@ static void test_midi_psg_note_off_only_triggered_if_specific_note_is_on(UNUSED __real_midi_note_off(chan, MIDI_PITCH_C4); } -static void test_midi_channel_volume_sets_psg_attenuation(UNUSED void** state) +void test_midi_channel_volume_sets_psg_attenuation(UNUSED void** state) { __real_midi_cc(MIN_PSG_CHAN, CC_VOLUME, 96); @@ -144,7 +145,7 @@ static void test_midi_channel_volume_sets_psg_attenuation(UNUSED void** state) __real_midi_note_on(MIN_PSG_CHAN, MIDI_PITCH_A2, MAX_MIDI_VOLUME); } -static void test_midi_channel_volume_sets_psg_attenuation_2(UNUSED void** state) +void test_midi_channel_volume_sets_psg_attenuation_2(UNUSED void** state) { __real_midi_cc(MIN_PSG_CHAN, CC_VOLUME, MAX_MIDI_VOLUME); @@ -154,7 +155,7 @@ static void test_midi_channel_volume_sets_psg_attenuation_2(UNUSED void** state) __real_midi_note_on(MIN_PSG_CHAN, MIDI_PITCH_A2, MAX_MIDI_VOLUME); } -static void test_midi_sets_psg_pitch_bend_down(UNUSED void** state) +void test_midi_sets_psg_pitch_bend_down(UNUSED void** state) { for (int chan = MIN_PSG_CHAN; chan <= MAX_PSG_CHAN; chan++) { u8 expectedPsgChan = chan - MIN_PSG_CHAN; @@ -167,7 +168,7 @@ static void test_midi_sets_psg_pitch_bend_down(UNUSED void** state) } } -static void test_midi_sets_psg_pitch_bend_up(UNUSED void** state) +void test_midi_sets_psg_pitch_bend_up(UNUSED void** state) { for (int chan = MIN_PSG_CHAN; chan <= MAX_PSG_CHAN; chan++) { u8 expectedPsgChan = chan - MIN_PSG_CHAN; @@ -180,7 +181,7 @@ static void test_midi_sets_psg_pitch_bend_up(UNUSED void** state) } } -static void test_midi_psg_pitch_bend_persists_after_tick(UNUSED void** state) +void test_midi_psg_pitch_bend_persists_after_tick(UNUSED void** state) { for (int chan = MIN_PSG_CHAN; chan <= MAX_PSG_CHAN; chan++) { debug_message("channel %d\n", chan); @@ -205,7 +206,7 @@ static void test_midi_psg_pitch_bend_persists_after_tick(UNUSED void** state) } } -static void test_midi_plays_psg_envelope(UNUSED void** state) +void test_midi_plays_psg_envelope(UNUSED void** state) { u8 pitch = MIDI_PITCH_C4; for (int chan = MIN_PSG_CHAN; chan <= MAX_PSG_CHAN; chan++) { @@ -224,7 +225,7 @@ static void test_midi_plays_psg_envelope(UNUSED void** state) } } -static void test_midi_plays_advanced_psg_envelope(UNUSED void** state) +void test_midi_plays_advanced_psg_envelope(UNUSED void** state) { u8 chan = MIN_PSG_CHAN; u8 expectedPsgChan = 0; @@ -242,7 +243,7 @@ static void test_midi_plays_advanced_psg_envelope(UNUSED void** state) __real_midi_psg_tick(); } -static void test_midi_loops_psg_envelope(UNUSED void** state) +void test_midi_loops_psg_envelope(UNUSED void** state) { u8 chan = MIN_PSG_CHAN; u8 expectedPsgChan = 0; @@ -263,7 +264,7 @@ static void test_midi_loops_psg_envelope(UNUSED void** state) __real_midi_psg_tick(); } -static void test_midi_psg_envelope_with_only_end_flag_is_silent(UNUSED void** state) +void test_midi_psg_envelope_with_only_end_flag_is_silent(UNUSED void** state) { u8 chan = MIN_PSG_CHAN; @@ -273,8 +274,7 @@ static void test_midi_psg_envelope_with_only_end_flag_is_silent(UNUSED void** st __real_midi_psg_tick(); } -static void test_midi_psg_envelope_with_loop_end_continues_playing_after_note_off( - UNUSED void** state) +void test_midi_psg_envelope_with_loop_end_continues_playing_after_note_off(UNUSED void** state) { u8 chan = MIN_PSG_CHAN; u8 expectedPsgChan = 0; @@ -295,7 +295,7 @@ static void test_midi_psg_envelope_with_loop_end_continues_playing_after_note_of __real_midi_psg_tick(); } -static void test_midi_psg_envelope_with_loop_end_resets_release_note_after_note_silenced( +void test_midi_psg_envelope_with_loop_end_resets_release_note_after_note_silenced( UNUSED void** state) { u8 chan = MIN_PSG_CHAN; @@ -325,7 +325,7 @@ static void test_midi_psg_envelope_with_loop_end_resets_release_note_after_note_ #define SHIFTS 14 -static void test_midi_shifts_semitone_in_psg_envelope(UNUSED void** state) +void test_midi_shifts_semitone_in_psg_envelope(UNUSED void** state) { u8 chan = MIN_PSG_CHAN; u8 expectedPsgChan = 0; @@ -357,7 +357,7 @@ static void test_midi_shifts_semitone_in_psg_envelope(UNUSED void** state) } } -static void test_midi_pitch_shift_handles_upper_limit_psg_envelope(UNUSED void** state) +void test_midi_pitch_shift_handles_upper_limit_psg_envelope(UNUSED void** state) { const u8 chan = MIN_PSG_CHAN; const u8 expectedPsgChan = 0; @@ -376,7 +376,7 @@ static void test_midi_pitch_shift_handles_upper_limit_psg_envelope(UNUSED void** __real_midi_psg_tick(); } -static void test_midi_pitch_shift_handles_lower_limit_psg_envelope(UNUSED void** state) +void test_midi_pitch_shift_handles_lower_limit_psg_envelope(UNUSED void** state) { const u8 chan = MIN_PSG_CHAN; const u8 expectedPsgChan = 0; @@ -395,7 +395,7 @@ static void test_midi_pitch_shift_handles_lower_limit_psg_envelope(UNUSED void** __real_midi_psg_tick(); } -static void test_midi_loads_psg_envelope(UNUSED void** state) +void test_midi_loads_psg_envelope(UNUSED void** state) { const u8 chan = MIN_PSG_CHAN; const u8 eef[] = { 0x66, EEF_END }; @@ -410,7 +410,7 @@ static void test_midi_loads_psg_envelope(UNUSED void** state) __real_midi_psg_tick(); } -static void test_midi_psg_sets_busy_indicators(UNUSED void** state) +void test_midi_psg_sets_busy_indicators(UNUSED void** state) { for (u8 chan = 0; chan < MAX_PSG_CHANS; chan++) { expect_psg_tone(chan, TONE_NTSC_C4); diff --git a/tests/unit/test_midi_psg.h b/tests/unit/test_midi_psg.h new file mode 100644 index 0000000..99be2a3 --- /dev/null +++ b/tests/unit/test_midi_psg.h @@ -0,0 +1,29 @@ +#include "cmocka_inc.h" + +void test_midi_triggers_psg_note_on(UNUSED void** state); +void test_midi_uses_PAL_tones_if_system_is_in_that_region(UNUSED void** state); +void test_midi_triggers_psg_note_on_with_velocity(UNUSED void** state); +void test_midi_triggers_psg_note_on_with_velocity_and_channel_volume(UNUSED void** state); +void test_midi_changing_volume_during_psg_note_on_respects_velocity(UNUSED void** state); +void test_midi_triggers_psg_note_off(UNUSED void** state); +void test_midi_drops_psg_key_below_45(UNUSED void** state); +void test_midi_triggers_psg_note_off_and_volume_change_does_not_cause_psg_channel_to_play( + UNUSED void** state); +void test_midi_psg_note_off_only_triggered_if_specific_note_is_on(UNUSED void** state); +void test_midi_channel_volume_sets_psg_attenuation(UNUSED void** state); +void test_midi_channel_volume_sets_psg_attenuation_2(UNUSED void** state); +void test_midi_sets_psg_pitch_bend_down(UNUSED void** state); +void test_midi_sets_psg_pitch_bend_up(UNUSED void** state); +void test_midi_psg_pitch_bend_persists_after_tick(UNUSED void** state); +void test_midi_plays_psg_envelope(UNUSED void** state); +void test_midi_plays_advanced_psg_envelope(UNUSED void** state); +void test_midi_loops_psg_envelope(UNUSED void** state); +void test_midi_psg_envelope_with_only_end_flag_is_silent(UNUSED void** state); +void test_midi_psg_envelope_with_loop_end_continues_playing_after_note_off(UNUSED void** state); +void test_midi_psg_envelope_with_loop_end_resets_release_note_after_note_silenced( + UNUSED void** state); +void test_midi_shifts_semitone_in_psg_envelope(UNUSED void** state); +void test_midi_pitch_shift_handles_upper_limit_psg_envelope(UNUSED void** state); +void test_midi_pitch_shift_handles_lower_limit_psg_envelope(UNUSED void** state); +void test_midi_loads_psg_envelope(UNUSED void** state); +void test_midi_psg_sets_busy_indicators(UNUSED void** state); diff --git a/tests/unit/test_midi_receiver.c b/tests/unit/test_midi_receiver.c index 5536e37..22900ed 100644 --- a/tests/unit/test_midi_receiver.c +++ b/tests/unit/test_midi_receiver.c @@ -1,4 +1,4 @@ -#include "cmocka_inc.h" +#include "test_midi_receiver.h" #include "midi.h" #include "midi_receiver.h" #include "comm/comm.h" @@ -22,18 +22,18 @@ static void init(void) midi_receiver_init(); } -static int test_midi_receiver_setup(UNUSED void** state) +int test_midi_receiver_setup(UNUSED void** state) { init(); return 0; } -static void test_midi_receiver_initialises(UNUSED void** state) +void test_midi_receiver_initialises(UNUSED void** state) { init(); } -static void test_midi_receiver_read_passes_note_on_to_midi_processor(UNUSED void** state) +void test_midi_receiver_read_passes_note_on_to_midi_processor(UNUSED void** state) { const u8 expectedData = 60; const u8 expectedData2 = 127; @@ -51,7 +51,7 @@ static void test_midi_receiver_read_passes_note_on_to_midi_processor(UNUSED void } } -static void test_midi_receiver_read_passes_note_off_to_midi_processor(UNUSED void** state) +void test_midi_receiver_read_passes_note_off_to_midi_processor(UNUSED void** state) { u8 expectedStatus = 0x80; u8 expectedData = 60; @@ -65,7 +65,7 @@ static void test_midi_receiver_read_passes_note_off_to_midi_processor(UNUSED voi midi_receiver_read(); } -static void test_midi_receiver_does_nothing_for_control_change(UNUSED void** state) +void test_midi_receiver_does_nothing_for_control_change(UNUSED void** state) { u8 expectedStatus = 0xA0; u8 expectedData = 106; @@ -78,7 +78,7 @@ static void test_midi_receiver_does_nothing_for_control_change(UNUSED void** sta midi_receiver_read(); } -static void test_midi_receiver_sets_unknown_event_for_unknown_status(UNUSED void** state) +void test_midi_receiver_sets_unknown_event_for_unknown_status(UNUSED void** state) { wraps_enable_logging_checks(); @@ -90,7 +90,7 @@ static void test_midi_receiver_sets_unknown_event_for_unknown_status(UNUSED void midi_receiver_read(); } -static void test_midi_receiver_sets_unknown_event_for_unknown_system_message(UNUSED void** state) +void test_midi_receiver_sets_unknown_event_for_unknown_system_message(UNUSED void** state) { wraps_enable_logging_checks(); @@ -102,7 +102,7 @@ static void test_midi_receiver_sets_unknown_event_for_unknown_system_message(UNU midi_receiver_read(); } -static void test_midi_receiver_sets_CC(UNUSED void** state) +void test_midi_receiver_sets_CC(UNUSED void** state) { u8 expectedStatus = STATUS_CC; u8 expectedController = CC_VOLUME; @@ -117,7 +117,7 @@ static void test_midi_receiver_sets_CC(UNUSED void** state) midi_receiver_read(); } -static void test_midi_receiver_sets_pitch_bend(UNUSED void** state) +void test_midi_receiver_sets_pitch_bend(UNUSED void** state) { u8 expectedStatus = STATUS_PITCH_BEND; u16 expectedValue = 12000; @@ -132,7 +132,7 @@ static void test_midi_receiver_sets_pitch_bend(UNUSED void** state) midi_receiver_read(); } -static void test_midi_receiver_does_nothing_on_midi_clock(UNUSED void** state) +void test_midi_receiver_does_nothing_on_midi_clock(UNUSED void** state) { u8 status = STATUS_CLOCK; will_return(__wrap_comm_read, status); @@ -140,7 +140,7 @@ static void test_midi_receiver_does_nothing_on_midi_clock(UNUSED void** state) midi_receiver_read(); } -static void test_midi_receiver_does_nothing_on_midi_start_midi(UNUSED void** state) +void test_midi_receiver_does_nothing_on_midi_start_midi(UNUSED void** state) { u8 status = STATUS_START; will_return(__wrap_comm_read, status); @@ -148,7 +148,7 @@ static void test_midi_receiver_does_nothing_on_midi_start_midi(UNUSED void** sta midi_receiver_read(); } -static void test_midi_receiver_swallows_midi_stop(UNUSED void** state) +void test_midi_receiver_swallows_midi_stop(UNUSED void** state) { u8 status = STATUS_STOP; will_return(__wrap_comm_read, status); @@ -156,7 +156,7 @@ static void test_midi_receiver_swallows_midi_stop(UNUSED void** state) midi_receiver_read(); } -static void test_midi_receiver_swallows_midi_continue(UNUSED void** state) +void test_midi_receiver_swallows_midi_continue(UNUSED void** state) { u8 status = STATUS_CONTINUE; will_return(__wrap_comm_read, status); @@ -164,7 +164,7 @@ static void test_midi_receiver_swallows_midi_continue(UNUSED void** state) midi_receiver_read(); } -static void test_midi_receiver_does_nothing_on_midi_position(UNUSED void** state) +void test_midi_receiver_does_nothing_on_midi_position(UNUSED void** state) { u8 status = STATUS_SONG_POSITION; @@ -175,7 +175,7 @@ static void test_midi_receiver_does_nothing_on_midi_position(UNUSED void** state midi_receiver_read(); } -static void test_midi_receiver_sets_midi_program(UNUSED void** state) +void test_midi_receiver_sets_midi_program(UNUSED void** state) { u8 status = STATUS_PROGRAM; u8 program = 12; @@ -189,7 +189,7 @@ static void test_midi_receiver_sets_midi_program(UNUSED void** state) midi_receiver_read(); } -static void test_midi_receiver_sends_midi_reset(UNUSED void** state) +void test_midi_receiver_sends_midi_reset(UNUSED void** state) { u8 status = STATUS_RESET; @@ -200,7 +200,7 @@ static void test_midi_receiver_sends_midi_reset(UNUSED void** state) midi_receiver_read(); } -static void test_midi_receiver_sends_sysex_to_midi_layer(UNUSED void** state) +void test_midi_receiver_sends_sysex_to_midi_layer(UNUSED void** state) { const u8 command = 0x12; will_return(__wrap_comm_read, STATUS_SYSEX_START); @@ -215,7 +215,7 @@ static void test_midi_receiver_sends_sysex_to_midi_layer(UNUSED void** state) midi_receiver_read(); } -static void test_midi_receiver_handles_sysex_limits(UNUSED void** state) +void test_midi_receiver_handles_sysex_limits(UNUSED void** state) { const u16 SYSEX_BUFFER_SIZE = 256; const u16 SYSEX_MESSAGE_SIZE = 300; diff --git a/tests/unit/test_midi_receiver.h b/tests/unit/test_midi_receiver.h new file mode 100644 index 0000000..37b7e24 --- /dev/null +++ b/tests/unit/test_midi_receiver.h @@ -0,0 +1,20 @@ +#include "cmocka_inc.h" + +int test_midi_receiver_setup(UNUSED void** state); +void test_midi_receiver_initialises(UNUSED void** state); +void test_midi_receiver_read_passes_note_on_to_midi_processor(UNUSED void** state); +void test_midi_receiver_read_passes_note_off_to_midi_processor(UNUSED void** state); +void test_midi_receiver_does_nothing_for_control_change(UNUSED void** state); +void test_midi_receiver_sets_unknown_event_for_unknown_status(UNUSED void** state); +void test_midi_receiver_sets_unknown_event_for_unknown_system_message(UNUSED void** state); +void test_midi_receiver_sets_CC(UNUSED void** state); +void test_midi_receiver_sets_pitch_bend(UNUSED void** state); +void test_midi_receiver_does_nothing_on_midi_clock(UNUSED void** state); +void test_midi_receiver_does_nothing_on_midi_start_midi(UNUSED void** state); +void test_midi_receiver_swallows_midi_stop(UNUSED void** state); +void test_midi_receiver_swallows_midi_continue(UNUSED void** state); +void test_midi_receiver_does_nothing_on_midi_position(UNUSED void** state); +void test_midi_receiver_sets_midi_program(UNUSED void** state); +void test_midi_receiver_sends_midi_reset(UNUSED void** state); +void test_midi_receiver_sends_sysex_to_midi_layer(UNUSED void** state); +void test_midi_receiver_handles_sysex_limits(UNUSED void** state); diff --git a/tests/unit/test_midi_sysex.c b/tests/unit/test_midi_sysex.c index 00ca1bd..a3fd42e 100644 --- a/tests/unit/test_midi_sysex.c +++ b/tests/unit/test_midi_sysex.c @@ -1,3 +1,4 @@ +#include "test_midi_sysex.h" #include "test_midi.h" static void remapChannel(u8 midiChannel, u8 deviceChannel) @@ -8,7 +9,7 @@ static void remapChannel(u8 midiChannel, u8 deviceChannel) __real_midi_sysex(sequence, sizeof(sequence)); } -static void test_midi_sysex_sends_all_notes_off(UNUSED void** state) +void test_midi_sysex_sends_all_notes_off(UNUSED void** state) { const u8 sysExGeneralMidiResetSequence[] = { 0x7E, 0x7F, 0x09, 0x01 }; @@ -33,7 +34,7 @@ static void test_midi_sysex_sends_all_notes_off(UNUSED void** state) __real_midi_sysex(sysExGeneralMidiResetSequence, sizeof(sysExGeneralMidiResetSequence)); } -static void test_midi_sysex_general_midi_reset_resets_synth_volume(UNUSED void** state) +void test_midi_sysex_general_midi_reset_resets_synth_volume(UNUSED void** state) { const u8 sysExGeneralMidiResetSequence[] = { 0x7E, 0x7F, 0x09, 0x01 }; @@ -54,14 +55,14 @@ static void test_midi_sysex_general_midi_reset_resets_synth_volume(UNUSED void** __real_midi_sysex(sysExGeneralMidiResetSequence, sizeof(sysExGeneralMidiResetSequence)); } -static void test_midi_sysex_ignores_unknown_sysex(UNUSED void** state) +void test_midi_sysex_ignores_unknown_sysex(UNUSED void** state) { const u8 sysExGeneralMidiResetSequence[] = { 0x12 }; __real_midi_sysex(sysExGeneralMidiResetSequence, sizeof(sysExGeneralMidiResetSequence)); } -static void test_midi_sysex_remaps_midi_channel_to_psg(UNUSED void** state) +void test_midi_sysex_remaps_midi_channel_to_psg(UNUSED void** state) { const u8 FM_CHAN_1 = 0; const u8 MIDI_CHAN_1 = 0; @@ -76,7 +77,7 @@ static void test_midi_sysex_remaps_midi_channel_to_psg(UNUSED void** state) __real_midi_note_on(0, MIDI_PITCH_AS6, MAX_MIDI_VOLUME); } -static void test_midi_sysex_remaps_midi_channel_to_fm(UNUSED void** state) +void test_midi_sysex_remaps_midi_channel_to_fm(UNUSED void** state) { const u8 FM_CHAN_2 = 1; const u8 MIDI_CHAN_1 = 0; @@ -94,14 +95,14 @@ static void test_midi_sysex_remaps_midi_channel_to_fm(UNUSED void** state) __real_midi_note_on(0, 60, MAX_MIDI_VOLUME); } -static void test_midi_sysex_unassigns_midi_channel(UNUSED void** state) +void test_midi_sysex_unassigns_midi_channel(UNUSED void** state) { remapChannel(0, 0x7F); __real_midi_note_on(0, 60, MAX_MIDI_VOLUME); } -static void test_midi_sysex_does_nothing_for_empty_payload(UNUSED void** state) +void test_midi_sysex_does_nothing_for_empty_payload(UNUSED void** state) { const u16 length = 0; u8 seq[1]; @@ -109,7 +110,7 @@ static void test_midi_sysex_does_nothing_for_empty_payload(UNUSED void** state) __real_midi_sysex(seq, length); } -static void test_midi_sysex_handles_incomplete_channel_mapping_command(UNUSED void** state) +void test_midi_sysex_handles_incomplete_channel_mapping_command(UNUSED void** state) { const u8 sequence[] = { SYSEX_MANU_EXTENDED, SYSEX_MANU_REGION, SYSEX_MANU_ID, SYSEX_COMMAND_REMAP }; @@ -117,7 +118,7 @@ static void test_midi_sysex_handles_incomplete_channel_mapping_command(UNUSED vo __real_midi_sysex(sequence, 4); } -static void test_midi_sysex_enables_dynamic_channel_mode(UNUSED void** state) +void test_midi_sysex_enables_dynamic_channel_mode(UNUSED void** state) { const u8 sequence[] = { SYSEX_MANU_EXTENDED, @@ -142,7 +143,7 @@ static void test_midi_sysex_enables_dynamic_channel_mode(UNUSED void** state) __real_midi_note_on(0, 61, MAX_MIDI_VOLUME); } -static void test_midi_sysex_sets_mapping_mode_to_auto(UNUSED void** state) +void test_midi_sysex_sets_mapping_mode_to_auto(UNUSED void** state) { const u8 sequence[] = { SYSEX_MANU_EXTENDED, @@ -172,7 +173,7 @@ static void test_midi_sysex_sets_mapping_mode_to_auto(UNUSED void** state) __real_midi_note_on(0, 61, MAX_MIDI_VOLUME); } -static void test_midi_sysex_disables_fm_parameter_CCs(UNUSED void** state) +void test_midi_sysex_disables_fm_parameter_CCs(UNUSED void** state) { const u8 sequence[] = { SYSEX_MANU_EXTENDED, @@ -196,7 +197,7 @@ static void test_midi_sysex_disables_fm_parameter_CCs(UNUSED void** state) } } -static void test_midi_sysex_loads_psg_envelope(UNUSED void** state) +void test_midi_sysex_loads_psg_envelope(UNUSED void** state) { wraps_enable_logging_checks(); @@ -213,7 +214,7 @@ static void test_midi_sysex_loads_psg_envelope(UNUSED void** state) __real_midi_sysex(sequence, sizeof(sequence)); } -static void test_midi_sysex_inverts_total_level_values(UNUSED void** state) +void test_midi_sysex_inverts_total_level_values(UNUSED void** state) { const u8 sequence[] = { SYSEX_MANU_EXTENDED, SYSEX_MANU_REGION, SYSEX_MANU_ID, SYSEX_COMMAND_INVERT_TOTAL_LEVEL, 0x01 }; @@ -226,7 +227,7 @@ static void test_midi_sysex_inverts_total_level_values(UNUSED void** state) __real_midi_cc(0, CC_GENMDM_TOTAL_LEVEL_OP1, 1); } -static void test_midi_sysex_sets_original_total_level_values(UNUSED void** state) +void test_midi_sysex_sets_original_total_level_values(UNUSED void** state) { const u8 invert_sequence[] = { SYSEX_MANU_EXTENDED, SYSEX_MANU_REGION, SYSEX_MANU_ID, SYSEX_COMMAND_INVERT_TOTAL_LEVEL, 0x01 }; @@ -247,7 +248,7 @@ static void test_midi_sysex_sets_original_total_level_values(UNUSED void** state __real_midi_cc(0, CC_GENMDM_TOTAL_LEVEL_OP1, 126); } -static void test_midi_sysex_writes_directly_to_ym2612_regs_part_0(UNUSED void** state) +void test_midi_sysex_writes_directly_to_ym2612_regs_part_0(UNUSED void** state) { const u8 sequence[] = { SYSEX_MANU_EXTENDED, SYSEX_MANU_REGION, SYSEX_MANU_ID, SYSEX_COMMAND_WRITE_YM2612_REG_PART_0, 0x0B, 0x01, 0x01, 0x02 }; @@ -258,7 +259,7 @@ static void test_midi_sysex_writes_directly_to_ym2612_regs_part_0(UNUSED void** __real_midi_sysex(sequence, sizeof(sequence)); } -static void test_midi_sysex_writes_directly_to_ym2612_regs_part_1(UNUSED void** state) +void test_midi_sysex_writes_directly_to_ym2612_regs_part_1(UNUSED void** state) { const u8 sequence[] = { SYSEX_MANU_EXTENDED, SYSEX_MANU_REGION, SYSEX_MANU_ID, SYSEX_COMMAND_WRITE_YM2612_REG_PART_1, 0x0B, 0x01, 0x01, 0x02 }; @@ -269,7 +270,7 @@ static void test_midi_sysex_writes_directly_to_ym2612_regs_part_1(UNUSED void** __real_midi_sysex(sequence, sizeof(sequence)); } -static void test_midi_sysex_ignores_incorrect_length_ym2612_direct_writes(UNUSED void** state) +void test_midi_sysex_ignores_incorrect_length_ym2612_direct_writes(UNUSED void** state) { const u8 badSeq1[] = { SYSEX_MANU_EXTENDED, SYSEX_MANU_REGION, SYSEX_MANU_ID, SYSEX_COMMAND_WRITE_YM2612_REG_PART_0, 0x0B, 0x01, 0x01, 0x02, 0x02 }; diff --git a/tests/unit/test_midi_sysex.h b/tests/unit/test_midi_sysex.h new file mode 100644 index 0000000..f5c231a --- /dev/null +++ b/tests/unit/test_midi_sysex.h @@ -0,0 +1,19 @@ +#include "cmocka_inc.h" + +void test_midi_sysex_sends_all_notes_off(UNUSED void** state); +void test_midi_sysex_general_midi_reset_resets_synth_volume(UNUSED void** state); +void test_midi_sysex_ignores_unknown_sysex(UNUSED void** state); +void test_midi_sysex_remaps_midi_channel_to_psg(UNUSED void** state); +void test_midi_sysex_remaps_midi_channel_to_fm(UNUSED void** state); +void test_midi_sysex_unassigns_midi_channel(UNUSED void** state); +void test_midi_sysex_does_nothing_for_empty_payload(UNUSED void** state); +void test_midi_sysex_handles_incomplete_channel_mapping_command(UNUSED void** state); +void test_midi_sysex_enables_dynamic_channel_mode(UNUSED void** state); +void test_midi_sysex_sets_mapping_mode_to_auto(UNUSED void** state); +void test_midi_sysex_disables_fm_parameter_CCs(UNUSED void** state); +void test_midi_sysex_loads_psg_envelope(UNUSED void** state); +void test_midi_sysex_inverts_total_level_values(UNUSED void** state); +void test_midi_sysex_sets_original_total_level_values(UNUSED void** state); +void test_midi_sysex_writes_directly_to_ym2612_regs_part_0(UNUSED void** state); +void test_midi_sysex_writes_directly_to_ym2612_regs_part_1(UNUSED void** state); +void test_midi_sysex_ignores_incorrect_length_ym2612_direct_writes(UNUSED void** state); diff --git a/tests/unit/test_note_priority.c b/tests/unit/test_note_priority.c index 3d2ade4..a015fae 100644 --- a/tests/unit/test_note_priority.c +++ b/tests/unit/test_note_priority.c @@ -1,16 +1,16 @@ -#include "cmocka_inc.h" +#include "test_note_priority.h" #include "note_priority.h" #include "debug.h" static NotePriorityStack testStack; -static int test_note_priority_setup(UNUSED void** state) +int test_note_priority_setup(UNUSED void** state) { note_priority_init(&testStack); return 0; } -static void test_note_priority_ignores_push_when_full(UNUSED void** state) +void test_note_priority_ignores_push_when_full(UNUSED void** state) { const u16 additive = 50; @@ -31,7 +31,7 @@ static void test_note_priority_ignores_push_when_full(UNUSED void** state) assert_int_equal(nilPop, 0); } -static void test_note_priority_indicates_when_full(UNUSED void** state) +void test_note_priority_indicates_when_full(UNUSED void** state) { for (u16 i = 0; i < NOTE_PRIORITY_LENGTH; i++) { assert_int_equal(note_priority_isFull(&testStack), false); @@ -41,7 +41,7 @@ static void test_note_priority_indicates_when_full(UNUSED void** state) assert_int_equal(note_priority_isFull(&testStack), true); } -static void test_note_priority_returns_size(UNUSED void** state) +void test_note_priority_returns_size(UNUSED void** state) { assert_int_equal(note_priority_count(&testStack), 0); note_priority_push(&testStack, 1); diff --git a/tests/unit/test_note_priority.h b/tests/unit/test_note_priority.h new file mode 100644 index 0000000..a149f20 --- /dev/null +++ b/tests/unit/test_note_priority.h @@ -0,0 +1,6 @@ +#include "cmocka_inc.h" + +int test_note_priority_setup(UNUSED void** state); +void test_note_priority_ignores_push_when_full(UNUSED void** state); +void test_note_priority_indicates_when_full(UNUSED void** state); +void test_note_priority_returns_size(UNUSED void** state); diff --git a/tests/unit/test_pitchcents.c b/tests/unit/test_pitchcents.c index f1c0eed..ece4e5d 100644 --- a/tests/unit/test_pitchcents.c +++ b/tests/unit/test_pitchcents.c @@ -1,6 +1,7 @@ +#include "test_pitchcents.h" #include "test_midi.h" -static void test_pitchcents_shift_extreme_up(UNUSED void** state) +void test_pitchcents_shift_extreme_up(UNUSED void** state) { PitchCents pc = { .pitch = 50, .cents = 99 }; pc = pitchcents_shift(pc, 255); @@ -9,7 +10,7 @@ static void test_pitchcents_shift_extreme_up(UNUSED void** state) assert_int_equal(pc.cents, 54); } -static void test_pitchcents_bend_nil(UNUSED void** state) +void test_pitchcents_bend_nil(UNUSED void** state) { PitchCents pc = pitchcents_bend(50, 0, 0x2000); @@ -17,7 +18,7 @@ static void test_pitchcents_bend_nil(UNUSED void** state) assert_int_equal(pc.cents, 0); } -static void test_pitchcents_bend_down_fully(UNUSED void** state) +void test_pitchcents_bend_down_fully(UNUSED void** state) { PitchCents pc = pitchcents_bend(50, 0, 0); @@ -25,7 +26,7 @@ static void test_pitchcents_bend_down_fully(UNUSED void** state) assert_int_equal(pc.cents, 0); } -static void test_pitchcents_bend_up_fully(UNUSED void** state) +void test_pitchcents_bend_up_fully(UNUSED void** state) { PitchCents pc = pitchcents_bend(50, 0, 0x4000); @@ -33,7 +34,7 @@ static void test_pitchcents_bend_up_fully(UNUSED void** state) assert_int_equal(pc.cents, 0); } -static void test_pitchcents_bend_up(UNUSED void** state) +void test_pitchcents_bend_up(UNUSED void** state) { PitchCents pc = pitchcents_bend(50, 0, 0x3000); @@ -41,7 +42,7 @@ static void test_pitchcents_bend_up(UNUSED void** state) assert_int_equal(pc.cents, 0); } -static void test_pitchcents_bend_down(UNUSED void** state) +void test_pitchcents_bend_down(UNUSED void** state) { PitchCents pc = pitchcents_bend(50, 0, 0x1800); @@ -49,7 +50,7 @@ static void test_pitchcents_bend_down(UNUSED void** state) assert_int_equal(pc.cents, 50); } -static void test_pitchcents_bend_up_2(UNUSED void** state) +void test_pitchcents_bend_up_2(UNUSED void** state) { PitchCents pc = pitchcents_bend(50, 0, 0x2800); @@ -57,7 +58,7 @@ static void test_pitchcents_bend_up_2(UNUSED void** state) assert_int_equal(pc.cents, 50); } -static void test_pitchcents_bend_cents_with_partial_bend_down(UNUSED void** state) +void test_pitchcents_bend_cents_with_partial_bend_down(UNUSED void** state) { PitchCents pc = pitchcents_bend(50, 25, 0x1800); @@ -65,7 +66,7 @@ static void test_pitchcents_bend_cents_with_partial_bend_down(UNUSED void** stat assert_int_equal(pc.cents, 75); } -static void test_pitchcents_bend_high_cents_with_partial_bend_down(UNUSED void** state) +void test_pitchcents_bend_high_cents_with_partial_bend_down(UNUSED void** state) { PitchCents pc = pitchcents_bend(50, 80, 0x1800); @@ -73,7 +74,7 @@ static void test_pitchcents_bend_high_cents_with_partial_bend_down(UNUSED void** assert_int_equal(pc.cents, 30); } -static void test_pitchcents_bend_cents_with_full_bend_up(UNUSED void** state) +void test_pitchcents_bend_cents_with_full_bend_up(UNUSED void** state) { PitchCents pc = pitchcents_bend(50, 25, 0x4000); @@ -81,7 +82,7 @@ static void test_pitchcents_bend_cents_with_full_bend_up(UNUSED void** state) assert_int_equal(pc.cents, 25); } -static void test_pitchcents_bend_high_cents_with_full_bend_up(UNUSED void** state) +void test_pitchcents_bend_high_cents_with_full_bend_up(UNUSED void** state) { PitchCents pc = pitchcents_bend(50, 80, 0x4000); diff --git a/tests/unit/test_pitchcents.h b/tests/unit/test_pitchcents.h new file mode 100644 index 0000000..3b2fa4f --- /dev/null +++ b/tests/unit/test_pitchcents.h @@ -0,0 +1,13 @@ +#include "cmocka_inc.h" + +void test_pitchcents_shift_extreme_up(UNUSED void** state); +void test_pitchcents_bend_nil(UNUSED void** state); +void test_pitchcents_bend_down_fully(UNUSED void** state); +void test_pitchcents_bend_up_fully(UNUSED void** state); +void test_pitchcents_bend_up(UNUSED void** state); +void test_pitchcents_bend_down(UNUSED void** state); +void test_pitchcents_bend_up_2(UNUSED void** state); +void test_pitchcents_bend_cents_with_partial_bend_down(UNUSED void** state); +void test_pitchcents_bend_high_cents_with_partial_bend_down(UNUSED void** state); +void test_pitchcents_bend_cents_with_full_bend_up(UNUSED void** state); +void test_pitchcents_bend_high_cents_with_full_bend_up(UNUSED void** state); diff --git a/tests/unit/test_scheduler.c b/tests/unit/test_scheduler.c index af58a80..4969480 100644 --- a/tests/unit/test_scheduler.c +++ b/tests/unit/test_scheduler.c @@ -1,3 +1,4 @@ +#include "test_scheduler.h" #include "cmocka_inc.h" #include "scheduler.h" @@ -26,19 +27,19 @@ static void dummy_tick_handler_2() function_called(); } -static int test_scheduler_setup(UNUSED void** state) +int test_scheduler_setup(UNUSED void** state) { __real_scheduler_init(); return 0; } -static void test_scheduler_nothing_called_on_vsync(UNUSED void** state) +void test_scheduler_nothing_called_on_vsync(UNUSED void** state) { scheduler_vsync(); } -static void test_scheduler_processes_frame_events_once_after_vsync(UNUSED void** state) +void test_scheduler_processes_frame_events_once_after_vsync(UNUSED void** state) { __real_scheduler_addFrameHandler(*dummy_frame_handler); __real_scheduler_addTickHandler(*dummy_tick_handler); @@ -53,7 +54,7 @@ static void test_scheduler_processes_frame_events_once_after_vsync(UNUSED void** __real_scheduler_tick(); } -static void test_scheduler_registered_frame_handler_called_on_vsync(UNUSED void** state) +void test_scheduler_registered_frame_handler_called_on_vsync(UNUSED void** state) { scheduler_vsync(); @@ -63,7 +64,7 @@ static void test_scheduler_registered_frame_handler_called_on_vsync(UNUSED void* __real_scheduler_tick(); } -static void test_scheduler_multiple_registered_frame_handlers_called_on_vsync(UNUSED void** state) +void test_scheduler_multiple_registered_frame_handlers_called_on_vsync(UNUSED void** state) { scheduler_vsync(); @@ -75,7 +76,7 @@ static void test_scheduler_multiple_registered_frame_handlers_called_on_vsync(UN __real_scheduler_tick(); } -static void test_scheduler_registered_tick_handler_called(UNUSED void** state) +void test_scheduler_registered_tick_handler_called(UNUSED void** state) { __real_scheduler_addTickHandler(*dummy_tick_handler); @@ -83,7 +84,7 @@ static void test_scheduler_registered_tick_handler_called(UNUSED void** state) __real_scheduler_tick(); } -static void test_scheduler_multiple_registered_tick_handlers_called(UNUSED void** state) +void test_scheduler_multiple_registered_tick_handlers_called(UNUSED void** state) { scheduler_vsync(); @@ -95,7 +96,7 @@ static void test_scheduler_multiple_registered_tick_handlers_called(UNUSED void* __real_scheduler_tick(); } -static void test_scheduler_errors_if_too_many_frame_handlers_are_registered(UNUSED void** state) +void test_scheduler_errors_if_too_many_frame_handlers_are_registered(UNUSED void** state) { for (u16 i = 0; i < 6; i++) { __real_scheduler_addFrameHandler(*dummy_frame_handler); @@ -105,7 +106,7 @@ static void test_scheduler_errors_if_too_many_frame_handlers_are_registered(UNUS __real_scheduler_addFrameHandler(*dummy_frame_handler); } -static void test_scheduler_errors_if_too_many_tick_handlers_are_registered(UNUSED void** state) +void test_scheduler_errors_if_too_many_tick_handlers_are_registered(UNUSED void** state) { for (u16 i = 0; i < 3; i++) { __real_scheduler_addTickHandler(*dummy_tick_handler); diff --git a/tests/unit/test_scheduler.h b/tests/unit/test_scheduler.h new file mode 100644 index 0000000..abdefc8 --- /dev/null +++ b/tests/unit/test_scheduler.h @@ -0,0 +1,11 @@ +#include "cmocka_inc.h" + +int test_scheduler_setup(UNUSED void** state); +void test_scheduler_nothing_called_on_vsync(UNUSED void** state); +void test_scheduler_processes_frame_events_once_after_vsync(UNUSED void** state); +void test_scheduler_registered_frame_handler_called_on_vsync(UNUSED void** state); +void test_scheduler_multiple_registered_frame_handlers_called_on_vsync(UNUSED void** state); +void test_scheduler_registered_tick_handler_called(UNUSED void** state); +void test_scheduler_multiple_registered_tick_handlers_called(UNUSED void** state); +void test_scheduler_errors_if_too_many_frame_handlers_are_registered(UNUSED void** state); +void test_scheduler_errors_if_too_many_tick_handlers_are_registered(UNUSED void** state); diff --git a/tests/unit/test_synth.c b/tests/unit/test_synth.c index 9825b45..9b65080 100644 --- a/tests/unit/test_synth.c +++ b/tests/unit/test_synth.c @@ -1,4 +1,4 @@ -#include "cmocka_inc.h" +#include "test_synth.h" #include "synth.h" #include "test_midi.h" #include "z80_ctrl.h" @@ -36,7 +36,7 @@ static void loads_pcm_driver(void) expect_value(__wrap_Z80_loadDriver, waitReady, true); } -static int test_synth_setup(UNUSED void** state) +int test_synth_setup(UNUSED void** state) { updated = false; loads_pcm_driver(); @@ -44,13 +44,13 @@ static int test_synth_setup(UNUSED void** state) return 0; } -static void test_synth_init_sets_initial_registers(UNUSED void** state) +void test_synth_init_sets_initial_registers(UNUSED void** state) { loads_pcm_driver(); set_initial_registers(); } -static void test_synth_sets_note_on_fm_reg_chan_0_to_2(UNUSED void** state) +void test_synth_sets_note_on_fm_reg_chan_0_to_2(UNUSED void** state) { for (u8 chan = 0; chan < 3; chan++) { expect_ym2612_write_reg(0, 0x28, 0xF0 + chan); @@ -58,7 +58,7 @@ static void test_synth_sets_note_on_fm_reg_chan_0_to_2(UNUSED void** state) } } -static void test_synth_sets_note_on_fm_reg_chan_3_to_5(UNUSED void** state) +void test_synth_sets_note_on_fm_reg_chan_3_to_5(UNUSED void** state) { for (u8 chan = 3; chan < MAX_FM_CHANS; chan++) { expect_ym2612_write_reg(0, 0x28, 0xF1 + chan); @@ -66,7 +66,7 @@ static void test_synth_sets_note_on_fm_reg_chan_3_to_5(UNUSED void** state) } } -static void test_synth_sets_note_off_fm_reg_chan_0_to_2(UNUSED void** state) +void test_synth_sets_note_off_fm_reg_chan_0_to_2(UNUSED void** state) { for (u8 chan = 0; chan < 3; chan++) { expect_ym2612_write_reg(0, 0x28, chan); @@ -74,7 +74,7 @@ static void test_synth_sets_note_off_fm_reg_chan_0_to_2(UNUSED void** state) } } -static void test_synth_sets_note_off_fm_reg_chan_3_to_5(UNUSED void** state) +void test_synth_sets_note_off_fm_reg_chan_3_to_5(UNUSED void** state) { for (u8 chan = 3; chan < MAX_FM_CHANS; chan++) { expect_ym2612_write_reg(0, 0x28, 1 + chan); @@ -82,7 +82,7 @@ static void test_synth_sets_note_off_fm_reg_chan_3_to_5(UNUSED void** state) } } -static void test_synth_sets_octave_and_freq_reg_chan(UNUSED void** state) +void test_synth_sets_octave_and_freq_reg_chan(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { expect_ym2612_write_channel(chan, 0xA4, 0x22); @@ -91,7 +91,7 @@ static void test_synth_sets_octave_and_freq_reg_chan(UNUSED void** state) } } -static void test_synth_sets_stereo_ams_and_freq(UNUSED void** state) +void test_synth_sets_stereo_ams_and_freq(UNUSED void** state) { const u8 ams = 1; const u8 fms = 1; @@ -107,7 +107,7 @@ static void test_synth_sets_stereo_ams_and_freq(UNUSED void** state) } } -static void test_synth_sets_algorithm(UNUSED void** state) +void test_synth_sets_algorithm(UNUSED void** state) { const u8 defaultFeedback = 0; const u8 algorithm = 1; @@ -117,7 +117,7 @@ static void test_synth_sets_algorithm(UNUSED void** state) } } -static void test_synth_sets_feedback(UNUSED void** state) +void test_synth_sets_feedback(UNUSED void** state) { const u8 defaultAlgorithm = 0; const u8 feedback = 1; @@ -127,7 +127,7 @@ static void test_synth_sets_feedback(UNUSED void** state) } } -static void test_synth_sets_feedback_and_algorithm(UNUSED void** state) +void test_synth_sets_feedback_and_algorithm(UNUSED void** state) { const u8 baseReg = 0xB0; const u8 defaultFeedback = 0; @@ -145,7 +145,7 @@ static void test_synth_sets_feedback_and_algorithm(UNUSED void** state) } } -static void test_synth_does_not_reset_operator_level_if_equal(UNUSED void** state) +void test_synth_does_not_reset_operator_level_if_equal(UNUSED void** state) { const u8 baseReg = 0x40; const u8 totalLevel = 50; @@ -157,7 +157,7 @@ static void test_synth_does_not_reset_operator_level_if_equal(UNUSED void** stat __real_synth_operatorTotalLevel(chan, op, totalLevel); } -static void test_synth_sets_operator_total_level(UNUSED void** state) +void test_synth_sets_operator_total_level(UNUSED void** state) { const u8 baseReg = 0x40; const u8 totalLevel = 50; @@ -169,7 +169,7 @@ static void test_synth_sets_operator_total_level(UNUSED void** state) } } -static void test_synth_sets_operator_multiple_and_detune(UNUSED void** state) +void test_synth_sets_operator_multiple_and_detune(UNUSED void** state) { const u8 baseReg = 0x30; for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { @@ -186,7 +186,7 @@ static void test_synth_sets_operator_multiple_and_detune(UNUSED void** state) } } -static void test_synth_sets_operator_attack_rate_and_rate_scaling(UNUSED void** state) +void test_synth_sets_operator_attack_rate_and_rate_scaling(UNUSED void** state) { const u8 baseReg = 0x50; for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { @@ -203,7 +203,7 @@ static void test_synth_sets_operator_attack_rate_and_rate_scaling(UNUSED void** } } -static void test_synth_sets_operator_sustain_rate(UNUSED void** state) +void test_synth_sets_operator_sustain_rate(UNUSED void** state) { const u8 baseReg = 0x70; u8 sustainRate = 16; @@ -215,7 +215,7 @@ static void test_synth_sets_operator_sustain_rate(UNUSED void** state) } } -static void test_synth_sets_operator_release_rate_and_sustain_level(UNUSED void** state) +void test_synth_sets_operator_release_rate_and_sustain_level(UNUSED void** state) { const u8 baseReg = 0x80; u8 sustainLevel = 15; @@ -230,7 +230,7 @@ static void test_synth_sets_operator_release_rate_and_sustain_level(UNUSED void* } } -static void test_synth_sets_operator_amplitude_modulation_and_decay_rate(UNUSED void** state) +void test_synth_sets_operator_amplitude_modulation_and_decay_rate(UNUSED void** state) { const u8 baseReg = 0x60; u8 amplitudeModulation = 1; @@ -245,7 +245,7 @@ static void test_synth_sets_operator_amplitude_modulation_and_decay_rate(UNUSED } } -static void test_synth_sets_operator_ssg_eg(UNUSED void** state) +void test_synth_sets_operator_ssg_eg(UNUSED void** state) { const u8 baseReg = 0x90; const u8 ssgEg = 11; @@ -257,7 +257,7 @@ static void test_synth_sets_operator_ssg_eg(UNUSED void** state) } } -static void test_synth_sets_global_LFO_enable_and_frequency(UNUSED void** state) +void test_synth_sets_global_LFO_enable_and_frequency(UNUSED void** state) { const u8 baseReg = 0x22; expect_ym2612_write_reg_any_data(0, baseReg); @@ -266,7 +266,7 @@ static void test_synth_sets_global_LFO_enable_and_frequency(UNUSED void** state) __real_synth_globalLfoFrequency(1); } -static void test_synth_sets_busy_indicators(UNUSED void** state) +void test_synth_sets_busy_indicators(UNUSED void** state) { for (u8 chan = 0; chan < MAX_FM_CHANS; chan += 2) { expect_ym2612_write_reg_any_data(0, 0x28); @@ -276,7 +276,7 @@ static void test_synth_sets_busy_indicators(UNUSED void** state) assert_int_equal(busy, 0b00010101); } -static void test_synth_sets_preset(UNUSED void** state) +void test_synth_sets_preset(UNUSED void** state) { const u8 chan = 0; @@ -318,7 +318,7 @@ static void test_synth_sets_preset(UNUSED void** state) __real_synth_preset(chan, &M_BANK_0_INST_7_CLAVINET); } -static void test_synth_sets_preset_retaining_pan(UNUSED void** state) +void test_synth_sets_preset_retaining_pan(UNUSED void** state) { const u8 chan = 0; @@ -362,7 +362,7 @@ static void test_synth_sets_preset_retaining_pan(UNUSED void** state) __real_synth_preset(chan, &M_BANK_0_INST_7_CLAVINET); } -static void test_synth_applies_volume_modifier_to_output_operators_algorithm_7(UNUSED void** state) +void test_synth_applies_volume_modifier_to_output_operators_algorithm_7(UNUSED void** state) { const u8 algorithm = 7; const u8 totalLevelReg = 0x40; @@ -393,7 +393,7 @@ static void test_synth_applies_volume_modifier_to_output_operators_algorithm_7(U } } -static void test_synth_does_not_apply_volume_if_equal(UNUSED void** state) +void test_synth_does_not_apply_volume_if_equal(UNUSED void** state) { const u8 algorithm = 7; const u8 totalLevelReg = 0x40; @@ -420,8 +420,7 @@ static void test_synth_does_not_apply_volume_if_equal(UNUSED void** state) __real_synth_volume(chan, loudestVolume / 2); } -static void test_synth_applies_volume_modifier_to_output_operators_algorithm_7_quieter( - UNUSED void** state) +void test_synth_applies_volume_modifier_to_output_operators_algorithm_7_quieter(UNUSED void** state) { const u8 algorithm = 7; const u8 totalLevelReg = 0x40; @@ -447,8 +446,7 @@ static void test_synth_applies_volume_modifier_to_output_operators_algorithm_7_q } } -static void test_synth_applies_volume_modifier_to_output_operators_algorithms_0_to_3( - UNUSED void** state) +void test_synth_applies_volume_modifier_to_output_operators_algorithms_0_to_3(UNUSED void** state) { const u8 totalLevelReg = 0x40; const u8 algorithmReg = 0xB0; @@ -473,7 +471,7 @@ static void test_synth_applies_volume_modifier_to_output_operators_algorithms_0_ } } -static void test_synth_applies_volume_modifier_to_output_operators_algorithm_4(UNUSED void** state) +void test_synth_applies_volume_modifier_to_output_operators_algorithm_4(UNUSED void** state) { const u8 totalLevelReg = 0x40; const u8 algorithmReg = 0xB0; @@ -492,8 +490,7 @@ static void test_synth_applies_volume_modifier_to_output_operators_algorithm_4(U } } -static void test_synth_applies_volume_modifier_to_output_operators_algorithms_5_and_6( - UNUSED void** state) +void test_synth_applies_volume_modifier_to_output_operators_algorithms_5_and_6(UNUSED void** state) { const u8 totalLevelReg = 0x40; const u8 algorithmReg = 0xB0; @@ -517,14 +514,14 @@ static void test_synth_applies_volume_modifier_to_output_operators_algorithms_5_ } } -static void test_synth_exposes_fm_channel_parameters(UNUSED void** state) +void test_synth_exposes_fm_channel_parameters(UNUSED void** state) { const FmChannel* chan = __real_synth_channelParameters(0); assert_int_equal(chan->stereo, STEREO_MODE_CENTRE); } -static void test_synth_exposes_global_parameters(UNUSED void** state) +void test_synth_exposes_global_parameters(UNUSED void** state) { const Global* global = __real_synth_globalParameters(); @@ -538,7 +535,7 @@ static void updateCallback(u8 chan, ParameterUpdated parameterUpdated) lastParameterUpdated = parameterUpdated; } -static void test_synth_calls_callback_when_parameter_changes(UNUSED void** state) +void test_synth_calls_callback_when_parameter_changes(UNUSED void** state) { synth_setParameterUpdateCallback(&updateCallback); @@ -553,7 +550,7 @@ static void test_synth_calls_callback_when_parameter_changes(UNUSED void** state assert_int_equal(lastParameterUpdated, Channel); } -static void test_synth_calls_callback_when_lfo_freq_changes(UNUSED void** state) +void test_synth_calls_callback_when_lfo_freq_changes(UNUSED void** state) { synth_setParameterUpdateCallback(&updateCallback); @@ -564,7 +561,7 @@ static void test_synth_calls_callback_when_lfo_freq_changes(UNUSED void** state) assert_int_equal(lastParameterUpdated, Lfo); } -static void test_synth_calls_callback_when_lfo_enable_changes(UNUSED void** state) +void test_synth_calls_callback_when_lfo_enable_changes(UNUSED void** state) { synth_setParameterUpdateCallback(&updateCallback); @@ -575,7 +572,7 @@ static void test_synth_calls_callback_when_lfo_enable_changes(UNUSED void** stat assert_int_equal(lastParameterUpdated, Lfo); } -static void test_synth_calls_callback_when_special_mode_changes(UNUSED void** state) +void test_synth_calls_callback_when_special_mode_changes(UNUSED void** state) { synth_setParameterUpdateCallback(&updateCallback); @@ -586,19 +583,19 @@ static void test_synth_calls_callback_when_special_mode_changes(UNUSED void** st assert_int_equal(lastParameterUpdated, SpecialMode); } -static void test_synth_enables_ch3_special_mode(UNUSED void** state) +void test_synth_enables_ch3_special_mode(UNUSED void** state) { expect_ym2612_write_reg(0, 0x27, 0x40); __real_synth_setSpecialMode(true); } -static void test_synth_disables_ch3_special_mode(UNUSED void** state) +void test_synth_disables_ch3_special_mode(UNUSED void** state) { expect_ym2612_write_reg(0, 0x27, 0); __real_synth_setSpecialMode(false); } -static void test_synth_sets_ch3_special_mode_operator_pitches(UNUSED void** state) +void test_synth_sets_ch3_special_mode_operator_pitches(UNUSED void** state) { const u8 upperRegs[] = { 0xAD, 0xAE, 0xAC }; const u8 lowerRegs[] = { 0xA9, 0xAA, 0xA8 }; @@ -611,7 +608,7 @@ static void test_synth_sets_ch3_special_mode_operator_pitches(UNUSED void** stat } } -static void test_synth_handles_out_of_range_ch3_special_mode_operator(UNUSED void** state) +void test_synth_handles_out_of_range_ch3_special_mode_operator(UNUSED void** state) { const u8 op = 3; // invalid op expect_ym2612_write_reg(0, 0xAD, 0x22); // safely wrap to valid reg @@ -675,69 +672,61 @@ static void synth_sets_ch3_special_mode_op_tl_only_if_output_operator(int alg) } } -static void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_0( - UNUSED void** state) +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_0(UNUSED void** state) { synth_sets_ch3_special_mode_op_tl_only_if_output_operator(0); } -static void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_1( - UNUSED void** state) +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_1(UNUSED void** state) { synth_sets_ch3_special_mode_op_tl_only_if_output_operator(1); } -static void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_2( - UNUSED void** state) +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_2(UNUSED void** state) { synth_sets_ch3_special_mode_op_tl_only_if_output_operator(2); } -static void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_3( - UNUSED void** state) +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_3(UNUSED void** state) { synth_sets_ch3_special_mode_op_tl_only_if_output_operator(3); } -static void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_4( - UNUSED void** state) +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_4(UNUSED void** state) { synth_sets_ch3_special_mode_op_tl_only_if_output_operator(4); } -static void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_5( - UNUSED void** state) +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_5(UNUSED void** state) { synth_sets_ch3_special_mode_op_tl_only_if_output_operator(5); } -static void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_6( - UNUSED void** state) +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_6(UNUSED void** state) { synth_sets_ch3_special_mode_op_tl_only_if_output_operator(6); } -static void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_7( - UNUSED void** state) +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_7(UNUSED void** state) { synth_sets_ch3_special_mode_op_tl_only_if_output_operator(7); } -static void test_synth_enables_dac(UNUSED void** state) +void test_synth_enables_dac(UNUSED void** state) { expect_ym2612_write_reg(0, 0x2B, 0x80); __real_synth_enableDac(true); } -static void test_synth_disables_dac(UNUSED void** state) +void test_synth_disables_dac(UNUSED void** state) { expect_ym2612_write_reg(0, 0x2B, 0); __real_synth_enableDac(false); } -static void test_requests_Z80_bus_if_not_already_taken(UNUSED void** state) +void test_requests_Z80_bus_if_not_already_taken(UNUSED void** state) { expect_value(__wrap_Z80_getAndRequestBus, wait, TRUE); will_return(__wrap_Z80_getAndRequestBus, false); @@ -753,7 +742,7 @@ static void test_requests_Z80_bus_if_not_already_taken(UNUSED void** state) __real_synth_directWriteYm2612(0, 0x2B, 0); } -static void test_does_not_release_Z80_bus_when_taken_prior_to_call(UNUSED void** state) +void test_does_not_release_Z80_bus_when_taken_prior_to_call(UNUSED void** state) { expect_value(__wrap_Z80_getAndRequestBus, wait, TRUE); will_return(__wrap_Z80_getAndRequestBus, true); diff --git a/tests/unit/test_synth.h b/tests/unit/test_synth.h new file mode 100644 index 0000000..8720d33 --- /dev/null +++ b/tests/unit/test_synth.h @@ -0,0 +1,54 @@ +#include "cmocka_inc.h" + +int test_synth_setup(UNUSED void** state); +void test_synth_init_sets_initial_registers(UNUSED void** state); +void test_synth_sets_note_on_fm_reg_chan_0_to_2(UNUSED void** state); +void test_synth_sets_note_on_fm_reg_chan_3_to_5(UNUSED void** state); +void test_synth_sets_note_off_fm_reg_chan_0_to_2(UNUSED void** state); +void test_synth_sets_note_off_fm_reg_chan_3_to_5(UNUSED void** state); +void test_synth_sets_octave_and_freq_reg_chan(UNUSED void** state); +void test_synth_sets_stereo_ams_and_freq(UNUSED void** state); +void test_synth_sets_algorithm(UNUSED void** state); +void test_synth_sets_feedback(UNUSED void** state); +void test_synth_sets_feedback_and_algorithm(UNUSED void** state); +void test_synth_does_not_reset_operator_level_if_equal(UNUSED void** state); +void test_synth_sets_operator_total_level(UNUSED void** state); +void test_synth_sets_operator_multiple_and_detune(UNUSED void** state); +void test_synth_sets_operator_attack_rate_and_rate_scaling(UNUSED void** state); +void test_synth_sets_operator_sustain_rate(UNUSED void** state); +void test_synth_sets_operator_release_rate_and_sustain_level(UNUSED void** state); +void test_synth_sets_operator_amplitude_modulation_and_decay_rate(UNUSED void** state); +void test_synth_sets_operator_ssg_eg(UNUSED void** state); +void test_synth_sets_global_LFO_enable_and_frequency(UNUSED void** state); +void test_synth_sets_busy_indicators(UNUSED void** state); +void test_synth_sets_preset(UNUSED void** state); +void test_synth_sets_preset_retaining_pan(UNUSED void** state); +void test_synth_applies_volume_modifier_to_output_operators_algorithm_7(UNUSED void** state); +void test_synth_does_not_apply_volume_if_equal(UNUSED void** state); +void test_synth_applies_volume_modifier_to_output_operators_algorithm_7_quieter( + UNUSED void** state); +void test_synth_applies_volume_modifier_to_output_operators_algorithms_0_to_3(UNUSED void** state); +void test_synth_applies_volume_modifier_to_output_operators_algorithm_4(UNUSED void** state); +void test_synth_applies_volume_modifier_to_output_operators_algorithms_5_and_6(UNUSED void** state); +void test_synth_exposes_fm_channel_parameters(UNUSED void** state); +void test_synth_exposes_global_parameters(UNUSED void** state); +void test_synth_calls_callback_when_parameter_changes(UNUSED void** state); +void test_synth_calls_callback_when_lfo_freq_changes(UNUSED void** state); +void test_synth_calls_callback_when_lfo_enable_changes(UNUSED void** state); +void test_synth_calls_callback_when_special_mode_changes(UNUSED void** state); +void test_synth_enables_ch3_special_mode(UNUSED void** state); +void test_synth_disables_ch3_special_mode(UNUSED void** state); +void test_synth_sets_ch3_special_mode_operator_pitches(UNUSED void** state); +void test_synth_handles_out_of_range_ch3_special_mode_operator(UNUSED void** state); +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_0(UNUSED void** state); +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_1(UNUSED void** state); +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_2(UNUSED void** state); +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_3(UNUSED void** state); +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_4(UNUSED void** state); +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_5(UNUSED void** state); +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_6(UNUSED void** state); +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_7(UNUSED void** state); +void test_synth_enables_dac(UNUSED void** state); +void test_synth_disables_dac(UNUSED void** state); +void test_requests_Z80_bus_if_not_already_taken(UNUSED void** state); +void test_does_not_release_Z80_bus_when_taken_prior_to_call(UNUSED void** state);