feat(panel): add Insert as FX — ReaSampler 9000 onto the selected track, preloaded with the focused capture, over the existing instrument-drop body
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
// Standalone tests for reasampler::ui::insert_fx_enable — no REAPER, no test framework.
|
||||
// Exhaustive over the fold's whole input space (track selected x capture-count class),
|
||||
// plus the two properties the shell leans on: the button bit is the fold restricted to
|
||||
// the payload axis, and every refusal carries a non-empty sentence (a silent refusal is
|
||||
// the failure mode this verb must not have).
|
||||
|
||||
#include "../src/core/ui/insert_fx_enable.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
using namespace reasampler::ui;
|
||||
|
||||
static int g_fail = 0;
|
||||
#define CHECK(cond) do { if(!(cond)) { \
|
||||
std::printf("FAIL line %d: %s\n", __LINE__, #cond); ++g_fail; } } while(0)
|
||||
|
||||
// All six combinations of {no track, track} x {0, 1, many captures}. The payload axis is
|
||||
// checked BEFORE the destination axis, so a press with neither a capture nor a track
|
||||
// reports the capture problem — the one the user can fix inside the panel they clicked.
|
||||
static void testEveryCombination() {
|
||||
CHECK(insertFxRefusal(0, false) == InsertFxRefusal::NoCapture);
|
||||
CHECK(insertFxRefusal(0, true) == InsertFxRefusal::NoCapture);
|
||||
CHECK(insertFxRefusal(1, false) == InsertFxRefusal::NoTrack);
|
||||
CHECK(insertFxRefusal(1, true) == InsertFxRefusal::None);
|
||||
CHECK(insertFxRefusal(3, false) == InsertFxRefusal::MultiCapture);
|
||||
CHECK(insertFxRefusal(3, true) == InsertFxRefusal::MultiCapture);
|
||||
}
|
||||
|
||||
// Exactly one capture is the only count that can run; two is already too many.
|
||||
static void testOnlyASingleCaptureRuns() {
|
||||
CHECK(insertFxRefusal(2, true) == InsertFxRefusal::MultiCapture);
|
||||
for (int n = 0; n <= 8; ++n) {
|
||||
const bool ready = insertFxRefusal(n, true) == InsertFxRefusal::None;
|
||||
CHECK(ready == (n == 1));
|
||||
}
|
||||
}
|
||||
|
||||
// A negative count can only come from a caller bug; it must fold to a refusal, never to
|
||||
// Ready (fail closed — this verb writes to the project).
|
||||
static void testNegativeCountRefuses() {
|
||||
CHECK(insertFxRefusal(-1, true) == InsertFxRefusal::NoCapture);
|
||||
CHECK(!insertFxButtonEnabled(-1));
|
||||
}
|
||||
|
||||
// The button bit is the fold with the destination axis held satisfied: it goes dead for
|
||||
// exactly the two panel-local refusals and stays live otherwise, whatever the project's
|
||||
// track selection happens to be.
|
||||
static void testButtonBitIsThePayloadAxisOfTheFold() {
|
||||
for (int n = -1; n <= 4; ++n) {
|
||||
const bool live = insertFxButtonEnabled(n);
|
||||
CHECK(live == (insertFxRefusal(n, true) == InsertFxRefusal::None));
|
||||
// A dead button always corresponds to a capture-side refusal, never to NoTrack.
|
||||
if (!live) {
|
||||
const InsertFxRefusal r = insertFxRefusal(n, false);
|
||||
CHECK(r == InsertFxRefusal::NoCapture || r == InsertFxRefusal::MultiCapture);
|
||||
}
|
||||
}
|
||||
CHECK(insertFxButtonEnabled(1));
|
||||
CHECK(!insertFxButtonEnabled(0));
|
||||
CHECK(!insertFxButtonEnabled(2));
|
||||
}
|
||||
|
||||
// Every refusal says something, and each says something DIFFERENT — a shared sentence
|
||||
// would leave the user unable to tell which condition they hit. None says nothing.
|
||||
static void testEveryRefusalHasItsOwnSentence() {
|
||||
const std::string none = insertFxRefusalMessage(InsertFxRefusal::None);
|
||||
const std::string noCap = insertFxRefusalMessage(InsertFxRefusal::NoCapture);
|
||||
const std::string multi = insertFxRefusalMessage(InsertFxRefusal::MultiCapture);
|
||||
const std::string noTrk = insertFxRefusalMessage(InsertFxRefusal::NoTrack);
|
||||
|
||||
CHECK(none.empty());
|
||||
CHECK(!noCap.empty());
|
||||
CHECK(!multi.empty());
|
||||
CHECK(!noTrk.empty());
|
||||
CHECK(noCap != multi);
|
||||
CHECK(noCap != noTrk);
|
||||
CHECK(multi != noTrk);
|
||||
}
|
||||
|
||||
int main() {
|
||||
testEveryCombination();
|
||||
testOnlyASingleCaptureRuns();
|
||||
testNegativeCountRefuses();
|
||||
testButtonBitIsThePayloadAxisOfTheFold();
|
||||
testEveryRefusalHasItsOwnSentence();
|
||||
|
||||
if (g_fail == 0) std::printf("insert_fx_enable: all tests passed\n");
|
||||
else std::printf("insert_fx_enable: %d CHECK(s) FAILED\n", g_fail);
|
||||
return g_fail == 0 ? 0 : 1;
|
||||
}
|
||||
Reference in New Issue
Block a user