summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp')
-rw-r--r--tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp49
1 files changed, 46 insertions, 3 deletions
diff --git a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
index 08c4086955..72a6427930 100644
--- a/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
@@ -35,6 +35,9 @@
#include <limits.h>
#include <private/qtools_p.h>
+#include <stdexcept>
+#include <string_view>
+
class tst_QByteArray : public QObject
{
Q_OBJECT
@@ -45,8 +48,8 @@ private slots:
void swap();
void qChecksum_data();
void qChecksum();
- void qCompress_data();
#ifndef QT_NO_COMPRESS
+ void qCompress_data();
void qCompress();
void qUncompressCorruptedData_data();
void qUncompressCorruptedData();
@@ -62,6 +65,7 @@ private slots:
void split();
void base64_data();
void base64();
+ void base64_2GiB();
void fromBase64_data();
void fromBase64();
void qvsnprintf();
@@ -187,7 +191,7 @@ QByteArray verifyZeroTermination(const QByteArray &ba)
if (!baDataPtr->isMutable())
return ba;
- int baSize = ba.size();
+ qsizetype baSize = ba.size();
char baTerminator = ba.constData()[baSize];
if ('\0' != baTerminator)
return QString::fromUtf8(
@@ -268,6 +272,7 @@ void tst_QByteArray::qChecksum()
QCOMPARE(::qChecksum(QByteArrayView(data.constData(), len), standard), static_cast<quint16>(checksum));
}
+#ifndef QT_NO_COMPRESS
void tst_QByteArray::qCompress_data()
{
QTest::addColumn<QByteArray>("ba");
@@ -294,7 +299,6 @@ void tst_QByteArray::qCompress_data()
QTest::newRow( "04" ) << file.readAll();
}
-#ifndef QT_NO_COMPRESS
void tst_QByteArray::qCompress()
{
QFETCH( QByteArray, ba );
@@ -618,6 +622,45 @@ void tst_QByteArray::base64()
QCOMPARE(arr64, base64urlnoequals);
}
+void tst_QByteArray::base64_2GiB()
+{
+#ifdef Q_OS_ANDROID
+ QSKIP("Android kills the test when using too much memory");
+#endif
+ if constexpr (sizeof(qsizetype) > sizeof(int)) {
+ try {
+ constexpr qint64 GiB = 1024 * 1024 * 1024;
+ static_assert((2 * GiB + 1) % 3 == 0);
+ const char inputChar = '\0'; // all-NULs encode as
+ const char outputChar = 'A'; // all-'A's
+ const qint64 inputSize = 2 * GiB + 1;
+ const qint64 outputSize = inputSize / 3 * 4;
+ const auto sv = [](const QByteArray &ba) {
+ return std::string_view{ba.data(), size_t(ba.size())};
+ };
+ QByteArray output;
+ {
+ const QByteArray input(inputSize, inputChar);
+ output = input.toBase64();
+ QCOMPARE(output.size(), outputSize);
+ QCOMPARE(sv(output).find_first_not_of(outputChar),
+ std::string_view::npos);
+ }
+ {
+ auto r = QByteArray::fromBase64Encoding(output);
+ QCOMPARE(r.decodingStatus, QByteArray::Base64DecodingStatus::Ok);
+ QCOMPARE(r.decoded.size(), inputSize);
+ QCOMPARE(sv(r.decoded).find_first_not_of(inputChar),
+ std::string_view::npos);
+ }
+ } catch (const std::bad_alloc &) {
+ QSKIP("Could not allocate enough RAM.");
+ }
+ } else {
+ QSKIP("This is a 64-bit only test");
+ }
+}
+
//different from the previous test as the input are invalid
void tst_QByteArray::fromBase64_data()
{