Re-derive the floor-size test fixtures from the constants and move the ceiling to sample_bands.h

This commit is contained in:
2026-08-01 19:05:48 -04:00
parent abb27f08f2
commit ae54ca8128
5 changed files with 109 additions and 29 deletions
+38 -21
View File
@@ -8,7 +8,8 @@
// octave boundaries and the 0..127 extremes; keyRect tiling and black-over-white overlap;
// keyAtPoint resolving black-over-white by zone and missing off-band; the root affordance's
// hit-to-marker round trip; resolveDragNote clamping a wandering pointer; noteName under the
// C4 (MIDI 60) DAW convention; and the gutter pinned at the shipped default window size.
// C4 (MIDI 60) DAW convention; the gutter at the sawtooth's maximum residue; and the gutter
// pinned at the shipped default window size (derived from kEditorMinWidth/kEditorMinHeight).
//
// Client-pixel-only guarantee: every width swept below is a CLIENT-pixel width. Nothing in
// the instrument implements IPlugViewContentScaleSupport, so if a host scales the plugin
@@ -280,28 +281,18 @@ static void testNoteNamesFollowTheC4Convention() {
CHECK(noteName(500) == "G9");
}
// --- the gutter at the shipped default window size -----------------------------
// --- the gutter at the sawtooth's maximum residue -------------------------------
// The rule-based sweep above pins `margins == w % 75` and `leftMargin == margins/2` at every
// width, but pins no concrete number — Daniel is making a visual call on the specific gutter
// at the shipped default, and neither kPad nor the 840 default is covered by another test
// firing if either ever changes. The strip is a sawtooth with period kStripWhiteKeyCount (75)
// px of window width, and the shipped 840 default lands on residue 74 — the cycle's maximum:
// one pixel of resize (840->841) collapses both gutters to zero and grows every white key
// from 10px to 11px.
static void testGutterAtTheShippedDefaultWindowSize() {
constexpr int kShippedDefaultWindowW = 840; // editor_session.cpp's ViewRect default
constexpr int kShippedDefaultWindowH = 620; // editor_session.cpp's ViewRect default
// Derive rootStrip's width the same way the shell does, through the real allocator +
// chrome layout, rather than re-deriving the inset formula — so a change to either one
// fails this test instead of silently moving the shipped gutter out from under it.
const SampleBands bands =
computeSampleBands(kShippedDefaultWindowW, kShippedDefaultWindowH, 0);
const ChromeRects chrome = chromeRects(bands.chrome, /*knobSize=*/24);
const int stripW = chrome.rootStrip.width;
CHECK(stripW == 824);
const StripLayout L = layoutStrip(stripW, 30);
// width, but pins no concrete number. The strip is a sawtooth with period kStripWhiteKeyCount
// (75) px of window width; 840 is an arbitrary but independently useful sample because it
// lands on residue 74 — the cycle's maximum: one pixel of resize (840->841) collapses both
// gutters to zero and grows every white key from 10px to 11px. Kept as a synthetic worst-case
// sample; NOT tied to any shipped window size (see testGutterAtTheShippedDefaultWindowSize
// below for that).
static void testGutterAtTheSawtoothMaximumResidueWidth() {
constexpr int kSawtoothMaxResidueStripW = 824; // an arbitrary width landing on residue 74
const StripLayout L = layoutStrip(kSawtoothMaxResidueStripW, 30);
CHECK(L.whiteWidth == 10);
const int margins = L.band.width - L.keys.width;
CHECK(margins == 74);
@@ -309,6 +300,31 @@ static void testGutterAtTheShippedDefaultWindowSize() {
CHECK(leftMargin == 37);
}
// --- the gutter at the shipped default window size -----------------------------
// Daniel is making a visual call on the specific gutter at the shipped default; neither kPad
// nor the floor is covered by another test firing if either ever changes. Derived from
// kEditorMinWidth/kEditorMinHeight (editor_session.cpp's ViewRect default IS the floor) rather
// than a hardcoded window size, so a floor change fails HERE instead of silently moving the
// shipped gutter out from under it. The numbers below are today's floor (1190x680); re-derive
// them by hand if the floor ever moves.
static void testGutterAtTheShippedDefaultWindowSize() {
// Derive rootStrip's width the same way the shell does, through the real allocator +
// chrome layout, rather than re-deriving the inset formula.
const SampleBands bands = computeSampleBands(kEditorMinWidth, kEditorMinHeight, 0);
const ChromeRects chrome = chromeRects(bands.chrome, /*knobSize=*/24);
const int stripW = chrome.rootStrip.width;
CHECK(stripW == kEditorMinWidth - 2 * kPad);
CHECK(stripW == 1174);
const StripLayout L = layoutStrip(stripW, 30);
CHECK(L.whiteWidth == 15);
const int margins = L.band.width - L.keys.width;
CHECK(margins == 49);
const int leftMargin = L.keys.x - L.band.x;
CHECK(leftMargin == 24);
}
int main() {
testLayoutFillsTheBandAndCentresTheKeys();
testDegenerateSizesYieldNoKeys();
@@ -325,6 +341,7 @@ int main() {
testHitTestingAKeyMarksThatSameKey();
testDragTracksThePointerAndClampsWhenItWanders();
testNoteNamesFollowTheC4Convention();
testGutterAtTheSawtoothMaximumResidueWidth();
testGutterAtTheShippedDefaultWindowSize();
if (g_fail == 0) {