Commit 0cbe2a0000ec9e9c2e0a23acbf94a6a0bfd9b6f2
1 parent
e1c7b86f
Fix main app scope in tests
It didn't clean up the old ones, causing unpredictable problems.
Showing
3 changed files
with
10 additions
and
4 deletions
FlashMQTests/mainappthread.cpp
| @@ -19,15 +19,19 @@ License along with FlashMQ. If not, see <https://www.gnu.org/licenses/>. | @@ -19,15 +19,19 @@ License along with FlashMQ. If not, see <https://www.gnu.org/licenses/>. | ||
| 19 | 19 | ||
| 20 | MainAppThread::MainAppThread(QObject *parent) : QThread(parent) | 20 | MainAppThread::MainAppThread(QObject *parent) : QThread(parent) |
| 21 | { | 21 | { |
| 22 | + MainApp::initMainApp(1, nullptr); | ||
| 23 | + appInstance = MainApp::getMainApp(); | ||
| 24 | + appInstance->settings->allowAnonymous = true; | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +MainAppThread::~MainAppThread() | ||
| 28 | +{ | ||
| 22 | if (appInstance) | 29 | if (appInstance) |
| 23 | { | 30 | { |
| 24 | delete appInstance; | 31 | delete appInstance; |
| 32 | + MainApp::instance = nullptr; | ||
| 25 | } | 33 | } |
| 26 | appInstance = nullptr; | 34 | appInstance = nullptr; |
| 27 | - MainApp::instance = nullptr; | ||
| 28 | - MainApp::initMainApp(1, nullptr); | ||
| 29 | - appInstance = MainApp::getMainApp(); | ||
| 30 | - appInstance->settings->allowAnonymous = true; | ||
| 31 | } | 35 | } |
| 32 | 36 | ||
| 33 | void MainAppThread::run() | 37 | void MainAppThread::run() |
FlashMQTests/mainappthread.h
| @@ -28,6 +28,7 @@ class MainAppThread : public QThread | @@ -28,6 +28,7 @@ class MainAppThread : public QThread | ||
| 28 | MainApp *appInstance = nullptr; | 28 | MainApp *appInstance = nullptr; |
| 29 | public: | 29 | public: |
| 30 | explicit MainAppThread(QObject *parent = nullptr); | 30 | explicit MainAppThread(QObject *parent = nullptr); |
| 31 | + ~MainAppThread(); | ||
| 31 | 32 | ||
| 32 | public slots: | 33 | public slots: |
| 33 | void run() override; | 34 | void run() override; |
FlashMQTests/tst_maintests.cpp
| @@ -102,6 +102,7 @@ MainTests::~MainTests() | @@ -102,6 +102,7 @@ MainTests::~MainTests() | ||
| 102 | 102 | ||
| 103 | void MainTests::init() | 103 | void MainTests::init() |
| 104 | { | 104 | { |
| 105 | + mainApp.reset(); | ||
| 105 | mainApp.reset(new MainAppThread()); | 106 | mainApp.reset(new MainAppThread()); |
| 106 | mainApp->start(); | 107 | mainApp->start(); |
| 107 | mainApp->waitForStarted(); | 108 | mainApp->waitForStarted(); |