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
qtestdata.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 <QtCore/qmetaobject.h>
5
6#include <QtTest/qtestassert.h>
7#include <QtTest/qtestdata.h>
8#include <QtTest/private/qtesttable_p.h>
9
10#include <string.h>
11#include <stdlib.h>
12
14
16{
17public:
18 char *tag = nullptr;
19 QTestTable *parent = nullptr;
20 void **data = nullptr;
21 int dataCount = 0;
22};
23
24QTestData::QTestData(const char *tag, QTestTable *parent)
25{
28 d = new QTestDataPrivate;
29 d->tag = qstrdup(tag);
30 d->parent = parent;
31 d->data = new void *[parent->elementCount()];
32 memset(d->data, 0, parent->elementCount() * sizeof(void*));
33}
34
36{
37 for (int i = 0; i < d->dataCount; ++i) {
38 if (d->data[i])
40 }
41 delete [] d->data;
42 delete [] d->tag;
43 delete d;
44}
45
46void QTestData::append(int type, const void *data)
47{
49 int expectedType = d->parent->elementTypeId(d->dataCount);
50 int dd = 0;
51 if constexpr (sizeof(qsizetype) == 8) {
52 // Compatibility with Qt 5. Passing a qsizetype to a test function expecting
53 // an int will work. This is required, as methods returning a qsizetype in Qt 6
54 // used to return an int in Qt 5.
55 if (type == QMetaType::LongLong && expectedType == QMetaType::Int) {
56 qlonglong d = *static_cast<const qlonglong *>(data);
57 if (d >= std::numeric_limits<int>::min() && d <= std::numeric_limits<int>::max()) {
58 dd = d;
59 data = &dd;
60 type = QMetaType::Int;
61 }
62 }
63 }
64 if (expectedType != type) {
65 qDebug("expected data of type '%s', got '%s' for element %d of data with tag '%s'",
66 QMetaType(expectedType).name(),
68 d->dataCount, d->tag);
69 QTEST_ASSERT(false);
70 }
72 ++d->dataCount;
73}
74
75void *QTestData::data(int index) const
76{
77 QTEST_ASSERT(index >= 0);
78 QTEST_ASSERT(index < d->parent->elementCount());
79 return d->data[index];
80}
81
83{
84 return d->parent;
85}
86
87const char *QTestData::dataTag() const
88{
89 return d->tag;
90}
91
93{
94 return d->dataCount;
95}
96
\inmodule QtCore
Definition qmetatype.h:341
void destroy(void *data) const
void * create(const void *copy=nullptr) const
QTestTable * parent
Definition qtestdata.cpp:19
const char * dataTag() const
Definition qtestdata.cpp:87
void * data(int index) const
Definition qtestdata.cpp:75
void append(int type, const void *data)
Definition qtestdata.cpp:46
int dataCount() const
Definition qtestdata.cpp:92
QTestTable * parent() const
Definition qtestdata.cpp:82
int elementCount() const
int elementTypeId(int index) const
Combined button and popup list for selecting options.
Q_CORE_EXPORT char * qstrdup(const char *)
AudioChannelLayoutTag tag
#define qDebug
[1]
Definition qlogging.h:164
GLuint index
[2]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum type
GLuint name
#define QTEST_ASSERT(cond)
Definition qtestassert.h:11
ptrdiff_t qsizetype
Definition qtypes.h:165
qint64 qlonglong
Definition qtypes.h:63