Encoder: add unit test for cbor_encode_raw

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Thiago Macieira
2025-03-12 15:21:35 -07:00
parent abb7b3fe35
commit 6e3333ebe0
+21
View File
@@ -90,6 +90,9 @@ private slots:
void tooBigMaps();
void illegalSimpleType_data();
void illegalSimpleType();
void encodeRaw_data() { tags_data(); }
void encodeRaw();
};
#include "tst_encoder.moc"
@@ -619,4 +622,22 @@ void tst_Encoder::illegalSimpleType()
QCOMPARE(cbor_encode_simple_value(&encoder, type), CborErrorIllegalSimpleType);
}
void tst_Encoder::encodeRaw()
{
QFETCH(QVariant, input);
QFETCH(QByteArray, output);
// just confirm it copies the data
QByteArray buffer(output.length(), Qt::Uninitialized);
uint8_t *bufptr = reinterpret_cast<quint8 *>(buffer.data());
CborEncoder encoder;
cbor_encoder_init(&encoder, bufptr, buffer.length(), 0);
CborError error = cbor_encode_raw(&encoder, reinterpret_cast<quint8 *>(output.data()),
output.size());
QCOMPARE(error, CborNoError);
QCOMPARE(buffer, output);
}
QTEST_MAIN(tst_Encoder)