summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2020-04-15 14:00:05 -0300
committerThiago Macieira <thiago.macieira@intel.com>2020-04-30 04:00:47 -0700
commit2a53017df488b3cedbfbf5a56bf105b9fc5392fa (patch)
tree728b8feed3533fe93149ebc45476e2a2775c6311 /tests
parent52a2505672cbb1ca8b5b32f7bc1259485c65483b (diff)
QCborValue: add an extra check against producing invalid ISO dates
By QCborValue design, we store the textual representation in ISO format, equivalent of CBOR tag 0, which isn't allowed to have negative years or beyond year 10000. Change-Id: Ibdc95e9af7bd456a94ecfffd16060ccff359c296 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
index 0b3046fbdc..d035ca4ee5 100644
--- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
+++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
@@ -1970,6 +1970,21 @@ void tst_QCborValue::extendedTypeValidation_data()
<< encode(0xc1, 0xfb, -fplimit)
<< QCborValue(QCborKnownTags::UnixTime_t, -fplimit);
}
+
+ // But in fact, QCborValue stores date/times as their ISO textual
+ // representation, which means it can't represent dates before year 1 or
+ // after year 9999.
+ {
+ QDateTime dt(QDate(-1, 1, 1), QTime(0, 0), Qt::UTC);
+ QTest::newRow("UnixTime_t:negative-year")
+ << encode(0xc1, 0x3b, quint64(-dt.toSecsSinceEpoch()) - 1)
+ << QCborValue(QCborKnownTags::UnixTime_t, dt.toSecsSinceEpoch());
+
+ dt.setDate(QDate(10000, 1, 1));
+ QTest::newRow("UnixTime_t:year10k")
+ << encode(0xc1, 0x1b, quint64(dt.toSecsSinceEpoch()))
+ << QCborValue(QCborKnownTags::UnixTime_t, dt.toSecsSinceEpoch());
+ }
}
void tst_QCborValue::extendedTypeValidation()