30
30
#endif
31
31
32
32
Q_DECLARE_METATYPE (CborError)
33
+ namespace QTest {
34
+ template <> char *toString<CborError>(const CborError &err)
35
+ {
36
+ return qstrdup (cbor_error_string (err));
37
+ }
38
+ }
33
39
34
40
class tst_Encoder : public QObject
35
41
{
@@ -269,7 +275,7 @@ void compare(const QVariant &input, const QByteArray &output)
269
275
CborEncoder encoder;
270
276
cbor_encoder_init (&encoder, bufptr, buffer.length (), 0 );
271
277
272
- QCOMPARE (int ( encodeVariant (&encoder, input)), int ( CborNoError) );
278
+ QCOMPARE (encodeVariant (&encoder, input), CborNoError);
273
279
QCOMPARE (encoder.added , size_t (1 ));
274
280
QCOMPARE (cbor_encoder_get_extra_bytes_needed (&encoder), size_t (0 ));
275
281
@@ -635,9 +641,9 @@ void tst_Encoder::tooShortArrays()
635
641
CborEncoder encoder, container;
636
642
cbor_encoder_init (&encoder, reinterpret_cast <quint8 *>(buffer.data ()), buffer.length (), 0 );
637
643
QCOMPARE (cbor_encoder_create_array (&encoder, &container, 2 ), CborNoError);
638
- QCOMPARE (int ( encodeVariant (&container, input)), int ( CborNoError) );
644
+ QCOMPARE (encodeVariant (&container, input), CborNoError);
639
645
QCOMPARE (container.added , size_t (1 ));
640
- QCOMPARE (int ( cbor_encoder_close_container_checked (&encoder, &container)), int ( CborErrorTooFewItems) );
646
+ QCOMPARE (cbor_encoder_close_container_checked (&encoder, &container), CborErrorTooFewItems);
641
647
}
642
648
643
649
void tst_Encoder::tooShortMaps ()
@@ -649,9 +655,9 @@ void tst_Encoder::tooShortMaps()
649
655
CborEncoder encoder, container;
650
656
cbor_encoder_init (&encoder, reinterpret_cast <quint8 *>(buffer.data ()), buffer.length (), 0 );
651
657
QCOMPARE (cbor_encoder_create_map (&encoder, &container, 2 ), CborNoError);
652
- QCOMPARE (int ( encodeVariant (&container, input)), int ( CborNoError) );
658
+ QCOMPARE (encodeVariant (&container, input), CborNoError);
653
659
QCOMPARE (container.added , size_t (1 ));
654
- QCOMPARE (int ( cbor_encoder_close_container_checked (&encoder, &container)), int ( CborErrorTooFewItems) );
660
+ QCOMPARE (cbor_encoder_close_container_checked (&encoder, &container), CborErrorTooFewItems);
655
661
}
656
662
657
663
void tst_Encoder::tooBigArrays ()
@@ -663,10 +669,10 @@ void tst_Encoder::tooBigArrays()
663
669
CborEncoder encoder, container;
664
670
cbor_encoder_init (&encoder, reinterpret_cast <quint8 *>(buffer.data ()), buffer.length (), 0 );
665
671
QCOMPARE (cbor_encoder_create_array (&encoder, &container, 1 ), CborNoError);
666
- QCOMPARE (int ( encodeVariant (&container, input)), int ( CborNoError) );
667
- QCOMPARE (int ( encodeVariant (&container, input)), int ( CborNoError) );
672
+ QCOMPARE (encodeVariant (&container, input), CborNoError);
673
+ QCOMPARE (encodeVariant (&container, input), CborNoError);
668
674
QCOMPARE (container.added , size_t (2 ));
669
- QCOMPARE (int ( cbor_encoder_close_container_checked (&encoder, &container)), int ( CborErrorTooManyItems) );
675
+ QCOMPARE (cbor_encoder_close_container_checked (&encoder, &container), CborErrorTooManyItems);
670
676
}
671
677
672
678
void tst_Encoder::tooBigMaps ()
@@ -678,11 +684,11 @@ void tst_Encoder::tooBigMaps()
678
684
CborEncoder encoder, container;
679
685
cbor_encoder_init (&encoder, reinterpret_cast <quint8 *>(buffer.data ()), buffer.length (), 0 );
680
686
QCOMPARE (cbor_encoder_create_map (&encoder, &container, 1 ), CborNoError);
681
- QCOMPARE (int ( encodeVariant (&container, input)), int ( CborNoError) );
682
- QCOMPARE (int ( encodeVariant (&container, input)), int ( CborNoError) );
683
- QCOMPARE (int ( encodeVariant (&container, input)), int ( CborNoError) );
687
+ QCOMPARE (encodeVariant (&container, input), CborNoError);
688
+ QCOMPARE (encodeVariant (&container, input), CborNoError);
689
+ QCOMPARE (encodeVariant (&container, input), CborNoError);
684
690
QCOMPARE (container.added , size_t (3 ));
685
- QCOMPARE (int ( cbor_encoder_close_container_checked (&encoder, &container)), int ( CborErrorTooManyItems) );
691
+ QCOMPARE (cbor_encoder_close_container_checked (&encoder, &container), CborErrorTooManyItems);
686
692
}
687
693
688
694
void tst_Encoder::illegalSimpleType_data ()
0 commit comments