summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qbytearrayapisymmetry/tst_qbytearrayapisymmetry.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Change license for tests filesLucie Gérard2024-02-041-1/+1
| | | | | | | | | | | | According to QUIP-18 [1], all tests file should be LicenseRef-Qt-Commercial OR GPL-3.0-only [1]: https://contribute.qt-project.org/quips/18 Pick-to: 6.7 Task-number: QTBUG-121787 Change-Id: I9657df5d660820e56c96d511ea49d321c54682e8 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
* QByteArrayApiSymmetry: silence two clang warningsAhmad Samir2022-12-131-0/+5
| | | | | | | | | | | | | | | | | | | | tests/auto/corelib/text/qbytearrayapisymmetry/tst_qbytearrayapisymmetry.cpp:1174:80: warning: overflow in expression; result is -9223372036854775808 with type 'long long' [-Winteger-overflow] const qlonglong longMaxPlusOne = static_cast<qlonglong>(Bounds::max()) + 1; tests/auto/corelib/text/qbytearrayapisymmetry/tst_qbytearrayapisymmetry.cpp:1175:81: warning: overflow in expression; result is 9223372036854775807 with type 'long long' [-Winteger-overflow] const qlonglong longMinMinusOne = static_cast<qlonglong>(Bounds::min()) - 1; I usually build with GCC, but building with Clang for clazy-standalone, so I saw these two warnings 500+ times, enough already. :) Change-Id: Idd86af568ffe89ae49b2a3f9bbeedf312de5e631 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* tst_QBAApiSymmetry::toInt_data(): deduplicate a data-row nameEdward Welbourne2022-10-111-1/+1
| | | | | | | | One "empty" test was base ten, the other left the code to work out the base. Change the latter's name to reflect that difference. Change-Id: I4918eb0d293420df315d86e532787950b8f05be8 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-27/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Silence compiler warningVolker Hilsheimer2021-10-061-1/+1
| | | | | | | | | | clang warns that: local variable 'big' will be copied despite being returned by name [-Wreturn-std-move] So force the intended move using std::move. Change-Id: If5ff557c1b577789e6659783d8106295fafb3485 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Teach QByteArrayView how to parse numbersEdward Welbourne2021-08-301-0/+660
| | | | | | | | | | | | Now that we don't need '\0'-termination on the data, this is possible. Moved QByteArray's tests to tst_QByteArrayApiSymmetry and added some more test-cases. [ChangeLog][QtCore][QByteArrayView] Added numeric parsing methods. Change-Id: Ic0df91ecfe5dbf6f008d344dd0464d7927f32273 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QS(V)/QBA(V)/QL1S::lastIndexOf: fix the offset calculationsGiuseppe D'Angelo2021-08-191-5/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When trying to fix 0-length matches at the end of a QString, be83ff65c424cff1036e7da19d6175826d9f7ed9 actually introduced a regression due to how lastIndexOf interprets its `from` parameter. The "established" (=legacy) interpretation of a negative `from` is that it is supposed to indicate that we want the last match at offset `from + size()`. With the default from of -1, that means we want a match starting at most at position `size() - 1` inclusive, i.e. *at* the last position in the string. The aforementioned commit changed that, by allowing a match at position `size()` instead, and this behavioral change broke code. The problem the commit tried to fix was that empty matches *are* allowed to happen at position size(): the last match of regexp // inside the string "test" is indeed at position 4 (the regexp matches 5 times). Changing the meaning of negative from to include that last position (in general: to include position `from+size()+1` as the last valid matching position, in case of a negative `from`) has unfortunately broken client code. Therefore, we need to revert it. This patch does that, adapting the tests as necessary (drive-by: a broken #undef is removed). Reverting the patch however is not sufficient. What we are facing here is an historical API mistake that forces the default `from` (-1) to *skip* the truly last possible match; the mistake is that thre is simply no way to pass a negative `from` and obtain that match. This means that the revert will now cause code like this: str.lastIndexOf(QRE("")); // `from` defaulted to -1 NOT to return str.size(), which is counter-intuitive and wrong. Other APIs expose this inconsistency: for instance, using QRegularExpressionIterator would actually yield a last match at position str.size(). Similarly, using QString::count would return `str.size()+1`. Note that, in general, it's still possible for clients to call str.lastIndexOf(~~~, str.size()) to get the "truly last" match. This patch also tries to fix this case ("have our cake and eat it"). First and foremost, a couple of bugs in QByteArray and QString code are fixed (when dealing with 0-length needles). Second, a lastIndexOf overload is added. One overload is the "legacy" one, that will honor the pre-existing semantics of negative `from`. The new overload does NOT take a `from` parameter at all, and will actually match from the truly end (by simply calling `lastIndexOf(~~~, size())` internally). These overloads are offered for all the existing lastIndexOf() overloads, not only the ones taking QRE. This means that code simply using `lastIndexOf` without any `from` parameter get the "correct" behavior for 0-length matches, and code that specifies one gets the legacy behavior. Matches of length > 0 are not affected anyways, as they can't match at position size(). [ChangeLog][Important Behavior Changes] A regression in the behavior of the lastIndexOf() function on text-related containers and views (QString, QStringView, QByteArray, QByteArrayView, QLatin1String) has been fixed, and the behavior made consistent and more in line with user expectations. When lastIndexOf() is invoked with a negative `from` position, the last match has now to start at the last character in the container/view (before, it was at the position *past* the last character). This makes a difference when using lastIndexOf() with a needle that has 0 length (for instance an empty string, a regular expression that can match 0 characters, and so on); any other case is unaffected. To retrieve the "truly last" match, one can pass a positive `from` offset to lastIndexOf() (basically, pass `size()` as the `from` parameter). To make calls such as `text.lastIndexOf(~~~);`, that do not pass any `from` parameter, behave properly, a new lastIndexOf() overload has been added to all the text containers/views. This overload does not take a `from` parameter at all, and will search starting from one character past the end of the text, therefore returning a correct result when used with needles that may yield 0-length matches. Client code may need to be recompiled in order to use this new overload. Conversely, client code that needs to skip the "truly last" match now needs to pass -1 as the `from` parameter instead of relying on the default. Change-Id: I5e92bdcf1a57c2c3cca97b6adccf0883d00a92e5 Fixes: QTBUG-94215 Pick-to: 6.2 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Add QByteArrayView::trimmed()Edward Welbourne2021-08-111-1/+37
| | | | | | | | | | | | Unlike simplified(), it just moves the end-points, without needing to modify contents, so it makes sense (as for QStringView and QLatin1String) to provide it. Moved QByteArray's trimmed() tests to tst_QByteArrayApiSymmetry so that QBAV can now share them. [ChangeLog][QtCore][QByteArrayView] Added trimmed(). Change-Id: Ifd7a752adb5f3d3e2ad0aa8220efa7e7d2d39baa Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* QByteArray: extend unit testsIvan Solovev2021-07-291-0/+12
| | | | | | | | | | | This patch introduces some test improvements to check the calls of different methods on an empty default-constructed string. Apart from that, many other tests are added to extend code coverage. Task-number: QTBUG-91736 Pick-to: 6.2 6.1 Change-Id: If86ef3d8611a678798b1bcc60a1a4f5598fd2179 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QByteArray: fix indexOf/lastIndexOfIvan Solovev2021-07-291-4/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch fixed two bugs in indexOf/lastIndexOf: 1. The lastIndexOf(char, qsizetype) overload was crashing with an empty QByteArray. It was unconditionally calling lastIndexOfCharHelper() which assumes that this QBA is not empty. An explicit check for the empty case is added. 2. The indexOf(QByteArray, qsizetype) overload was behaving incorrectly while searching for an empty QByteArray. In this case it unconditionally returned its second parameter (from). However, from can be negative, or even exceed the size of this QByteArray. This patch handles this cases properly. As a drive-by: this patch adjusts the QByteArray::indexOf(char, qsizetype) and QByteArray::lastIndexOf(char, qsizetype) overloads to match with the QByteArrayView implementation. This is done to have similar code paths in both cases and avoid tricky bugs in future. Ideally we had to adjust the QByteArrayView implementation, but it's fully inline, so can't be changed without breaking BC. Task-number: QTBUG-91736 Pick-to: 6.2 6.1 Change-Id: Iaef2fdc5b99cce6aa342cca2d17544a1ad7ca677 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix QByteArray::count implementation for longer dataSona Kurazyan2020-07-091-0/+7
| | | | | | | | | | | | | The issue has been introduced when refactoring QByteArray::count implementation (see 631127126cc14e7c01cc611532b3256b58785670). Because the last argument of QByteArrayMatcher::indexIn() method has a defult value, it has been compiling without issues, but was being called with incorrect size parameter. Fixed it to pass the length of the input data correctly. Change-Id: Ic9c2f33733131ec17276aa889f2d7ea40ec79b01 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* Add tst_QByteArrayApiSymmetry testSona Kurazyan2020-07-081-0/+843
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>