umbrello 2.38.4
Umbrello UML Modeller is a Unified Modelling Language (UML) diagram program based on KDE Technology
testbase.h
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2015, 2019 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#ifndef TESTBASE_H
8#define TESTBASE_H
9
10// qt includes
11#include <QObject>
12#include <QtTest>
13
14#ifdef RUN_ALL
15#undef QCOMPARE
16#define QCOMPARE(actual, expected) \
17 QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__)
18#undef QVERIFY
19#define QVERIFY(statement) \
20 QTest::qVerify((statement), #statement, "", __FILE__, __LINE__)
21#endif
22
23#define IS_NOT_IMPL() QSKIP("not implemented yet", SkipSingle)
24
33class TestBase : public QObject
34{
35 Q_OBJECT
36public:
37 explicit TestBase(QObject *parent = 0);
38
39protected slots:
40 virtual void initTestCase();
41 virtual void cleanupTestCase();
42 virtual void cleanupOnExit(QObject *p);
43
44protected:
45 QList<QPointer<QObject>> m_objectsToDelete;
46};
47
57{
58 Q_OBJECT
59private slots:
60 virtual void initTestCase();
61
62protected:
63 QString m_tempPath;
64 QString temporaryPath();
65};
66
67#include <QSignalBlocker>
68typedef QSignalBlocker SignalBlocker;
69
74{
75public:
76 SetLoading();
78protected:
79 bool _state;
80};
81
82#include <QDomDocument>
83#include <QXmlStreamWriter>
84#include "uml.h"
85#include "umldoc.h"
86
90template <class T, typename N>
91class TestUML : public T
92{
93public:
94 TestUML<T,N>() : T() {}
95 TestUML<T,N>(N name) : T(name) {}
96 TestUML<T,N>(N p1, UMLObject *p2, UMLObject *p3) : T(p1, p2, p3) {}
97 QString testSave1();
98 bool testLoad1(const QString& xml);
99 void testDump(const QString &title = QString());
101};
102
103template <class T, typename N>
105{
106 QString xml;
107 QXmlStreamWriter stream(&xml);
108 stream.writeStartElement("unittest");
109 T::saveToXMI(stream);
110 stream.writeEndElement();
111 return xml;
112}
113
114template <class T, typename N>
115bool TestUML<T,N>::testLoad1(const QString& xml)
116{
117 QDomDocument qDoc;
118 QString error;
119 int line;
120 if (!qDoc.setContent(xml, &error, &line))
121 return false;
122 QDomElement root = qDoc.childNodes().at(0).toElement();
123 QDomElement e = root.childNodes().at(0).toElement();
124 bool result = T::loadFromXMI(e);
125 if (result) {
126 const SignalBlocker sb(UMLApp::app()->document());
127 result = T::resolveRef();
128 }
129 return result;
130}
131
132template <class T, typename N>
133void TestUML<T,N>::testDump(const QString &title)
134{
135 QString xml = testSave1();
136 qDebug() << title << xml;
137}
138
139// used by resolveRef() tests
140template <class T, typename N>
142{
143 return T::m_pSecondary.data();
144}
145
149template <class T, typename N>
150class TestWidget : public T
151{
152public:
153 TestWidget<T,N>(UMLScene *scene, N w) : T(scene, w) {}
154 QString testSave1();
155 bool testLoad1(const QString& xml);
156 void testDump(const QString &title = QString());
157};
158
159template <class T, typename N>
161{
162 QString xml;
163 QXmlStreamWriter stream(&xml);
164 stream.writeStartElement("unittest");
165 T::saveToXMI(stream);
166 stream.writeEndElement();
167 return xml;
168}
169
170template <class T, typename N>
171bool TestWidget<T,N>::testLoad1(const QString& xml)
172{
173 QDomDocument qDoc;
174 QString error;
175 int line;
176 if (!qDoc.setContent(xml, &error, &line))
177 return false;
178 QDomElement root = qDoc.childNodes().at(0).toElement();
179 QDomElement e = root.childNodes().at(0).toElement();
180 bool result = T::loadFromXMI(e);
181 if (result) {
182 const SignalBlocker sb(UMLApp::app()->document());
183 result = T::activate(nullptr);
184 }
185 return result;
186}
187
188template <class T, typename N>
189void TestWidget<T,N>::testDump(const QString &title)
190{
191 QString xml = testSave1();
192 qDebug() << title << xml;
193}
194
195#endif // TESTBASE_H
Definition testbase.h:74
SetLoading()
Definition testbase.cpp:67
~SetLoading()
Definition testbase.cpp:73
bool _state
Definition testbase.h:79
Definition testbase.h:34
virtual void initTestCase()
Definition testbase.cpp:28
virtual void cleanupOnExit(QObject *p)
Definition testbase.cpp:44
virtual void cleanupTestCase()
Definition testbase.cpp:36
QList< QPointer< QObject > > m_objectsToDelete
Definition testbase.h:45
Definition testbase.h:57
virtual void initTestCase()
Definition testbase.cpp:49
QString temporaryPath()
Definition testbase.cpp:62
QString m_tempPath
holds path to temporary directory
Definition testbase.h:63
Definition testbase.h:92
QString testSave1()
Definition testbase.h:104
UMLObject * secondary() const
Definition testbase.h:141
void testDump(const QString &title=QString())
Definition testbase.h:133
bool testLoad1(const QString &xml)
Definition testbase.h:115
Definition testbase.h:151
void testDump(const QString &title=QString())
Definition testbase.h:189
bool testLoad1(const QString &xml)
Definition testbase.h:171
QString testSave1()
Definition testbase.h:160
static UMLApp * app()
Definition uml.cpp:306
The base class for UML objects.
Definition umlobject.h:70
Definition umlscene.h:65
QSignalBlocker SignalBlocker
Definition testbase.h:68