Skip to content

Commit cc7774e

Browse files
Encoder: add unit test for cbor_encode_raw
Signed-off-by: Thiago Macieira <[email protected]>
1 parent c9ebbaa commit cc7774e

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
@@ -77,6 +77,9 @@ private slots:
7777
void tooBigMaps();
7878
void illegalSimpleType_data();
7979
void illegalSimpleType();
80+
81+
void encodeRaw_data() { tags_data(); }
82+
void encodeRaw();
8083
};
8184

8285
#include "tst_encoder.moc"
@@ -606,4 +609,22 @@ void tst_Encoder::illegalSimpleType()
606609
QCOMPARE(cbor_encode_simple_value(&encoder, type), CborErrorIllegalSimpleType);
607610
}
608611

612+
void tst_Encoder::encodeRaw()
613+
{
614+
QFETCH(QVariant, input);
615+
QFETCH(QByteArray, output);
616+
617+
// just confirm it copies the data
618+
QByteArray buffer(output.length(), Qt::Uninitialized);
619+
620+
uint8_t *bufptr = reinterpret_cast<quint8 *>(buffer.data());
621+
CborEncoder encoder;
622+
cbor_encoder_init(&encoder, bufptr, buffer.length(), 0);
623+
624+
CborError error = cbor_encode_raw(&encoder, reinterpret_cast<quint8 *>(output.data()),
625+
output.size());
626+
QCOMPARE(error, CborNoError);
627+
QCOMPARE(buffer, output);
628+
}
629+
609630
QTEST_MAIN(tst_Encoder)

0 commit comments

Comments
 (0)