Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtesttable.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <QtTest/private/qtesttable_p.h>
5#include <QtTest/qtestdata.h>
6#include <QtTest/qtestassert.h>
7
8#include <QtCore/private/qduplicatetracker_p.h>
9#include <QtCore/qmetaobject.h>
10
11#include <string.h>
12#include <vector>
13#include <algorithm>
14
16
18{
19public:
21 {
22 qDeleteAll(dataList.begin(), dataList.end());
23 }
24
25 struct Element {
26 Element() = default;
27 Element(const char *n, int t) : name(n), type(t) {}
28
29 const char *name = nullptr;
30 int type = 0;
31 };
32
33 using ElementList = std::vector<Element>;
35
36 using DataList = std::vector<QTestData *>;
38
39 using TagSet = QDuplicateTracker<std::string>;
41
42 void addColumn(int elemType, const char *elemName) { elementList.push_back(Element(elemName, elemType)); }
43 void addRow(QTestData *data) { dataList.push_back(data); }
44
47};
48
51
52void QTestTable::addColumn(int type, const char *name)
53{
56 if (indexOf(name) != -1)
57 qWarning() << "Duplicate data column" << name << "- please rename.";
58
59 d->addColumn(type, name);
60}
61
63{
64 return int(d->elementList.size());
65}
66
68{
69 return int(d->dataList.size());
70}
71
73{
74 return d->elementList.empty();
75}
76
78{
80 if (d->tagSet.hasSeen(tag))
81 qWarning("Duplicate data tag \"%s\" - please rename.", tag);
82
83 QTestData *dt = new QTestData(tag, this);
84 d->addRow(dt);
85 return dt;
86}
87
93
99
101{
102 return size_t(index) < d->elementList.size() ? d->elementList[index].type : -1;
103}
104
105const char *QTestTable::dataTag(int index) const
106{
107 return size_t(index) < d->elementList.size() ? d->elementList[index].name : nullptr;
108}
109
111{
112 return size_t(index) < d->dataList.size() ? d->dataList[index] : nullptr;
113}
114
116{
117public:
118 explicit NamePredicate(const char *needle) : m_needle(needle) {}
119
121 { return !strcmp(e.name, m_needle); }
122
123 bool operator()(const QTestData *e) const
124 { return !strcmp(e->dataTag(), m_needle); }
125
126private:
127 const char *m_needle;
128};
129
130int QTestTable::indexOf(const char *elementName) const
131{
132 QTEST_ASSERT(elementName);
133
134 const QTestTablePrivate::ElementList &elementList = d->elementList;
135
136 const auto it = std::find_if(elementList.begin(), elementList.end(),
137 NamePredicate(elementName));
138 return it != elementList.end() ?
139 int(it - elementList.begin()) : -1;
140}
141
148
154
159
bool operator()(const QTestTablePrivate::Element &e) const
bool operator()(const QTestData *e) const
NamePredicate(const char *needle)
bool hasSeen(const T &s)
iterator begin()
Definition qset.h:136
iterator end()
Definition qset.h:140
const char * dataTag() const
Definition qtestdata.cpp:87
static QTestTable * currentTestTable
void addColumn(int elemType, const char *elemName)
std::vector< Element > ElementList
ElementList elementList
static QTestTable * gTable
std::vector< QTestData * > DataList
void addRow(QTestData *data)
int dataCount() const
int elementCount() const
const char * dataTag(int index) const
bool isEmpty() const
static QTestTable * currentTestTable()
int elementTypeId(int index) const
QTestData * testData(int index) const
QTestData * newData(const char *tag)
static void clearGlobalTestTable()
void addColumn(int elementType, const char *elementName)
static QTestTable * globalTestTable()
int indexOf(const char *elementName) const
qDeleteAll(list.begin(), list.end())
QSet< QString >::iterator it
Combined button and popup list for selecting options.
AudioChannelLayoutTag tag
#define qWarning
Definition qlogging.h:166
GLuint index
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum type
GLuint name
GLfloat n
GLdouble GLdouble t
Definition qopenglext.h:243
QWidget Element
Definition main.cpp:7
#define QTEST_ASSERT(cond)
Definition qtestassert.h:11
Element(const char *n, int t)