Skip to content

Commit

Permalink
Refactor expect_value() calls for some test_midi_fm tests
Browse files Browse the repository at this point in the history
Using Cursor and AI to do the work!
  • Loading branch information
rhargreaves committed Feb 18, 2025
1 parent c225ef5 commit 932d20c
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 40 deletions.
77 changes: 77 additions & 0 deletions tests/asserts.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
37 changes: 37 additions & 0 deletions tests/asserts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
52 changes: 12 additions & 40 deletions tests/unit/test_midi_fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 932d20c

Please sign in to comment.