From 932d20cb8b07e1047f568604e5dd7c540c33cb02 Mon Sep 17 00:00:00 2001 From: Robert Hargreaves Date: Tue, 18 Feb 2025 20:38:21 +0000 Subject: [PATCH] Refactor expect_value() calls for some test_midi_fm tests Using Cursor and AI to do the work! --- tests/asserts.c | 77 +++++++++++++++++++++++++++++++++++++++ tests/asserts.h | 37 +++++++++++++++++++ tests/unit/test_midi_fm.c | 52 ++++++-------------------- 3 files changed, 126 insertions(+), 40 deletions(-) diff --git a/tests/asserts.c b/tests/asserts.c index 7fb764f..d16fc6f 100644 --- a/tests/asserts.c +++ b/tests/asserts.c @@ -285,3 +285,80 @@ void _expect_synth_volume(u8 channel, u8 volume, const char* const file, const i expect_value_with_pos(__wrap_synth_volume, channel, channel, file, line); expect_value_with_pos(__wrap_synth_volume, volume, volume, 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_operatorMultiple(u8 channel, u8 op, u8 multiple, const char* const file, const int line) +{ + expect_value_with_pos(__wrap_synth_operatorMultiple, channel, channel, file, line); + expect_value_with_pos(__wrap_synth_operatorMultiple, op, op, file, line); + expect_value_with_pos(__wrap_synth_operatorMultiple, multiple, multiple, file, line); +} + +void _expect_synth_operatorDetune(u8 channel, u8 op, u8 detune, const char* const file, const int line) +{ + expect_value_with_pos(__wrap_synth_operatorDetune, channel, channel, file, line); + expect_value_with_pos(__wrap_synth_operatorDetune, op, op, file, line); + expect_value_with_pos(__wrap_synth_operatorDetune, detune, detune, file, line); +} + +void _expect_synth_operatorRateScaling(u8 channel, u8 op, u8 rateScaling, const char* const file, const int line) +{ + expect_value_with_pos(__wrap_synth_operatorRateScaling, channel, channel, file, line); + expect_value_with_pos(__wrap_synth_operatorRateScaling, op, op, file, line); + expect_value_with_pos(__wrap_synth_operatorRateScaling, rateScaling, rateScaling, file, line); +} + +void _expect_synth_operatorAttackRate(u8 channel, u8 op, u8 rate, const char* const file, const int line) +{ + expect_value_with_pos(__wrap_synth_operatorAttackRate, channel, channel, file, line); + expect_value_with_pos(__wrap_synth_operatorAttackRate, op, op, file, line); + expect_value_with_pos(__wrap_synth_operatorAttackRate, attackRate, rate, file, line); +} + +void _expect_synth_operatorDecayRate(u8 channel, u8 op, u8 rate, const char* const file, const int line) +{ + expect_value_with_pos(__wrap_synth_operatorDecayRate, channel, channel, file, line); + expect_value_with_pos(__wrap_synth_operatorDecayRate, op, op, file, line); + expect_value_with_pos(__wrap_synth_operatorDecayRate, decayRate, rate, file, line); +} + +void _expect_synth_operatorSustainRate(u8 channel, u8 op, u8 rate, const char* const file, const int line) +{ + expect_value_with_pos(__wrap_synth_operatorSustainRate, channel, channel, file, line); + expect_value_with_pos(__wrap_synth_operatorSustainRate, op, op, file, line); + expect_value_with_pos(__wrap_synth_operatorSustainRate, sustainRate, rate, file, line); +} + +void _expect_synth_operatorSustainLevel(u8 channel, u8 op, u8 level, const char* const file, const int line) +{ + expect_value_with_pos(__wrap_synth_operatorSustainLevel, channel, channel, file, line); + expect_value_with_pos(__wrap_synth_operatorSustainLevel, op, op, file, line); + expect_value_with_pos(__wrap_synth_operatorSustainLevel, sustainLevel, level, file, line); +} + +void _expect_synth_operatorReleaseRate(u8 channel, u8 op, u8 rate, const char* const file, const int line) +{ + expect_value_with_pos(__wrap_synth_operatorReleaseRate, channel, channel, file, line); + expect_value_with_pos(__wrap_synth_operatorReleaseRate, op, op, file, line); + expect_value_with_pos(__wrap_synth_operatorReleaseRate, releaseRate, rate, file, line); +} + +void _expect_synth_operatorSsgEg(u8 channel, u8 op, u8 enabled, const char* const file, const int line) +{ + expect_value_with_pos(__wrap_synth_operatorSsgEg, channel, channel, file, line); + expect_value_with_pos(__wrap_synth_operatorSsgEg, op, op, file, line); + expect_value_with_pos(__wrap_synth_operatorSsgEg, ssgEg, enabled, file, line); +} + +void _expect_synth_operatorAmplitudeModulation(u8 channel, u8 op, u8 enabled, const char* const file, const int line) +{ + expect_value_with_pos(__wrap_synth_operatorAmplitudeModulation, channel, channel, file, line); + expect_value_with_pos(__wrap_synth_operatorAmplitudeModulation, op, op, file, line); + expect_value_with_pos(__wrap_synth_operatorAmplitudeModulation, amplitudeModulation, enabled, file, line); +} diff --git a/tests/asserts.h b/tests/asserts.h index 5b57208..bf029f8 100644 --- a/tests/asserts.h +++ b/tests/asserts.h @@ -156,3 +156,40 @@ void _expect_synth_volume(u8 channel, u8 volume, const char* const file, const i #define expect_synth_volume(channel, volume) \ _expect_synth_volume(channel, volume, __FILE__, __LINE__) + +void _expect_synth_operatorTotalLevel(u8 channel, u8 op, u8 totalLevel, const char* const file, const int line); +void _expect_synth_operatorMultiple(u8 channel, u8 op, u8 multiple, const char* const file, const int line); +void _expect_synth_operatorDetune(u8 channel, u8 op, u8 detune, const char* const file, const int line); +void _expect_synth_operatorRateScaling(u8 channel, u8 op, u8 rateScaling, const char* const file, const int line); + +#define expect_synth_operatorTotalLevel(channel, op, totalLevel) \ + _expect_synth_operatorTotalLevel(channel, op, totalLevel, __FILE__, __LINE__) +#define expect_synth_operatorMultiple(channel, op, multiple) \ + _expect_synth_operatorMultiple(channel, op, multiple, __FILE__, __LINE__) +#define expect_synth_operatorDetune(channel, op, detune) \ + _expect_synth_operatorDetune(channel, op, detune, __FILE__, __LINE__) +#define expect_synth_operatorRateScaling(channel, op, rateScaling) \ + _expect_synth_operatorRateScaling(channel, op, rateScaling, __FILE__, __LINE__) + +void _expect_synth_operatorAttackRate(u8 channel, u8 op, u8 rate, const char* const file, const int line); +void _expect_synth_operatorDecayRate(u8 channel, u8 op, u8 rate, const char* const file, const int line); +void _expect_synth_operatorSustainRate(u8 channel, u8 op, u8 rate, const char* const file, const int line); +void _expect_synth_operatorSustainLevel(u8 channel, u8 op, u8 level, const char* const file, const int line); +void _expect_synth_operatorReleaseRate(u8 channel, u8 op, u8 rate, const char* const file, const int line); +void _expect_synth_operatorSsgEg(u8 channel, u8 op, u8 enabled, const char* const file, const int line); +void _expect_synth_operatorAmplitudeModulation(u8 channel, u8 op, u8 enabled, const char* const file, const int line); + +#define expect_synth_operatorAttackRate(channel, op, rate) \ + _expect_synth_operatorAttackRate(channel, op, rate, __FILE__, __LINE__) +#define expect_synth_operatorDecayRate(channel, op, rate) \ + _expect_synth_operatorDecayRate(channel, op, rate, __FILE__, __LINE__) +#define expect_synth_operatorSustainRate(channel, op, rate) \ + _expect_synth_operatorSustainRate(channel, op, rate, __FILE__, __LINE__) +#define expect_synth_operatorSustainLevel(channel, op, level) \ + _expect_synth_operatorSustainLevel(channel, op, level, __FILE__, __LINE__) +#define expect_synth_operatorReleaseRate(channel, op, rate) \ + _expect_synth_operatorReleaseRate(channel, op, rate, __FILE__, __LINE__) +#define expect_synth_operatorSsgEg(channel, op, enabled) \ + _expect_synth_operatorSsgEg(channel, op, enabled, __FILE__, __LINE__) +#define expect_synth_operatorAmplitudeModulation(channel, op, enabled) \ + _expect_synth_operatorAmplitudeModulation(channel, op, enabled, __FILE__, __LINE__) diff --git a/tests/unit/test_midi_fm.c b/tests/unit/test_midi_fm.c index 70421ee..b9621f9 100644 --- a/tests/unit/test_midi_fm.c +++ b/tests/unit/test_midi_fm.c @@ -203,10 +203,7 @@ void test_midi_sets_operator_total_level(UNUSED void** state) for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { for (u8 cc = 16; cc <= 19; cc++) { u8 expectedOp = cc - 16; - expect_value(__wrap_synth_operatorTotalLevel, channel, chan); - expect_value(__wrap_synth_operatorTotalLevel, op, expectedOp); - expect_value(__wrap_synth_operatorTotalLevel, totalLevel, expectedValue); - + expect_synth_operatorTotalLevel(chan, expectedOp, expectedValue); __real_midi_cc(chan, cc, expectedValue); } } @@ -219,9 +216,7 @@ void test_midi_sets_operator_multiple(UNUSED void** state) for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { for (u8 cc = 20; cc <= 23; cc++) { u8 expectedOp = cc - 20; - expect_value(__wrap_synth_operatorMultiple, channel, chan); - expect_value(__wrap_synth_operatorMultiple, op, expectedOp); - expect_value(__wrap_synth_operatorMultiple, multiple, expectedValue); + expect_synth_operatorMultiple(chan, expectedOp, expectedValue); __real_midi_cc(chan, cc, 32); } @@ -235,9 +230,7 @@ void test_midi_sets_operator_detune(UNUSED void** state) for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { for (u8 cc = 24; cc <= 27; cc++) { u8 expectedOp = cc - 24; - expect_value(__wrap_synth_operatorDetune, channel, chan); - expect_value(__wrap_synth_operatorDetune, op, expectedOp); - expect_value(__wrap_synth_operatorDetune, detune, expectedValue); + expect_synth_operatorDetune(chan, expectedOp, expectedValue); __real_midi_cc(chan, cc, 32); } @@ -251,10 +244,7 @@ void test_midi_sets_operator_rate_scaling(UNUSED void** state) for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { for (u8 cc = 39; cc <= 42; cc++) { u8 expectedOp = cc - 39; - expect_value(__wrap_synth_operatorRateScaling, channel, chan); - expect_value(__wrap_synth_operatorRateScaling, op, expectedOp); - expect_value(__wrap_synth_operatorRateScaling, rateScaling, expectedValue); - + expect_synth_operatorRateScaling(chan, expectedOp, expectedValue); __real_midi_cc(chan, cc, 64); } } @@ -267,10 +257,7 @@ void test_midi_sets_operator_attack_rate(UNUSED void** state) for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { for (u8 cc = 43; cc <= 46; cc++) { u8 expectedOp = cc - 43; - expect_value(__wrap_synth_operatorAttackRate, channel, chan); - expect_value(__wrap_synth_operatorAttackRate, op, expectedOp); - expect_value(__wrap_synth_operatorAttackRate, attackRate, expectedValue); - + expect_synth_operatorAttackRate(chan, expectedOp, expectedValue); __real_midi_cc(chan, cc, 8); } } @@ -279,13 +266,11 @@ void test_midi_sets_operator_attack_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++) { for (u8 cc = 47; cc <= 50; cc++) { u8 expectedOp = cc - 47; - expect_value(__wrap_synth_operatorDecayRate, channel, chan); - expect_value(__wrap_synth_operatorDecayRate, op, expectedOp); - expect_value(__wrap_synth_operatorDecayRate, decayRate, expectedValue); - + expect_synth_operatorDecayRate(chan, expectedOp, expectedValue); __real_midi_cc(chan, cc, 8); } } @@ -298,10 +283,7 @@ void test_midi_sets_operator_sustain_rate(UNUSED void** state) for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { for (u8 cc = 51; cc <= 54; cc++) { u8 expectedOp = cc - 51; - expect_value(__wrap_synth_operatorSustainRate, channel, chan); - expect_value(__wrap_synth_operatorSustainRate, op, expectedOp); - expect_value(__wrap_synth_operatorSustainRate, sustainRate, expectedValue); - + expect_synth_operatorSustainRate(chan, expectedOp, expectedValue); __real_midi_cc(chan, cc, 8); } } @@ -314,10 +296,7 @@ void test_midi_sets_operator_sustain_level(UNUSED void** state) for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { for (u8 cc = 55; cc <= 58; cc++) { u8 expectedOp = cc - 55; - expect_value(__wrap_synth_operatorSustainLevel, channel, chan); - expect_value(__wrap_synth_operatorSustainLevel, op, expectedOp); - expect_value(__wrap_synth_operatorSustainLevel, sustainLevel, expectedValue); - + expect_synth_operatorSustainLevel(chan, expectedOp, expectedValue); __real_midi_cc(chan, cc, 8); } } @@ -330,10 +309,7 @@ void test_midi_sets_operator_amplitude_modulation(UNUSED void** state) for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { for (u8 cc = 70; cc <= 73; cc++) { u8 expectedOp = cc - 70; - expect_value(__wrap_synth_operatorAmplitudeModulation, channel, chan); - expect_value(__wrap_synth_operatorAmplitudeModulation, op, expectedOp); - expect_value( - __wrap_synth_operatorAmplitudeModulation, amplitudeModulation, expectedValue); + expect_synth_operatorAmplitudeModulation(chan, expectedOp, expectedValue); __real_midi_cc(chan, cc, 96); } @@ -347,9 +323,7 @@ void test_midi_sets_operator_release_rate(UNUSED void** state) for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { for (u8 cc = 59; cc <= 62; cc++) { u8 expectedOp = cc - 59; - expect_value(__wrap_synth_operatorReleaseRate, channel, chan); - expect_value(__wrap_synth_operatorReleaseRate, op, expectedOp); - expect_value(__wrap_synth_operatorReleaseRate, releaseRate, expectedValue); + expect_synth_operatorReleaseRate(chan, expectedOp, expectedValue); __real_midi_cc(chan, cc, 8); } @@ -366,9 +340,7 @@ void test_midi_sets_operator_ssg_eg(UNUSED void** state) for (u8 chan = 0; chan < MAX_FM_CHANS; chan++) { for (u8 cc = MIN_CC; cc <= MAX_CC; cc++) { u8 expectedOp = cc - MIN_CC; - expect_value(__wrap_synth_operatorSsgEg, channel, chan); - expect_value(__wrap_synth_operatorSsgEg, op, expectedOp); - expect_value(__wrap_synth_operatorSsgEg, ssgEg, expectedValue); + expect_synth_operatorSsgEg(chan, expectedOp, expectedValue); __real_midi_cc(chan, cc, 88); }