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#include <QtTest/private/qtestelementattribute_p.h>
41#include <QtCore/qbytearray.h>
42#include <string.h>
43#include <stdlib.h>
44
45QT_BEGIN_NAMESPACE
46
47/*! \enum QTest::AttributeIndex
48 This enum numbers the different tests.
49
50 \value AI_Undefined
51
52 \value AI_Name
53
54 \value AI_Result
55
56 \value AI_Tests
57
58 \value AI_Failures
59
60 \value AI_Errors
61
62 \value AI_Type
63
64 \value AI_Description
65
66 \value AI_PropertyValue
67
68 \value AI_QTestVersion
69
70 \value AI_QtVersion
71
72 \value AI_File
73
74 \value AI_Line
75
76 \value AI_Metric
77
78 \value AI_Tag
79
80 \value AI_Value
81
82 \value AI_Iterations
83
84 \value AI_Time
85
86 \value AI_Timestamp
87*/
88
89/*! \enum QTest::LogElementType
90 The enum specifies the kinds of test log messages.
91
92 \value LET_Undefined
93
94 \value LET_Property
95
96 \value LET_Properties
97
98 \value LET_Failure
99
100 \value LET_Message
101
102 \value LET_TestCase
103
104 \value LET_TestSuite
105
106 \value LET_Benchmark
107
108 \value LET_SystemError
109
110 \value LET_SystemOutput
111*/
112
113QTestElementAttribute::QTestElementAttribute() = default;
114
115QTestElementAttribute::~QTestElementAttribute()
116{
117 delete[] attributeValue;
118}
119
120const char *QTestElementAttribute::value() const
121{
122 return attributeValue;
123}
124
125const char *QTestElementAttribute::name() const
126{
127 const char *AttributeNames[] =
128 {
129 "name",
130 "result",
131 "tests",
132 "failures",
133 "errors",
134 "type",
135 "description",
136 "value",
137 "qtestversion",
138 "qtversion",
139 "file",
140 "line",
141 "metric",
142 "tag",
143 "value",
144 "iterations",
145 "time",
146 "timestamp"
147 };
148
149 if (attributeIndex != QTest::AI_Undefined)
150 return AttributeNames[attributeIndex];
151
152 return nullptr;
153}
154
155QTest::AttributeIndex QTestElementAttribute::index() const
156{
157 return attributeIndex;
158}
159
160bool QTestElementAttribute::isNull() const
161{
162 return attributeIndex == QTest::AI_Undefined;
163}
164
165bool QTestElementAttribute::setPair(QTest::AttributeIndex index, const char *value)
166{
167 if (!value)
168 return false;
169
170 delete[] attributeValue;
171
172 attributeIndex = index;
173 attributeValue = qstrdup(value);
174
175 return attributeValue != nullptr;
176}
177
178QT_END_NAMESPACE
179
180