summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qbytearrayapisymmetry/tst_qbytearrayapisymmetry.cpp
blob: f03086342ce2a106832824237c8a332ea3258972 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include <QTest>

#include <QByteArrayView>

#include <limits>

class tst_QByteArrayApiSymmetry : public QObject
{
    Q_OBJECT
private slots:
    void startsWith_QByteArray_QByteArray_data() { startsWith_data(); }
    void startsWith_QByteArray_QByteArray() { startsWith_impl<QByteArray, QByteArray>(); }
    void startsWith_QByteArray_QByteArrayView_data() { startsWith_data(); }
    void startsWith_QByteArray_QByteArrayView() { startsWith_impl<QByteArray, QByteArrayView>(); }
    void startsWith_QByteArrayView_QByteArrayView_data() { startsWith_data(); }
    void startsWith_QByteArrayView_QByteArrayView() { startsWith_impl<QByteArrayView, QByteArrayView>(); }
    void startsWith_QByteArrayView_QByteArray_data() { startsWith_data(); }
    void startsWith_QByteArrayView_QByteArray() { startsWith_impl<QByteArrayView, QByteArray>(); }
    void startsWithChar_QByteArray() { startsWithChar_impl<QByteArray>(); }
    void startsWithChar_QByteArrayView() { startsWithChar_impl<QByteArrayView>(); }

    void endsWith_QByteArray_QByteArray_data() { endsWith_data(); }
    void endsWith_QByteArray_QByteArray() { endsWith_impl<QByteArray, QByteArray>(); }
    void endsWith_QByteArray_QByteArrayView_data() { endsWith_data(); }
    void endsWith_QByteArray_QByteArrayView() { endsWith_impl<QByteArray, QByteArrayView>(); }
    void endsWith_QByteArrayView_QByteArrayView_data() { endsWith_data(); }
    void endsWith_QByteArrayView_QByteArrayView() { endsWith_impl<QByteArrayView, QByteArrayView>(); }
    void endsWith_QByteArrayView_QByteArray_data() { endsWith_data(); }
    void endsWith_QByteArrayView_QByteArray() { endsWith_impl<QByteArrayView, QByteArray>(); }
    void endsWithChar_QByteArray() { endsWithChar_impl<QByteArray>(); }
    void endsWithChar_QByteArrayView() { endsWithChar_impl<QByteArrayView>(); }

    void indexOf_QByteArray_QByteArray_data() { indexOf_data(); }
    void indexOf_QByteArray_QByteArray() { indexOf_impl<QByteArray, QByteArray>(); }
    void indexOf_QByteArray_QByteArrayView_data() { indexOf_data(); }
    void indexOf_QByteArray_QByteArrayView() { indexOf_impl<QByteArray, QByteArrayView>(); }
    void indexOf_QByteArrayView_QByteArrayView_data() { indexOf_data(); }
    void indexOf_QByteArrayView_QByteArrayView() { indexOf_impl<QByteArrayView, QByteArrayView>(); }
    void indexOf_QByteArrayView_QByteArray_data() { indexOf_data(); }
    void indexOf_QByteArrayView_QByteArray() { indexOf_impl<QByteArrayView, QByteArray>(); }

    void lastIndexOf_QByteArray_QByteArray_data() { lastIndexOf_data(); }
    void lastIndexOf_QByteArray_QByteArray() { lastIndexOf_impl<QByteArray, QByteArray>(); }
    void lastIndexOf_QByteArray_QByteArrayView_data() { lastIndexOf_data(); }
    void lastIndexOf_QByteArray_QByteArrayView() { lastIndexOf_impl<QByteArray, QByteArrayView>(); }
    void lastIndexOf_QByteArrayView_QByteArrayView_data() { lastIndexOf_data(); }
    void lastIndexOf_QByteArrayView_QByteArrayView() { lastIndexOf_impl<QByteArrayView, QByteArrayView>(); }
    void lastIndexOf_QByteArrayView_QByteArray_data() { lastIndexOf_data(); }
    void lastIndexOf_QByteArrayView_QByteArray() { lastIndexOf_impl<QByteArrayView, QByteArray>(); }

    void contains_QByteArray_QByteArray_data() { contains_data(); }
    void contains_QByteArray_QByteArray() { contains_impl<QByteArray, QByteArray>(); }
    void contains_QByteArray_QByteArrayView_data() { contains_data(); }
    void contains_QByteArray_QByteArrayView() { contains_impl<QByteArray, QByteArrayView>(); }
    void contains_QByteArrayView_QByteArrayView_data() { contains_data(); }
    void contains_QByteArrayView_QByteArrayView() { contains_impl<QByteArrayView, QByteArrayView>(); }
    void contains_QByteArrayView_QByteArray_data() { contains_data(); }
    void contains_QByteArrayView_QByteArray() { contains_impl<QByteArrayView, QByteArray>(); }

    void count_QByteArray_QByteArray_data() { count_data(); }
    void count_QByteArray_QByteArray() { count_impl<QByteArray, QByteArray>(); }
    void count_QByteArray_QByteArrayView_data() { count_data(); }
    void count_QByteArray_QByteArrayView() { count_impl<QByteArray, QByteArrayView>(); }
    void count_QByteArrayView_QByteArrayView_data() { count_data(); }
    void count_QByteArrayView_QByteArrayView() { count_impl<QByteArrayView, QByteArrayView>(); }
    void count_QByteArrayView_QByteArray_data() { count_data(); }
    void count_QByteArrayView_QByteArray() { count_impl<QByteArrayView, QByteArray>(); }

    void compare_QByteArray_QByteArray_data() { compare_data(); }
    void compare_QByteArray_QByteArray() { compare_impl<QByteArray, QByteArray>(); }
    void compare_QByteArray_QByteArrayView_data() { compare_data(); }
    void compare_QByteArray_QByteArrayView() { compare_impl<QByteArray, QByteArrayView>(); }
    void compare_QByteArrayView_QByteArray_data() { compare_data(); }
    void compare_QByteArrayView_QByteArray() { compare_impl<QByteArrayView, QByteArray>(); }
    void compare_QByteArrayView_QByteArrayView_data() { compare_data(); }
    void compare_QByteArrayView_QByteArrayView() { compare_impl<QByteArrayView, QByteArrayView>(); }

    void sliced_QByteArray_data() { sliced_data(); }
    void sliced_QByteArray() { sliced_impl<QByteArray>(); }
    void sliced_QByteArrayView_data() { sliced_data(); }
    void sliced_QByteArrayView() { sliced_impl<QByteArrayView>(); }

    void first_QByteArray_data() { first_data(); }
    void first_QByteArray() { first_impl<QByteArray>(); }
    void first_QByteArrayView_data() { first_data(); }
    void first_QByteArrayView() { first_impl<QByteArrayView>(); }

    void last_QByteArray_data() { last_data(); }
    void last_QByteArray() { last_impl<QByteArray>(); }
    void last_QByteArrayView_data() { last_data(); }
    void last_QByteArrayView() { last_impl<QByteArrayView>(); }

    void chop_QByteArray_data() { chop_data(); }
    void chop_QByteArray() { chop_impl<QByteArray>(); }
    void chop_QByteArrayView_data() { chop_data(); }
    void chop_QByteArrayView() { chop_impl<QByteArrayView>(); }

    void trimmed_QByteArray_data() { trimmed_data(); }
    void trimmed_QByteArray() { trimmed_impl<QByteArray>(); }
    void trimmed_QByteArrayView_data() { trimmed_data(); }
    void trimmed_QByteArrayView() { trimmed_impl<QByteArrayView>(); }

    void toShort_QByteArray() const { toShort<QByteArray>(); }
    void toShort_QByteArrayView() const { toShort<QByteArrayView>(); }
    void toUShort_QByteArray() const { toUShort<QByteArray>(); }
    void toUShort_QByteArrayView() const { toUShort<QByteArrayView>(); }
    void toInt_QByteArray_data() const { toInt_data(); }
    void toInt_QByteArrayView_data() const { toInt_data(); }
    void toInt_QByteArray() const { toInt<QByteArray>(); }
    void toInt_QByteArrayView() const { toInt<QByteArrayView>(); }
    void toUInt_QByteArray_data() const { toUInt_data(); }
    void toUInt_QByteArrayView_data() const { toUInt_data(); }
    void toUInt_QByteArray() const { toUInt<QByteArray>(); }
    void toUInt_QByteArrayView() const { toUInt<QByteArrayView>(); }
    void toLong_QByteArray_data() const { toLong_data(); }
    void toLong_QByteArrayView_data() const { toLong_data(); }
    void toLong_QByteArray() const { toLong<QByteArray>(); }
    void toLong_QByteArrayView() const { toLong<QByteArrayView>(); }
    void toULong_QByteArray_data() const { toULong_data(); }
    void toULong_QByteArrayView_data() const { toULong_data(); }
    void toULong_QByteArray() const { toULong<QByteArray>(); }
    void toULong_QByteArrayView() const { toULong<QByteArrayView>(); }
    void toLongLong_QByteArray_data() const { toLongLong_data(); }
    void toLongLong_QByteArrayView_data() const { toLongLong_data(); }
    void toLongLong_QByteArray() const { toLongLong<QByteArray>(); }
    void toLongLong_QByteArrayView() const { toLongLong<QByteArrayView>(); }
    void toULongLong_QByteArray_data() const { toULongLong_data(); }
    void toULongLong_QByteArrayView_data() const { toULongLong_data(); }
    void toULongLong_QByteArray() const { toULongLong<QByteArray>(); }
    void toULongLong_QByteArrayView() const { toULongLong<QByteArrayView>(); }
    void toFloat_QByteArray() const { toFloat<QByteArray>(); }
    void toFloat_QByteArrayView() const { toFloat<QByteArrayView>(); }
    void toDouble_QByteArray_data() const { toDouble_data(); }
    void toDouble_QByteArrayView_data() const { toDouble_data(); }
    void toDouble_QByteArray() const { toDouble<QByteArray>(); }
    void toDouble_QByteArrayView() const { toDouble<QByteArrayView>(); }

private:
    void startsWith_data();
    template<typename Haystack, typename Needle> void startsWith_impl();
    template<typename Haystack> void startsWithChar_impl();

    void endsWith_data();
    template<typename Haystack, typename Needle> void endsWith_impl();
    template<typename Haystack> void endsWithChar_impl();

    void indexOf_data();
    template<typename Haystack, typename Needle> void indexOf_impl();

    void lastIndexOf_data();
    template<typename Haystack, typename Needle> void lastIndexOf_impl();

    void contains_data();
    template<typename Haystack, typename Needle> void contains_impl();

    void count_data();
    template <typename Haystack, typename Needle> void count_impl();

    void compare_data();
    template <typename LHS, typename RHS> void compare_impl();

    void sliced_data();
    template <typename ByteArray> void sliced_impl();

    void first_data();
    template <typename ByteArray> void first_impl();

    void last_data();
    template <typename ByteArray> void last_impl();

    void chop_data();
    template <typename ByteArray> void chop_impl();

    void trimmed_data();
    template <typename ByteArray> void trimmed_impl();

    template <typename ByteArray> void toShort() const;
    template <typename ByteArray> void toUShort() const;
    void toInt_data() const;
    template <typename ByteArray> void toInt() const;
    void toUInt_data() const;
    template <typename ByteArray> void toUInt() const;
    void toLong_data() const;
    template <typename ByteArray> void toLong() const;
    void toULong_data() const;
    template <typename ByteArray> void toULong() const;
    void toLongLong_data() const;
    template <typename ByteArray> void toLongLong() const;
    void toULongLong_data() const;
    template <typename ByteArray> void toULongLong() const;
    template <typename ByteArray> void toFloat() const;
    void toDouble_data() const;
    template <typename ByteArray> void toDouble() const;
};

static const auto empty = QByteArray("");
static const QByteArray null;
// the tests below rely on the fact that these objects' names match their contents:
static const auto a = QByteArrayLiteral("a");
static const auto A = QByteArrayLiteral("A");
static const auto b = QByteArrayLiteral("b");
static const auto B = QByteArrayLiteral("B");
static const auto c = QByteArrayLiteral("c");
static const auto C = QByteArrayLiteral("C");
static const auto ab = QByteArrayLiteral("ab");
static const auto aB = QByteArrayLiteral("aB");
static const auto bc = QByteArrayLiteral("bc");
static const auto bC = QByteArrayLiteral("bC");
static const auto Bc = QByteArrayLiteral("Bc");
static const auto BC = QByteArrayLiteral("BC");
static const auto abc = QByteArrayLiteral("abc");
static const auto aBc = QByteArrayLiteral("aBc");

void tst_QByteArrayApiSymmetry::startsWith_data()
{
    QTest::addColumn<QByteArray>("ba");
    QTest::addColumn<QByteArray>("sw");
    QTest::addColumn<bool>("result");

    QTest::newRow("01") << QByteArray() << QByteArray() << true;
    QTest::newRow("02") << QByteArray() << QByteArray("") << true;
    QTest::newRow("03") << QByteArray() << QByteArray("hallo") << false;

    QTest::newRow("04") << QByteArray("") << QByteArray() << true;
    QTest::newRow("05") << QByteArray("") << QByteArray("") << true;
    QTest::newRow("06") << QByteArray("") << QByteArray("h") << false;

    QTest::newRow("07") << QByteArray("hallo") << QByteArray("h") << true;
    QTest::newRow("08") << QByteArray("hallo") << QByteArray("hallo") << true;
    QTest::newRow("09") << QByteArray("hallo") << QByteArray("") << true;
    QTest::newRow("10") << QByteArray("hallo") << QByteArray("hallohallo") << false;
    QTest::newRow("11") << QByteArray("hallo") << QByteArray() << true;
}

template<typename Haystack, typename Needle>
void tst_QByteArrayApiSymmetry::startsWith_impl()
{
    QFETCH(QByteArray, ba);
    QFETCH(QByteArray, sw);
    QFETCH(bool, result);

    const Haystack haystack(ba.data(), ba.size());
    const Needle needle(sw.data(), sw.size());

    QVERIFY(haystack.startsWith(needle) == result);
    if (needle.isNull()) {
        QVERIFY(haystack.startsWith((char *)0) == result);
    } else {
        QVERIFY(haystack.startsWith(needle.data()) == result);
        if (needle.size() == 1)
            QVERIFY(haystack.startsWith(needle.at(0)) == result);
    }
}

template<typename Haystack>
void tst_QByteArrayApiSymmetry::startsWithChar_impl()
{
    QVERIFY(Haystack("hallo").startsWith('h'));
    QVERIFY(!Haystack("hallo").startsWith('\0'));
    QVERIFY(!Haystack("hallo").startsWith('o'));
    QVERIFY(Haystack("h").startsWith('h'));
    QVERIFY(!Haystack("h").startsWith('\0'));
    QVERIFY(!Haystack("h").startsWith('o'));
    QVERIFY(!Haystack("hallo").startsWith('l'));
    QVERIFY(!Haystack("").startsWith('\0'));
    QVERIFY(!Haystack("").startsWith('a'));
    QVERIFY(!Haystack().startsWith('a'));
    QVERIFY(!Haystack().startsWith('\0'));
}

void tst_QByteArrayApiSymmetry::endsWith_data()
{
    QTest::addColumn<QByteArray>("ba");
    QTest::addColumn<QByteArray>("sw");
    QTest::addColumn<bool>("result");

    QTest::newRow("01") << QByteArray() << QByteArray() << true;
    QTest::newRow("02") << QByteArray() << QByteArray("") << true;
    QTest::newRow("03") << QByteArray() << QByteArray("hallo") << false;

    QTest::newRow("04") << QByteArray("") << QByteArray() << true;
    QTest::newRow("05") << QByteArray("") << QByteArray("") << true;
    QTest::newRow("06") << QByteArray("") << QByteArray("h") << false;

    QTest::newRow("07") << QByteArray("hallo") << QByteArray("o") << true;
    QTest::newRow("08") << QByteArray("hallo") << QByteArray("hallo") << true;
    QTest::newRow("09") << QByteArray("hallo") << QByteArray("") << true;
    QTest::newRow("10") << QByteArray("hallo") << QByteArray("hallohallo") << false;
    QTest::newRow("11") << QByteArray("hallo") << QByteArray() << true;
}

template<typename Haystack, typename Needle>
void tst_QByteArrayApiSymmetry::endsWith_impl()
{
    QFETCH(QByteArray, ba);
    QFETCH(QByteArray, sw);
    QFETCH(bool, result);

    const Haystack haystack(ba.data(), ba.size());
    const Needle needle(sw.data(), sw.size());

    QVERIFY(haystack.endsWith(needle) == result);
    if (needle.isNull()) {
        QVERIFY(haystack.endsWith((char *)0) == result);
    } else {
        QVERIFY(haystack.endsWith(needle.data()) == result);
        if (needle.size() == 1)
            QVERIFY(haystack.endsWith(needle.at(0)) == result);
    }
}

template<typename Haystack>
void tst_QByteArrayApiSymmetry::endsWithChar_impl()
{
    QVERIFY(Haystack("hallo").endsWith('o'));
    QVERIFY(!Haystack("hallo").endsWith('\0'));
    QVERIFY(!Haystack("hallo").endsWith('h'));
    QVERIFY(Haystack("h").endsWith('h'));
    QVERIFY(!Haystack("h").endsWith('\0'));
    QVERIFY(!Haystack("h").endsWith('o'));
    QVERIFY(!Haystack("hallo").endsWith('l'));
    QVERIFY(!Haystack("").endsWith('\0'));
    QVERIFY(!Haystack("").endsWith('a'));
    QVERIFY(!Haystack().endsWith('a'));
    QVERIFY(!Haystack().endsWith('\0'));
}

void tst_QByteArrayApiSymmetry::indexOf_data()
{
    QTest::addColumn<QByteArray>("ba1");
    QTest::addColumn<QByteArray>("ba2");
    QTest::addColumn<int>("startpos");
    QTest::addColumn<int>("expected");

    QTest::newRow("1") << abc << a << 0 << 0;
    QTest::newRow("2") << abc << A << 0 << -1;
    QTest::newRow("3") << abc << a << 1 << -1;
    QTest::newRow("4") << abc << A << 1 << -1;
    QTest::newRow("5") << abc << b << 0 << 1;
    QTest::newRow("6") << abc << B << 0 << -1;
    QTest::newRow("7") << abc << b << 1 << 1;
    QTest::newRow("8") << abc << B << 1 << -1;
    QTest::newRow("9") << abc << b << 2 << -1;
    QTest::newRow("10") << abc << c << 0 << 2;
    QTest::newRow("11") << abc << C << 0 << -1;
    QTest::newRow("12") << abc << c << 1 << 2;
    QTest::newRow("13") << abc << C << 1 << -1;
    QTest::newRow("14") << abc << c << 2 << 2;
    QTest::newRow("15") << aBc << bc << 0 << -1;
    QTest::newRow("16") << aBc << Bc << 0 << 1;
    QTest::newRow("17") << aBc << bC << 0 << -1;
    QTest::newRow("18") << aBc << BC << 0 << -1;

    static const char h19[] = { 'x', 0x00, (char)0xe7, 0x25, 0x1c, 0x0a };
    static const char n19[] = { 0x00, 0x00, 0x01, 0x00 };
    QTest::newRow("19") << QByteArray(h19, sizeof(h19)) << QByteArray(n19, sizeof(n19)) << 0 << -1;

    QTest::newRow("empty from 0") << QByteArray("") << QByteArray("x") << 0 << -1;
    QTest::newRow("empty from -1") << QByteArray("") << QByteArray("x") << -1 << -1;
    QTest::newRow("empty from 1") << QByteArray("") << QByteArray("x") << 1 << -1;
    QTest::newRow("null from 0") << QByteArray() << QByteArray("x") << 0 << -1;
    QTest::newRow("null from -1") << QByteArray() << QByteArray("x") << -1 << -1;
    QTest::newRow("null from 1") << QByteArray() << QByteArray("x") << 1 << -1;
    QTest::newRow("null-in-null") << QByteArray() << QByteArray() << 0 << 0;
    QTest::newRow("empty-in-null") << QByteArray() << QByteArray("") << 0 << 0;
    QTest::newRow("null-in-empty") << QByteArray("") << QByteArray() << 0 << 0;
    QTest::newRow("empty-in-empty") << QByteArray("") << QByteArray("") << 0 << 0;
    QTest::newRow("empty in abc from 0") << abc << QByteArray() << 0 << 0;
    QTest::newRow("empty in abc from 2") << abc << QByteArray() << 2 << 2;
    QTest::newRow("empty in abc from 5") << abc << QByteArray() << 5 << -1;
    QTest::newRow("empty in abc from -1") << abc << QByteArray() << -1 << 2;

    QByteArray veryBigHaystack(500, 'a');
    veryBigHaystack += 'B';
    QTest::newRow("BoyerMooreStressTest") << veryBigHaystack << veryBigHaystack << 0 << 0;
    QTest::newRow("BoyerMooreStressTest2")
            << QByteArray(veryBigHaystack + 'c') << QByteArray(veryBigHaystack) << 0 << 0;
    QTest::newRow("BoyerMooreStressTest3")
            << QByteArray('c' + veryBigHaystack) << QByteArray(veryBigHaystack) << 0 << 1;
    QTest::newRow("BoyerMooreStressTest4")
            << QByteArray(veryBigHaystack) << QByteArray(veryBigHaystack + 'c') << 0 << -1;
    QTest::newRow("BoyerMooreStressTest5")
            << QByteArray(veryBigHaystack) << QByteArray('c' + veryBigHaystack) << 0 << -1;
    QTest::newRow("BoyerMooreStressTest6")
            << QByteArray('d' + veryBigHaystack) << QByteArray('c' + veryBigHaystack) << 0 << -1;
    QTest::newRow("BoyerMooreStressTest7")
            << QByteArray(veryBigHaystack + 'c') << QByteArray('c' + veryBigHaystack) << 0 << -1;
}

template<typename Haystack, typename Needle>
void tst_QByteArrayApiSymmetry::indexOf_impl()
{
    QFETCH(QByteArray, ba1);
    QFETCH(QByteArray, ba2);
    QFETCH(int, startpos);
    QFETCH(int, expected);

    const Haystack haystack(ba1.data(), ba1.size());
    const Needle needle(ba2.data(), ba2.size());

    bool hasNull = needle.contains('\0');

    QCOMPARE(haystack.indexOf(needle, startpos), expected);
    if (!hasNull)
        QCOMPARE(haystack.indexOf(needle.data(), startpos), expected);
    if (needle.size() == 1)
        QCOMPARE(haystack.indexOf(needle.at(0), startpos), expected);

    if (startpos == 0) {
        QCOMPARE(haystack.indexOf(needle), expected);
        if (!hasNull)
            QCOMPARE(haystack.indexOf(needle.data()), expected);
        if (needle.size() == 1)
            QCOMPARE(haystack.indexOf(needle.at(0)), expected);
    }
}

void tst_QByteArrayApiSymmetry::lastIndexOf_data()
{
    QTest::addColumn<QByteArray>("ba1");
    QTest::addColumn<QByteArray>("ba2");
    QTest::addColumn<int>("startpos");
    QTest::addColumn<int>("expected");

    QTest::newRow("1") << abc << a << 0 << 0;
    QTest::newRow("2") << abc << A << 0 << -1;
    QTest::newRow("3") << abc << a << 1 << 0;
    QTest::newRow("4") << abc << A << 1 << -1;
    QTest::newRow("5") << abc << a << -1 << 0;
    QTest::newRow("6") << abc << b << 0 << -1;
    QTest::newRow("7") << abc << B << 0 << -1;
    QTest::newRow("8") << abc << b << 1 << 1;
    QTest::newRow("9") << abc << B << 1 << -1;
    QTest::newRow("10") << abc << b << 2 << 1;
    QTest::newRow("11") << abc << b << -1 << 1;
    QTest::newRow("12") << abc << c << 0 << -1;
    QTest::newRow("13") << abc << C << 0 << -1;
    QTest::newRow("14") << abc << c << 1 << -1;
    QTest::newRow("15") << abc << C << 1 << -1;
    QTest::newRow("16") << abc << c << 2 << 2;
    QTest::newRow("17") << abc << c << -1 << 2;
    QTest::newRow("18") << aBc << bc << 0 << -1;
    QTest::newRow("19") << aBc << Bc << 0 << -1;
    QTest::newRow("20") << aBc << Bc << 2 << 1;
    QTest::newRow("21") << aBc << Bc << 1 << 1;
    QTest::newRow("22") << aBc << Bc << -1 << 1;
    QTest::newRow("23") << aBc << bC << 0 << -1;
    QTest::newRow("24") << aBc << BC << 0 << -1;

    static const char h25[] = { 0x00, (char)0xbc, 0x03, 0x10, 0x0a };
    static const char n25[] = { 0x00, 0x00, 0x01, 0x00 };
    QTest::newRow("25") << QByteArray(h25, sizeof(h25)) << QByteArray(n25, sizeof(n25)) << 0 << -1;

    QTest::newRow("empty from 0") << QByteArray("") << QByteArray("x") << 0 << -1;
    QTest::newRow("empty from -1") << QByteArray("") << QByteArray("x") << -1 << -1;
    QTest::newRow("empty from 1") << QByteArray("") << QByteArray("x") << 1 << -1;
    QTest::newRow("null from 0") << QByteArray() << QByteArray("x") << 0 << -1;
    QTest::newRow("null from -1") << QByteArray() << QByteArray("x") << -1 << -1;
    QTest::newRow("null from 1") << QByteArray() << QByteArray("x") << 1 << -1;
    QTest::newRow("null-in-null-off--1") << QByteArray() << QByteArray() << -1 << -1;
    QTest::newRow("null-in-null-off-0") << QByteArray() << QByteArray() << 0 << 0;
    QTest::newRow("empty-in-null-off--1") << QByteArray() << QByteArray("") << -1 << -1;
    QTest::newRow("empty-in-null-off-0") << QByteArray() << QByteArray("") << 0 << 0;
    QTest::newRow("null-in-empty-off--1") << QByteArray("") << QByteArray() << -1 << -1;
    QTest::newRow("null-in-empty-off-0") << QByteArray("") << QByteArray() << 0 << 0;
    QTest::newRow("empty-in-empty-off--1") << QByteArray("") << QByteArray("") << -1 << -1;
    QTest::newRow("empty-in-empty-off-0") << QByteArray("") << QByteArray("") << 0 << 0;
    QTest::newRow("empty in abc from 0") << abc << QByteArray() << 0 << 0;
    QTest::newRow("empty in abc from 2") << abc << QByteArray() << 2 << 2;
    QTest::newRow("empty in abc from 5")
            << abc << QByteArray() << 5 << -1; // perversely enough, should be 3?
    QTest::newRow("empty in abc from -1") << abc << QByteArray() << -1 << 3;
    QTest::newRow("empty in abc from -5")
            << abc << QByteArray() << -5 << 3; // perversely enough, should be -1?
}

template<typename Haystack, typename Needle>
void tst_QByteArrayApiSymmetry::lastIndexOf_impl()
{
    QFETCH(QByteArray, ba1);
    QFETCH(QByteArray, ba2);
    QFETCH(int, startpos);
    QFETCH(int, expected);

    const Haystack haystack(ba1.data(), ba1.size());
    const Needle needle(ba2.data(), ba2.size());

    bool hasNull = needle.contains('\0');

    QCOMPARE(haystack.lastIndexOf(needle, startpos), expected);
    if (!hasNull)
        QCOMPARE(haystack.lastIndexOf(needle.data(), startpos), expected);
    if (needle.size() == 1)
        QCOMPARE(haystack.lastIndexOf(needle.at(0), startpos), expected);

    if (startpos == haystack.size()) {
        QCOMPARE(haystack.lastIndexOf(needle), expected);
        if (!hasNull)
            QCOMPARE(haystack.lastIndexOf(needle.data()), expected);
        if (needle.size() == 1)
            QCOMPARE(haystack.lastIndexOf(needle.at(0)), expected);
    }
}

void tst_QByteArrayApiSymmetry::contains_data()
{
    QTest::addColumn<QByteArray>("ba1");
    QTest::addColumn<QByteArray>("ba2");
    QTest::addColumn<bool>("result");

    QTest::newRow("1") << abc << a << true;
    QTest::newRow("2") << abc << A << false;
    QTest::newRow("3") << abc << b << true;
    QTest::newRow("4") << abc << B << false;
    QTest::newRow("5") << abc << c << true;
    QTest::newRow("6") << abc << C << false;
    QTest::newRow("7") << aBc << Bc << true;
    QTest::newRow("8") << aBc << bc << false;

    const char withnull[] = "a\0bc";
    QTest::newRow("withnull") << QByteArray(withnull, 4) << QByteArray("bc") << true;

    QTest::newRow("empty") << QByteArray("") << QByteArray("x") << false;
    QTest::newRow("null") << QByteArray() << QByteArray("x") << false;
    QTest::newRow("null-in-null") << QByteArray() << QByteArray() << true;
    QTest::newRow("empty-in-null") << QByteArray() << QByteArray("") << true;
    QTest::newRow("null-in-empty") << QByteArray("") << QByteArray() << true;
    QTest::newRow("empty-in-empty") << QByteArray("") << QByteArray("") << true;
}

template<typename Haystack, typename Needle>
void tst_QByteArrayApiSymmetry::contains_impl()
{
    QFETCH(QByteArray, ba1);
    QFETCH(QByteArray, ba2);
    QFETCH(bool, result);

    const Haystack haystack(ba1.data(), ba1.size());
    const Needle needle(ba2.data(), ba2.size());

    QCOMPARE(haystack.contains(needle), result);
    if (needle.size() == 1)
        QCOMPARE(haystack.contains(needle.at(0)), result);
}


void tst_QByteArrayApiSymmetry::count_data()
{
    QTest::addColumn<QByteArray>("ba1");
    QTest::addColumn<QByteArray>("ba2");
    QTest::addColumn<int>("result");

    QTest::addRow("aaa") << QByteArray("aaa") << QByteArray("a") << 3;
    QTest::addRow("xyzaaaxyz") << QByteArray("xyzaaxyaxyz") << QByteArray("xyz") << 2;
    QTest::addRow("a in null") << QByteArray() << QByteArray("a") << 0;
    QTest::addRow("a in empty") << QByteArray("") << QByteArray("a") << 0;
    QTest::addRow("xyz in null") << QByteArray() << QByteArray("xyz") << 0;
    QTest::addRow("xyz in empty") << QByteArray("") << QByteArray("xyz") << 0;
    QTest::addRow("null in null") << QByteArray() << QByteArray() << 1;
    QTest::addRow("empty in empty") << QByteArray("") << QByteArray("") << 1;
    QTest::addRow("empty in null") << QByteArray() << QByteArray("") << 1;
    QTest::addRow("null in empty") << QByteArray("") << QByteArray() << 1;

    const int len = 500;
    QByteArray longData(len, 'a');
    const QByteArray needle("abcdef");
    longData.insert(0, needle);
    longData.insert(len / 2, needle);
    QTest::addRow("longInput") << longData << needle << 2;
}

template <typename Haystack, typename Needle>
void tst_QByteArrayApiSymmetry::count_impl()
{
    QFETCH(const QByteArray, ba1);
    QFETCH(const QByteArray, ba2);
    QFETCH(int, result);

    const Haystack haystack(ba1.data(), ba1.size());
    const Needle needle(ba2.data(), ba2.size());

    QCOMPARE(haystack.count(needle), result);
    if (needle.size() == 1)
        QCOMPARE(haystack.count(needle.at(0)), result);
}

void tst_QByteArrayApiSymmetry::compare_data()
{
    QTest::addColumn<QByteArray>("ba1");
    QTest::addColumn<QByteArray>("ba2");
    QTest::addColumn<int>("result");

    QTest::newRow("null")      << QByteArray() << QByteArray() << 0;
    QTest::newRow("null-empty")<< QByteArray() << QByteArray("") << 0;
    QTest::newRow("empty-null")<< QByteArray("") << QByteArray() << 0;
    QTest::newRow("null-full") << QByteArray() << QByteArray("abc") << -1;
    QTest::newRow("full-null") << QByteArray("abc") << QByteArray() << +1;
    QTest::newRow("empty-full")<< QByteArray("") << QByteArray("abc") << -1;
    QTest::newRow("full-empty")<< QByteArray("abc") << QByteArray("") << +1;
    QTest::newRow("rawempty-full") << QByteArray::fromRawData("abc", 0) << QByteArray("abc") << -1;
    QTest::newRow("full-rawempty") << QByteArray("abc") << QByteArray::fromRawData("abc", 0) << +1;

    QTest::newRow("equal   1") << QByteArray("abc") << QByteArray("abc") << 0;
    QTest::newRow("equal   2") << QByteArray::fromRawData("abc", 3) << QByteArray("abc") << 0;
    QTest::newRow("equal   3") << QByteArray::fromRawData("abcdef", 3) << QByteArray("abc") << 0;
    QTest::newRow("equal   4") << QByteArray("abc") << QByteArray::fromRawData("abc", 3) << 0;
    QTest::newRow("equal   5") << QByteArray("abc") << QByteArray::fromRawData("abcdef", 3) << 0;
    QTest::newRow("equal   6") << QByteArray("a\0bc", 4) << QByteArray("a\0bc", 4) << 0;
    QTest::newRow("equal   7") << QByteArray::fromRawData("a\0bcdef", 4) << QByteArray("a\0bc", 4) << 0;
    QTest::newRow("equal   8") << QByteArray("a\0bc", 4) << QByteArray::fromRawData("a\0bcdef", 4) << 0;

    QTest::newRow("less    1") << QByteArray("000") << QByteArray("abc") << -1;
    QTest::newRow("less    2") << QByteArray::fromRawData("00", 3) << QByteArray("abc") << -1;
    QTest::newRow("less    3") << QByteArray("000") << QByteArray::fromRawData("abc", 3) << -1;
    QTest::newRow("less    4") << QByteArray("abc", 3) << QByteArray("abc", 4) << -1;
    QTest::newRow("less    5") << QByteArray::fromRawData("abc\0", 3) << QByteArray("abc\0", 4) << -1;
    QTest::newRow("less    6") << QByteArray("a\0bc", 4) << QByteArray("a\0bd", 4) << -1;

    QTest::newRow("greater 1") << QByteArray("abc") << QByteArray("000") << +1;
    QTest::newRow("greater 2") << QByteArray("abc") << QByteArray::fromRawData("00", 3) << +1;
    QTest::newRow("greater 3") << QByteArray("abcd") << QByteArray::fromRawData("abcd", 3) << +1;
    QTest::newRow("greater 4") << QByteArray("a\0bc", 4) << QByteArray("a\0bb", 4) << +1;
}

template <typename LHS, typename RHS>
void tst_QByteArrayApiSymmetry::compare_impl()
{
    QFETCH(QByteArray, ba1);
    QFETCH(QByteArray, ba2);
    QFETCH(int, result);

    const bool isEqual   = result == 0;
    const bool isLess    = result < 0;
    const bool isGreater = result > 0;

    const LHS lhs(ba1);
    const RHS rhs(ba2);

    if constexpr (std::is_same_v<QByteArray, LHS>) {
        int cmp = lhs.compare(rhs);
        if (cmp)
            cmp = (cmp < 0 ? -1 : 1);
        QCOMPARE(cmp, result);
    }

    // basic tests:
    QCOMPARE(lhs == rhs, isEqual);
    QCOMPARE(lhs < rhs, isLess);
    QCOMPARE(lhs > rhs, isGreater);

    // composed tests:
    QCOMPARE(lhs <= rhs, isLess || isEqual);
    QCOMPARE(lhs >= rhs, isGreater || isEqual);
    QCOMPARE(lhs != rhs, !isEqual);

    // inverted tests:
    QCOMPARE(rhs == lhs, isEqual);
    QCOMPARE(rhs < lhs, isGreater);
    QCOMPARE(rhs > lhs, isLess);

    // composed, inverted tests:
    QCOMPARE(rhs <= lhs, isGreater || isEqual);
    QCOMPARE(rhs >= lhs, isLess || isEqual);
    QCOMPARE(rhs != lhs, !isEqual);

    if (isEqual)
        QVERIFY(qHash(lhs) == qHash(rhs));
}

template <typename ByteArray> ByteArray detached(ByteArray b)
{
    if (!b.isNull()) { // detaching loses nullness, but we need to preserve it
        auto d = b.data();
        Q_UNUSED(d);
    }
    return b;
}

void tst_QByteArrayApiSymmetry::sliced_data()
{
    QTest::addColumn<QByteArray>("ba");
    QTest::addColumn<int>("pos");
    QTest::addColumn<int>("n");
    QTest::addColumn<QByteArray>("result1");
    QTest::addColumn<QByteArray>("result2");

    QTest::addRow("empty") << empty << 0 << 0 << empty << empty;
#define ROW(base, p, n, r1, r2) \
    QTest::addRow("%s%d%d", #base, p, n) << base << p << n << r1 << r2

    ROW(a, 0, 0, a, empty);
    ROW(a, 0, 1, a, a);
    ROW(a, 1, 0, empty, empty);

    ROW(ab, 0, 0, ab, empty);
    ROW(ab, 0, 1, ab, a);
    ROW(ab, 0, 2, ab, ab);
    ROW(ab, 1, 0, b,  empty);
    ROW(ab, 1, 1, b,  b);
    ROW(ab, 2, 0, empty, empty);

    ROW(abc, 0, 0, abc, empty);
    ROW(abc, 0, 1, abc, a);
    ROW(abc, 0, 2, abc, ab);
    ROW(abc, 0, 3, abc, abc);
    ROW(abc, 1, 0, bc,  empty);
    ROW(abc, 1, 1, bc,  b);
    ROW(abc, 1, 2, bc,  bc);
    ROW(abc, 2, 0, c,   empty);
    ROW(abc, 2, 1, c,   c);
    ROW(abc, 3, 0, empty, empty);
#undef ROW
}

template <typename ByteArray>
void tst_QByteArrayApiSymmetry::sliced_impl()
{
    QFETCH(const QByteArray, ba);
    QFETCH(const int, pos);
    QFETCH(const int, n);
    QFETCH(const QByteArray, result1);
    QFETCH(const QByteArray, result2);

    const ByteArray b(ba);
    {
        const auto sliced1 = b.sliced(pos);
        const auto sliced2 = b.sliced(pos, n);

        QCOMPARE(sliced1, result1);
        QCOMPARE(sliced1.isNull(), result1.isNull());
        QCOMPARE(sliced1.isEmpty(), result1.isEmpty());

        QCOMPARE(sliced2, result2);
        QCOMPARE(sliced2.isNull(), result2.isNull());
        QCOMPARE(sliced2.isEmpty(), result2.isEmpty());
    }

    {
        const auto sliced1 = detached(b).sliced(pos);
        const auto sliced2 = detached(b).sliced(pos, n);

        QCOMPARE(sliced1, result1);
        QCOMPARE(sliced1.isNull(), result1.isNull());
        QCOMPARE(sliced1.isEmpty(), result1.isEmpty());

        QCOMPARE(sliced2, result2);
        QCOMPARE(sliced2.isNull(), result2.isNull());
        QCOMPARE(sliced2.isEmpty(), result2.isEmpty());
    }
}

void tst_QByteArrayApiSymmetry::first_data()
{
    QTest::addColumn<QByteArray>("ba");
    QTest::addColumn<int>("n");
    QTest::addColumn<QByteArray>("result");

    QTest::addRow("empty") << empty << 0 << empty;

#define ROW(base, n, res) \
    QTest::addRow("%s%d", #base, n) << base << n << res

    ROW(a, 0, empty);
    ROW(a, 1, a);

    ROW(ab, 0, empty);
    ROW(ab, 1, a);
    ROW(ab, 2, ab);

    ROW(abc, 0, empty);
    ROW(abc, 1, a);
    ROW(abc, 2, ab);
    ROW(abc, 3, abc);
#undef ROW
}

template <typename ByteArray>
void tst_QByteArrayApiSymmetry::first_impl()
{
    QFETCH(const QByteArray, ba);
    QFETCH(const int, n);
    QFETCH(const QByteArray, result);

    const ByteArray b(ba);
    {
        const auto first = b.first(n);

        QCOMPARE(first, result);
        QCOMPARE(first.isNull(), result.isNull());
        QCOMPARE(first.isEmpty(), result.isEmpty());
    }
    {
        const auto first = detached(b).first(n);

        QCOMPARE(first, result);
        QCOMPARE(first.isNull(), result.isNull());
        QCOMPARE(first.isEmpty(), result.isEmpty());
    }
    {
        auto first = b;
        first.truncate(n);

        QCOMPARE(first, result);
        QCOMPARE(first.isNull(), result.isNull());
        QCOMPARE(first.isEmpty(), result.isEmpty());
    }
}

void tst_QByteArrayApiSymmetry::last_data()
{
    QTest::addColumn<QByteArray>("ba");
    QTest::addColumn<int>("n");
    QTest::addColumn<QByteArray>("result");

    QTest::addRow("empty") << empty << 0 << empty;

#define ROW(base, n, res) \
    QTest::addRow("%s%d", #base, n) << base << n << res

    ROW(a, 0, empty);
    ROW(a, 1, a);

    ROW(ab, 0, empty);
    ROW(ab, 1, b);
    ROW(ab, 2, ab);

    ROW(abc, 0, empty);
    ROW(abc, 1, c);
    ROW(abc, 2, bc);
    ROW(abc, 3, abc);
#undef ROW
}

template <typename ByteArray>
void tst_QByteArrayApiSymmetry::last_impl()
{
    QFETCH(const QByteArray, ba);
    QFETCH(const int, n);
    QFETCH(const QByteArray, result);

    const ByteArray b(ba);

    {
        const auto last = b.last(n);

        QCOMPARE(last, result);
        QCOMPARE(last.isNull(), result.isNull());
        QCOMPARE(last.isEmpty(), result.isEmpty());
    }
    {
        const auto last = detached(b).last(n);

        QCOMPARE(last, result);
        QCOMPARE(last.isNull(), result.isNull());
        QCOMPARE(last.isEmpty(), result.isEmpty());
    }
}

void tst_QByteArrayApiSymmetry::chop_data()
{
    QTest::addColumn<QByteArray>("ba");
    QTest::addColumn<int>("n");
    QTest::addColumn<QByteArray>("result");

    QTest::addRow("empty") << empty << 0 << empty;

    // Some classes' truncate() implementations have a wide contract, others a narrow one
    // so only test valid arguents here:
#define ROW(base, n, res) \
    QTest::addRow("%s%d", #base, n) << base << n << res

    ROW(a, 0, a);
    ROW(a, 1, empty);

    ROW(ab, 0, ab);
    ROW(ab, 1, a);
    ROW(ab, 2, empty);

    ROW(abc, 0, abc);
    ROW(abc, 1, ab);
    ROW(abc, 2, a);
    ROW(abc, 3, empty);
#undef ROW
}

template <typename ByteArray>
void tst_QByteArrayApiSymmetry::chop_impl()
{
    QFETCH(const QByteArray, ba);
    QFETCH(const int, n);
    QFETCH(const QByteArray, result);

    const ByteArray b(ba);

    {
        const auto chopped = b.chopped(n);

        QCOMPARE(chopped, result);
        QCOMPARE(chopped.isNull(), result.isNull());
        QCOMPARE(chopped.isEmpty(), result.isEmpty());
    }
    {
        const auto chopped = detached(b).chopped(n);

        QCOMPARE(chopped, result);
        QCOMPARE(chopped.isNull(), result.isNull());
        QCOMPARE(chopped.isEmpty(), result.isEmpty());
    }
    {
        auto chopped = b;
        chopped.chop(n);

        QCOMPARE(chopped, result);
        QCOMPARE(chopped.isNull(), result.isNull());
        QCOMPARE(chopped.isEmpty(), result.isEmpty());
    }
}

void tst_QByteArrayApiSymmetry::trimmed_data()
{
    QTest::addColumn<QByteArray>("source");
    QTest::addColumn<QByteArray>("expected");

    QTest::newRow("null") << QByteArray() << QByteArray();
    QTest::newRow("empty") << QByteArray("") << QByteArray("");
    QTest::newRow("no end-spaces") << QByteArray("a b\nc\td") << QByteArray("a b\nc\td");
    QTest::newRow("with end-spaces")
        << QByteArray("\t \v a b\r\nc \td\ve   f \r\n\f") << QByteArray("a b\r\nc \td\ve   f");
    QTest::newRow("all spaces") << QByteArray("\t \r \n \v \f") << QByteArray("");
}

template <typename ByteArray> void tst_QByteArrayApiSymmetry::trimmed_impl()
{
    QFETCH(QByteArray, source);
    QFETCH(QByteArray, expected);

    QCOMPARE(ByteArray(source).trimmed(), ByteArray(expected));
    ByteArray copy{source};
    QCOMPARE(std::move(copy).trimmed(), ByteArray(expected));

    if constexpr (std::is_same_v<QByteArray, ByteArray>) {
        if (source.isEmpty())
            QVERIFY(!source.isDetached());
    }
}

template <typename ByteArray> void tst_QByteArrayApiSymmetry::toShort() const
{
    bool ok = true; // opposite to the first expected result

    QCOMPARE(ByteArray().toShort(&ok), 0);
    QVERIFY(!ok);

    QCOMPARE(ByteArray("").toShort(&ok), 0);
    QVERIFY(!ok);

    QCOMPARE(ByteArray("12345").toShort(&ok), 12345);
    QVERIFY(ok);

    QCOMPARE(ByteArray("-12345").toShort(&ok), -12345);
    QVERIFY(ok);

    QCOMPARE(ByteArray("-12345 and a bit", 5).toShort(&ok), -1234);
    QVERIFY(ok);

    QCOMPARE(ByteArray("-12345 and a bit").sliced(1, 4).toShort(&ok), 1234);
    QVERIFY(ok);

    QCOMPARE(ByteArray("-012345 and a bit", 2).toShort(&ok), 0);
    QVERIFY(ok);

    QCOMPARE(ByteArray("-12345 and a bit", 6).toShort(&ok), -12345);
    QVERIFY(ok);

    QCOMPARE(ByteArray("-12345 and a bit", 7).toShort(&ok), -12345);
    QVERIFY(ok);

    QCOMPARE(ByteArray("12345 and a bit", 10).toShort(&ok), 0);
    QVERIFY(!ok);

    QCOMPARE(ByteArray("32767").toShort(&ok), 32767);
    QVERIFY(ok);

    QCOMPARE(ByteArray("-32768").toShort(&ok), -32768);
    QVERIFY(ok);

    QCOMPARE(ByteArray("32768").toShort(&ok), 0);
    QVERIFY(!ok);

    QCOMPARE(ByteArray("-32769").toShort(&ok), 0);
    QVERIFY(!ok);
}

template <typename ByteArray> void tst_QByteArrayApiSymmetry::toUShort() const
{
    bool ok = true; // opposite to the first expected result

    QCOMPARE(ByteArray().toUShort(&ok), 0);
    QVERIFY(!ok);

    QCOMPARE(ByteArray("").toUShort(&ok), 0);
    QVERIFY(!ok);

    QCOMPARE(ByteArray("12345").toUShort(&ok), 12345);
    QVERIFY(ok);

    QCOMPARE(ByteArray("12345 and a bit", 4).toUShort(&ok), 1234);
    QVERIFY(ok);

    QCOMPARE(ByteArray("012345 and a bit").sliced(1, 4).toUShort(&ok), 1234);
    QVERIFY(ok);

    QCOMPARE(ByteArray("012345 and a bit", 1).toUShort(&ok), 0);
    QVERIFY(ok);

    QCOMPARE(ByteArray("12345 and a bit", 5).toUShort(&ok), 12345);
    QVERIFY(ok);

    QCOMPARE(ByteArray("12345 and a bit", 6).toUShort(&ok), 12345);
    QVERIFY(ok);

    QCOMPARE(ByteArray("12345 and a bit", 10).toUShort(&ok), 0);
    QVERIFY(!ok);

    QCOMPARE(ByteArray("-12345").toUShort(&ok), 0);
    QVERIFY(!ok);

    QCOMPARE(ByteArray("32767").toUShort(&ok), 32767);
    QVERIFY(ok);

    QCOMPARE(ByteArray("32768").toUShort(&ok), 32768);
    QVERIFY(ok);

    QCOMPARE(ByteArray("65535").toUShort(&ok), 65535);
    QVERIFY(ok);

    QCOMPARE(ByteArray("65536").toUShort(&ok), 0);
    QVERIFY(!ok);
}

// defined later
extern const char globalChar;

void tst_QByteArrayApiSymmetry::toInt_data() const
{
    QTest::addColumn<QByteArray>("string");
    QTest::addColumn<int>("base");
    QTest::addColumn<int>("expectednumber");
    QTest::addColumn<bool>("expectedok");

    QTest::newRow("null") << QByteArray() << 10 << 0 << false;
    QTest::newRow("empty") << QByteArray("") << 10 << 0 << false;

    QTest::newRow("base 10") << QByteArray("100") << 10 << 100 << true;
    QTest::newRow("base 16-1") << QByteArray("100") << 16 << 256 << true;
    QTest::newRow("base 16-2") << QByteArray("0400") << 16 << 1024 << true;
    QTest::newRow("base 2") << QByteArray("1111") << 2 << 15 << true;
    QTest::newRow("base 8") << QByteArray("100") << 8 << 64 << true;
    QTest::newRow("base 0-1") << QByteArray("0x10") << 0 << 16 << true;
    QTest::newRow("base 0-2") << QByteArray("10") << 0 << 10 << true;
    QTest::newRow("base 0-3") << QByteArray("010") << 0 << 8 << true;
    QTest::newRow("base 0 empty") << QByteArray() << 0 << 0 << false;

    QTest::newRow("leading space") << QByteArray(" 100") << 10 << 100 << true;
    QTest::newRow("trailing space") << QByteArray("100 ") << 10 << 100 << true;
    QTest::newRow("leading junk") << QByteArray("x100") << 10 << 0 << false;
    QTest::newRow("trailing junk") << QByteArray("100x") << 10 << 0 << false;

    // using fromRawData
    QTest::newRow("raw1") << QByteArray::fromRawData("1", 1) << 10 << 1 << true;
    QTest::newRow("raw2") << QByteArray::fromRawData("1foo", 1) << 10 << 1 << true;
    QTest::newRow("raw3") << QByteArray::fromRawData("12", 1) << 10 << 1 << true;
    QTest::newRow("raw4") << QByteArray::fromRawData("123456789", 1) << 10 << 1 << true;
    QTest::newRow("raw5") << QByteArray::fromRawData("123456789", 2) << 10 << 12 << true;

    QTest::newRow("raw-static") << QByteArray::fromRawData(&globalChar, 1) << 10 << 1 << true;
}

template <typename ByteArray> void tst_QByteArrayApiSymmetry::toInt() const
{
    QFETCH(QByteArray, string);
    QFETCH(int, base);
    QFETCH(int, expectednumber);
    QFETCH(bool, expectedok);

    bool ok;
    int number = ByteArray(string).toInt(&ok, base);

    QCOMPARE(ok, expectedok);
    QCOMPARE(number, expectednumber);
}

void tst_QByteArrayApiSymmetry::toUInt_data() const
{
    QTest::addColumn<QByteArray>("string");
    QTest::addColumn<int>("base");
    QTest::addColumn<uint>("expectednumber");
    QTest::addColumn<bool>("expectedok");

    QTest::newRow("null") << QByteArray() << 10 << 0u << false;
    QTest::newRow("empty") << QByteArray("") << 10 << 0u << false;

    QTest::newRow("negative value") << QByteArray("-50") << 10 << 0u << false;
    QTest::newRow("more than MAX_INT") << QByteArray("3234567890") << 10 << 3234567890u << true;
    QTest::newRow("2^32 - 1") << QByteArray("4294967295") << 10 << 4294967295u << true;
    if constexpr (sizeof(int) > 4)
        QTest::newRow("2^32") << QByteArray("4294967296") << 10 << (1u << 32) << true;
    else
        QTest::newRow("2^32") << QByteArray("4294967296") << 10 << 0u << false;
}

template <typename ByteArray> void tst_QByteArrayApiSymmetry::toUInt() const
{
    QFETCH(QByteArray, string);
    QFETCH(int, base);
    QFETCH(uint, expectednumber);
    QFETCH(bool, expectedok);

    bool ok;
    const uint number = ByteArray(string).toUInt(&ok, base);

    QCOMPARE(ok, expectedok);
    QCOMPARE(number, expectednumber);
}

void tst_QByteArrayApiSymmetry::toLong_data() const
{
    QTest::addColumn<QByteArray>("str");
    QTest::addColumn<int>("base");
    QTest::addColumn<long>("result");
    QTest::addColumn<bool>("ok");

    QTest::newRow("null") << QByteArray() << 10 << 0L << false;
    QTest::newRow("empty") << QByteArray("") << 16 << 0L << false;
    QTest::newRow("in range dec") << QByteArray("1608507359") << 10 << 1608507359L << true;
    QTest::newRow("in range dec neg") << QByteArray("-1608507359") << 10 << -1608507359L << true;
    QTest::newRow("in range hex") << QByteArray("12ABCDEF") << 16 << 0x12ABCDEFL << true;
    QTest::newRow("in range hex neg") << QByteArray("-12ABCDEF") << 16 << -0x12ABCDEFL << true;
    QTest::newRow("Fibonacci's last int32")
        << QByteArray("1836311903") << 10 << 1836311903L << true;

    QTest::newRow("leading spaces") << QByteArray(" \r\n\tABC123") << 16 << 0xABC123L << true;
    QTest::newRow("trailing spaces") << QByteArray("1234567\t\r \n") << 10 << 1234567L << true;
    QTest::newRow("leading junk") << QByteArray("q12345") << 10 << 0L << false;
    QTest::newRow("trailing junk") << QByteArray("abc12345t") << 16 << 0L << false;

    QTest::newRow("dec with base 0") << QByteArray("123") << 0 << 123L << true;
    QTest::newRow("neg dec with base 0") << QByteArray("-123") << 0 << -123L << true;
    QTest::newRow("hex with base 0") << QByteArray("0x123") << 0 << 0x123L << true;
    QTest::newRow("neg hex with base 0") << QByteArray("-0x123") << 0 << -0x123L << true;
    QTest::newRow("oct with base 0") << QByteArray("0123") << 0 << 0123L << true;
    QTest::newRow("neg oct with base 0") << QByteArray("-0123") << 0 << -0123L << true;

    QTest::newRow("base 3") << QByteArray("12012") << 3 << 140L << true;
    QTest::newRow("neg base 3") << QByteArray("-201") << 3 << -19L << true;

    using Bounds = std::numeric_limits<long>;
    QTest::newRow("long max") << QByteArray::number(Bounds::max()) << 10 << Bounds::max() << true;
    QTest::newRow("long min") << QByteArray::number(Bounds::min()) << 10 << Bounds::min() << true;

    using B32 = std::numeric_limits<qint32>;
    QTest::newRow("int32 min bin")
        << (QByteArray("-1") + QByteArray(31, '0')) << 2 << long(B32::min()) << true;
    QTest::newRow("int32 max bin") << QByteArray(31, '1') << 2 << long(B32::max()) << true;
    QTest::newRow("int32 min hex") << QByteArray("-80000000") << 16 << long(B32::min()) << true;
    QTest::newRow("int32 max hex") << QByteArray("7fffffff") << 16 << long(B32::max()) << true;
    QTest::newRow("int32 min dec") << QByteArray("-2147483648") << 10 << long(B32::min()) << true;
    QTest::newRow("int32 max dec") << QByteArray("2147483647") << 10 << long(B32::max()) << true;

    if constexpr (sizeof(long) < sizeof(qlonglong)) {
        QT_WARNING_PUSH
        // See: https://github.com/llvm/llvm-project/issues/59448
        QT_WARNING_DISABLE_CLANG("-Winteger-overflow")
        const qlonglong longMaxPlusOne = static_cast<qlonglong>(Bounds::max()) + 1;
        const qlonglong longMinMinusOne = static_cast<qlonglong>(Bounds::min()) - 1;
        QT_WARNING_POP

        QTest::newRow("long max + 1") << QByteArray::number(longMaxPlusOne) << 10 << 0L << false;
        QTest::newRow("long min - 1") << QByteArray::number(longMinMinusOne) << 10 << 0L << false;
    }
}

template <typename ByteArray> void tst_QByteArrayApiSymmetry::toLong() const
{
    QFETCH(QByteArray, str);
    QFETCH(int, base);
    QFETCH(long, result);
    QFETCH(bool, ok);

    bool good;
    QCOMPARE(ByteArray(str).toLong(nullptr, base), result);
    QCOMPARE(ByteArray(str).toLong(&good, base), result);
    QCOMPARE(good, ok);
    if (base == 10) {
        // check that by default base is assumed to be 10
        QCOMPARE(ByteArray(str).toLong(&good), result);
        QCOMPARE(good, ok);
    }
}

void tst_QByteArrayApiSymmetry::toULong_data() const
{
    QTest::addColumn<QByteArray>("str");
    QTest::addColumn<int>("base");
    QTest::addColumn<ulong>("result");
    QTest::addColumn<bool>("ok");

    ulong LongMaxPlusOne = (ulong)LONG_MAX + 1;
    QTest::newRow("LONG_MAX+1")
        << QString::number(LongMaxPlusOne).toUtf8() << 10 << LongMaxPlusOne << true;
    QTest::newRow("null") << QByteArray() << 10 << 0UL << false;
    QTest::newRow("empty") << QByteArray("") << 10 << 0UL << false;
    QTest::newRow("ulong1") << QByteArray("3234567890") << 10 << 3234567890UL << true;
    QTest::newRow("ulong2") << QByteArray("fFFfFfFf") << 16 << 0xFFFFFFFFUL << true;

    QTest::newRow("leading spaces") << QByteArray(" \n\r\t100") << 10 << 100UL << true;
    QTest::newRow("trailing spaces") << QByteArray("100 \n\r\t") << 10 << 100UL << true;
    QTest::newRow("leading junk") << QByteArray("x100") << 10 << 0UL << false;
    QTest::newRow("trailing junk") << QByteArray("100x") << 10 << 0UL << false;
}

template <typename ByteArray> void tst_QByteArrayApiSymmetry::toULong() const
{
    QFETCH(QByteArray, str);
    QFETCH(int, base);
    QFETCH(ulong, result);
    QFETCH(bool, ok);

    bool good;
    QCOMPARE(ByteArray(str).toULong(0, base), result);
    QCOMPARE(ByteArray(str).toULong(&good, base), result);
    QCOMPARE(good, ok);
}

static QByteArray decNext(QByteArray &&big)
{
    // Increments a decimal digit-string (ignoring sign, so decrements if
    // negative); only intended for taking a boundary value just out of range,
    // so big is never a string of only 9s (that'd be one less than a power of
    // ten, which cannot be a power of two, as odd, or one less than one, as the
    // power of ten isn't a power of two).
    int i = big.size() - 1;
    while (big.at(i) == '9')
        big[i--] = '0';
    big[i] += 1;
    return std::move(big);
}

void tst_QByteArrayApiSymmetry::toLongLong_data() const
{
    QTest::addColumn<QByteArray>("str");
    QTest::addColumn<int>("base");
    QTest::addColumn<qlonglong>("result");
    QTest::addColumn<bool>("ok");

    QTest::newRow("null") << QByteArray() << 10 << 0LL << false;
    QTest::newRow("empty") << QByteArray("") << 10 << 0LL << false;
    QTest::newRow("out of base bound") << QByteArray("c") << 10 << 0LL << false;

    QTest::newRow("in range dec")
        << QByteArray("7679359922672374856") << 10 << 7679359922672374856LL << true;
    QTest::newRow("in range dec neg")
        << QByteArray("-7679359922672374856") << 10 << -7679359922672374856LL << true;
    QTest::newRow("in range hex")
        << QByteArray("6A929129A5421448") << 16 << 0x6A929129A5421448LL << true;
    QTest::newRow("in range hex prefix")
        << QByteArray("0x6A929129A5421448") << 16 << 0x6A929129A5421448LL << true;
    QTest::newRow("in range hex neg")
        << QByteArray("-6A929129A5421448") << 16 << -0x6A929129A5421448LL << true;
    QTest::newRow("in range hex prefix neg")
        << QByteArray("-0x6A929129A5421448") << 16 << -0x6A929129A5421448LL << true;
    QTest::newRow("Fibonacci's last int64")
        << QByteArray("7540113804746346429") << 10 << 7540113804746346429LL << true;

    QTest::newRow("leading spaces")
        << QByteArray(" \r\n\tABCFFFFFFF123") << 16 << 0xABCFFFFFFF123LL << true;
    QTest::newRow("trailing spaces")
        << QByteArray("9876543210\t\r \n") << 10 << 9876543210LL << true;
    QTest::newRow("space after plus") << QByteArray("+ 12") << 10 << 0LL << false;
    QTest::newRow("space after minus") << QByteArray("- 12") << 10 << 0LL << false;
    QTest::newRow("leading junk") << QByteArray("q12345") << 10 << 0LL << false;
    QTest::newRow("trailing junk") << QByteArray("abc12345t") << 16 << 0LL << false;

    QTest::newRow("dec with base 0") << QByteArray("9876543210") << 0 << 9876543210LL << true;
    QTest::newRow("neg dec with base 0") << QByteArray("-9876543210") << 0 << -9876543210LL << true;
    QTest::newRow("hex with base 0") << QByteArray("0x9876543210") << 0 << 0x9876543210LL << true;
    QTest::newRow("neg hex with base 0")
        << QByteArray("-0x9876543210") << 0 << -0x9876543210LL << true;
    QTest::newRow("oct with base 0")
        << QByteArray("07654321234567") << 0 << 07654321234567LL << true;
    QTest::newRow("neg oct with base 0")
        << QByteArray("-07654321234567") << 0 << -07654321234567LL << true;

    QTest::newRow("base 3") << QByteArray("12012") << 3 << 140LL << true;
    QTest::newRow("neg base 3") << QByteArray("-201") << 3 << -19LL << true;

    // Boundary values, first in every base:
    using LL = std::numeric_limits<qlonglong>;
    for (int b = 0; b <= 36; ++b) {
        if (b == 1) // bases 0 and 2 through 36 are allowed
            ++b;
        QTest::addRow("max base %d", b)
            << QByteArray::number(LL::max(), b ? b : 10) << b << LL::max() << true;
        QTest::addRow("min base %d", b)
            << QByteArray::number(LL::min(), b ? b : 10) << b << LL::min() << true;
    }
    // Check leading zeros don't hit any buffer-too-big problems:
    QTest::newRow("many-0 max dec")
        << (QByteArray(512, '0') + QByteArray::number(LL::max())) << 10 << LL::max() << true;

    // Special bases (and let's include some leading space, too !), first decimal:
    QTest::newRow("max space dec")
        << ("\t\r\n\f\v " + QByteArray::number(LL::max())) << 10 << LL::max() << true;
    QTest::newRow("max space dec, base 0")
        << ("\t\r\n\f\v " + QByteArray::number(LL::max())) << 0 << LL::max() << true;
    QTest::newRow("min space dec")
        << ("\t\r\n\f\v " + QByteArray::number(LL::min())) << 10 << LL::min() << true;
    QTest::newRow("min space dec, base 0")
        << ("\t\r\n\f\v " + QByteArray::number(LL::min())) << 0 << LL::min() << true;

    // Hex with prefix:
    QTest::newRow("max 0x base 0")
        << ("0x" + QByteArray::number(LL::max(), 16)) << 0 << LL::max() << true;
    QTest::newRow("max +0x base 0")
        << ("+0x" + QByteArray::number(LL::max(), 16)) << 0 << LL::max() << true;
    QTest::newRow("max space 0x base 0")
        << ("\t\r\n\f\v 0x" + QByteArray::number(LL::max(), 16)) << 0 << LL::max() << true;
    QTest::newRow("max space +0x base 0")
        << ("\t\r\n\f\v +0x" + QByteArray::number(LL::max(), 16)) << 0 << LL::max() << true;
    QByteArray big = QByteArray::number(LL::min(), 16);
    big.insert(1, "0x"); // after sign
    QTest::newRow("min hex prefix") << big << 16 << LL::min() << true;
    QTest::newRow("min 0x base 0") << big << 0 << LL::min() << true;
    big.prepend("\t\r\n\f\v ");
    QTest::newRow("min space hex prefix") << big << 16 << LL::min() << true;
    QTest::newRow("min space 0x base 0") << big << 0 << LL::min() << true;

    // Octal with prefix:
    QTest::newRow("max octal base 0")
        << ('0' + QByteArray::number(LL::max(), 8)) << 0 << LL::max() << true;
    QTest::newRow("max +octal base 0")
        << ("+0" + QByteArray::number(LL::max(), 8)) << 0 << LL::max() << true;
    QTest::newRow("max space octal base 0")
        << ("\t\r\n\f\v 0" + QByteArray::number(LL::max(), 8)) << 0 << LL::max() << true;
    QTest::newRow("max space +octal base 0")
        << ("\t\r\n\f\v +0" + QByteArray::number(LL::max(), 8)) << 0 << LL::max() << true;
    big = QByteArray::number(LL::min(), 8);
    big.insert(1, '0'); // after sign
    QTest::newRow("min octal prefix") << big << 8 << LL::min() << true;
    QTest::newRow("min octal base 0") << big << 0 << LL::min() << true;
    big.prepend("\t\r\n\f\v ");
    QTest::newRow("min space octal prefix") << big << 8 << LL::min() << true;
    QTest::newRow("min space octal base 0") << big << 0 << LL::min() << true;

    // Values *just* out of range:
    QTest::newRow("max + 1 dec") << decNext(QByteArray::number(LL::max())) << 10 << 0LL << false;
    QTest::newRow("max + 1 dec base 0")
        << decNext(QByteArray::number(LL::max())) << 0 << 0LL << false;
    QTest::newRow("min - 1 dec") << decNext(QByteArray::number(LL::min())) << 10 << 0LL << false;
    QTest::newRow("min - 1 dec base 0")
        << decNext(QByteArray::number(LL::min())) << 0 << 0LL << false;
    // For hex and octal, we know the last digit of min is 0 and skipping its sign gets max+1:
    big = QByteArray::number(LL::min(), 8);
    QTest::newRow("max + 1 oct") << big.sliced(1) << 8 << 0LL << false;
    big[big.size() - 1] = '1';
    QTest::newRow("min - 1 oct") << big << 8 << 0LL << false;
    big.insert(1, '0'); // after minus sign
    QTest::newRow("min - 1 octal base 0") << big << 0 << 0LL << false;
    big = QByteArray::number(LL::min(), 16);
    QTest::newRow("max + 1 hex") << big.sliced(1) << 16 << 0LL << false;
    big[big.size() - 1] = '1';
    QTest::newRow("min - 1 hex") << big << 16 << 0LL << false;
    big.insert(1, "0x"); // after minus sign
    QTest::newRow("min - 1, 0x base 0") << big << 0 << 0LL << false;
}

template <typename ByteArray> void tst_QByteArrayApiSymmetry::toLongLong() const
{
    QFETCH(QByteArray, str);
    QFETCH(int, base);
    QFETCH(qlonglong, result);
    QFETCH(bool, ok);

    bool good;
    QCOMPARE(ByteArray(str).toLongLong(nullptr, base), result);
    QCOMPARE(ByteArray(str).toLongLong(&good, base), result);
    QCOMPARE(good, ok);
    if (base == 10) {
        QCOMPARE(ByteArray(str).toLongLong(&good), result);
        QCOMPARE(good, ok);
    }
}

void tst_QByteArrayApiSymmetry::toULongLong_data() const
{
    QTest::addColumn<QByteArray>("str");
    QTest::addColumn<int>("base");
    QTest::addColumn<qulonglong>("result");
    QTest::addColumn<bool>("ok");

    QTest::newRow("null") << QByteArray() << 10 << 0ULL << false;
    QTest::newRow("empty") << QByteArray("") << 10 << 0ULL << false;
    QTest::newRow("out of base bound") << QByteArray("c") << 10 << 0ULL << false;

    QTest::newRow("in range dec")
        << QByteArray("7679359922672374856") << 10 << 7679359922672374856ULL << true;
    QTest::newRow("in range hex")
        << QByteArray("6A929129A5421448") << 16 << 0x6A929129A5421448ULL << true;
    QTest::newRow("in range hex prefix")
        << QByteArray("0x6A929129A5421448") << 16 << 0x6A929129A5421448ULL << true;

    QTest::newRow("leading spaces") << QByteArray(" \n\r\t100") << 10 << 100ULL << true;
    QTest::newRow("trailing spaces") << QByteArray("100 \n\r\t") << 10 << 100ULL << true;
    QTest::newRow("leading plus") << QByteArray("+100") << 10 << 100ULL << true;
    QTest::newRow("space after plus") << QByteArray("+ 12") << 10 << 0ULL << false;
    QTest::newRow("leading minus") << QByteArray("-100") << 10 << 0ULL << false;
    QTest::newRow("leading junk") << QByteArray("x100") << 10 << 0ULL << false;
    QTest::newRow("trailing junk") << QByteArray("100x") << 10 << 0ULL << false;

    QTest::newRow("dec, base 0") << QByteArray("9876543210") << 0 << 9876543210ULL << true;
    QTest::newRow("hex, base 0") << QByteArray("0x9876543210") << 0 << 0x9876543210ULL << true;
    QTest::newRow("oct, base 0") << QByteArray("07654321234567") << 0 << 07654321234567ULL << true;
    QTest::newRow("base 3") << QByteArray("12012") << 3 << 140ULL << true;

    // Boundary values, first in every base:
    using ULL = std::numeric_limits<qulonglong>;
    for (int b = 0; b <= 36; ++b) {
        if (b == 1) // bases 0 and 2 through 36 are allowed
            ++b;
        QTest::addRow("max base %d", b)
            << QByteArray::number(ULL::max(), b ? b : 10) << b << ULL::max() << true;
    }
    // Check leading zeros don't hit any buffer-too-big problems:
    QTest::newRow("many-0 max dec")
        << (QByteArray(512, '0') + QByteArray::number(ULL::max())) << 10 << ULL::max() << true;

    // Special bases (and let's include some leading space, too !), first decimal:
    QTest::newRow("max space dec")
        << ("\t\r\n\f\v " + QByteArray::number(ULL::max())) << 10 << ULL::max() << true;
    QTest::newRow("max space dec, base 0")
        << ("\t\r\n\f\v " + QByteArray::number(ULL::max())) << 0 << ULL::max() << true;

    // Hex with prefix:
    QTest::newRow("max 0x base 0")
        << ("0x" + QByteArray::number(ULL::max(), 16)) << 0 << ULL::max() << true;
    QTest::newRow("max +0x base 0")
        << ("+0x" + QByteArray::number(ULL::max(), 16)) << 0 << ULL::max() << true;
    QTest::newRow("max space 0x base 0")
        << ("\t\r\n\f\v 0x" + QByteArray::number(ULL::max(), 16)) << 0 << ULL::max() << true;
    QTest::newRow("max space +0x base 0")
        << ("\t\r\n\f\v +0x" + QByteArray::number(ULL::max(), 16)) << 0 << ULL::max() << true;

    // Octal with prefix:
    QTest::newRow("max octal base 0")
        << ('0' + QByteArray::number(ULL::max(), 8)) << 0 << ULL::max() << true;
    QTest::newRow("max +octal base 0")
        << ("+0" + QByteArray::number(ULL::max(), 8)) << 0 << ULL::max() << true;
    QTest::newRow("max space octal base 0")
        << ("\t\r\n\f\v 0" + QByteArray::number(ULL::max(), 8)) << 0 << ULL::max() << true;
    QTest::newRow("max space +octal base 0")
        << ("\t\r\n\f\v +0" + QByteArray::number(ULL::max(), 8)) << 0 << ULL::max() << true;

    // Values *just* out of range:
    QTest::newRow("max + 1 dec") << decNext(QByteArray::number(ULL::max())) << 10 << 0ULL << false;
    QTest::newRow("max + 1 dec base 0")
        << decNext(QByteArray::number(ULL::max())) << 0 << 0ULL << false;
    auto big = QByteArray::number(ULL::max(), 8).replace('7', '0');
    // Number of bits is a power of two, so not a multiple of three; so (only)
    // first digit of max wasn't 7:
    big[0] += 1;
    QTest::newRow("max + 1 oct") << big << 8 << 0ULL << false;
    // Number of bits is a multiple of four, so every digit of max is 'f'.
    big = '1' + QByteArray::number(ULL::max(), 16).replace('f', '0');
    QTest::newRow("max + 1 hex") << big << 16 << 0ULL << false;
}

template <typename ByteArray> void tst_QByteArrayApiSymmetry::toULongLong() const
{
    QFETCH(QByteArray, str);
    QFETCH(int, base);
    QFETCH(qulonglong, result);
    QFETCH(bool, ok);

    bool good;
    QCOMPARE(ByteArray(str).toULongLong(0, base), result);
    QCOMPARE(ByteArray(str).toULongLong(&good, base), result);
    QCOMPARE(good, ok);
}

template <typename ByteArray> void tst_QByteArrayApiSymmetry::toFloat() const
{
    bool ok = true; // opposite to the next expected result

    QCOMPARE(ByteArray().toFloat(&ok), 0.0f);
    QVERIFY(!ok);

    QCOMPARE(ByteArray("").toFloat(&ok), 0.0f);
    QVERIFY(!ok);

    // NB: floats < 1e-6 are zero as far as QCOMPARE() is concerned !
    const char data[] = "0.0000931322574615478515625";
    const float expectedValue = 9.31322574615478515625e-5f;
    QCOMPARE(ByteArray(data).toFloat(&ok), expectedValue);
    QVERIFY(ok);
    QCOMPARE(ByteArray(data, 6).toFloat(&ok), 0.0f);
    QVERIFY(ok);

    const char crufty[] = "3.14 and a bit";
    QCOMPARE(ByteArray(crufty).toFloat(&ok), 0.0f);
    QVERIFY(!ok);
    QCOMPARE(ByteArray(crufty, 4).toFloat(&ok), 3.14f);
    QVERIFY(ok);
}

void tst_QByteArrayApiSymmetry::toDouble_data() const
{
    QTest::addColumn<QByteArray>("string");
    QTest::addColumn<double>("expectedNumber");
    QTest::addColumn<bool>("expectedOk");

    QTest::newRow("null") << QByteArray() << 0.0 << false;
    QTest::newRow("empty") << QByteArray("") << 0.0 << false;

    QTest::newRow("decimal") << QByteArray("1.2345") << 1.2345 << true;
    QTest::newRow("exponent lowercase") << QByteArray("1.2345e+01") << 12.345 << true;
    QTest::newRow("exponent uppercase") << QByteArray("1.2345E+02") << 123.45 << true;
    QTest::newRow("leading spaces") << QByteArray(" \n\r\t1.2345") << 1.2345 << true;
    QTest::newRow("trailing spaces") << QByteArray("1.2345 \n\r\t") << 1.2345 << true;
    QTest::newRow("leading junk") << QByteArray("x1.2345") << 0.0 << false;
    QTest::newRow("trailing junk") << QByteArray("1.2345x") << 0.0 << false;
    QTest::newRow("high precision")
        << QByteArray("0.000000000931322574615478515625") << 9.31322574615478515625e-10 << true;
    QTest::newRow("exponential")
        << QByteArray("9.31322574615478515625e-10") << 9.31322574615478515625e-10 << true;

    QTest::newRow("raw, null plus junk")
        << QByteArray::fromRawData("1.2\0 junk", 9) << 0.0 << false;
    QTest::newRow("raw, null-terminator excluded")
        << QByteArray::fromRawData("2.3", 3) << 2.3 << true;
}

template <typename ByteArray> void tst_QByteArrayApiSymmetry::toDouble() const
{
    QFETCH(QByteArray, string);
    QFETCH(double, expectedNumber);
    QFETCH(bool, expectedOk);

    bool ok;
    const double number = ByteArray(string).toDouble(&ok);

    QCOMPARE(ok, expectedOk);
    QCOMPARE(number, expectedNumber);
}

const char globalChar = '1'; // Used as staic data for a raw byte array

QTEST_APPLESS_MAIN(tst_QByteArrayApiSymmetry)
#include "tst_qbytearrayapisymmetry.moc"