Skip to content

Commit d51dba1

Browse files
thiagomacieirasjlongland
authored andcommitted
Encoder: add unit test for cbor_encode_raw
Signed-off-by: Thiago Macieira <[email protected]>
1 parent 087d213 commit d51dba1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/encoder/tst_encoder.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ private slots:
9090
void tooBigMaps();
9191
void illegalSimpleType_data();
9292
void illegalSimpleType();
93+
94+
void encodeRaw_data() { tags_data(); }
95+
void encodeRaw();
9396
};
9497

9598
#include "tst_encoder.moc"
@@ -619,4 +622,22 @@ void tst_Encoder::illegalSimpleType()
619622
QCOMPARE(cbor_encode_simple_value(&encoder, type), CborErrorIllegalSimpleType);
620623
}
621624

625+
void tst_Encoder::encodeRaw()
626+
{
627+
QFETCH(QVariant, input);
628+
QFETCH(QByteArray, output);
629+
630+
// just confirm it copies the data
631+
QByteArray buffer(output.length(), Qt::Uninitialized);
632+
633+
uint8_t *bufptr = reinterpret_cast<quint8 *>(buffer.data());
634+
CborEncoder encoder;
635+
cbor_encoder_init(&encoder, bufptr, buffer.length(), 0);
636+
637+
CborError error = cbor_encode_raw(&encoder, reinterpret_cast<quint8 *>(output.data()),
638+
output.size());
639+
QCOMPARE(error, CborNoError);
640+
QCOMPARE(buffer, output);
641+
}
642+
622643
QTEST_MAIN(tst_Encoder)

0 commit comments

Comments
 (0)