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 | #ifndef QTESTDATA_H |
5 | #define QTESTDATA_H |
6 | |
7 | #include <QtTest/qttestglobal.h> |
8 | |
9 | #include <QtCore/qmetatype.h> |
10 | #include <QtCore/qstring.h> |
11 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | |
15 | class QTestTable; |
16 | class QTestDataPrivate; |
17 | |
18 | class Q_TESTLIB_EXPORT QTestData |
19 | { |
20 | public: |
21 | ~QTestData(); |
22 | |
23 | void append(int type, const void *data); |
24 | void *data(int index) const; |
25 | const char *dataTag() const; |
26 | QTestTable *parent() const; |
27 | int dataCount() const; |
28 | |
29 | private: |
30 | friend class QTestTable; |
31 | QTestData(const char *tag, QTestTable *parent); |
32 | |
33 | Q_DISABLE_COPY(QTestData) |
34 | |
35 | QTestDataPrivate *d; |
36 | }; |
37 | |
38 | template<typename T> |
39 | QTestData &operator<<(QTestData &data, const T &value) |
40 | { |
41 | data.append(type: qMetaTypeId<T>(), data: &value); |
42 | return data; |
43 | } |
44 | |
45 | inline QTestData &operator<<(QTestData &data, const char * value) |
46 | { |
47 | QString str = QString::fromUtf8(utf8: value); |
48 | data.append(type: QMetaType::QString, data: &str); |
49 | return data; |
50 | } |
51 | |
52 | #ifdef __cpp_char8_t |
53 | Q_WEAK_OVERLOAD |
54 | inline QTestData &operator<<(QTestData &data, const char8_t *value) |
55 | { |
56 | return data << reinterpret_cast<const char *>(value); |
57 | } |
58 | #endif |
59 | |
60 | #ifdef QT_USE_QSTRINGBUILDER |
61 | template<typename A, typename B> |
62 | inline QTestData &operator<<(QTestData &data, const QStringBuilder<A, B> &value) |
63 | { |
64 | return data << typename QConcatenable<QStringBuilder<A, B> >::ConvertTo(value); |
65 | } |
66 | #endif |
67 | |
68 | QT_END_NAMESPACE |
69 | |
70 | #endif |
71 | |