Fix binary incompatibility between openssl versions
[profile/ivi/qtbase.git] / src / testlib / qtesttable.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 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) {}
58         const char *elementName;
59         int elementType;
60         ElementList *next;
61     };
62
63     struct DataList
64     {
65         DataList(): data(0), next(0) {}
66         QTestData *data;
67         DataList *next;
68     };
69
70     QTestTablePrivate(): list(0), dataList(0) {}
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;
91     for (int i = 0; i < index; ++i) {
92         if (!iter)
93             return 0;
94         iter = iter->next;
95     }
96     return iter;
97 }
98
99 QTestData *QTestTablePrivate::dataAt(int index)
100 {
101     DataList *iter = dataList;
102     for (int i = 0; i < index; ++i) {
103         if (!iter)
104             return 0;
105         iter = iter->next;
106     }
107     return iter ? iter->data : 0;
108 }
109
110 QTestTablePrivate::~QTestTablePrivate()
111 {
112     DataList *dit = dataList;
113     while (dit) {
114         DataList *next = dit->next;
115         delete dit->data;
116         delete dit;
117         dit = next;
118     }
119     ElementList *iter = list;
120     while (iter) {
121         ElementList *next = iter->next;
122         delete iter;
123         iter = next;
124     }
125 }
126
127 void QTestTablePrivate::addColumn(int elemType, const char *elemName)
128 {
129     ElementList *item = new ElementList;
130     item->elementName = elemName;
131     item->elementType = elemType;
132     if (!list) {
133         list = item;
134         return;
135     }
136     ElementList *last = list;
137     while (last->next != 0)
138         last = last->next;
139     last->next = item;
140 }
141
142 void QTestTablePrivate::addRow(QTestData *data)
143 {
144     DataList *item = new DataList;
145     item->data = data;
146     if (!dataList) {
147         dataList = item;
148         return;
149     }
150     DataList *last = dataList;
151     while (last->next != 0)
152         last = last->next;
153     last->next = item;
154 }
155
156 void QTestTable::addColumn(int type, const char *name)
157 {
158     QTEST_ASSERT(type);
159     QTEST_ASSERT(name);
160
161     d->addColumn(type, name);
162 }
163
164 int QTestTable::elementCount() const
165 {
166     QTestTablePrivate::ElementList *item = d->list;
167     int count = 0;
168     while (item) {
169         ++count;
170         item = item->next;
171     }
172     return count;
173 }
174
175
176 int QTestTable::dataCount() const
177 {
178     QTestTablePrivate::DataList *item = d->dataList;
179     int count = 0;
180     while (item) {
181         ++count;
182         item = item->next;
183     }
184     return count;
185 }
186
187 bool QTestTable::isEmpty() const
188 {
189     return !d->list;
190 }
191
192 QTestData *QTestTable::newData(const char *tag)
193 {
194     QTestData *dt = new QTestData(tag, this);
195     d->addRow(dt);
196     return dt;
197 }
198
199 QTestTable::QTestTable()
200 {
201     d = new QTestTablePrivate;
202     QTestTablePrivate::currentTestTable = this;
203 }
204
205 QTestTable::~QTestTable()
206 {
207     QTestTablePrivate::currentTestTable = 0;
208     delete d;
209 }
210
211 int QTestTable::elementTypeId(int index) const
212 {
213     QTestTablePrivate::ElementList *item = d->elementAt(index);
214     if (!item)
215         return -1;
216     return item->elementType;
217 }
218
219 const char *QTestTable::dataTag(int index) const
220 {
221     QTestTablePrivate::ElementList *item = d->elementAt(index);
222     if (!item)
223         return 0;
224     return item->elementName;
225 }
226
227 QTestData *QTestTable::testData(int index) const
228 {
229     return d->dataAt(index);
230 }
231
232 int QTestTable::indexOf(const char *elementName) const
233 {
234     QTEST_ASSERT(elementName);
235
236     QTestTablePrivate::ElementList *item = d->list;
237     int i = 0;
238     while (item) {
239         if (strcmp(elementName, item->elementName) == 0)
240             return i;
241         item = item->next;
242         ++i;
243     }
244     return -1;
245 }
246
247 QTestTable *QTestTable::globalTestTable()
248 {
249     if (!QTestTablePrivate::gTable)
250         QTestTablePrivate::gTable = new QTestTable();
251     return QTestTablePrivate::gTable;
252 }
253
254 void QTestTable::clearGlobalTestTable()
255 {
256     delete QTestTablePrivate::gTable;
257     QTestTablePrivate::gTable = 0;
258 }
259
260 QTestTable *QTestTable::currentTestTable()
261 {
262     return QTestTablePrivate::currentTestTable;
263 }
264
265 QT_END_NAMESPACE