diff --git a/tests/cmocka_inc.h b/tests/cmocka_inc.h index d1708a8..1173bde 100644 --- a/tests/cmocka_inc.h +++ b/tests/cmocka_inc.h @@ -2,5 +2,8 @@ #include #include #include "asserts.h" -#include "unused.h" #include "wraps.h" + +#define INT_PTR(val) (&((int) { val })) + +#define UNUSED __attribute__((unused)) diff --git a/tests/unit/main.c b/tests/unit/main.c index 3f1b8e3..2e1c834 100644 --- a/tests/unit/main.c +++ b/tests/unit/main.c @@ -27,6 +27,8 @@ #define midi_dac_test(test) cmocka_unit_test_setup(test, test_midi_dac_setup) #define dynamic_midi_test(test) cmocka_unit_test_setup(test, test_dynamic_midi_setup) #define synth_test(test) cmocka_unit_test_setup(test, test_synth_setup) +#define synth_test_case(test, state) \ + cmocka_unit_test_prestate_setup_teardown(test, test_synth_setup, NULL, state) #define comm_test(test) cmocka_unit_test_setup(test, test_comm_setup) #define comm_megawifi_test(test) cmocka_unit_test_setup(test, test_comm_megawifi_setup) #define comm_demo_test(test) cmocka_unit_test_setup(test, test_comm_demo_setup) @@ -253,22 +255,22 @@ int main(void) synth_test(test_synth_disables_ch3_special_mode), synth_test(test_synth_sets_ch3_special_mode_operator_pitches), synth_test(test_synth_handles_out_of_range_ch3_special_mode_operator), - synth_test( - test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_0), - synth_test( - test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_1), - synth_test( - test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_2), - synth_test( - test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_3), - synth_test( - test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_4), - synth_test( - test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_5), - synth_test( - test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_6), - synth_test( - test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator_alg_7), + synth_test_case( + test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator, INT_PTR(0)), + synth_test_case( + test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator, INT_PTR(1)), + synth_test_case( + test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator, INT_PTR(2)), + synth_test_case( + test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator, INT_PTR(3)), + synth_test_case( + test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator, INT_PTR(4)), + synth_test_case( + test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator, INT_PTR(5)), + synth_test_case( + test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator, INT_PTR(6)), + synth_test_case( + test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator, INT_PTR(7)), synth_test(test_synth_enables_dac), synth_test(test_synth_disables_dac), synth_test(test_requests_Z80_bus_if_not_already_taken), diff --git a/tests/unit/test_synth.c b/tests/unit/test_synth.c index 9b65080..be551f5 100644 --- a/tests/unit/test_synth.c +++ b/tests/unit/test_synth.c @@ -617,20 +617,22 @@ void test_synth_handles_out_of_range_ch3_special_mode_operator(UNUSED void** sta __real_synth_specialModePitch(op, 4, SYNTH_NTSC_C); } -static void synth_sets_ch3_special_mode_op_tl_only_if_output_operator(int alg) +void test_synth_sets_ch3_special_mode_op_tl_only_if_output_operator(UNUSED void** state) { + int algorithm = (*(int*)(*state)); + const u8 baseReg = 0x40; const u8 chan = CH_SPECIAL_MODE; - expect_ym2612_write_channel(chan, 0xB0, alg); - __real_synth_algorithm(chan, alg); + expect_ym2612_write_channel(chan, 0xB0, algorithm); + __real_synth_algorithm(chan, algorithm); for (u8 op = 0; op <= 2; op++) { // set initial TL expect_ym2612_write_operator(chan, op, baseReg, 2); __real_synth_operatorTotalLevel(chan, op, 2); - switch (alg) { + switch (algorithm) { case 0: case 1: case 2: @@ -672,46 +674,6 @@ static void synth_sets_ch3_special_mode_op_tl_only_if_output_operator(int alg) } } -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - void test_synth_enables_dac(UNUSED void** state) { expect_ym2612_write_reg(0, 0x2B, 0x80); diff --git a/tests/unit/test_synth.h b/tests/unit/test_synth.h index 8720d33..bb25d66 100644 --- a/tests/unit/test_synth.h +++ b/tests/unit/test_synth.h @@ -40,14 +40,7 @@ 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_sets_ch3_special_mode_op_tl_only_if_output_operator(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); diff --git a/tests/unused.h b/tests/unused.h deleted file mode 100644 index c783242..0000000 --- a/tests/unused.h +++ /dev/null @@ -1 +0,0 @@ -#define UNUSED __attribute__((unused))