Loading...
Searching...
No Matches
score-lib-state/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
20namespace
21{
22struct ScoreTestApplicationStarter final : Catch::EventListenerBase
23{
24 using Catch::EventListenerBase::EventListenerBase;
25 // NOT a function-local static. A static here is destroyed from the atexit
26 // chain, after main has returned and after Qt's own static state is gone.
27 // On Windows that gives:
28 // common_exit -> execute_onexit_table
29 // -> QApplication::~QApplication -> QGuiApplication::~QGuiApplication
30 // c0000005, reading 0xffffffffffffffff
31 // A test binary prints "All tests passed" and THEN faults, so ctest records
32 // a SegFault for a run that had entirely succeeded.
33 //
34 // Owning it here and dropping it in testRunEnded destroys the QApplication
35 // while the runtime is still intact. MinimalApplication's own destructor
36 // already tears the settings models down before releasing the app, for the
37 // same class of reason (see MinimalApplication.hpp) -- it just needs to run
38 // at a sane time.
39 std::unique_ptr<score::MinimalApplication> app;
40
41 void testRunStarting(const Catch::TestRunInfo&) override
42 {
43#if !defined(__EMSCRIPTEN__)
44 if(!qEnvironmentVariableIsSet("QT_QPA_PLATFORM"))
45 qputenv("QT_QPA_PLATFORM", "offscreen");
46#endif
47 app = std::make_unique<score::MinimalApplication>();
48 }
49
50 void testRunEnded(const Catch::TestRunStats&) override { app.reset(); }
51};
52}
53CATCH_REGISTER_LISTENER(ScoreTestApplicationStarter)