Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
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 Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include <QtTest/private/qtesttable_p.h> | - |
43 | #include <QtTest/qtestdata.h> | - |
44 | #include <QtTest/qtestassert.h> | - |
45 | | - |
46 | #include <QtCore/qmetaobject.h> | - |
47 | | - |
48 | #include <string.h> | - |
49 | | - |
50 | QT_BEGIN_NAMESPACE | - |
51 | | - |
52 | class QTestTablePrivate | - |
53 | { | - |
54 | public: | - |
55 | struct ElementList | - |
56 | { | - |
57 | ElementList(): elementName(0), elementType(0), next(0) {} executed: } Execution Count:5550 | 5550 |
58 | const char *elementName; | - |
59 | int elementType; | - |
60 | ElementList *next; | - |
61 | }; | - |
62 | | - |
63 | struct DataList | - |
64 | { | - |
65 | DataList(): data(0), next(0) {} executed: } Execution Count:61136 | 61136 |
66 | QTestData *data; | - |
67 | DataList *next; | - |
68 | }; | - |
69 | | - |
70 | QTestTablePrivate(): list(0), dataList(0) {} executed: } Execution Count:7218 | 7218 |
71 | ~QTestTablePrivate(); | - |
72 | | - |
73 | ElementList *list; | - |
74 | DataList *dataList; | - |
75 | | - |
76 | void addColumn(int elemType, const char *elemName); | - |
77 | void addRow(QTestData *data); | - |
78 | ElementList *elementAt(int index); | - |
79 | QTestData *dataAt(int index); | - |
80 | | - |
81 | static QTestTable *currentTestTable; | - |
82 | static QTestTable *gTable; | - |
83 | }; | - |
84 | | - |
85 | QTestTable *QTestTablePrivate::currentTestTable = 0; | - |
86 | QTestTable *QTestTablePrivate::gTable = 0; | - |
87 | | - |
88 | QTestTablePrivate::ElementList *QTestTablePrivate::elementAt(int index) | - |
89 | { | - |
90 | ElementList *iter = list; executed (the execution status of this line is deduced): ElementList *iter = list; | - |
91 | for (int i = 0; i < index; ++i) { evaluated: i < index yes Evaluation Count:1081780 | yes Evaluation Count:547122 |
| 547122-1081780 |
92 | if (!iter) partially evaluated: !iter no Evaluation Count:0 | yes Evaluation Count:1081780 |
| 0-1081780 |
93 | return 0; never executed: return 0; | 0 |
94 | iter = iter->next; executed (the execution status of this line is deduced): iter = iter->next; | - |
95 | } executed: } Execution Count:1081780 | 1081780 |
96 | return iter; executed: return iter; Execution Count:547122 | 547122 |
97 | } | - |
98 | | - |
99 | QTestData *QTestTablePrivate::dataAt(int index) | - |
100 | { | - |
101 | DataList *iter = dataList; executed (the execution status of this line is deduced): DataList *iter = dataList; | - |
102 | for (int i = 0; i < index; ++i) { evaluated: i < index yes Evaluation Count:184058187 | yes Evaluation Count:61587 |
| 61587-184058187 |
103 | if (!iter) partially evaluated: !iter no Evaluation Count:0 | yes Evaluation Count:184058187 |
| 0-184058187 |
104 | return 0; never executed: return 0; | 0 |
105 | iter = iter->next; executed (the execution status of this line is deduced): iter = iter->next; | - |
106 | } executed: } Execution Count:184058187 | 184058187 |
107 | return iter ? iter->data : 0; executed: return iter ? iter->data : 0; Execution Count:61587 | 61587 |
108 | } | - |
109 | | - |
110 | QTestTablePrivate::~QTestTablePrivate() | - |
111 | { | - |
112 | DataList *dit = dataList; executed (the execution status of this line is deduced): DataList *dit = dataList; | - |
113 | while (dit) { evaluated: dit yes Evaluation Count:61133 | yes Evaluation Count:7204 |
| 7204-61133 |
114 | DataList *next = dit->next; executed (the execution status of this line is deduced): DataList *next = dit->next; | - |
115 | delete dit->data; executed (the execution status of this line is deduced): delete dit->data; | - |
116 | delete dit; executed (the execution status of this line is deduced): delete dit; | - |
117 | dit = next; executed (the execution status of this line is deduced): dit = next; | - |
118 | } executed: } Execution Count:61133 | 61133 |
119 | ElementList *iter = list; executed (the execution status of this line is deduced): ElementList *iter = list; | - |
120 | while (iter) { evaluated: iter yes Evaluation Count:5549 | yes Evaluation Count:7204 |
| 5549-7204 |
121 | ElementList *next = iter->next; executed (the execution status of this line is deduced): ElementList *next = iter->next; | - |
122 | delete iter; executed (the execution status of this line is deduced): delete iter; | - |
123 | iter = next; executed (the execution status of this line is deduced): iter = next; | - |
124 | } executed: } Execution Count:5549 | 5549 |
125 | } executed: } Execution Count:7204 | 7204 |
126 | | - |
127 | void QTestTablePrivate::addColumn(int elemType, const char *elemName) | - |
128 | { | - |
129 | ElementList *item = new ElementList; executed (the execution status of this line is deduced): ElementList *item = new ElementList; | - |
130 | item->elementName = elemName; executed (the execution status of this line is deduced): item->elementName = elemName; | - |
131 | item->elementType = elemType; executed (the execution status of this line is deduced): item->elementType = elemType; | - |
132 | if (!list) { evaluated: !list yes Evaluation Count:1867 | yes Evaluation Count:3683 |
| 1867-3683 |
133 | list = item; executed (the execution status of this line is deduced): list = item; | - |
134 | return; executed: return; Execution Count:1867 | 1867 |
135 | } | - |
136 | ElementList *last = list; executed (the execution status of this line is deduced): ElementList *last = list; | - |
137 | while (last->next != 0) evaluated: last->next != 0 yes Evaluation Count:7290 | yes Evaluation Count:3683 |
| 3683-7290 |
138 | last = last->next; executed: last = last->next; Execution Count:7290 | 7290 |
139 | last->next = item; executed (the execution status of this line is deduced): last->next = item; | - |
140 | } executed: } Execution Count:3683 | 3683 |
141 | | - |
142 | void QTestTablePrivate::addRow(QTestData *data) | - |
143 | { | - |
144 | DataList *item = new DataList; executed (the execution status of this line is deduced): DataList *item = new DataList; | - |
145 | item->data = data; executed (the execution status of this line is deduced): item->data = data; | - |
146 | if (!dataList) { evaluated: !dataList yes Evaluation Count:1796 | yes Evaluation Count:59340 |
| 1796-59340 |
147 | dataList = item; executed (the execution status of this line is deduced): dataList = item; | - |
148 | return; executed: return; Execution Count:1796 | 1796 |
149 | } | - |
150 | DataList *last = dataList; executed (the execution status of this line is deduced): DataList *last = dataList; | - |
151 | while (last->next != 0) evaluated: last->next != 0 yes Evaluation Count:183989585 | yes Evaluation Count:59340 |
| 59340-183989585 |
152 | last = last->next; executed: last = last->next; Execution Count:183989585 | 183989585 |
153 | last->next = item; executed (the execution status of this line is deduced): last->next = item; | - |
154 | } executed: } Execution Count:59340 | 59340 |
155 | | - |
156 | void QTestTable::addColumn(int type, const char *name) | - |
157 | { | - |
158 | QTEST_ASSERT(type); never executed: qt_assert("type","qtesttable.cpp",158); executed: } Execution Count:5550 partially evaluated: !(type) no Evaluation Count:0 | yes Evaluation Count:5550 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:5550 |
| 0-5550 |
159 | QTEST_ASSERT(name); never executed: qt_assert("name","qtesttable.cpp",159); executed: } Execution Count:5550 partially evaluated: !(name) no Evaluation Count:0 | yes Evaluation Count:5550 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:5550 |
| 0-5550 |
160 | | - |
161 | d->addColumn(type, name); executed (the execution status of this line is deduced): d->addColumn(type, name); | - |
162 | } executed: } Execution Count:5550 | 5550 |
163 | | - |
164 | int QTestTable::elementCount() const | - |
165 | { | - |
166 | QTestTablePrivate::ElementList *item = d->list; executed (the execution status of this line is deduced): QTestTablePrivate::ElementList *item = d->list; | - |
167 | int count = 0; executed (the execution status of this line is deduced): int count = 0; | - |
168 | while (item) { evaluated: item yes Evaluation Count:2350215 | yes Evaluation Count:547031 |
| 547031-2350215 |
169 | ++count; executed (the execution status of this line is deduced): ++count; | - |
170 | item = item->next; executed (the execution status of this line is deduced): item = item->next; | - |
171 | } executed: } Execution Count:2350215 | 2350215 |
172 | return count; executed: return count; Execution Count:547031 | 547031 |
173 | } | - |
174 | | - |
175 | | - |
176 | int QTestTable::dataCount() const | - |
177 | { | - |
178 | QTestTablePrivate::DataList *item = d->dataList; executed (the execution status of this line is deduced): QTestTablePrivate::DataList *item = d->dataList; | - |
179 | int count = 0; executed (the execution status of this line is deduced): int count = 0; | - |
180 | while (item) { evaluated: item yes Evaluation Count:61589 | yes Evaluation Count:13623 |
| 13623-61589 |
181 | ++count; executed (the execution status of this line is deduced): ++count; | - |
182 | item = item->next; executed (the execution status of this line is deduced): item = item->next; | - |
183 | } executed: } Execution Count:61589 | 61589 |
184 | return count; executed: return count; Execution Count:13623 | 13623 |
185 | } | - |
186 | | - |
187 | bool QTestTable::isEmpty() const | - |
188 | { | - |
189 | return !d->list; executed: return !d->list; Execution Count:6879 | 6879 |
190 | } | - |
191 | | - |
192 | QTestData *QTestTable::newData(const char *tag) | - |
193 | { | - |
194 | QTestData *dt = new QTestData(tag, this); executed (the execution status of this line is deduced): QTestData *dt = new QTestData(tag, this); | - |
195 | d->addRow(dt); executed (the execution status of this line is deduced): d->addRow(dt); | - |
196 | return dt; executed: return dt; Execution Count:61136 | 61136 |
197 | } | - |
198 | | - |
199 | QTestTable::QTestTable() | - |
200 | { | - |
201 | d = new QTestTablePrivate; executed (the execution status of this line is deduced): d = new QTestTablePrivate; | - |
202 | QTestTablePrivate::currentTestTable = this; executed (the execution status of this line is deduced): QTestTablePrivate::currentTestTable = this; | - |
203 | } executed: } Execution Count:7218 | 7218 |
204 | | - |
205 | QTestTable::~QTestTable() | - |
206 | { | - |
207 | QTestTablePrivate::currentTestTable = 0; executed (the execution status of this line is deduced): QTestTablePrivate::currentTestTable = 0; | - |
208 | delete d; executed (the execution status of this line is deduced): delete d; | - |
209 | } executed: } Execution Count:7204 | 7204 |
210 | | - |
211 | int QTestTable::elementTypeId(int index) const | - |
212 | { | - |
213 | QTestTablePrivate::ElementList *item = d->elementAt(index); executed (the execution status of this line is deduced): QTestTablePrivate::ElementList *item = d->elementAt(index); | - |
214 | if (!item) partially evaluated: !item no Evaluation Count:0 | yes Evaluation Count:547122 |
| 0-547122 |
215 | return -1; never executed: return -1; | 0 |
216 | return item->elementType; executed: return item->elementType; Execution Count:547122 | 547122 |
217 | } | - |
218 | | - |
219 | const char *QTestTable::dataTag(int index) const | - |
220 | { | - |
221 | QTestTablePrivate::ElementList *item = d->elementAt(index); never executed (the execution status of this line is deduced): QTestTablePrivate::ElementList *item = d->elementAt(index); | - |
222 | if (!item) | 0 |
223 | return 0; never executed: return 0; | 0 |
224 | return item->elementName; never executed: return item->elementName; | 0 |
225 | } | - |
226 | | - |
227 | QTestData *QTestTable::testData(int index) const | - |
228 | { | - |
229 | return d->dataAt(index); executed: return d->dataAt(index); Execution Count:61587 | 61587 |
230 | } | - |
231 | | - |
232 | int QTestTable::indexOf(const char *elementName) const | - |
233 | { | - |
234 | QTEST_ASSERT(elementName); never executed: qt_assert("elementName","qtesttable.cpp",234); executed: } Execution Count:182312 partially evaluated: !(elementName) no Evaluation Count:0 | yes Evaluation Count:182312 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:182312 |
| 0-182312 |
235 | | - |
236 | QTestTablePrivate::ElementList *item = d->list; executed (the execution status of this line is deduced): QTestTablePrivate::ElementList *item = d->list; | - |
237 | int i = 0; executed (the execution status of this line is deduced): int i = 0; | - |
238 | while (item) { partially evaluated: item yes Evaluation Count:528734 | no Evaluation Count:0 |
| 0-528734 |
239 | if (strcmp(elementName, item->elementName) == 0) evaluated: strcmp(elementName, item->elementName) == 0 yes Evaluation Count:182312 | yes Evaluation Count:346422 |
| 182312-346422 |
240 | return i; executed: return i; Execution Count:182312 | 182312 |
241 | item = item->next; executed (the execution status of this line is deduced): item = item->next; | - |
242 | ++i; executed (the execution status of this line is deduced): ++i; | - |
243 | } executed: } Execution Count:346422 | 346422 |
244 | return -1; never executed: return -1; | 0 |
245 | } | - |
246 | | - |
247 | QTestTable *QTestTable::globalTestTable() | - |
248 | { | - |
249 | if (!QTestTablePrivate::gTable) evaluated: !QTestTablePrivate::gTable yes Evaluation Count:399 | yes Evaluation Count:6819 |
| 399-6819 |
250 | QTestTablePrivate::gTable = new QTestTable(); executed: QTestTablePrivate::gTable = new QTestTable(); Execution Count:399 | 399 |
251 | return QTestTablePrivate::gTable; executed: return QTestTablePrivate::gTable; Execution Count:7218 | 7218 |
252 | } | - |
253 | | - |
254 | void QTestTable::clearGlobalTestTable() | - |
255 | { | - |
256 | delete QTestTablePrivate::gTable; executed (the execution status of this line is deduced): delete QTestTablePrivate::gTable; | - |
257 | QTestTablePrivate::gTable = 0; executed (the execution status of this line is deduced): QTestTablePrivate::gTable = 0; | - |
258 | } executed: } Execution Count:391 | 391 |
259 | | - |
260 | QTestTable *QTestTable::currentTestTable() | - |
261 | { | - |
262 | return QTestTablePrivate::currentTestTable; executed: return QTestTablePrivate::currentTestTable; Execution Count:66686 | 66686 |
263 | } | - |
264 | | - |
265 | QT_END_NAMESPACE | - |
266 | | - |
| | |