1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtTest module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #include <QtTest/private/qtesttable_p.h>
43 #include <QtTest/qtestdata.h>
44 #include <QtTest/qtestassert.h>
46 #include <QtCore/qmetaobject.h>
52 class QTestTablePrivate
57 ElementList(): elementName(0), elementType(0), next(0) {}
58 const char *elementName;
65 DataList(): data(0), next(0) {}
70 QTestTablePrivate(): list(0), dataList(0) {}
76 void addColumn(int elemType, const char *elemName);
77 void addRow(QTestData *data);
78 ElementList *elementAt(int index);
79 QTestData *dataAt(int index);
81 static QTestTable *currentTestTable;
82 static QTestTable *gTable;
85 QTestTable *QTestTablePrivate::currentTestTable = 0;
86 QTestTable *QTestTablePrivate::gTable = 0;
88 QTestTablePrivate::ElementList *QTestTablePrivate::elementAt(int index)
90 ElementList *iter = list;
91 for (int i = 0; i < index; ++i) {
99 QTestData *QTestTablePrivate::dataAt(int index)
101 DataList *iter = dataList;
102 for (int i = 0; i < index; ++i) {
107 return iter ? iter->data : 0;
110 QTestTablePrivate::~QTestTablePrivate()
112 DataList *dit = dataList;
114 DataList *next = dit->next;
119 ElementList *iter = list;
121 ElementList *next = iter->next;
127 void QTestTablePrivate::addColumn(int elemType, const char *elemName)
129 ElementList *item = new ElementList;
130 item->elementName = elemName;
131 item->elementType = elemType;
136 ElementList *last = list;
137 while (last->next != 0)
142 void QTestTablePrivate::addRow(QTestData *data)
144 DataList *item = new DataList;
150 DataList *last = dataList;
151 while (last->next != 0)
156 void QTestTable::addColumn(int type, const char *name)
161 d->addColumn(type, name);
164 int QTestTable::elementCount() const
166 QTestTablePrivate::ElementList *item = d->list;
176 int QTestTable::dataCount() const
178 QTestTablePrivate::DataList *item = d->dataList;
187 bool QTestTable::isEmpty() const
192 QTestData *QTestTable::newData(const char *tag)
194 QTestData *dt = new QTestData(tag, this);
199 QTestTable::QTestTable()
201 d = new QTestTablePrivate;
202 QTestTablePrivate::currentTestTable = this;
205 QTestTable::~QTestTable()
207 QTestTablePrivate::currentTestTable = 0;
211 int QTestTable::elementTypeId(int index) const
213 QTestTablePrivate::ElementList *item = d->elementAt(index);
216 return item->elementType;
219 const char *QTestTable::dataTag(int index) const
221 QTestTablePrivate::ElementList *item = d->elementAt(index);
224 return item->elementName;
227 QTestData *QTestTable::testData(int index) const
229 return d->dataAt(index);
232 int QTestTable::indexOf(const char *elementName) const
234 QTEST_ASSERT(elementName);
236 QTestTablePrivate::ElementList *item = d->list;
239 if (strcmp(elementName, item->elementName) == 0)
247 QTestTable *QTestTable::globalTestTable()
249 if (!QTestTablePrivate::gTable)
250 QTestTablePrivate::gTable = new QTestTable();
251 return QTestTablePrivate::gTable;
254 void QTestTable::clearGlobalTestTable()
256 delete QTestTablePrivate::gTable;
257 QTestTablePrivate::gTable = 0;
260 QTestTable *QTestTable::currentTestTable()
262 return QTestTablePrivate::currentTestTable;