Loading...
Searching...
No Matches
score-lib-device/Tests/Utils.hpp
1#pragma once
2
3#include <State/Message.hpp>
4
6
7#include <core/application/MinimalApplication.hpp>
8#include <core/application/MockApplication.hpp>
9
10#include <ossia/network/domain/domain.hpp>
11
12#include <QMetaType>
13#include <QObject>
14
15#include <catch2/reporters/catch_reporter_event_listener.hpp>
16#include <catch2/reporters/catch_reporter_registrars.hpp>
17
18#include <memory>
19// Qt6: QDataStream stream operators and comparators for registered metatypes
20// are picked up automatically (qRegisterMetaTypeStreamOperators /
21// QMetaType::registerComparators were removed).
22namespace
23{
24struct ScoreTestApplicationStarter final : Catch::EventListenerBase
25{
26 using Catch::EventListenerBase::EventListenerBase;
27 // NOT a function-local static. A static here is destroyed from the atexit
28 // chain, after main has returned and after Qt's own static state is gone.
29 // On Windows that gives:
30 // common_exit -> execute_onexit_table
31 // -> QApplication::~QApplication -> QGuiApplication::~QGuiApplication
32 // c0000005, reading 0xffffffffffffffff
33 // A test binary prints "All tests passed" and THEN faults, so ctest records
34 // a SegFault for a run that had entirely succeeded.
35 //
36 // Owning it here and dropping it in testRunEnded destroys the QApplication
37 // while the runtime is still intact. MinimalApplication's own destructor
38 // already tears the settings models down before releasing the app, for the
39 // same class of reason (see MinimalApplication.hpp) -- it just needs to run
40 // at a sane time.
41 std::unique_ptr<score::MinimalApplication> app;
42
43 void testRunStarting(const Catch::TestRunInfo&) override
44 {
45#if !defined(__EMSCRIPTEN__)
46 if(!qEnvironmentVariableIsSet("QT_QPA_PLATFORM"))
47 qputenv("QT_QPA_PLATFORM", "offscreen");
48#endif
49 app = std::make_unique<score::MinimalApplication>();
50 }
51
52 void testRunEnded(const Catch::TestRunStats&) override { app.reset(); }
53};
54}
55CATCH_REGISTER_LISTENER(ScoreTestApplicationStarter)