1 /*
2     SPDX-FileCopyrightText: 2015-2020 Ralf Habacker <ralf.habacker@freenet.de>
3 
4     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5 */
6 
7 #include "testbase.h"
8 
9 // app includes
10 #include "codegenerationpolicy.h"
11 #include "uml.h"
12 #include "umldoc.h"
13 
14 // qt includes
15 #include <QApplication>
16 
17 #if !defined(QT_GUI_LIB)
18 #error umbrello unittests require QT_GUI_LIB to be present
19 #endif
20 
21 #if QT_VERSION < 0x050000
22 #include <KTempDir>
23 #endif
24 
25 #if QT_VERSION >= 0x050000
26 #include <QTemporaryDir>
27 #endif
28 
TestBase(QObject * parent)29 TestBase::TestBase(QObject *parent)
30   : QObject(parent)
31 {
32 }
33 
initTestCase()34 void TestBase::initTestCase()
35 {
36     QWidget *w = new QWidget;
37     UMLApp *app = new UMLApp(w);
38     app->setActiveLanguage(Uml::ProgrammingLanguage::Cpp);
39 }
40 
cleanupTestCase()41 void TestBase::cleanupTestCase()
42 {
43     foreach(QObject *p, m_objectsToDelete) {
44         delete p;
45     }
46     delete UMLApp::app();
47 }
48 
cleanupOnExit(QObject * p)49 void TestBase::cleanupOnExit(QObject *p)
50 {
51     m_objectsToDelete.append(p);
52 }
53 
initTestCase()54 void TestCodeGeneratorBase::initTestCase()
55 {
56     TestBase::initTestCase();
57 
58 #if QT_VERSION >= 0x050000
59     static QTemporaryDir tmpDir;
60     m_tempPath = tmpDir.path() + QLatin1String("/");
61 #else
62     static KTempDir tmpDir;
63     m_tempPath = tmpDir.name();
64 #endif
65     UMLApp::app()->commonPolicy()->setOutputDirectory(m_tempPath);
66 }
67 
68 /**
69  * Return temporary path usable to generated code.
70  * @return
71  */
temporaryPath()72 QString TestCodeGeneratorBase::temporaryPath()
73 {
74     return m_tempPath;
75 }
76 
SetLoading()77 SetLoading::SetLoading()
78 {
79     _state = UMLApp::app()->document()->loading();
80     UMLApp::app()->document()->setLoading();
81 }
82 
~SetLoading()83 SetLoading::~SetLoading()
84 {
85     UMLApp::app()->document()->setLoading(_state);
86 }
87