Skip to content

Commit

Permalink
Simplify tests using prestate
Browse files Browse the repository at this point in the history
  • Loading branch information
rhargreaves committed Sep 8, 2024
1 parent 79149b8 commit 83a16f2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 70 deletions.
5 changes: 4 additions & 1 deletion tests/cmocka_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
#include <setjmp.h>
#include <cmocka.h>
#include "asserts.h"
#include "unused.h"
#include "wraps.h"

#define INT_PTR(val) (&((int) { val }))

#define UNUSED __attribute__((unused))
34 changes: 18 additions & 16 deletions tests/unit/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down
50 changes: 6 additions & 44 deletions tests/unit/test_synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 1 addition & 8 deletions tests/unit/test_synth.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion tests/unused.h

This file was deleted.

0 comments on commit 83a16f2

Please sign in to comment.