Skip to content

Commit

Permalink
Use more helper methods in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rhargreaves committed Feb 19, 2025
1 parent d3167d9 commit 103c813
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 44 deletions.
8 changes: 8 additions & 0 deletions tests/mocks/mock_synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,11 @@ void _expect_synth_setSpecialMode(bool enable, const char* const file, const int
{
expect_value_with_pos(__wrap_synth_setSpecialMode, enable, enable, file, line);
}

void _expect_synth_directWriteYm2612(
u8 part, u8 reg, u8 data, const char* const file, const int line)
{
expect_value_with_pos(__wrap_synth_directWriteYm2612, part, part, file, line);
expect_value_with_pos(__wrap_synth_directWriteYm2612, reg, reg, file, line);
expect_value_with_pos(__wrap_synth_directWriteYm2612, data, data, file, line);
}
4 changes: 4 additions & 0 deletions tests/mocks/mock_synth.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ void _expect_synth_specialModePitch(
u8 op, u8 octave, u16 freqNumber, const char* const file, const int line);
void _expect_synth_specialModeVolume(u8 op, u8 volume, const char* const file, const int line);
void _expect_synth_setSpecialMode(bool enable, const char* const file, const int line);
void _expect_synth_directWriteYm2612(
u8 part, u8 reg, u8 data, const char* const file, const int line);

#define expect_synth_algorithm(channel, algorithm) \
_expect_synth_algorithm(channel, algorithm, __FILE__, __LINE__)
Expand Down Expand Up @@ -159,3 +161,5 @@ void _expect_synth_setSpecialMode(bool enable, const char* const file, const int
#define expect_synth_specialModeVolume(op, volume) \
_expect_synth_specialModeVolume(op, volume, __FILE__, __LINE__)
#define expect_synth_setSpecialMode(enable) _expect_synth_setSpecialMode(enable, __FILE__, __LINE__)
#define expect_synth_directWriteYm2612(part, reg, data) \
_expect_synth_directWriteYm2612(part, reg, data, __FILE__, __LINE__)
16 changes: 0 additions & 16 deletions tests/mocks/mock_ym2612.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,3 @@ void _expect_ym2612_write_operator_volumes(
_expect_ym2612_write_operator(chan, op, YM_BASE_TOTAL_LEVEL, volumes[op], file, line);
}
}

void _expect_synth_operatorTotalLevel(
u8 channel, u8 op, u8 totalLevel, const char* const file, const int line)
{
expect_value_with_pos(__wrap_synth_operatorTotalLevel, channel, channel, file, line);
expect_value_with_pos(__wrap_synth_operatorTotalLevel, op, op, file, line);
expect_value_with_pos(__wrap_synth_operatorTotalLevel, totalLevel, totalLevel, file, line);
}

void _expect_synth_directWriteYm2612(
u8 part, u8 reg, u8 data, const char* const file, const int line)
{
expect_value_with_pos(__wrap_synth_directWriteYm2612, part, part, file, line);
expect_value_with_pos(__wrap_synth_directWriteYm2612, reg, reg, file, line);
expect_value_with_pos(__wrap_synth_directWriteYm2612, data, data, file, line);
}
8 changes: 0 additions & 8 deletions tests/mocks/mock_ym2612.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ void _expect_ym2612_write_frequency(
void _expect_ym2612_write_frequency_any_data(u8 chan, const char* const file, const int line);
void _expect_ym2612_write_operator_volumes(
u8 chan, const u8* volumes, u8 count, const char* const file, const int line);
void _expect_synth_operatorTotalLevel(
u8 channel, u8 op, u8 totalLevel, const char* const file, const int line);
void _expect_synth_directWriteYm2612(
u8 part, u8 reg, u8 data, const char* const file, const int line);

#define expect_ym2612_write_reg(part, reg, data) \
_expect_ym2612_write_reg(part, reg, data, __FILE__, __LINE__)
Expand All @@ -59,7 +55,3 @@ void _expect_synth_directWriteYm2612(
_expect_ym2612_write_frequency_any_data(chan, __FILE__, __LINE__)
#define expect_ym2612_write_operator_volumes(chan, volumes, count) \
_expect_ym2612_write_operator_volumes(chan, volumes, count, __FILE__, __LINE__)
#define expect_synth_operatorTotalLevel(channel, op, totalLevel) \
_expect_synth_operatorTotalLevel(channel, op, totalLevel, __FILE__, __LINE__)
#define expect_synth_directWriteYm2612(part, reg, data) \
_expect_synth_directWriteYm2612(part, reg, data, __FILE__, __LINE__)
36 changes: 16 additions & 20 deletions tests/unit/test_midi_polyphony.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ void test_midi_polyphonic_mode_sends_CCs_to_all_FM_channels(UNUSED void** state)
for (int chan = 0; chan <= MAX_FM_CHAN; chan++) {
expect_synth_pitch_any();
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, chan);
expect_synth_noteOn(chan);

__real_midi_note_on(0, MIDI_PITCH_AS6, MAX_MIDI_VOLUME);
}
for (int chan = 0; chan <= MAX_FM_CHAN; chan++) {
expect_value(__wrap_synth_algorithm, channel, chan);
expect_value(__wrap_synth_algorithm, algorithm, 1);
expect_synth_algorithm(chan, 1);
}

__real_midi_cc(0, CC_GENMDM_FM_ALGORITHM, 16);
Expand All @@ -28,7 +27,7 @@ void test_midi_set_overflow_flag_on_polyphony_breach(UNUSED void** state)
for (int chan = 0; chan <= MAX_FM_CHAN; chan++) {
expect_synth_pitch(chan, 6, SYNTH_NTSC_AS);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, chan);
expect_synth_noteOn(chan);
__real_midi_note_on(chan, MIDI_PITCH_AS6, MAX_MIDI_VOLUME);
}
for (int chan = MIN_PSG_CHAN; chan <= MAX_PSG_CHAN - 1; chan++) {
Expand All @@ -48,21 +47,21 @@ void test_midi_polyphonic_mode_uses_multiple_fm_channels(UNUSED void** state)
for (int chan = 0; chan <= MAX_FM_CHAN; chan++) {
expect_synth_pitch(0, 6, SYNTH_NTSC_AS);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, 0);
expect_synth_noteOn(0);

__real_midi_note_on(chan, MIDI_PITCH_AS6, MAX_MIDI_VOLUME);

expect_synth_pitch(1, 7, 0x25f);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, 1);
expect_synth_noteOn(1);

__real_midi_note_on(chan, MIDI_PITCH_B6, MAX_MIDI_VOLUME);

expect_value(__wrap_synth_noteOff, channel, 0);
expect_synth_noteOff(0);

__real_midi_note_off(chan, MIDI_PITCH_AS6);

expect_value(__wrap_synth_noteOff, channel, 1);
expect_synth_noteOff(1);

__real_midi_note_off(chan, MIDI_PITCH_B6);
}
Expand All @@ -77,18 +76,18 @@ void test_midi_polyphonic_mode_note_off_silences_all_matching_pitch(UNUSED void*
for (int chan = 0; chan <= MAX_FM_CHAN; chan++) {
expect_synth_pitch(0, 6, SYNTH_NTSC_AS);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, 0);
expect_synth_noteOn(0);

__real_midi_note_on(chan, MIDI_PITCH_AS6, MAX_MIDI_VOLUME);

expect_synth_pitch(1, 6, SYNTH_NTSC_AS);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, 1);
expect_synth_noteOn(1);

__real_midi_note_on(chan, MIDI_PITCH_AS6, MAX_MIDI_VOLUME);

expect_value(__wrap_synth_noteOff, channel, 0);
expect_value(__wrap_synth_noteOff, channel, 1);
expect_synth_noteOff(0);
expect_synth_noteOff(1);

__real_midi_note_off(chan, MIDI_PITCH_AS6);
}
Expand All @@ -104,24 +103,21 @@ void test_midi_sets_all_notes_off_in_polyphonic_mode(UNUSED void** state)
expect_any(__wrap_synth_pitch, octave);
expect_any(__wrap_synth_pitch, freqNumber);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, 0);
expect_synth_noteOn(0);

__real_midi_note_on(0, MIDI_PITCH_AS6, MAX_MIDI_VOLUME);

expect_value(__wrap_synth_pitch, channel, 1);
expect_any(__wrap_synth_pitch, octave);
expect_any(__wrap_synth_pitch, freqNumber);
expect_synth_volume_any();
expect_value(__wrap_synth_noteOn, channel, 1);
expect_synth_noteOn(1);

__real_midi_note_on(0, MIDI_PITCH_B6, MAX_MIDI_VOLUME);

expect_value(__wrap_synth_noteOff, channel, 0);
expect_value(__wrap_synth_noteOff, channel, 1);
expect_value(__wrap_synth_noteOff, channel, 2);
expect_value(__wrap_synth_noteOff, channel, 3);
expect_value(__wrap_synth_noteOff, channel, 4);
expect_value(__wrap_synth_noteOff, channel, 5);
for (int chan = FM_CH1; chan <= FM_CH6; chan++) {
expect_synth_noteOff(chan);
}

__real_midi_cc(0, CC_ALL_NOTES_OFF, 0);

Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_midi_sysex.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "test_midi_sysex.h"
#include "test_midi.h"
#include "mocks/mock_synth.h"

static void remapChannel(u8 midiChannel, u8 deviceChannel)
{
Expand Down

0 comments on commit 103c813

Please sign in to comment.