60 lines
2.4 KiB
C++
60 lines
2.4 KiB
C++
#include "../../src/gui/main_window.hpp"
|
|
#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;
|
|
}
|
|
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) {
|
|
MainWindow window;
|
|
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);
|
|
for (int restart = 0; restart < 3; ++restart) {
|
|
CHECK(play->active());
|
|
play->do_callback();
|
|
pump();
|
|
CHECK(find(window, "running (silence") != nullptr);
|
|
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);
|
|
}
|
|
reconnect->do_callback();
|
|
CHECK(find(window, "ready / stopped") != nullptr);
|
|
play->do_callback();
|
|
pump();
|
|
CHECK(find(window, "running (silence") != nullptr);
|
|
window.do_callback(); // Close with an active client; synchronizes callbacks.
|
|
CHECK(!window.shown());
|
|
pump(); // No timer may access the closed client.
|
|
}
|
|
std::puts("Live GUI/JACK start/stop/reconnect/active-close tests passed.");
|
|
return 0;
|
|
}
|