Skip to content

Commit

Permalink
Introduce more expectation synth helper functions for sysex tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rhargreaves committed Feb 19, 2025
1 parent 3173f51 commit d3167d9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
16 changes: 16 additions & 0 deletions tests/mocks/mock_ym2612.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,19 @@ 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: 8 additions & 0 deletions tests/mocks/mock_ym2612.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ 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 @@ -55,3 +59,7 @@ void _expect_ym2612_write_operator_volumes(
_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__)
20 changes: 5 additions & 15 deletions tests/unit/test_midi_sysex.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@ void test_midi_sysex_inverts_total_level_values(UNUSED void** state)

__real_midi_sysex(sequence, sizeof(sequence));

expect_value(__wrap_synth_operatorTotalLevel, channel, 0);
expect_value(__wrap_synth_operatorTotalLevel, op, 0);
expect_value(__wrap_synth_operatorTotalLevel, totalLevel, 126);
expect_synth_operatorTotalLevel(0, 0, 126);
__real_midi_cc(0, CC_GENMDM_TOTAL_LEVEL_OP1, 1);
}

Expand All @@ -222,18 +220,14 @@ void test_midi_sysex_sets_original_total_level_values(UNUSED void** state)
SYSEX_COMMAND_INVERT_TOTAL_LEVEL, 0x01 };

__real_midi_sysex(invert_sequence, sizeof(invert_sequence));
expect_value(__wrap_synth_operatorTotalLevel, channel, 0);
expect_value(__wrap_synth_operatorTotalLevel, op, 0);
expect_value(__wrap_synth_operatorTotalLevel, totalLevel, 126);
expect_synth_operatorTotalLevel(0, 0, 126);
__real_midi_cc(0, CC_GENMDM_TOTAL_LEVEL_OP1, 1);

const u8 original_sequence[] = { SYSEX_MANU_EXTENDED, SYSEX_MANU_REGION, SYSEX_MANU_ID,
SYSEX_COMMAND_INVERT_TOTAL_LEVEL, 0x00 };

__real_midi_sysex(original_sequence, sizeof(original_sequence));
expect_value(__wrap_synth_operatorTotalLevel, channel, 0);
expect_value(__wrap_synth_operatorTotalLevel, op, 0);
expect_value(__wrap_synth_operatorTotalLevel, totalLevel, 126);
expect_synth_operatorTotalLevel(0, 0, 126);
__real_midi_cc(0, CC_GENMDM_TOTAL_LEVEL_OP1, 126);
}

Expand All @@ -242,9 +236,7 @@ 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 };

expect_value(__wrap_synth_directWriteYm2612, part, 0);
expect_value(__wrap_synth_directWriteYm2612, reg, 0xB1);
expect_value(__wrap_synth_directWriteYm2612, data, 0x12);
expect_synth_directWriteYm2612(0, 0xB1, 0x12);
__real_midi_sysex(sequence, sizeof(sequence));
}

Expand All @@ -253,9 +245,7 @@ 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 };

expect_value(__wrap_synth_directWriteYm2612, part, 1);
expect_value(__wrap_synth_directWriteYm2612, reg, 0xB1);
expect_value(__wrap_synth_directWriteYm2612, data, 0x12);
expect_synth_directWriteYm2612(1, 0xB1, 0x12);
__real_midi_sysex(sequence, sizeof(sequence));
}

Expand Down

0 comments on commit d3167d9

Please sign in to comment.