From 1d9cd50463725abc82f33aaffb8227325b0806b8 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 11 Oct 2019 00:38:12 +0200 Subject: [PATCH] [AFV] Fix context UNIT test crash * crash: A crash occurred in C:\jenkins\workspace\swift_wip_fsd_and_afv_client\build\out\release\bin\testcontext.exe. * ASSERT in const QList allQtDevices2 = QAudioDeviceInfo::availableDevices(QAudio::AudioInput) * figured out it fails in a Qt console app, runs in a widget app * see https://discordapp.com/channels/539048679160676382/623947987822837779/631939335255752704 --- .../context/testcontext/testcontext.cpp | 20 ++++++++++++++++++- .../context/testcontext/testcontext.pro | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/blackcore/context/testcontext/testcontext.cpp b/tests/blackcore/context/testcontext/testcontext.cpp index 3d14d86ef..e25807082 100644 --- a/tests/blackcore/context/testcontext/testcontext.cpp +++ b/tests/blackcore/context/testcontext/testcontext.cpp @@ -17,6 +17,10 @@ #include "test.h" #include +#ifdef _WIN32 +#include "comdef.h" +#endif + using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::Simulation; @@ -48,6 +52,9 @@ namespace BlackCoreTest return; } + // CContextAudioProxy::unitTestRelaySignals() crashes in QAudioDeviceInfo::availableDevices(QAudio::AudioInput) + // discussion https://discordapp.com/channels/539048679160676382/623947987822837779/631940817669455903 + // solved if unit test initializes a QGuiApplication CContextAudioProxy::unitTestRelaySignals(); CContextNetworkProxy::unitTestRelaySignals(); CContextOwnAircraftProxy::unitTestRelaySignals(); @@ -79,7 +86,18 @@ namespace BlackCoreTest //! main int main(int argc, char *argv[]) { - QCoreApplication app(argc, argv); + // QCoreApplication app(argc, argv); + // discussion https://discordapp.com/channels/539048679160676382/623947987822837779/631940817669455903 + // QDeviceInfo crashes using QCoreApplication + +#ifdef _WIN32 + QGuiApplication app(argc, argv); + const HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED); + Q_UNUSED(hr) +#else + QCoreApplication app(argc, argv); // using QGuiApplication fails on Jenkins Linux, no display +#endif + BLACKTEST_INIT(BlackCoreTest::CTestContext) CApplication a(CApplicationInfo::UnitTest); a.addVatlibOptions(); diff --git a/tests/blackcore/context/testcontext/testcontext.pro b/tests/blackcore/context/testcontext/testcontext.pro index da9edf2a8..cde45d81e 100644 --- a/tests/blackcore/context/testcontext/testcontext.pro +++ b/tests/blackcore/context/testcontext/testcontext.pro @@ -1,6 +1,6 @@ load(common_pre) -QT += core dbus network testlib multimedia +QT += core dbus network testlib multimedia gui TARGET = testcontext CONFIG -= app_bundle