Tests: print the error message insead of just a number (or nothing)
Some QCOMPARE did convert to int() so we would see an error number, but
not all comparisons did. For those those that didn't, QCOMPARE would
just print that the values differed, but not show what.
So try to harmonize on printing the error message.
I may not have caught all uses...
Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
diff --git a/tests/encoder/tst_encoder.cpp b/tests/encoder/tst_encoder.cpp
index 4ee9b03..858d712 100644
--- a/tests/encoder/tst_encoder.cpp
+++ b/tests/encoder/tst_encoder.cpp
@@ -30,6 +30,12 @@
#endif
Q_DECLARE_METATYPE(CborError)
+namespace QTest {
+template<> char *toString<CborError>(const CborError &err)
+{
+ return qstrdup(cbor_error_string(err));
+}
+}
class tst_Encoder : public QObject
{
@@ -269,7 +275,7 @@
CborEncoder encoder;
cbor_encoder_init(&encoder, bufptr, buffer.length(), 0);
- QCOMPARE(int(encodeVariant(&encoder, input)), int(CborNoError));
+ QCOMPARE(encodeVariant(&encoder, input), CborNoError);
QCOMPARE(encoder.added, size_t(1));
QCOMPARE(cbor_encoder_get_extra_bytes_needed(&encoder), size_t(0));
@@ -635,9 +641,9 @@
CborEncoder encoder, container;
cbor_encoder_init(&encoder, reinterpret_cast<quint8 *>(buffer.data()), buffer.length(), 0);
QCOMPARE(cbor_encoder_create_array(&encoder, &container, 2), CborNoError);
- QCOMPARE(int(encodeVariant(&container, input)), int(CborNoError));
+ QCOMPARE(encodeVariant(&container, input), CborNoError);
QCOMPARE(container.added, size_t(1));
- QCOMPARE(int(cbor_encoder_close_container_checked(&encoder, &container)), int(CborErrorTooFewItems));
+ QCOMPARE(cbor_encoder_close_container_checked(&encoder, &container), CborErrorTooFewItems);
}
void tst_Encoder::tooShortMaps()
@@ -649,9 +655,9 @@
CborEncoder encoder, container;
cbor_encoder_init(&encoder, reinterpret_cast<quint8 *>(buffer.data()), buffer.length(), 0);
QCOMPARE(cbor_encoder_create_map(&encoder, &container, 2), CborNoError);
- QCOMPARE(int(encodeVariant(&container, input)), int(CborNoError));
+ QCOMPARE(encodeVariant(&container, input), CborNoError);
QCOMPARE(container.added, size_t(1));
- QCOMPARE(int(cbor_encoder_close_container_checked(&encoder, &container)), int(CborErrorTooFewItems));
+ QCOMPARE(cbor_encoder_close_container_checked(&encoder, &container), CborErrorTooFewItems);
}
void tst_Encoder::tooBigArrays()
@@ -663,10 +669,10 @@
CborEncoder encoder, container;
cbor_encoder_init(&encoder, reinterpret_cast<quint8 *>(buffer.data()), buffer.length(), 0);
QCOMPARE(cbor_encoder_create_array(&encoder, &container, 1), CborNoError);
- QCOMPARE(int(encodeVariant(&container, input)), int(CborNoError));
- QCOMPARE(int(encodeVariant(&container, input)), int(CborNoError));
+ QCOMPARE(encodeVariant(&container, input), CborNoError);
+ QCOMPARE(encodeVariant(&container, input), CborNoError);
QCOMPARE(container.added, size_t(2));
- QCOMPARE(int(cbor_encoder_close_container_checked(&encoder, &container)), int(CborErrorTooManyItems));
+ QCOMPARE(cbor_encoder_close_container_checked(&encoder, &container), CborErrorTooManyItems);
}
void tst_Encoder::tooBigMaps()
@@ -678,11 +684,11 @@
CborEncoder encoder, container;
cbor_encoder_init(&encoder, reinterpret_cast<quint8 *>(buffer.data()), buffer.length(), 0);
QCOMPARE(cbor_encoder_create_map(&encoder, &container, 1), CborNoError);
- QCOMPARE(int(encodeVariant(&container, input)), int(CborNoError));
- QCOMPARE(int(encodeVariant(&container, input)), int(CborNoError));
- QCOMPARE(int(encodeVariant(&container, input)), int(CborNoError));
+ QCOMPARE(encodeVariant(&container, input), CborNoError);
+ QCOMPARE(encodeVariant(&container, input), CborNoError);
+ QCOMPARE(encodeVariant(&container, input), CborNoError);
QCOMPARE(container.added, size_t(3));
- QCOMPARE(int(cbor_encoder_close_container_checked(&encoder, &container)), int(CborErrorTooManyItems));
+ QCOMPARE(cbor_encoder_close_container_checked(&encoder, &container), CborErrorTooManyItems);
}
void tst_Encoder::illegalSimpleType_data()
diff --git a/tests/parser/tst_parser.cpp b/tests/parser/tst_parser.cpp
index ebeecc9..b4dc679 100644
--- a/tests/parser/tst_parser.cpp
+++ b/tests/parser/tst_parser.cpp
@@ -33,6 +33,12 @@
#endif
Q_DECLARE_METATYPE(CborError)
+namespace QTest {
+template<> char *toString<CborError>(const CborError &err)
+{
+ return qstrdup(cbor_error_string(err));
+}
+}
class tst_Parser : public QObject
{
@@ -233,7 +239,7 @@
QCOMPARE(decoded, expected);
// check that the errors are the same
- QCOMPARE(int(err2), int(err));
+ QCOMPARE(err2, err);
// check that we consumed everything
QCOMPARE((void*)cbor_value_get_next_byte(&first), (void*)data.constEnd());
@@ -1261,7 +1267,7 @@
int64_t v;
err = cbor_value_get_int64_checked(&value, &v);
if (result.isNull()) {
- QCOMPARE(int(err), int(CborErrorDataTooLarge));
+ QCOMPARE(err, CborErrorDataTooLarge);
} else {
QCOMPARE(v, expected);
}
@@ -1269,7 +1275,7 @@
int v2;
err = cbor_value_get_int_checked(&value, &v2);
if (result.isNull() || expected < std::numeric_limits<int>::min() || expected > std::numeric_limits<int>::max()) {
- QCOMPARE(int(err), int(CborErrorDataTooLarge));
+ QCOMPARE(err, CborErrorDataTooLarge);
} else {
QCOMPARE(int64_t(v2), expected);
}
@@ -1534,10 +1540,10 @@
CborError err2 = cbor_value_validate_basic(&first);
CborError err3 = cbor_value_validate(&first, CborValidateBasic);
err = parseOne(&first, &decoded);
- QCOMPARE(int(err), int(expectedError));
+ QCOMPARE(err, expectedError);
if (!QByteArray(QTest::currentDataTag()).contains("utf8")) {
- QCOMPARE(int(err2), int(expectedError));
- QCOMPARE(int(err3), int(expectedError));
+ QCOMPARE(err2, expectedError);
+ QCOMPARE(err3, expectedError);
}
}
@@ -1903,7 +1909,7 @@
QVERIFY2(!err, QByteArray("Got error \"") + cbor_error_string(err) + "\"");
err = cbor_value_validate(&first, flags);
- QCOMPARE(int(err), int(expectedError));
+ QCOMPARE(err, expectedError);
}
void tst_Parser::resumeParsing_data()
@@ -1930,7 +1936,7 @@
}
if (err != CborErrorUnexpectedEOF)
qDebug() << "Length is" << len;
- QCOMPARE(int(err), int(CborErrorUnexpectedEOF));
+ QCOMPARE(err, CborErrorUnexpectedEOF);
}
}
@@ -2025,13 +2031,13 @@
it = first;
err = cbor_value_advance(&it);
- QCOMPARE(int(err), int(CborErrorNestingTooDeep));
+ QCOMPARE(err, CborErrorNestingTooDeep);
it = first;
if (cbor_value_is_map(&it)) {
CborValue dummy;
err = cbor_value_map_find_value(&it, "foo", &dummy);
- QCOMPARE(int(err), int(CborErrorNestingTooDeep));
+ QCOMPARE(err, CborErrorNestingTooDeep);
}
}