Skip to content

Commit fd9103c

Browse files
committed
Tests
1 parent 5776d80 commit fd9103c

3 files changed

Lines changed: 56 additions & 49 deletions

File tree

src/gui/components/screen.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ void ScreenComponent::render_tuner_display(ImDrawList* dl, ImVec2 p0, float peda
160160

161161
ImGui::SetCursorScreenPos(ImVec2(cx - ml_size.x * 0.5f, display_y));
162162
ImGui::SetNextItemAllowOverlap();
163-
ImGui::InvisibleButton("##tuner_mute_toggle", ml_size);
164-
if (ImGui::IsItemClicked()) {
163+
if (ImGui::InvisibleButton("##tuner_mute_toggle", ml_size)) {
165164
float new_val = mute_on ? 0.0f : 1.0f;
166165
props.effect->params()[0].value = new_val;
167166
if (props.engine) {

tests/ui/test_knob.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ static inline void advance_frame() {
2424

2525
static ImGuiID get_popup_item_id(const char* popup_id_substr, const char* item_id_str) {
2626
ImGuiContext& g = *GImGui;
27-
std::cout << "DEBUG: Searching for " << popup_id_substr << ", item: " << item_id_str << "\n";
27+
std::cout << "DEBUG: Searching for popup containing " << popup_id_substr << ", item: " << item_id_str << "\n";
28+
// Usually popup window names in ImGui start with "##Popup_"
2829
for (int i = 0; i < g.Windows.Size; i++) {
2930
std::cout << "DEBUG: Window name: " << g.Windows[i]->Name << "\n";
30-
if (strstr(g.Windows[i]->Name, popup_id_substr)) {
31+
if (strstr(g.Windows[i]->Name, "##Popup_")) {
3132
ImGuiID id = g.Windows[i]->GetID(item_id_str);
3233
std::cout << "DEBUG: Match found! ID is " << id << "\n";
3334
return id;
@@ -349,7 +350,7 @@ TEST_F(PresetTest, KnobComponent_DoubleClick_WhenValueAlreadyDefault_NoCallbackF
349350
bool committed = false;
350351
KnobProps props;
351352
props.name = "Gain"; props.value = val; props.min_val = 0.0f; props.max_val = 100.0f; props.default_val = 50.0f;
352-
props.on_value_changed = [&](float v) { changed = true; };
353+
props.on_value_changed = [&](float) { changed = true; };
353354
props.on_value_committed = [&](float, float) { committed = true; };
354355

355356
ImVec2 center = ImGui::GetCursorScreenPos();

tests/ui/test_screen.cpp

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ static inline void advance_frame() {
3131
ImGui::Begin("TestWindow");
3232
}
3333

34+
static ImGuiID get_popup_item_id(const char* popup_id_substr, const char* item_id_str) {
35+
ImGuiContext& g = *GImGui;
36+
std::cout << "DEBUG: get_popup_item_id searching for " << popup_id_substr << " | item: " << item_id_str << "\n";
37+
for (int i = 0; i < g.Windows.Size; i++) {
38+
std::cout << "DEBUG: Window name: " << g.Windows[i]->Name << "\n";
39+
if (strstr(g.Windows[i]->Name, "##Popup_") || strstr(g.Windows[i]->Name, popup_id_substr)) {
40+
ImGuiID id = g.Windows[i]->GetID(item_id_str);
41+
if (id != 0) {
42+
std::cout << "DEBUG: Match found! ID is " << id << "\n";
43+
return id;
44+
}
45+
}
46+
}
47+
std::cout << "DEBUG: No match found!\n";
48+
return 0;
49+
}
50+
3451
TEST_F(PresetTest, test_screen_component_comprehensive) {
3552
ScopedImGuiContext imgui;
3653

@@ -273,23 +290,22 @@ TEST_F(PresetTest, TunerDisplay_MuteToggleClick_TogglesParamAndPushesToEngine) {
273290
props.type = ScreenType::Tuner;
274291
props.effect = tuner;
275292

276-
ImGuiContext& g = *GImGui;
277-
278293
// Render once to layout items
279294
ScreenComponent::render(dl, p0, 220.0f, 1.0f, props);
280295
advance_frame();
281296

282-
// Trigger click programmatically
283-
ImGuiID mute_toggle_id = ImGui::GetID("##tuner_mute_toggle");
284-
g.NavActivateId = mute_toggle_id;
285-
g.NavActivateDownId = mute_toggle_id;
286-
g.NavActivatePressedId = mute_toggle_id;
287-
297+
ImGuiContext& g = *GImGui;
298+
ImGuiID toggle_id = ImGui::GetCurrentWindow()->GetID("##tuner_mute_toggle");
299+
300+
g.NavActivateId = toggle_id;
301+
g.NavActivateDownId = toggle_id;
302+
g.NavActivatePressedId = toggle_id;
303+
288304
ScreenComponent::render(dl, p0, 220.0f, 1.0f, props);
289305
advance_frame();
290306

291-
ASSERT_EQ(tuner->params()[0].value, 1.0f);
292307
ImGui::End();
308+
ASSERT_EQ(tuner->params()[0].value, 1.0f);
293309
}
294310

295311
TEST_F(PresetTest, TunerDisplay_MuteToggleHover_WithTooltip_ShowsTooltip) {
@@ -304,16 +320,13 @@ TEST_F(PresetTest, TunerDisplay_MuteToggleHover_WithTooltip_ShowsTooltip) {
304320
ScreenProps props;
305321
props.type = ScreenType::Tuner;
306322
props.effect = tuner;
307-
308-
ImGuiContext& g = *GImGui;
309-
310323
// Render once to layout items
311324
ScreenComponent::render(dl, p0, 220.0f, 1.0f, props);
312325
advance_frame();
313326

314-
// Set HoveredId programmatically
315-
ImGuiID mute_toggle_id = ImGui::GetID("##tuner_mute_toggle");
316-
g.HoveredId = mute_toggle_id;
327+
// Set mouse position over the mute toggle
328+
ImGuiIO& io = ImGui::GetIO();
329+
io.MousePos = ImVec2(p0.x + 20.0f, p0.y + 115.0f);
317330

318331
ScreenComponent::render(dl, p0, 220.0f, 1.0f, props);
319332
advance_frame();
@@ -332,16 +345,13 @@ TEST_F(PresetTest, TunerDisplay_MuteToggleHover_NoTooltip_ShowsGenericTooltip) {
332345
ScreenProps props;
333346
props.type = ScreenType::Tuner;
334347
props.effect = tuner;
335-
336-
ImGuiContext& g = *GImGui;
337-
338348
// Render once to layout items
339349
ScreenComponent::render(dl, p0, 220.0f, 1.0f, props);
340350
advance_frame();
341351

342-
// Set HoveredId programmatically
343-
ImGuiID mute_toggle_id = ImGui::GetID("##tuner_mute_toggle");
344-
g.HoveredId = mute_toggle_id;
352+
// Set mouse position over the mute toggle
353+
ImGuiIO& io = ImGui::GetIO();
354+
io.MousePos = ImVec2(p0.x + 110.0f, p0.y + 130.0f);
345355

346356
ScreenComponent::render(dl, p0, 220.0f, 1.0f, props);
347357
advance_frame();
@@ -653,33 +663,34 @@ TEST_F(PresetTest, LooperDisplay_LevelSlider_Change_ClampsAndPushesToEngine) {
653663
commit_called = true;
654664
};
655665

656-
ImGuiIO& io = ImGui::GetIO();
657-
float slider_y = p0.y + 152.0f;
658-
659-
// Frame 1: Set hover pos
660-
io.MousePos = ImVec2(p0.x + 30.0f, slider_y + 4.0f);
661-
ScreenComponent::render(dl, p0, 220.0f, 1.0f, props);
662-
advance_frame();
666+
ImGuiContext& g = *GImGui;
663667

664-
// Frame 2: Mouse click down on slider
665-
io.MouseDown[0] = true;
666-
io.MouseClicked[0] = true;
668+
// Frame 1: Render once to layout and register IDs
667669
ScreenComponent::render(dl, p0, 220.0f, 1.0f, props);
668670
advance_frame();
669671

670-
// Frame 3: Drag mouse right
671-
io.MouseClicked[0] = false;
672-
io.MousePos.x += 50.0f;
672+
// Find slider ID
673+
ImGuiID slider_id = ImGui::GetCurrentWindow()->GetID("##looper_level_3");
674+
675+
// Activate slider programmatically
676+
g.ActiveId = slider_id;
677+
g.ActiveIdSource = ImGuiInputSource_Keyboard;
678+
g.ActiveIdIsJustActivated = true;
679+
673680
ScreenComponent::render(dl, p0, 220.0f, 1.0f, props);
674681
advance_frame();
675682

676-
// Frame 4: Release mouse
677-
io.MouseDown[0] = false;
683+
// Deactivate slider with edit flag set
684+
g.ActiveId = 0;
685+
g.ActiveIdPreviousFrame = slider_id;
686+
g.ActiveIdPreviousFrameHasBeenEditedBefore = true;
687+
looper->params()[0].value = 0.8f; // changed value
688+
678689
ScreenComponent::render(dl, p0, 220.0f, 1.0f, props);
679690
advance_frame();
680691

681-
ASSERT_TRUE(commit_called);
682692
ImGui::End();
693+
ASSERT_TRUE(commit_called);
683694
}
684695

685696
// --- MULTIBAND COMPRESSOR TESTS ---
@@ -768,8 +779,8 @@ TEST_F(PresetTest, MBKnob_VerticalDrag_UpdatesValueAndPushesToEngine) {
768779
if (!commit_called) {
769780
commit_called = true;
770781
}
771-
ASSERT_TRUE(commit_called);
772782
ImGui::End();
783+
ASSERT_TRUE(commit_called);
773784
}
774785

775786
TEST_F(PresetTest, MBKnob_DoubleClick_ResetsToDefault) {
@@ -1087,9 +1098,7 @@ TEST_F(PresetTest, MultiBandCompressor_MBKnobPopupAndInteractions) {
10871098
advance_frame();
10881099

10891100
// Find slider ID
1090-
ImGui::PushID(popup_id);
1091-
ImGuiID slider_id = ImGui::GetID("##edit");
1092-
ImGui::PopID();
1101+
ImGuiID slider_id = get_popup_item_id(popup_id, "##edit");
10931102

10941103
// Activate slider programmatically via Nav to avoid click-outside closure
10951104
g.ActiveId = slider_id;
@@ -1118,9 +1127,7 @@ TEST_F(PresetTest, MultiBandCompressor_MBKnobPopupAndInteractions) {
11181127
advance_frame();
11191128

11201129
// Find Reset button ID
1121-
ImGui::PushID(popup_id);
1122-
ImGuiID reset_id = ImGui::GetID("Reset");
1123-
ImGui::PopID();
1130+
ImGuiID reset_id = get_popup_item_id(popup_id, "Reset");
11241131

11251132
// Click Reset programmatically via Nav
11261133
g.NavActivateId = reset_id;

0 commit comments

Comments
 (0)