51c7505dc0
Renames the permanent action id out of the placement family, makes the button's painted state and pressed outcome share one selection count, surfaces panel-known refusals in the tooltip, reports the target track on success, distinguishes a master-only selection, and pins the overflow-reserve test to the real bar spec.
110 lines
4.9 KiB
C++
110 lines
4.9 KiB
C++
// 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);
|
|
}
|
|
|
|
// GetSelectedTrack ignores the master track, so "only the master is selected" is a
|
|
// distinct refusal from a plain empty selection -- both are !trackSelected, but the
|
|
// message differs so a master-only user isn't told "select a track" when they did.
|
|
static void testMasterOnlySelectedIsDistinctFromNoTrack() {
|
|
CHECK(insertFxRefusal(1, false, /*masterOnlySelected=*/true) ==
|
|
InsertFxRefusal::MasterOnlySelected);
|
|
CHECK(insertFxRefusal(1, false, /*masterOnlySelected=*/false) == InsertFxRefusal::NoTrack);
|
|
// The payload axis still runs first -- a bad capture count refuses on ITS reason
|
|
// even with the master selected.
|
|
CHECK(insertFxRefusal(0, false, /*masterOnlySelected=*/true) == InsertFxRefusal::NoCapture);
|
|
}
|
|
|
|
// 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);
|
|
const std::string masterOnly = insertFxRefusalMessage(InsertFxRefusal::MasterOnlySelected);
|
|
|
|
CHECK(none.empty());
|
|
CHECK(!noCap.empty());
|
|
CHECK(!multi.empty());
|
|
CHECK(!noTrk.empty());
|
|
CHECK(!masterOnly.empty());
|
|
CHECK(noCap != multi);
|
|
CHECK(noCap != noTrk);
|
|
CHECK(multi != noTrk);
|
|
CHECK(masterOnly != noTrk);
|
|
CHECK(masterOnly != noCap);
|
|
CHECK(masterOnly != multi);
|
|
}
|
|
|
|
int main() {
|
|
testEveryCombination();
|
|
testMasterOnlySelectedIsDistinctFromNoTrack();
|
|
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;
|
|
}
|