2026-10-26 23:40:28 +01:00
|
|
|
#include "../../src/gui/main_window.hpp"
|
2026-10-26 23:55:35 +01:00
|
|
|
#include "../../src/gui/graph_widget.hpp"
|
2026-10-27 00:10:45 +01:00
|
|
|
#include "../../src/gui/sequencer_widget.hpp"
|
2026-10-26 23:40:28 +01:00
|
|
|
#include <FL/Fl.H>
|
|
|
|
|
#include <FL/Fl_Group.H>
|
|
|
|
|
#include <chrono>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
Fl_Widget *find(Fl_Group &group, const char *label)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < group.children(); ++i) {
|
|
|
|
|
Fl_Widget *child = group.child(i);
|
|
|
|
|
if (child->label() != nullptr && std::strstr(child->label(), label) != nullptr) return child;
|
|
|
|
|
if (auto *nested = dynamic_cast<Fl_Group *>(child)) if (auto *match = find(*nested, label)) return match;
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2026-10-26 23:55:35 +01:00
|
|
|
GraphWidget *canvas_in(Fl_Group &group)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < group.children(); ++i) {
|
|
|
|
|
if (auto *canvas = dynamic_cast<GraphWidget *>(group.child(i))) return canvas;
|
|
|
|
|
if (auto *nested = dynamic_cast<Fl_Group *>(group.child(i))) if (auto *canvas = canvas_in(*nested)) return canvas;
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2026-10-27 00:10:45 +01:00
|
|
|
SequencerWidget *timeline_in(Fl_Group &group)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < group.children(); ++i) {
|
|
|
|
|
if (auto *s = dynamic_cast<SequencerWidget *>(group.child(i))) return s;
|
|
|
|
|
if (auto *g = dynamic_cast<Fl_Group *>(group.child(i))) if (auto *s = timeline_in(*g)) return s;
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2026-10-26 23:40:28 +01:00
|
|
|
void pump()
|
|
|
|
|
{
|
|
|
|
|
const auto end = std::chrono::steady_clock::now() + std::chrono::milliseconds(400);
|
|
|
|
|
while (std::chrono::steady_clock::now() < end) Fl::wait(0.02);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#define CHECK(c) do { if (!(c)) { std::fprintf(stderr,"FAIL %s:%d: %s\n",__FILE__,__LINE__,#c); return 1; } } while (0)
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
// Real JACK backend and real FLTK event loop. No routes, no playback data.
|
|
|
|
|
for (int iteration = 0; iteration < 3; ++iteration) {
|
2026-10-27 00:10:45 +01:00
|
|
|
MainWindow window(false);
|
2026-10-26 23:40:28 +01:00
|
|
|
window.show(argc, argv);
|
|
|
|
|
CHECK(find(window, "ready / stopped") != nullptr);
|
|
|
|
|
auto *play = find(window, "Play");
|
|
|
|
|
auto *stop = find(window, "Stop");
|
|
|
|
|
auto *reconnect = find(window, "Reconnect");
|
|
|
|
|
CHECK(play != nullptr && stop != nullptr && reconnect != nullptr);
|
2026-10-26 23:55:35 +01:00
|
|
|
auto *canvas = canvas_in(window);
|
|
|
|
|
CHECK(canvas != nullptr);
|
2026-10-27 00:10:45 +01:00
|
|
|
auto *timeline = timeline_in(window); CHECK(timeline != nullptr);
|
2026-10-26 23:55:35 +01:00
|
|
|
CHECK(canvas->add_node(XTC_NODE_OSCILLATOR) == XTC_OK);
|
|
|
|
|
CHECK(canvas->add_node(XTC_NODE_GAIN) == XTC_OK);
|
|
|
|
|
CHECK(canvas->add_node(XTC_NODE_OUTPUT) == XTC_OK);
|
|
|
|
|
CHECK(canvas->connect_ports({0U, 1U, 1U, 0U}) == XTC_OK);
|
|
|
|
|
CHECK(canvas->connect_ports({1U, 1U, 2U, 0U}) == XTC_OK);
|
2026-10-26 23:40:28 +01:00
|
|
|
for (int restart = 0; restart < 3; ++restart) {
|
2026-10-27 00:10:45 +01:00
|
|
|
uint64_t previous = timeline->position();
|
2026-10-26 23:40:28 +01:00
|
|
|
CHECK(play->active());
|
|
|
|
|
play->do_callback();
|
|
|
|
|
pump();
|
2026-10-26 23:55:35 +01:00
|
|
|
CHECK(find(window, "running — modular graph") != nullptr);
|
2026-10-27 00:10:45 +01:00
|
|
|
CHECK(timeline->position() > previous);
|
2026-10-26 23:55:35 +01:00
|
|
|
CHECK(find(window, "Graph: active in engine") != nullptr);
|
|
|
|
|
const xtc_graph *unchanged = canvas->graph();
|
|
|
|
|
CHECK(canvas->connect_ports({1U, 1U, 1U, 0U}) == XTC_ERR_GRAPH_CYCLE);
|
|
|
|
|
CHECK(canvas->graph() == unchanged);
|
|
|
|
|
CHECK(canvas->add_node(XTC_NODE_METER) == XTC_OK);
|
|
|
|
|
pump();
|
|
|
|
|
CHECK(find(window, "Graph: active in engine") != nullptr);
|
|
|
|
|
CHECK(canvas->delete_selected() == XTC_OK);
|
|
|
|
|
pump();
|
|
|
|
|
CHECK(find(window, "Graph: active in engine") != nullptr);
|
2026-10-26 23:40:28 +01:00
|
|
|
auto *status = find(window, "JACK |");
|
|
|
|
|
CHECK(status != nullptr);
|
|
|
|
|
unsigned int rate = 0U, frames = 0U, blocks = 0U;
|
|
|
|
|
CHECK(std::sscanf(status->label(), "JACK | %u Hz | %u frames | mono | %u blocks", &rate, &frames, &blocks) == 3);
|
|
|
|
|
CHECK(rate > 0U && frames > 0U && blocks > 0U);
|
|
|
|
|
stop->do_callback();
|
|
|
|
|
CHECK(find(window, "ready / stopped") != nullptr);
|
2026-10-27 00:10:45 +01:00
|
|
|
uint64_t paused = timeline->position(); pump();
|
|
|
|
|
CHECK(timeline->position() == paused);
|
2026-10-26 23:40:28 +01:00
|
|
|
}
|
|
|
|
|
reconnect->do_callback();
|
|
|
|
|
CHECK(find(window, "ready / stopped") != nullptr);
|
|
|
|
|
play->do_callback();
|
|
|
|
|
pump();
|
2026-10-26 23:55:35 +01:00
|
|
|
CHECK(find(window, "running — modular graph") != nullptr);
|
2026-10-26 23:40:28 +01:00
|
|
|
window.do_callback(); // Close with an active client; synchronizes callbacks.
|
|
|
|
|
CHECK(!window.shown());
|
|
|
|
|
pump(); // No timer may access the closed client.
|
|
|
|
|
}
|
2026-10-26 23:55:35 +01:00
|
|
|
std::puts("Live GUI/JACK graph edits/revision acknowledgements/start/stop/reconnect/active-close tests passed.");
|
2026-10-26 23:40:28 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|