summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qbytearray/tst_qbytearray.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Add QByteArray::insert(qsizetype, const QByteArray &)Mårten Nordheim2020-11-111-0/+12
| | | | | | | | | | | | | | | | For consistency with append and prepend we should have an overload for insert() as well. This also enables insert() to be used with QStringBuilder, i.e. qba.insert(2, qba2 + "abc"). Because simply adding a const QByteArray & overload causes ambiguity with QByteArrayView we also add a const char * overload. Add some extra test-cases. Two for QByteArrayView since it's not directly tested anymore. One for inserting self directly. Change-Id: Ieb43a6a7d1afbb498bc89c690908d7f0faa94687 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QByteArray: make (ap|pre)pend(const QByteArray &) consider reservedMårten Nordheim2020-10-281-0/+12
| | | | | | | | | | Append was previously optimized for lhs being empty but it should've also taken into account if space had been reserved. Apply the same optimization to prepend while we're at it. Change-Id: I5e5d33a3189b9ad88d45e858a2ac412cbc294f79 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix warnings coming from using the deprecated overload of qCheckSumLars Knoll2020-09-111-2/+2
| | | | | | | Change-Id: I719c2d56a690fd245d3917045de4005f118c688b Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
* Change QByteArray to handle large arraysLars Knoll2020-08-271-2/+2
| | | | | | | | | | Use qsizetype throughout. Change-Id: I787af7fcfa17e1be87decb64c41c609cc24be117 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Cleanup QTypeInfoLars Knoll2020-08-261-1/+1
| | | | | | | | | | | | | | | Remove QTypeInfo::isStatic, as that's not used anymore in Qt 6. Also remove sizeOf, it's unused, and we have QMetaType for that if required. Remove all typeinfo declaractions for trivial types, as the default template covers them correctly nowadays. Finally set up a better default for isPointer, and do some smaller cleanups all over the place. Change-Id: I6758ed37dfc701feaaf0ff105cc95e32da9f9c33 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add tst_QByteArrayApiSymmetry testSona Kurazyan2020-07-081-334/+0
| | | | | | | | | | | | | | | Created tst_QByteArrayApiSymmetry test for the common APIs of QByteArray and QByteArrayView. Moved the tests for startsWith(), endsWith(), indexOf(), lastIndexOf(), compare(), from tst_QByteArray to tst_QByteArrayApiSymmetry and adapted them to check different QByteArray/QByteArrayView combinations. Added tests for first(), last(), sliced(), chopped(), chop(), truncate(), count(), contains() (test inputs are taken from corresponding tst_QStringApiSymmetry tests). Task-number: QTBUG-84321 Change-Id: I4e712b1692e3c1271d51ddcda6c9eb8bb01e11d4 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Allow allocating more than 2G items in a vectorLars Knoll2020-07-061-30/+39
| | | | | | | | | | | Also adjust qCalculateBlockSize() to be able to handle large allocations. QVector::length() is currently still limited to 2G items, that will get changed in a later commit. Change-Id: I3a92fbfd7f281d30844c5fafa3b9a474bc347c19 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Get rid of QArrayData::sharedNull()Lars Knoll2020-07-061-2/+2
| | | | | | | | Remove the last places where those got used and avoid allocations when we resize to 0. Change-Id: Ib553f4e7ce7cc24c31da15a55a86d18bdf1cc5c3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Get rid of unused flags in QArrayDataLars Knoll2020-07-061-5/+4
| | | | | Change-Id: I3ea754b44fb33e33baba0781d9ae15b7f3b3d8eb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Get rid of shared null for QByteArray, QString and QVectorLars Knoll2020-07-061-1/+1
| | | | | | | | | | | | | | As a side effect, data() can now return a nullptr. This has the potential to cause crashes in existig code. To work around this, return an empty string from QString::data() and QByteArray::data() for now. For Qt 6 (and once all our internal issues are fixed), data() will by default return a nullptr for a null QString, but we'll offer a #define to enable backwards compatible behavior. Change-Id: I4f66d97ff1dce3eb99a239f1eab9106fa9b1741a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port Q_STATIC_ASSERT(_X) to static_assertGiuseppe D'Angelo2020-06-191-1/+1
| | | | | | | | | | | | | | | | | There is no reason for keep using our macro now that we have C++17. The macro itself is left in for the moment being, as well as its detection logic, because it's needed for C code (not everything supports C11 yet). A few more cleanups will arrive in the next few patches. Note that this is a mere search/replace; some places were using double braces to work around the presence of commas in a macro, no attempt has been done to fix those. tst_qglobal had just some minor changes to keep testing the macro. Change-Id: I1c1c397d9f3e63db3338842bf350c9069ea57639 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Rework testing of qstr*cmp() functionsEdward Welbourne2020-06-051-79/+81
| | | | | | | | | | | | | | | Previously only qstr*icmp() were tested and the test data was sent via QString and {en,de}coding. Use a local data-type to package pointers to actual string literals for passing to these functions that take them. Fold the various tests involving null pointers and empty strings into the general testing, removing from "singularity" tests, and combine the remainders of those tests into a single test of singular cases for QByteArray::ompare. Move all these tests to alongside the existing tests for QByteArray::compare. Use nullptr rather than 0 as the null string. Change-Id: Ie6d01e839c330c2f960af4bcc95e5633539337d6 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Limit QByteArray's 8-bit support to ASCIIEdward Welbourne2020-06-041-20/+24
| | | | | | | | | | | | | | | | | | | | | Previously it handled Latin-1, which made it incompatible with UTF-8, which is now our preferred 8-bit encoding. For Qt6 it is limited to ASCII. Adjusted tests to match. QLatin1String::compare() turned out to be relying on qstrnicmp()'s Latin-1 handling. Removed some spurious Q_UNLIKELY()s and tidied up code a little in the process. [ChangeLog][QtCore][Important Behavior Changes] Encoding-dependent features of QByteArrray are now limited to ASCII, where previously they worked for the whole of Latin-1. This affects case-insensitive comparison, notably including qstricmp() and qstrnicmp(), and case-transforming functions. Fixes: QTBUG-84323 Change-Id: I2925d9908f8654599195a2860847b17083911b41 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Adjust resize() behavior of QString and QByteArray to match Qt 5Lars Knoll2020-05-211-1/+3
| | | | | | | | | | | | | resize() to a smaller size does not reallocate in Qt 5 if the container is not shared. Match this here. As a drive-by also fix resize calls on raw data strings to ensure they are null terminated after the resize. Change-Id: Ic4d8830e86ed3f247020d7ece3217cebd344ae96 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Enforce that statically allocated array-like containers have 0 capacityGiuseppe D'Angelo2020-05-141-0/+4
| | | | | | | | | | | | | | | | It has been the case for both QStringLiteral and QByteArrayLiteral since Qt 5.0, and Q_ARRAY_LITERAL since Qt 6.0. Since it's definitely surprising, add a note in the docs, which is "somehow" consistent with the interpretation of capacity as the biggest possible size before we reallocate. Since it's 0, any manipulation of the size will cause a reallocation. (Alternatively: the capacity() is for how many elements memory was requested from the free store. No memory was allocated, so 0...) Task-number: QTBUG-84069 Change-Id: I5c7d21a22d1bd8b8d9b71143e33d537ca0224acd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge remote-tracking branch 'origin/5.15' into devQt Forward Merge Bot2019-12-091-34/+138
|\ | | | | | | Change-Id: Ia24cc8b86def0d9d9c17d6775cc519e491b860b1
| * QByteArray: add a strict mode to fromBase64Giuseppe D'Angelo2019-12-051-34/+138
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | QByteArray::fromBase64 was liberal in its input, simply skipping over invalid characters. As a side-effect of this, it had no error reporting, meaning it could not be used to convert fromBase64 _and_ validate the input in one go. Add more option flags to make fromBase64 strictly validate its input. Since we want to know whether it has succeeded or not, and the existing fromBase64 overloads do not allow for that, introduce a new function that returns an optional-like datatype. While at it: base64 decoding can be done in-place; add an rvalue overload to enable this use case. [ChangeLog][QtCore][QByteArray] Added the new fromBase64Encoding function. [ChangeLog][QtCore][QByteArray] Added new flags to make fromBase64 / fromBase64Encoding strictly validate their input, instead of skipping over invalid characters. Change-Id: I99cd5f2230f3d62970b28b4cb102913301da6ccd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Use QArrayDataPointer to implement QByteArrayLars Knoll2019-12-081-3/+3
| | | | | | | | | | Change-Id: I2ee28023c2dea9fc3160400112c59a47566a4868 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Use the QByteArray::DataPointer typedef instead of QByteArrayDataLars Knoll2019-12-081-3/+3
| | | | | | | | | | | | | | | | The goal here is to move things over to QArrayDataPointer. This prepares for it. Change-Id: I32f54a47594274799600c618f7341c200ceaa306 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Get rid of QCharRef and QByteRefLars Knoll2019-12-081-1/+1
| | | | | | | | | | | | | | | | | | | | We already detach immediately since change c2d2757bccc68e1b981df059786c2e76f2969530. That basically removes the main purpose of having QChar/ByteRef, and we can just as well get rid of those classes for Qt 6. Change-Id: I8dc566a1948ddc29c0cb8a77ec7310654a7219a4 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Inline the size and data pointers in QByteArrayThiago Macieira2019-12-081-45/+14
| | | | | | | | | | Change-Id: I82feeb2c9bd2900f421fc0c8d78698b1e83db043 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Add reference-count manipulation functions to QArrayData and hide refThiago Macieira2019-12-081-3/+3
| | | | | | | | | | | | | | | | The next change will stop using some values in the reference counter as settings from the data. Change-Id: I94df1fe643896373fac2f000fff55bc7708fc807 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Introduce the Mutable flag and move QArrayDataPointer::needsDetachThiago Macieira2019-12-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The Mutable flag now contains the information on whether the data this QArrayData points to is mutable. This decouples the mutability / immutability setting from the allocation and from the type of data, opening the way for mutable raw or foreign data. There are still plenty of places in the source code that check the size of the allocation when it actually wants d->isMutable(). Fixing this will require reviewing all the code, so is left for later. The needsDetach() function is moved to QArrayData and de-constified. It returns true when a reallocation is necessary if the data is to be modified. Change-Id: I17e2bc5a3f6ef1f3eba8a205acd9852b95524f57 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* | Fix qChecksum testLars Knoll2019-12-071-5/+6
|/ | | | | | | | | | The test passed mostly by accident so far, as the created QByteArray was shorter than what the test assumed. Change-Id: I06858801d83a504eadc73ec2be281c88f8ffad5d Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move text-related code out of corelib/tools/ to corelib/text/Edward Welbourne2019-07-101-0/+2343
This includes byte array, string, char, unicode, locale, collation and regular expressions. Change-Id: I8b125fa52c8c513eb57a0f1298b91910e5a0d786 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>