|
25 | 25 | #include <QtTest>
|
26 | 26 | #include "cbor.h"
|
27 | 27 |
|
| 28 | +#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0) |
| 29 | +#include <qfloat16.h> |
| 30 | +#endif |
| 31 | + |
28 | 32 | Q_DECLARE_METATYPE(CborError)
|
29 | 33 |
|
30 | 34 | class tst_Encoder : public QObject
|
@@ -201,8 +205,13 @@ CborError encodeVariant(CborEncoder *encoder, const QVariant &v)
|
201 | 205 | default:
|
202 | 206 | if (type == qMetaTypeId<SimpleType>())
|
203 | 207 | return cbor_encode_simple_value(encoder, v.value<SimpleType>().type);
|
| 208 | +#if QT_VERSION < QT_VERSION_CHECK(5, 9, 0) |
204 | 209 | if (type == qMetaTypeId<Float16Standin>())
|
205 | 210 | return cbor_encode_half_float(encoder, v.constData());
|
| 211 | +#else |
| 212 | + if (type == qMetaTypeId<qfloat16>()) |
| 213 | + return cbor_encode_half_float(encoder, v.constData()); |
| 214 | +#endif |
206 | 215 | if (type == qMetaTypeId<Tag>()) {
|
207 | 216 | CborError err = cbor_encode_tag(encoder, v.value<Tag>().tag);
|
208 | 217 | if (err && !isOomError(err))
|
@@ -328,7 +337,16 @@ void addFixedData()
|
328 | 337 | QTest::newRow("simple255") << raw("\xf8\xff") << QVariant::fromValue(SimpleType{255});
|
329 | 338 |
|
330 | 339 | // floating point
|
331 |
| - QTest::newRow("0f16") << raw("\xf9\0\0") << QVariant::fromValue(Float16Standin{0x0000}); |
| 340 | +#if QT_VERSION < QT_VERSION_CHECK(5, 9, 0) |
| 341 | + QTest::newRow("0.f16") << raw("\xf9\0\0") << QVariant::fromValue(Float16Standin{0x0000}); |
| 342 | +#else |
| 343 | + QTest::newRow("0.f16") << raw("\xf9\0\0") << QVariant::fromValue(qfloat16(0)); |
| 344 | + QTest::newRow("-1.f16") << raw("\xf9\xbc\0") << QVariant::fromValue(qfloat16(-1)); |
| 345 | + QTest::newRow("1.5f16") << raw("\xf9\x3e\0") << QVariant::fromValue(qfloat16(1.5)); |
| 346 | + QTest::newRow("nan_f16") << raw("\xf9\x7e\0") << QVariant::fromValue<qfloat16>(myNaNf()); |
| 347 | + QTest::newRow("-inf_f16") << raw("\xf9\xfc\0") << QVariant::fromValue<qfloat16>(myNInff()); |
| 348 | + QTest::newRow("+inf_f16") << raw("\xf9\x7c\0") << QVariant::fromValue<qfloat16>(myInff()); |
| 349 | +#endif |
332 | 350 |
|
333 | 351 | QTest::newRow("0.f") << raw("\xfa\0\0\0\0") << QVariant::fromValue(0.f);
|
334 | 352 | QTest::newRow("0.") << raw("\xfb\0\0\0\0\0\0\0\0") << QVariant(0.);
|
|
0 commit comments