1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtTest module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #ifndef QTESTCOREELEMENT_P_H
41 #define QTESTCOREELEMENT_P_H
42
43 //
44 // W A R N I N G
45 // -------------
46 //
47 // This file is not part of the Qt API. It exists purely as an
48 // implementation detail. This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53
54 #include <QtTest/private/qtestcorelist_p.h>
55 #include <QtTest/private/qtestelementattribute_p.h>
56
57 QT_BEGIN_NAMESPACE
58
59
60 template <class ElementType>
61 class QTestCoreElement: public QTestCoreList<ElementType>
62 {
63 public:
64 QTestCoreElement( int type = -1 );
65 virtual ~QTestCoreElement();
66
67 void addAttribute(const QTest::AttributeIndex index, const char *value);
68 QTestElementAttribute *attributes() const;
69 const char *attributeValue(QTest::AttributeIndex index) const;
70 const char *attributeName(QTest::AttributeIndex index) const;
71 const QTestElementAttribute *attribute(QTest::AttributeIndex index) const;
72
73 const char *elementName() const;
74 QTest::LogElementType elementType() const;
75
76 private:
77 QTestElementAttribute *listOfAttributes = nullptr;
78 QTest::LogElementType type;
79 };
80
81 template<class ElementType>
QTestCoreElement(int t)82 QTestCoreElement<ElementType>::QTestCoreElement(int t)
83 : type(QTest::LogElementType(t))
84 {
85 }
86
87 template<class ElementType>
~QTestCoreElement()88 QTestCoreElement<ElementType>::~QTestCoreElement()
89 {
90 delete listOfAttributes;
91 }
92
93 template <class ElementType>
addAttribute(const QTest::AttributeIndex attributeIndex,const char * value)94 void QTestCoreElement<ElementType>::addAttribute(const QTest::AttributeIndex attributeIndex, const char *value)
95 {
96 if (attributeIndex == -1 || attribute(attributeIndex))
97 return;
98
99 QTestElementAttribute *testAttribute = new QTestElementAttribute;
100 testAttribute->setPair(attributeIndex, value);
101 testAttribute->addToList(&listOfAttributes);
102 }
103
104 template <class ElementType>
attributes()105 QTestElementAttribute *QTestCoreElement<ElementType>::attributes() const
106 {
107 return listOfAttributes;
108 }
109
110 template <class ElementType>
attributeValue(QTest::AttributeIndex index)111 const char *QTestCoreElement<ElementType>::attributeValue(QTest::AttributeIndex index) const
112 {
113 const QTestElementAttribute *attrb = attribute(index);
114 if (attrb)
115 return attrb->value();
116
117 return nullptr;
118 }
119
120 template <class ElementType>
attributeName(QTest::AttributeIndex index)121 const char *QTestCoreElement<ElementType>::attributeName(QTest::AttributeIndex index) const
122 {
123 const QTestElementAttribute *attrb = attribute(index);
124 if (attrb)
125 return attrb->name();
126
127 return nullptr;
128 }
129
130 template <class ElementType>
elementName()131 const char *QTestCoreElement<ElementType>::elementName() const
132 {
133 const char *xmlElementNames[] =
134 {
135 "property",
136 "properties",
137 "failure",
138 "error",
139 "testcase",
140 "testsuite",
141 "benchmark",
142 "system-err"
143 };
144
145 if (type != QTest::LET_Undefined)
146 return xmlElementNames[type];
147
148 return nullptr;
149 }
150
151 template <class ElementType>
elementType()152 QTest::LogElementType QTestCoreElement<ElementType>::elementType() const
153 {
154 return type;
155 }
156
157 template <class ElementType>
attribute(QTest::AttributeIndex index)158 const QTestElementAttribute *QTestCoreElement<ElementType>::attribute(QTest::AttributeIndex index) const
159 {
160 QTestElementAttribute *iterator = listOfAttributes;
161 while (iterator) {
162 if (iterator->index() == index)
163 return iterator;
164
165 iterator = iterator->nextElement();
166 }
167
168 return nullptr;
169 }
170
171 QT_END_NAMESPACE
172
173 #endif
174