0
+ − 1
/****************************************************************************
+ − 2
**
4
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 3
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
0
+ − 4
** All rights reserved.
+ − 5
** Contact: Nokia Corporation (qt-info@nokia.com)
+ − 6
**
+ − 7
** This file is part of the test suite of the Qt Toolkit.
+ − 8
**
+ − 9
** $QT_BEGIN_LICENSE:LGPL$
+ − 10
** No Commercial Usage
+ − 11
** This file contains pre-release code and may not be distributed.
+ − 12
** You may use this file in accordance with the terms and conditions
+ − 13
** contained in the Technology Preview License Agreement accompanying
+ − 14
** this package.
+ − 15
**
+ − 16
** GNU Lesser General Public License Usage
+ − 17
** Alternatively, this file may be used under the terms of the GNU Lesser
+ − 18
** General Public License version 2.1 as published by the Free Software
+ − 19
** Foundation and appearing in the file LICENSE.LGPL included in the
+ − 20
** packaging of this file. Please review the following information to
+ − 21
** ensure the GNU Lesser General Public License version 2.1 requirements
+ − 22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+ − 23
**
+ − 24
** In addition, as a special exception, Nokia gives you certain additional
+ − 25
** rights. These rights are described in the Nokia Qt LGPL Exception
+ − 26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+ − 27
**
+ − 28
** If you have questions regarding the use of this file, please contact
+ − 29
** Nokia at qt-info@nokia.com.
+ − 30
**
+ − 31
**
+ − 32
**
+ − 33
**
+ − 34
**
+ − 35
**
+ − 36
**
+ − 37
**
+ − 38
** $QT_END_LICENSE$
+ − 39
**
+ − 40
****************************************************************************/
+ − 41
+ − 42
+ − 43
#include <QtTest/QtTest>
+ − 44
#include <qregexp.h>
+ − 45
#include <qtextcodec.h>
+ − 46
#include <qtextstream.h>
+ − 47
#include <qstringlist.h>
+ − 48
#include <qstringmatcher.h>
+ − 49
#include <qbytearraymatcher.h>
+ − 50
#include <qvariant.h>
+ − 51
+ − 52
#include <qlocale.h>
+ − 53
#include <locale.h>
+ − 54
+ − 55
Q_DECLARE_METATYPE(qlonglong)
+ − 56
+ − 57
//TESTED_CLASS=
+ − 58
//TESTED_FILES=
+ − 59
+ − 60
class tst_QString : public QObject
+ − 61
{
+ − 62
Q_OBJECT
+ − 63
+ − 64
public:
+ − 65
tst_QString();
+ − 66
virtual ~tst_QString();
+ − 67
+ − 68
+ − 69
public slots:
+ − 70
void init();
+ − 71
void cleanup();
+ − 72
private slots:
+ − 73
void fromStdString();
+ − 74
void toStdString();
+ − 75
void check_QTextIOStream();
+ − 76
void check_QTextStream();
+ − 77
void check_QDataStream();
+ − 78
void fromRawData();
+ − 79
void endsWith();
+ − 80
void startsWith();
+ − 81
void setNum();
+ − 82
void toDouble_data();
+ − 83
void toDouble();
+ − 84
void toFloat();
+ − 85
void toLong_data();
+ − 86
void toLong();
+ − 87
void toULong_data();
+ − 88
void toULong();
+ − 89
void toLongLong();
+ − 90
void toULongLong();
+ − 91
void toUInt();
+ − 92
void toInt();
+ − 93
void toShort();
+ − 94
void toUShort();
+ − 95
void replace_qchar_qchar_data();
+ − 96
void replace_qchar_qchar();
+ − 97
void replace_qchar_qstring_data();
+ − 98
void replace_qchar_qstring();
+ − 99
void replace_uint_uint_data();
+ − 100
void replace_uint_uint();
+ − 101
void replace_uint_uint_extra();
+ − 102
void replace_string_data();
+ − 103
void replace_string();
+ − 104
void replace_regexp_data();
+ − 105
void replace_regexp();
+ − 106
void remove_uint_uint_data();
+ − 107
void remove_uint_uint();
+ − 108
void remove_string_data();
+ − 109
void remove_string();
+ − 110
void remove_regexp_data();
+ − 111
void remove_regexp();
+ − 112
void prepend();
+ − 113
void prepend_bytearray_data();
+ − 114
void prepend_bytearray();
+ − 115
void append();
+ − 116
void append_bytearray_data();
+ − 117
void append_bytearray();
+ − 118
void operator_pluseq_bytearray_data();
+ − 119
void operator_pluseq_bytearray();
+ − 120
void operator_eqeq_nullstring();
+ − 121
void operator_smaller();
+ − 122
void insert();
+ − 123
void simplified();
+ − 124
void trimmed();
+ − 125
void toLower();
+ − 126
void toUpper();
+ − 127
void rightJustified();
+ − 128
void leftJustified();
+ − 129
void mid();
+ − 130
void right();
+ − 131
void left();
+ − 132
void midRef();
+ − 133
void rightRef();
+ − 134
void leftRef();
+ − 135
void stringRef();
+ − 136
void contains();
+ − 137
void lastIndexOf_data();
+ − 138
void lastIndexOf();
+ − 139
void indexOf_data();
+ − 140
void indexOf();
+ − 141
void indexOf2_data();
+ − 142
void indexOf2();
+ − 143
void indexOf3_data();
+ − 144
// void indexOf3();
+ − 145
void sprintf();
+ − 146
void copy();
+ − 147
void fill();
+ − 148
void truncate();
+ − 149
void constructor();
+ − 150
void constructorQByteArray_data();
+ − 151
void constructorQByteArray();
+ − 152
void STL();
+ − 153
void isEmpty();
+ − 154
void isNull();
+ − 155
void acc_01();
+ − 156
void length_data();
+ − 157
void length();
+ − 158
void utf8_data();
+ − 159
void utf8();
+ − 160
void fromUtf8_data();
+ − 161
void fromUtf8();
+ − 162
void nullFromUtf8();
+ − 163
void fromLocal8Bit_data();
+ − 164
void fromLocal8Bit();
+ − 165
void local8Bit_data();
+ − 166
void local8Bit();
+ − 167
void fromLatin1();
+ − 168
void fromAscii();
+ − 169
void arg();
+ − 170
void number();
+ − 171
void arg_fillChar_data();
+ − 172
void arg_fillChar();
+ − 173
void capacity_data();
+ − 174
void capacity();
+ − 175
void section_data();
+ − 176
void section();
+ − 177
void double_conversion_data();
+ − 178
void double_conversion();
+ − 179
void integer_conversion_data();
+ − 180
void integer_conversion();
+ − 181
void tortureSprintfDouble();
+ − 182
void toNum();
+ − 183
void localeAwareCompare_data();
+ − 184
void localeAwareCompare();
+ − 185
void split_data();
+ − 186
void split();
+ − 187
void split_regexp();
+ − 188
void fromUtf16_data();
+ − 189
void fromUtf16();
+ − 190
void latin1String();
+ − 191
void nanAndInf();
+ − 192
void compare_data();
+ − 193
void compare();
+ − 194
void resizeAfterFromRawData();
+ − 195
void resizeAfterReserve();
+ − 196
void resizeWithNegative() const;
+ − 197
void truncateWithNegative() const;
+ − 198
void QCharRefMutableUnicode() const;
+ − 199
void QCharRefDetaching() const;
+ − 200
void sprintfZU() const;
+ − 201
void repeatedSignature() const;
+ − 202
void repeated() const;
+ − 203
void repeated_data() const;
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 204
void task262677remove();
0
+ − 205
};
+ − 206
+ − 207
typedef QList<int> IntList;
+ − 208
+ − 209
Q_DECLARE_METATYPE(QList<QVariant>)
+ − 210
Q_DECLARE_METATYPE(IntList)
+ − 211
+ − 212
// This next bit is needed for the NAN and INF in string -> number conversion tests
+ − 213
#include <float.h>
+ − 214
#include <limits.h>
+ − 215
#include <math.h>
+ − 216
#if defined (Q_WS_WIN)
+ − 217
# include <windows.h>
+ − 218
// mingw defines NAN and INFINITY to 0/0 and x/0
+ − 219
# if defined(Q_CC_GNU)
+ − 220
# undef NAN
+ − 221
# undef INFINITY
+ − 222
# else
+ − 223
# define isnan(d) _isnan(d)
+ − 224
# endif
+ − 225
#endif
+ − 226
#if defined (Q_OS_MAC) && !defined isnan
+ − 227
#define isnan(d) __isnand(d)
+ − 228
#endif
+ − 229
#if defined (Q_OS_SOLARIS)
+ − 230
# include <ieeefp.h>
+ − 231
#endif
+ − 232
#if defined (Q_OS_OSF) && (defined(__DECC) || defined(__DECCXX))
+ − 233
# define INFINITY DBL_INFINITY
+ − 234
# define NAN DBL_QNAN
+ − 235
#endif
+ − 236
#if defined(Q_OS_IRIX) && defined(Q_CC_GNU)
+ − 237
# include <ieeefp.h>
+ − 238
# define isnan(d) isnand(d)
+ − 239
#endif
+ − 240
+ − 241
enum {
+ − 242
LittleEndian,
+ − 243
BigEndian
+ − 244
#ifdef Q_BYTE_ORDER
+ − 245
# if Q_BYTE_ORDER == Q_BIG_ENDIAN
+ − 246
, ByteOrder = BigEndian
+ − 247
# elif Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ − 248
, ByteOrder = LittleEndian
+ − 249
# else
+ − 250
# error "undefined byte order"
+ − 251
# endif
+ − 252
};
+ − 253
#else
+ − 254
};
+ − 255
static const unsigned int one = 1;
+ − 256
static const bool ByteOrder = ((*((unsigned char *) &one) == 0) ? BigEndian : LittleEndian);
+ − 257
#endif
+ − 258
#if !defined(INFINITY)
+ − 259
static const unsigned char be_inf_bytes[] = { 0x7f, 0xf0, 0, 0, 0, 0, 0,0 };
+ − 260
static const unsigned char le_inf_bytes[] = { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f };
+ − 261
static inline double inf()
+ − 262
{
+ − 263
if (ByteOrder == BigEndian)
+ − 264
return *reinterpret_cast<const double *>(be_inf_bytes);
+ − 265
return *reinterpret_cast<const double *>(le_inf_bytes);
+ − 266
}
+ − 267
# define INFINITY (::inf())
+ − 268
#endif
+ − 269
#if !defined(NAN)
+ − 270
static const unsigned char be_nan_bytes[] = { 0x7f, 0xf8, 0, 0, 0, 0, 0,0 };
+ − 271
static const unsigned char le_nan_bytes[] = { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f };
+ − 272
static inline double nan()
+ − 273
{
+ − 274
if (ByteOrder == BigEndian)
+ − 275
return *reinterpret_cast<const double *>(be_nan_bytes);
+ − 276
return *reinterpret_cast<const double *>(le_nan_bytes);
+ − 277
}
+ − 278
# define NAN (::nan())
+ − 279
#endif
+ − 280
+ − 281
tst_QString::tst_QString()
+ − 282
{
+ − 283
QTextCodec::setCodecForLocale(QTextCodec::codecForName("ISO 8859-1"));
+ − 284
}
+ − 285
+ − 286
tst_QString::~tst_QString()
+ − 287
{
+ − 288
}
+ − 289
+ − 290
void tst_QString::init()
+ − 291
{
+ − 292
}
+ − 293
+ − 294
void tst_QString::cleanup()
+ − 295
{
+ − 296
QLocale::setDefault(QString("C"));
+ − 297
}
+ − 298
+ − 299
void tst_QString::remove_uint_uint_data()
+ − 300
{
+ − 301
replace_uint_uint_data();
+ − 302
}
+ − 303
+ − 304
void tst_QString::remove_string_data()
+ − 305
{
+ − 306
replace_string_data();
+ − 307
}
+ − 308
+ − 309
void tst_QString::remove_regexp_data()
+ − 310
{
+ − 311
replace_regexp_data();
+ − 312
}
+ − 313
+ − 314
void tst_QString::indexOf3_data()
+ − 315
{
+ − 316
indexOf2_data();
+ − 317
}
+ − 318
+ − 319
void tst_QString::length_data()
+ − 320
{
+ − 321
QTest::addColumn<QString>("s1" );
+ − 322
QTest::addColumn<int>("res" );
+ − 323
+ − 324
QTest::newRow( "data0" ) << QString("Test") << 4;
+ − 325
QTest::newRow( "data1" ) << QString("The quick brown fox jumps over the lazy dog") << 43;
+ − 326
QTest::newRow( "data2" ) << QString() << 0;
+ − 327
QTest::newRow( "data3" ) << QString("A") << 1;
+ − 328
QTest::newRow( "data4" ) << QString("AB") << 2;
+ − 329
QTest::newRow( "data5" ) << QString("AB\n") << 3;
+ − 330
QTest::newRow( "data6" ) << QString("AB\nC") << 4;
+ − 331
QTest::newRow( "data7" ) << QString("\n") << 1;
+ − 332
QTest::newRow( "data8" ) << QString("\nA") << 2;
+ − 333
QTest::newRow( "data9" ) << QString("\nAB") << 3;
+ − 334
QTest::newRow( "data10" ) << QString("\nAB\nCDE") << 7;
+ − 335
QTest::newRow( "data11" ) << QString("shdnftrheid fhgnt gjvnfmd chfugkh bnfhg thgjf vnghturkf chfnguh bjgnfhvygh hnbhgutjfv dhdnjds dcjs d") << 100;
+ − 336
}
+ − 337
+ − 338
void tst_QString::replace_qchar_qchar_data()
+ − 339
{
+ − 340
QTest::addColumn<QString>("src" );
+ − 341
QTest::addColumn<QChar>("before" );
+ − 342
QTest::addColumn<QChar>("after" );
+ − 343
QTest::addColumn<int>("cs" );
+ − 344
QTest::addColumn<QString>("expected" );
+ − 345
+ − 346
QTest::newRow( "1" ) << QString("foo") << QChar('o') << QChar('a')
+ − 347
<< int(Qt::CaseSensitive) << QString("faa");
+ − 348
QTest::newRow( "2" ) << QString("foo") << QChar('o') << QChar('a')
+ − 349
<< int(Qt::CaseInsensitive) << QString("faa");
+ − 350
QTest::newRow( "3" ) << QString("foo") << QChar('O') << QChar('a')
+ − 351
<< int(Qt::CaseSensitive) << QString("foo");
+ − 352
QTest::newRow( "4" ) << QString("foo") << QChar('O') << QChar('a')
+ − 353
<< int(Qt::CaseInsensitive) << QString("faa");
+ − 354
QTest::newRow( "5" ) << QString("ababABAB") << QChar('a') << QChar(' ')
+ − 355
<< int(Qt::CaseSensitive) << QString(" b bABAB");
+ − 356
QTest::newRow( "6" ) << QString("ababABAB") << QChar('a') << QChar(' ')
+ − 357
<< int(Qt::CaseInsensitive) << QString(" b b B B");
+ − 358
QTest::newRow( "7" ) << QString("ababABAB") << QChar() << QChar(' ')
+ − 359
<< int(Qt::CaseInsensitive) << QString("ababABAB");
+ − 360
}
+ − 361
+ − 362
void tst_QString::replace_qchar_qchar()
+ − 363
{
+ − 364
QFETCH(QString, src);
+ − 365
QFETCH(QChar, before);
+ − 366
QFETCH(QChar, after);
+ − 367
QFETCH(int, cs);
+ − 368
QFETCH(QString, expected);
+ − 369
+ − 370
QCOMPARE(src.replace(before, after, Qt::CaseSensitivity(cs)), expected);
+ − 371
}
+ − 372
+ − 373
void tst_QString::replace_qchar_qstring_data()
+ − 374
{
+ − 375
QTest::addColumn<QString>("src" );
+ − 376
QTest::addColumn<QChar>("before" );
+ − 377
QTest::addColumn<QString>("after" );
+ − 378
QTest::addColumn<int>("cs" );
+ − 379
QTest::addColumn<QString>("expected" );
+ − 380
+ − 381
QTest::newRow( "1" ) << QString("foo") << QChar('o') << QString("aA")
+ − 382
<< int(Qt::CaseSensitive) << QString("faAaA");
+ − 383
QTest::newRow( "2" ) << QString("foo") << QChar('o') << QString("aA")
+ − 384
<< int(Qt::CaseInsensitive) << QString("faAaA");
+ − 385
QTest::newRow( "3" ) << QString("foo") << QChar('O') << QString("aA")
+ − 386
<< int(Qt::CaseSensitive) << QString("foo");
+ − 387
QTest::newRow( "4" ) << QString("foo") << QChar('O') << QString("aA")
+ − 388
<< int(Qt::CaseInsensitive) << QString("faAaA");
+ − 389
QTest::newRow( "5" ) << QString("ababABAB") << QChar('a') << QString(" ")
+ − 390
<< int(Qt::CaseSensitive) << QString(" b bABAB");
+ − 391
QTest::newRow( "6" ) << QString("ababABAB") << QChar('a') << QString(" ")
+ − 392
<< int(Qt::CaseInsensitive) << QString(" b b B B");
+ − 393
QTest::newRow( "7" ) << QString("ababABAB") << QChar() << QString(" ")
+ − 394
<< int(Qt::CaseInsensitive) << QString("ababABAB");
+ − 395
QTest::newRow( "8" ) << QString("ababABAB") << QChar() << QString()
+ − 396
<< int(Qt::CaseInsensitive) << QString("ababABAB");
+ − 397
}
+ − 398
+ − 399
void tst_QString::replace_qchar_qstring()
+ − 400
{
+ − 401
QFETCH(QString, src);
+ − 402
QFETCH(QChar, before);
+ − 403
QFETCH(QString, after);
+ − 404
QFETCH(int, cs);
+ − 405
QFETCH(QString, expected);
+ − 406
+ − 407
QCOMPARE(src.replace(before, after, Qt::CaseSensitivity(cs)), expected);
+ − 408
}
+ − 409
+ − 410
void tst_QString::replace_uint_uint_data()
+ − 411
{
+ − 412
QTest::addColumn<QString>("string" );
+ − 413
QTest::addColumn<int>("index" );
+ − 414
QTest::addColumn<int>("len" );
+ − 415
QTest::addColumn<QString>("after" );
+ − 416
QTest::addColumn<QString>("result" );
+ − 417
+ − 418
QTest::newRow( "rem00" ) << QString("-<>ABCABCABCABC>") << 0 << 3 << QString("") << QString("ABCABCABCABC>");
+ − 419
QTest::newRow( "rem01" ) << QString("ABCABCABCABC>") << 1 << 4 << QString("") << QString("ACABCABC>");
+ − 420
QTest::newRow( "rem04" ) << QString("ACABCABC>") << 8 << 4 << QString("") << QString("ACABCABC");
+ − 421
QTest::newRow( "rem05" ) << QString("ACABCABC") << 7 << 1 << QString("") << QString("ACABCAB");
+ − 422
QTest::newRow( "rem06" ) << QString("ACABCAB") << 4 << 0 << QString("") << QString("ACABCAB");
+ − 423
+ − 424
QTest::newRow( "rep00" ) << QString("ACABCAB") << 4 << 0 << QString("X") << QString("ACABXCAB");
+ − 425
QTest::newRow( "rep01" ) << QString("ACABXCAB") << 4 << 1 << QString("Y") << QString("ACABYCAB");
+ − 426
QTest::newRow( "rep02" ) << QString("ACABYCAB") << 4 << 1 << QString("") << QString("ACABCAB");
+ − 427
QTest::newRow( "rep03" ) << QString("ACABCAB") << 0 << 9999 << QString("XX") << QString("XX");
+ − 428
QTest::newRow( "rep04" ) << QString("XX") << 0 << 9999 << QString("") << QString("");
+ − 429
QTest::newRow( "rep05" ) << QString("ACABCAB") << 0 << 2 << QString("XX") << QString("XXABCAB");
+ − 430
QTest::newRow( "rep06" ) << QString("ACABCAB") << 1 << 2 << QString("XX") << QString("AXXBCAB");
+ − 431
QTest::newRow( "rep07" ) << QString("ACABCAB") << 2 << 2 << QString("XX") << QString("ACXXCAB");
+ − 432
QTest::newRow( "rep08" ) << QString("ACABCAB") << 3 << 2 << QString("XX") << QString("ACAXXAB");
+ − 433
QTest::newRow( "rep09" ) << QString("ACABCAB") << 4 << 2 << QString("XX") << QString("ACABXXB");
+ − 434
QTest::newRow( "rep10" ) << QString("ACABCAB") << 5 << 2 << QString("XX") << QString("ACABCXX");
+ − 435
QTest::newRow( "rep10" ) << QString("ACABCAB") << 6 << 2 << QString("XX") << QString("ACABCAXX");
+ − 436
QTest::newRow( "rep12" ) << QString() << 0 << 10 << QString("X") << QString("X");
+ − 437
QTest::newRow( "rep13" ) << QString("short") << 0 << 10 << QString("X") << QString("X");
+ − 438
QTest::newRow( "rep14" ) << QString() << 0 << 10 << QString("XX") << QString("XX");
+ − 439
QTest::newRow( "rep15" ) << QString("short") << 0 << 10 << QString("XX") << QString("XX");
+ − 440
}
+ − 441
+ − 442
void tst_QString::replace_string_data()
+ − 443
{
+ − 444
QTest::addColumn<QString>("string" );
+ − 445
QTest::addColumn<QString>("before" );
+ − 446
QTest::addColumn<QString>("after" );
+ − 447
QTest::addColumn<QString>("result" );
+ − 448
QTest::addColumn<bool>("bcs" );
+ − 449
+ − 450
QTest::newRow( "rem00" ) << QString("") << QString("") << QString("") << QString("") << true;
+ − 451
QTest::newRow( "rem01" ) << QString("A") << QString("") << QString("") << QString("A") << true;
+ − 452
QTest::newRow( "rem02" ) << QString("A") << QString("A") << QString("") << QString("") << true;
+ − 453
QTest::newRow( "rem03" ) << QString("A") << QString("B") << QString("") << QString("A") << true;
+ − 454
QTest::newRow( "rem04" ) << QString("AA") << QString("A") << QString("") << QString("") << true;
+ − 455
QTest::newRow( "rem05" ) << QString("AB") << QString("A") << QString("") << QString("B") << true;
+ − 456
QTest::newRow( "rem06" ) << QString("AB") << QString("B") << QString("") << QString("A") << true;
+ − 457
QTest::newRow( "rem07" ) << QString("AB") << QString("C") << QString("") << QString("AB") << true;
+ − 458
QTest::newRow( "rem08" ) << QString("ABA") << QString("A") << QString("") << QString("B") << true;
+ − 459
QTest::newRow( "rem09" ) << QString("ABA") << QString("B") << QString("") << QString("AA") << true;
+ − 460
QTest::newRow( "rem10" ) << QString("ABA") << QString("C") << QString("") << QString("ABA") << true;
+ − 461
QTest::newRow( "rem11" ) << QString("banana") << QString("an") << QString("") << QString("ba") << true;
+ − 462
QTest::newRow( "rem12" ) << QString("") << QString("A") << QString("") << QString("") << true;
+ − 463
QTest::newRow( "rem13" ) << QString("") << QString("A") << QString() << QString("") << true;
+ − 464
QTest::newRow( "rem14" ) << QString() << QString("A") << QString("") << QString() << true;
+ − 465
QTest::newRow( "rem15" ) << QString() << QString("A") << QString() << QString() << true;
+ − 466
QTest::newRow( "rem16" ) << QString() << QString("") << QString("") << QString("") << true;
+ − 467
QTest::newRow( "rem17" ) << QString("") << QString() << QString("") << QString("") << true;
+ − 468
QTest::newRow( "rem18" ) << QString("a") << QString("a") << QString("") << QString("") << false;
+ − 469
QTest::newRow( "rem19" ) << QString("A") << QString("A") << QString("") << QString("") << false;
+ − 470
QTest::newRow( "rem20" ) << QString("a") << QString("A") << QString("") << QString("") << false;
+ − 471
QTest::newRow( "rem21" ) << QString("A") << QString("a") << QString("") << QString("") << false;
+ − 472
QTest::newRow( "rem22" ) << QString("Alpha beta") << QString("a") << QString("") << QString("lph bet") << false;
+ − 473
+ − 474
QTest::newRow( "rep00" ) << QString("ABC") << QString("B") << QString("-") << QString("A-C") << true;
+ − 475
QTest::newRow( "rep01" ) << QString("$()*+.?[\\]^{|}") << QString("$()*+.?[\\]^{|}") << QString("X") << QString("X") << true;
+ − 476
QTest::newRow( "rep02" ) << QString("ABCDEF") << QString("") << QString("X") << QString("XAXBXCXDXEXFX") << true;
+ − 477
QTest::newRow( "rep03" ) << QString("") << QString("") << QString("X") << QString("X") << true;
+ − 478
QTest::newRow( "rep04" ) << QString("a") << QString("a") << QString("b") << QString("b") << false;
+ − 479
QTest::newRow( "rep05" ) << QString("A") << QString("A") << QString("b") << QString("b") << false;
+ − 480
QTest::newRow( "rep06" ) << QString("a") << QString("A") << QString("b") << QString("b") << false;
+ − 481
QTest::newRow( "rep07" ) << QString("A") << QString("a") << QString("b") << QString("b") << false;
+ − 482
QTest::newRow( "rep08" ) << QString("a") << QString("a") << QString("a") << QString("a") << false;
+ − 483
QTest::newRow( "rep09" ) << QString("A") << QString("A") << QString("a") << QString("a") << false;
+ − 484
QTest::newRow( "rep10" ) << QString("a") << QString("A") << QString("a") << QString("a") << false;
+ − 485
QTest::newRow( "rep11" ) << QString("A") << QString("a") << QString("a") << QString("a") << false;
+ − 486
QTest::newRow( "rep12" ) << QString("Alpha beta") << QString("a") << QString("o") << QString("olpho beto") << false;
+ − 487
QTest::newRow( "rep13" ) << QString() << QString("") << QString("A") << QString("A") << true;
+ − 488
QTest::newRow( "rep14" ) << QString("") << QString() << QString("A") << QString("A") << true;
+ − 489
QTest::newRow( "rep15" ) << QString("fooxbarxbazxblub") << QString("x") << QString("yz") << QString("fooyzbaryzbazyzblub") << true;
+ − 490
QTest::newRow( "rep16" ) << QString("fooxbarxbazxblub") << QString("x") << QString("z") << QString("foozbarzbazzblub") << true;
+ − 491
QTest::newRow( "rep17" ) << QString("fooxybarxybazxyblub") << QString("xy") << QString("z") << QString("foozbarzbazzblub") << true;
+ − 492
}
+ − 493
+ − 494
void tst_QString::replace_regexp_data()
+ − 495
{
+ − 496
QTest::addColumn<QString>("string" );
+ − 497
QTest::addColumn<QString>("regexp" );
+ − 498
QTest::addColumn<QString>("after" );
+ − 499
QTest::addColumn<QString>("result" );
+ − 500
+ − 501
QTest::newRow( "rem00" ) << QString("alpha") << QString("a+") << QString("") << QString("lph");
+ − 502
QTest::newRow( "rem01" ) << QString("banana") << QString("^.a") << QString("") << QString("nana");
+ − 503
QTest::newRow( "rem02" ) << QString("") << QString("^.a") << QString("") << QString("");
+ − 504
QTest::newRow( "rem03" ) << QString("") << QString("^.a") << QString() << QString("");
+ − 505
QTest::newRow( "rem04" ) << QString() << QString("^.a") << QString("") << QString();
+ − 506
QTest::newRow( "rem05" ) << QString() << QString("^.a") << QString() << QString();
+ − 507
+ − 508
QTest::newRow( "rep00" ) << QString("A <i>bon mot</i>.") << QString("<i>([^<]*)</i>") << QString("\\emph{\\1}") << QString("A \\emph{bon mot}.");
+ − 509
QTest::newRow( "rep01" ) << QString("banana") << QString("^.a()") << QString("\\1") << QString("nana");
+ − 510
QTest::newRow( "rep02" ) << QString("banana") << QString("(ba)") << QString("\\1X\\1") << QString("baXbanana");
+ − 511
QTest::newRow( "rep03" ) << QString("banana") << QString("(ba)(na)na") << QString("\\2X\\1") << QString("naXba");
+ − 512
+ − 513
QTest::newRow("backref00") << QString("\\1\\2\\3\\4\\5\\6\\7\\8\\9\\A\\10\\11") << QString("\\\\[34]")
+ − 514
<< QString("X") << QString("\\1\\2XX\\5\\6\\7\\8\\9\\A\\10\\11");
+ − 515
QTest::newRow("backref01") << QString("foo") << QString("[fo]") << QString("\\1") << QString("\\1\\1\\1");
+ − 516
QTest::newRow("backref02") << QString("foo") << QString("([fo])") << QString("(\\1)") << QString("(f)(o)(o)");
+ − 517
QTest::newRow("backref03") << QString("foo") << QString("([fo])") << QString("\\2") << QString("\\2\\2\\2");
+ − 518
QTest::newRow("backref04") << QString("foo") << QString("([fo])") << QString("\\10") << QString("f0o0o0");
+ − 519
QTest::newRow("backref05") << QString("foo") << QString("([fo])") << QString("\\11") << QString("f1o1o1");
+ − 520
QTest::newRow("backref06") << QString("foo") << QString("([fo])") << QString("\\19") << QString("f9o9o9");
+ − 521
QTest::newRow("backref07") << QString("foo") << QString("(f)(o+)")
+ − 522
<< QString("\\2\\1\\10\\20\\11\\22\\19\\29\\3")
+ − 523
<< QString("ooff0oo0f1oo2f9oo9\\3");
+ − 524
QTest::newRow("backref08") << QString("abc") << QString("(((((((((((((([abc]))))))))))))))")
+ − 525
<< QString("{\\14}") << QString("{a}{b}{c}");
+ − 526
QTest::newRow("backref09") << QString("abcdefghijklmn")
+ − 527
<< QString("(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)")
+ − 528
<< QString("\\19\\18\\17\\16\\15\\14\\13\\12\\11\\10"
+ − 529
"\\9\\90\\8\\80\\7\\70\\6\\60\\5\\50\\4\\40\\3\\30\\2\\20\\1")
+ − 530
<< QString("a9a8a7a6a5nmlkjii0hh0gg0ff0ee0dd0cc0bb0a");
+ − 531
QTest::newRow("backref10") << QString("abc") << QString("((((((((((((((abc))))))))))))))")
+ − 532
<< QString("\\0\\01\\011") << QString("\\0\\01\\011");
+ − 533
}
+ − 534
+ − 535
void tst_QString::utf8_data()
+ − 536
{
+ − 537
QString str;
+ − 538
QTest::addColumn<QByteArray>("utf8" );
+ − 539
QTest::addColumn<QString>("res" );
+ − 540
+ − 541
QTest::newRow( "str0" ) << QByteArray("abcdefgh")
+ − 542
<< QString("abcdefgh");
+ − 543
QTest::newRow( "str1" ) << QByteArray("\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205")
+ − 544
<< QString("\366\344\374\326\304\334\370\346\345\330\306\305") ;
+ − 545
str += QChar( 0x05e9 );
+ − 546
str += QChar( 0x05d3 );
+ − 547
str += QChar( 0x05d2 );
+ − 548
QTest::newRow( "str2" ) << QByteArray("\327\251\327\223\327\222")
+ − 549
<< str;
+ − 550
+ − 551
str = QChar( 0x20ac );
+ − 552
str += " some text";
+ − 553
QTest::newRow( "str3" ) << QByteArray("\342\202\254 some text")
+ − 554
<< str;
+ − 555
+ − 556
str = "Old Italic: ";
+ − 557
str += QChar(0xd800);
+ − 558
str += QChar(0xdf00);
+ − 559
str += QChar(0xd800);
+ − 560
str += QChar(0xdf01);
+ − 561
str += QChar(0xd800);
+ − 562
str += QChar(0xdf02);
+ − 563
str += QChar(0xd800);
+ − 564
str += QChar(0xdf03);
+ − 565
str += QChar(0xd800);
+ − 566
str += QChar(0xdf04);
+ − 567
QTest::newRow("surrogate") << QByteArray("Old Italic: \360\220\214\200\360\220\214\201\360\220\214\202\360\220\214\203\360\220\214\204") << str;
+ − 568
}
+ − 569
+ − 570
void tst_QString::length()
+ − 571
{
+ − 572
QFETCH( QString, s1 );
+ − 573
QTEST( (int)s1.length(), "res" );
+ − 574
}
+ − 575
+ − 576
#include <qfile.h>
+ − 577
+ − 578
void tst_QString::acc_01()
+ − 579
{
+ − 580
QString a;
+ − 581
QString b; //b(10);
+ − 582
QString bb; //bb((int)0);
+ − 583
QString c("String C");
+ − 584
QChar tmp[10];
+ − 585
tmp[0] = 'S';
+ − 586
tmp[1] = 't';
+ − 587
tmp[2] = 'r';
+ − 588
tmp[3] = 'i';
+ − 589
tmp[4] = 'n';
+ − 590
tmp[5] = 'g';
+ − 591
tmp[6] = ' ';
+ − 592
tmp[7] = 'D';
+ − 593
tmp[8] = 'X';
+ − 594
tmp[9] = '\0';
+ − 595
QString d(tmp,8);
+ − 596
QString ca(a);
+ − 597
QString cb(b);
+ − 598
QString cc(c);
+ − 599
QString n;
+ − 600
QString e("String E");
+ − 601
QString f;
+ − 602
f = e;
+ − 603
f[7]='F';
+ − 604
QCOMPARE(e,(QString)"String E");
+ − 605
char text[]="String f";
+ − 606
f = text;
+ − 607
text[7]='!';
+ − 608
QCOMPARE(f,(QString)"String f");
+ − 609
f[7]='F';
+ − 610
QCOMPARE(text[7],'!');
+ − 611
+ − 612
a="";
+ − 613
a[0]='A';
+ − 614
QCOMPARE(a,(QString)"A");
+ − 615
QCOMPARE(a.length(),1);
+ − 616
a[1]='B';
+ − 617
QCOMPARE(a,(QString)"AB");
+ − 618
QCOMPARE(a.length(),2);
+ − 619
a[2]='C';
+ − 620
QCOMPARE(a,(QString)"ABC");
+ − 621
QCOMPARE(a.length(),3);
+ − 622
a = QString();
+ − 623
QVERIFY(a.isNull());
+ − 624
a[0]='A';
+ − 625
QCOMPARE(a,(QString)"A");
+ − 626
QCOMPARE(a.length(),1);
+ − 627
a[1]='B';
+ − 628
QCOMPARE(a,(QString)"AB");
+ − 629
QCOMPARE(a.length(),2);
+ − 630
a[2]='C';
+ − 631
QCOMPARE(a,(QString)"ABC");
+ − 632
QCOMPARE(a.length(),3);
+ − 633
+ − 634
a="123";
+ − 635
b="456";
+ − 636
a[0]=a[1];
+ − 637
QCOMPARE(a,(QString)"223");
+ − 638
a[1]=b[1];
+ − 639
QCOMPARE(b,(QString)"456");
+ − 640
QCOMPARE(a,(QString)"253");
+ − 641
+ − 642
char t[]="TEXT";
+ − 643
a="A";
+ − 644
a=t;
+ − 645
QCOMPARE(a,(QString)"TEXT");
+ − 646
QCOMPARE(a,(QString)t);
+ − 647
a[0]='X';
+ − 648
QCOMPARE(a,(QString)"XEXT");
+ − 649
QCOMPARE(t[0],'T');
+ − 650
t[0]='Z';
+ − 651
QCOMPARE(a,(QString)"XEXT");
+ − 652
+ − 653
a="ABC";
+ − 654
QCOMPARE(char(a.toLatin1()[1]),'B');
+ − 655
QCOMPARE(strcmp(a.toLatin1(),((QString)"ABC").toLatin1()),0);
+ − 656
QCOMPARE(a+="DEF",(QString)"ABCDEF");
+ − 657
QCOMPARE(a+='G',(QString)"ABCDEFG");
+ − 658
QCOMPARE(a+=((const char*)(0)),(QString)"ABCDEFG");
+ − 659
+ − 660
// non-member operators
+ − 661
+ − 662
a="ABC";
+ − 663
b="ABC";
+ − 664
c="ACB";
+ − 665
d="ABCD";
+ − 666
QVERIFY(a==b);
+ − 667
QVERIFY(!(a==d));
+ − 668
QVERIFY(!(a!=b));
+ − 669
QVERIFY(a!=d);
+ − 670
QVERIFY(!(a<b));
+ − 671
QVERIFY(a<c);
+ − 672
QVERIFY(a<d);
+ − 673
QVERIFY(!(d<a));
+ − 674
QVERIFY(!(c<a));
+ − 675
QVERIFY(a<=b);
+ − 676
QVERIFY(a<=d);
+ − 677
QVERIFY(a<=c);
+ − 678
QVERIFY(!(c<=a));
+ − 679
QVERIFY(!(d<=a));
+ − 680
QCOMPARE(a+b,(QString)"ABCABC");
+ − 681
QCOMPARE(a +"XXXX",(QString)"ABCXXXX");
+ − 682
QCOMPARE(a+'X',(QString)"ABCX");
+ − 683
QCOMPARE("XXXX"+a,(QString)"XXXXABC");
+ − 684
QCOMPARE('X'+a,(QString)"XABC");
+ − 685
a = (const char*)0;
+ − 686
QVERIFY(a.isNull());
+ − 687
QVERIFY(*a.toLatin1().constData() == '\0');
+ − 688
{
+ − 689
#if defined(Q_OS_WINCE)
+ − 690
int argc = 0;
+ − 691
QCoreApplication app(argc, 0);
+ − 692
#endif
+ − 693
QFile f("COMPARE.txt");
+ − 694
f.open(QIODevice::ReadOnly);
+ − 695
QTextStream ts( &f );
+ − 696
ts.setCodec(QTextCodec::codecForName("UTF-16"));
+ − 697
ts << "Abc";
+ − 698
}
+ − 699
}
+ − 700
+ − 701
void tst_QString::isNull()
+ − 702
{
+ − 703
QString a;
+ − 704
QVERIFY(a.isNull());
+ − 705
+ − 706
const char *zero = 0;
+ − 707
a.sprintf( zero );
+ − 708
QVERIFY(!a.isNull());
+ − 709
}
+ − 710
+ − 711
void tst_QString::isEmpty()
+ − 712
{
+ − 713
QString a;
+ − 714
QVERIFY(a.isEmpty());
+ − 715
QString c("Not empty");
+ − 716
QVERIFY(!c.isEmpty());
+ − 717
}
+ − 718
+ − 719
void tst_QString::constructor()
+ − 720
{
+ − 721
QString a;
+ − 722
QString b; //b(10);
+ − 723
QString c("String C");
+ − 724
QChar tmp[10];
+ − 725
tmp[0] = 'S';
+ − 726
tmp[1] = 't';
+ − 727
tmp[2] = 'r';
+ − 728
tmp[3] = 'i';
+ − 729
tmp[4] = 'n';
+ − 730
tmp[5] = 'g';
+ − 731
tmp[6] = ' ';
+ − 732
tmp[7] = 'D';
+ − 733
tmp[8] = 'X';
+ − 734
tmp[9] = '\0';
+ − 735
QString d(tmp,8);
+ − 736
QString ca(a);
+ − 737
QString cb(b);
+ − 738
QString cc(c);
+ − 739
+ − 740
QCOMPARE(a,ca);
+ − 741
QVERIFY(a.isNull());
+ − 742
QVERIFY(a == (QString)"");
+ − 743
QCOMPARE(b,cb);
+ − 744
QCOMPARE(c,cc);
+ − 745
QCOMPARE(d,(QString)"String D");
+ − 746
+ − 747
QString nullStr;
+ − 748
QVERIFY( nullStr.isNull() );
+ − 749
QVERIFY( nullStr.isEmpty() );
+ − 750
QString empty("");
+ − 751
QVERIFY( !empty.isNull() );
+ − 752
QVERIFY( empty.isEmpty() );
+ − 753
}
+ − 754
+ − 755
+ − 756
+ − 757
void tst_QString::constructorQByteArray_data()
+ − 758
{
+ − 759
QTest::addColumn<QByteArray>("src" );
+ − 760
QTest::addColumn<QString>("expected" );
+ − 761
+ − 762
QByteArray ba( 4, 0 );
+ − 763
ba[0] = 'C';
+ − 764
ba[1] = 'O';
+ − 765
ba[2] = 'M';
+ − 766
ba[3] = 'P';
+ − 767
+ − 768
QTest::newRow( "1" ) << ba << QString("COMP");
+ − 769
+ − 770
QByteArray ba1( 7, 0 );
+ − 771
ba1[0] = 'a';
+ − 772
ba1[1] = 'b';
+ − 773
ba1[2] = 'c';
+ − 774
ba1[3] = '\0';
+ − 775
ba1[4] = 'd';
+ − 776
ba1[5] = 'e';
+ − 777
ba1[6] = 'f';
+ − 778
+ − 779
QTest::newRow( "2" ) << ba1 << QString("abc");
+ − 780
+ − 781
QTest::newRow( "3" ) << QByteArray::fromRawData("abcd", 3) << QString("abc");
+ − 782
}
+ − 783
+ − 784
void tst_QString::constructorQByteArray()
+ − 785
{
+ − 786
QFETCH(QByteArray, src);
+ − 787
QFETCH(QString, expected);
+ − 788
+ − 789
QString str1(src);
+ − 790
QCOMPARE(str1.length(), expected.length());
+ − 791
QCOMPARE( str1, expected );
+ − 792
+ − 793
QTextCodec::setCodecForCStrings( QTextCodec::codecForMib(4) ); // Latin 1
+ − 794
QString strBA(src);
+ − 795
QTextCodec::setCodecForCStrings( 0 );
+ − 796
+ − 797
QCOMPARE( strBA, expected );
+ − 798
}
+ − 799
+ − 800
void tst_QString::STL()
+ − 801
{
+ − 802
#ifdef Q_CC_HPACC
+ − 803
QSKIP("This test crashes on HP-UX with aCC", SkipSingle);
+ − 804
#endif
+ − 805
#ifndef QT_NO_STL
+ − 806
#ifndef QT_NO_CAST_TO_ASCII
+ − 807
QString qt( "QString" );
+ − 808
+ − 809
std::string stdstr( "QString" );
+ − 810
+ − 811
QString stlqt;
+ − 812
+ − 813
// constructor
+ − 814
stlqt = QString( stdstr );
+ − 815
QCOMPARE( stlqt, qt );
+ − 816
+ − 817
// assignment
+ − 818
stlqt = stdstr;
+ − 819
QCOMPARE( stlqt, qt );
+ − 820
+ − 821
std::string stdstr2 = stlqt;
+ − 822
QCOMPARE( stdstr2, stdstr );
+ − 823
+ − 824
// prepend
+ − 825
stlqt = QString();
+ − 826
stlqt.prepend( stdstr );
+ − 827
QCOMPARE( stlqt, qt );
+ − 828
+ − 829
// append
+ − 830
stlqt = QString();
+ − 831
stlqt.append( stdstr );
+ − 832
QCOMPARE( stlqt, qt );
+ − 833
+ − 834
// pathologics (null-strings not supported by many STLs, so test only empty strings)
+ − 835
stdstr = std::string();
+ − 836
stlqt = stdstr;
+ − 837
QVERIFY( stlqt.isEmpty() );
+ − 838
std::string stdstr3 = stlqt;
+ − 839
QVERIFY( !stdstr3.length() );
+ − 840
#endif
+ − 841
+ − 842
//skip test if glibc is not compiled with wide character support
+ − 843
#if (defined Q_CC_GNU && !defined _GLIBCPP_USE_WCHAR_T) || defined QT_NO_STL_WCHAR
+ − 844
QSKIP( "Not tested without wide character support", SkipAll);
+ − 845
#else
+ − 846
const wchar_t arr[] = {'h', 'e', 'l', 'l', 'o', 0};
+ − 847
QStdWString stlStr = arr;
+ − 848
+ − 849
QString s = QString::fromStdWString(stlStr);
+ − 850
+ − 851
QCOMPARE(s, QString::fromLatin1("hello"));
+ − 852
QCOMPARE(stlStr, s.toStdWString());
+ − 853
#endif
+ − 854
#else
+ − 855
QSKIP( "Not tested without STL support", SkipAll);
+ − 856
#endif
+ − 857
}
+ − 858
+ − 859
void tst_QString::truncate()
+ − 860
{
+ − 861
QString e("String E");
+ − 862
e.truncate(4);
+ − 863
QCOMPARE(e,(QString)"Stri");
+ − 864
+ − 865
e = "String E";
+ − 866
e.truncate(0);
+ − 867
QCOMPARE(e,(QString)"");
+ − 868
QVERIFY(e.isEmpty());
+ − 869
QVERIFY(!e.isNull());
+ − 870
+ − 871
}
+ − 872
+ − 873
void tst_QString::fill()
+ − 874
{
+ − 875
QString e;
+ − 876
e.fill('e',1);
+ − 877
QCOMPARE(e,(QString)"e");
+ − 878
QString f;
+ − 879
f.fill('f',3);
+ − 880
QCOMPARE(f,(QString)"fff");
+ − 881
f.fill('F');
+ − 882
QCOMPARE(f,(QString)"FFF");
+ − 883
}
+ − 884
+ − 885
void tst_QString::copy()
+ − 886
{
+ − 887
#ifdef QT3_SUPPORT
+ − 888
QString e;
+ − 889
e = "String E";
+ − 890
QString ce = e.copy();
+ − 891
QCOMPARE(ce,(QString)"String E");
+ − 892
e = "XXX";
+ − 893
QCOMPARE(ce,(QString)"String E");
+ − 894
QCOMPARE(e,(QString)"XXX");
+ − 895
#endif
+ − 896
}
+ − 897
+ − 898
void tst_QString::sprintf()
+ − 899
{
+ − 900
QString a;
+ − 901
a.sprintf("COMPARE");
+ − 902
QCOMPARE(a,(QString)"COMPARE");
+ − 903
a.sprintf("%%%d",1);
+ − 904
QCOMPARE(a,(QString)"%1");
+ − 905
QCOMPARE(a.sprintf("X%dY",2),(QString)"X2Y");
+ − 906
QCOMPARE(a.sprintf("X%9iY", 50000 ),(QString)"X 50000Y");
+ − 907
QCOMPARE(a.sprintf("X%-9sY","hello"),(QString)"Xhello Y");
+ − 908
QCOMPARE(a.sprintf("X%-9iY", 50000 ),(QString)"X50000 Y");
+ − 909
QCOMPARE(a.sprintf("%lf", 1.23), QString("1.230000"));
+ − 910
QCOMPARE(a.sprintf("%lf", 1.23456789), QString("1.234568"));
+ − 911
QCOMPARE(a.sprintf("%p", (void *)0xbfffd350), QString("0xbfffd350"));
+ − 912
QCOMPARE(a.sprintf("%p", (void *)0), QString("0x0"));
+ − 913
+ − 914
int i = 6;
+ − 915
long l = -2;
+ − 916
float f = 4.023f;
+ − 917
QString S1;
+ − 918
S1.sprintf("%d %ld %f",i,l,f);
+ − 919
QCOMPARE(S1,QString("6 -2 4.023000"));
+ − 920
+ − 921
double d = -514.25683;
+ − 922
S1.sprintf("%f",d);
+ − 923
QCOMPARE(S1, QString("-514.256830"));
+ − 924
+ − 925
QCOMPARE(a.sprintf("%.3s", "Hello" ),(QString)"Hel");
+ − 926
QCOMPARE(a.sprintf("%10.3s", "Hello" ),(QString)" Hel");
+ − 927
QCOMPARE(a.sprintf("%.10s", "Hello" ),(QString)"Hello");
+ − 928
QCOMPARE(a.sprintf("%10.10s", "Hello" ),(QString)" Hello");
+ − 929
QCOMPARE(a.sprintf("%-10.10s", "Hello" ),(QString)"Hello ");
+ − 930
QCOMPARE(a.sprintf("%-10.3s", "Hello" ),(QString)"Hel ");
+ − 931
QCOMPARE(a.sprintf("%-5.5s", "Hello" ),(QString)"Hello");
+ − 932
+ − 933
// Check utf8 conversion for %s
+ − 934
QCOMPARE(a.sprintf("%s", "\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205"), QString("\366\344\374\326\304\334\370\346\345\330\306\305"));
+ − 935
+ − 936
int n1;
+ − 937
a.sprintf("%s%n%s", "hello", &n1, "goodbye");
+ − 938
QCOMPARE(n1, 5);
+ − 939
QCOMPARE(a, QString("hellogoodbye"));
+ − 940
qlonglong n2;
+ − 941
a.sprintf("%s%s%lln%s", "foo", "bar", &n2, "whiz");
+ − 942
QCOMPARE((int)n2, 6);
+ − 943
QCOMPARE(a, QString("foobarwhiz"));
+ − 944
}
+ − 945
+ − 946
/*
+ − 947
indexOf() and indexOf02() test QString::indexOf(),
+ − 948
QString::lastIndexOf(), and their QByteArray equivalents.
+ − 949
+ − 950
lastIndexOf() tests QString::lastIndexOf() more in depth, but it
+ − 951
should probably be rewritten to use a data table.
+ − 952
*/
+ − 953
+ − 954
void tst_QString::indexOf_data()
+ − 955
{
+ − 956
QTest::addColumn<QString>("haystack" );
+ − 957
QTest::addColumn<QString>("needle" );
+ − 958
QTest::addColumn<int>("startpos" );
+ − 959
QTest::addColumn<bool>("bcs" );
+ − 960
QTest::addColumn<int>("resultpos" );
+ − 961
+ − 962
QTest::newRow( "data0" ) << QString("abc") << QString("a") << 0 << true << 0;
+ − 963
QTest::newRow( "data1" ) << QString("abc") << QString("a") << 0 << false << 0;
+ − 964
QTest::newRow( "data2" ) << QString("abc") << QString("A") << 0 << true << -1;
+ − 965
QTest::newRow( "data3" ) << QString("abc") << QString("A") << 0 << false << 0;
+ − 966
QTest::newRow( "data4" ) << QString("abc") << QString("a") << 1 << true << -1;
+ − 967
QTest::newRow( "data5" ) << QString("abc") << QString("a") << 1 << false << -1;
+ − 968
QTest::newRow( "data6" ) << QString("abc") << QString("A") << 1 << true << -1;
+ − 969
QTest::newRow( "data7" ) << QString("abc") << QString("A") << 1 << false << -1;
+ − 970
QTest::newRow( "data8" ) << QString("abc") << QString("b") << 0 << true << 1;
+ − 971
QTest::newRow( "data9" ) << QString("abc") << QString("b") << 0 << false << 1;
+ − 972
QTest::newRow( "data10" ) << QString("abc") << QString("B") << 0 << true << -1;
+ − 973
QTest::newRow( "data11" ) << QString("abc") << QString("B") << 0 << false << 1;
+ − 974
QTest::newRow( "data12" ) << QString("abc") << QString("b") << 1 << true << 1;
+ − 975
QTest::newRow( "data13" ) << QString("abc") << QString("b") << 1 << false << 1;
+ − 976
QTest::newRow( "data14" ) << QString("abc") << QString("B") << 1 << true << -1;
+ − 977
QTest::newRow( "data15" ) << QString("abc") << QString("B") << 1 << false << 1;
+ − 978
QTest::newRow( "data16" ) << QString("abc") << QString("b") << 2 << true << -1;
+ − 979
QTest::newRow( "data17" ) << QString("abc") << QString("b") << 2 << false << -1;
+ − 980
+ − 981
QTest::newRow( "data20" ) << QString("ABC") << QString("A") << 0 << true << 0;
+ − 982
QTest::newRow( "data21" ) << QString("ABC") << QString("A") << 0 << false << 0;
+ − 983
QTest::newRow( "data22" ) << QString("ABC") << QString("a") << 0 << true << -1;
+ − 984
QTest::newRow( "data23" ) << QString("ABC") << QString("a") << 0 << false << 0;
+ − 985
QTest::newRow( "data24" ) << QString("ABC") << QString("A") << 1 << true << -1;
+ − 986
QTest::newRow( "data25" ) << QString("ABC") << QString("A") << 1 << false << -1;
+ − 987
QTest::newRow( "data26" ) << QString("ABC") << QString("a") << 1 << true << -1;
+ − 988
QTest::newRow( "data27" ) << QString("ABC") << QString("a") << 1 << false << -1;
+ − 989
QTest::newRow( "data28" ) << QString("ABC") << QString("B") << 0 << true << 1;
+ − 990
QTest::newRow( "data29" ) << QString("ABC") << QString("B") << 0 << false << 1;
+ − 991
QTest::newRow( "data30" ) << QString("ABC") << QString("b") << 0 << true << -1;
+ − 992
QTest::newRow( "data31" ) << QString("ABC") << QString("b") << 0 << false << 1;
+ − 993
QTest::newRow( "data32" ) << QString("ABC") << QString("B") << 1 << true << 1;
+ − 994
QTest::newRow( "data33" ) << QString("ABC") << QString("B") << 1 << false << 1;
+ − 995
QTest::newRow( "data34" ) << QString("ABC") << QString("b") << 1 << true << -1;
+ − 996
QTest::newRow( "data35" ) << QString("ABC") << QString("b") << 1 << false << 1;
+ − 997
QTest::newRow( "data36" ) << QString("ABC") << QString("B") << 2 << true << -1;
+ − 998
QTest::newRow( "data37" ) << QString("ABC") << QString("B") << 2 << false << -1;
+ − 999
+ − 1000
QTest::newRow( "data40" ) << QString("aBc") << QString("bc") << 0 << true << -1;
+ − 1001
QTest::newRow( "data41" ) << QString("aBc") << QString("Bc") << 0 << true << 1;
+ − 1002
QTest::newRow( "data42" ) << QString("aBc") << QString("bC") << 0 << true << -1;
+ − 1003
QTest::newRow( "data43" ) << QString("aBc") << QString("BC") << 0 << true << -1;
+ − 1004
QTest::newRow( "data44" ) << QString("aBc") << QString("bc") << 0 << false << 1;
+ − 1005
QTest::newRow( "data45" ) << QString("aBc") << QString("Bc") << 0 << false << 1;
+ − 1006
QTest::newRow( "data46" ) << QString("aBc") << QString("bC") << 0 << false << 1;
+ − 1007
QTest::newRow( "data47" ) << QString("aBc") << QString("BC") << 0 << false << 1;
+ − 1008
QTest::newRow( "data48" ) << QString("AbC") << QString("bc") << 0 << true << -1;
+ − 1009
QTest::newRow( "data49" ) << QString("AbC") << QString("Bc") << 0 << true << -1;
+ − 1010
QTest::newRow( "data50" ) << QString("AbC") << QString("bC") << 0 << true << 1;
+ − 1011
QTest::newRow( "data51" ) << QString("AbC") << QString("BC") << 0 << true << -1;
+ − 1012
QTest::newRow( "data52" ) << QString("AbC") << QString("bc") << 0 << false << 1;
+ − 1013
QTest::newRow( "data53" ) << QString("AbC") << QString("Bc") << 0 << false << 1;
+ − 1014
+ − 1015
QTest::newRow( "data54" ) << QString("AbC") << QString("bC") << 0 << false << 1;
+ − 1016
QTest::newRow( "data55" ) << QString("AbC") << QString("BC") << 0 << false << 1;
+ − 1017
QTest::newRow( "data56" ) << QString("AbC") << QString("BC") << 1 << false << 1;
+ − 1018
QTest::newRow( "data57" ) << QString("AbC") << QString("BC") << 2 << false << -1;
+ − 1019
#if 0
+ − 1020
QTest::newRow( "null-in-null") << QString() << QString() << 0 << false << 0;
+ − 1021
QTest::newRow( "empty-in-null") << QString() << QString("") << 0 << false << 0;
+ − 1022
QTest::newRow( "null-in-empty") << QString("") << QString() << 0 << false << 0;
+ − 1023
QTest::newRow( "empty-in-empty") << QString("") << QString("") << 0 << false << 0;
+ − 1024
#endif
+ − 1025
+ − 1026
+ − 1027
QString s1 = "abc";
+ − 1028
s1 += QChar(0xb5);
+ − 1029
QString s2;
+ − 1030
s2 += QChar(0x3bc);
+ − 1031
QTest::newRow( "data58" ) << s1 << s2 << 0 << false << 3;
+ − 1032
s2.prepend("C");
+ − 1033
QTest::newRow( "data59" ) << s1 << s2 << 0 << false << 2;
+ − 1034
+ − 1035
QString veryBigHaystack(500, 'a');
+ − 1036
veryBigHaystack += 'B';
+ − 1037
QTest::newRow("BoyerMooreStressTest") << veryBigHaystack << veryBigHaystack << 0 << true << 0;
+ − 1038
QTest::newRow("BoyerMooreStressTest2") << veryBigHaystack + 'c' << veryBigHaystack << 0 << true << 0;
+ − 1039
QTest::newRow("BoyerMooreStressTest3") << 'c' + veryBigHaystack << veryBigHaystack << 0 << true << 1;
+ − 1040
QTest::newRow("BoyerMooreStressTest4") << veryBigHaystack << veryBigHaystack + 'c' << 0 << true << -1;
+ − 1041
QTest::newRow("BoyerMooreStressTest5") << veryBigHaystack << 'c' + veryBigHaystack << 0 << true << -1;
+ − 1042
QTest::newRow("BoyerMooreStressTest6") << 'd' + veryBigHaystack << 'c' + veryBigHaystack << 0 << true << -1;
+ − 1043
QTest::newRow("BoyerMooreStressTest6") << veryBigHaystack + 'c' << 'c' + veryBigHaystack << 0 << true << -1;
+ − 1044
+ − 1045
QTest::newRow("BoyerMooreInsensitiveStressTest") << veryBigHaystack << veryBigHaystack << 0 << false << 0;
+ − 1046
+ − 1047
}
+ − 1048
+ − 1049
void tst_QString::indexOf()
+ − 1050
{
+ − 1051
QFETCH( QString, haystack );
+ − 1052
QFETCH( QString, needle );
+ − 1053
QFETCH( int, startpos );
+ − 1054
QFETCH( bool, bcs );
+ − 1055
QFETCH( int, resultpos );
+ − 1056
+ − 1057
Qt::CaseSensitivity cs = bcs ? Qt::CaseSensitive : Qt::CaseInsensitive;
+ − 1058
+ − 1059
bool needleIsLatin = (QString::fromLatin1(needle.toLatin1()) == needle);
+ − 1060
+ − 1061
QCOMPARE( haystack.indexOf(needle, startpos, cs), resultpos );
+ − 1062
if (needleIsLatin) {
+ − 1063
QCOMPARE( haystack.indexOf(needle.toLatin1(), startpos, cs), resultpos );
+ − 1064
QCOMPARE( haystack.indexOf(needle.toLatin1().data(), startpos, cs), resultpos );
+ − 1065
}
+ − 1066
+ − 1067
{
+ − 1068
QRegExp rx1 = QRegExp(QRegExp::escape(needle), cs);
+ − 1069
QRegExp rx2 = QRegExp(needle, cs, QRegExp::FixedString);
+ − 1070
QCOMPARE( haystack.indexOf(rx1, startpos), resultpos );
+ − 1071
QCOMPARE( haystack.indexOf(rx2, startpos), resultpos );
+ − 1072
// these QRegExp must have been modified
+ − 1073
QVERIFY( resultpos == -1 || rx1.matchedLength() > 0);
+ − 1074
QVERIFY( resultpos == -1 || rx2.matchedLength() > 0);
+ − 1075
}
+ − 1076
+ − 1077
{
+ − 1078
const QRegExp rx1 = QRegExp(QRegExp::escape(needle), cs);
+ − 1079
const QRegExp rx2 = QRegExp(needle, cs, QRegExp::FixedString);
+ − 1080
QCOMPARE( haystack.indexOf(rx1, startpos), resultpos );
+ − 1081
QCOMPARE( haystack.indexOf(rx2, startpos), resultpos );
+ − 1082
// our QRegExp mustn't have been modified
+ − 1083
QCOMPARE( rx1.matchedLength(), -1 );
+ − 1084
QCOMPARE( rx2.matchedLength(), -1 );
+ − 1085
}
+ − 1086
+ − 1087
if (cs == Qt::CaseSensitive) {
+ − 1088
QCOMPARE( haystack.indexOf(needle, startpos), resultpos );
+ − 1089
if (needleIsLatin) {
+ − 1090
QCOMPARE( haystack.indexOf(needle.toLatin1(), startpos), resultpos );
+ − 1091
QCOMPARE( haystack.indexOf(needle.toLatin1().data(), startpos), resultpos );
+ − 1092
}
+ − 1093
if (startpos == 0) {
+ − 1094
QCOMPARE( haystack.indexOf(needle), resultpos );
+ − 1095
if (needleIsLatin) {
+ − 1096
QCOMPARE( haystack.indexOf(needle.toLatin1()), resultpos );
+ − 1097
QCOMPARE( haystack.indexOf(needle.toLatin1().data()), resultpos );
+ − 1098
}
+ − 1099
}
+ − 1100
}
+ − 1101
if (needle.size() == 1) {
+ − 1102
QCOMPARE(haystack.indexOf(needle.at(0), startpos, cs), resultpos);
+ − 1103
}
+ − 1104
+ − 1105
}
+ − 1106
+ − 1107
void tst_QString::indexOf2_data()
+ − 1108
{
+ − 1109
QTest::addColumn<QString>("haystack" );
+ − 1110
QTest::addColumn<QString>("needle" );
+ − 1111
QTest::addColumn<int>("resultpos" );
+ − 1112
+ − 1113
QTest::newRow( "data0" ) << QString() << QString() << 0;
+ − 1114
QTest::newRow( "data1" ) << QString() << QString("") << 0;
+ − 1115
QTest::newRow( "data2" ) << QString("") << QString() << 0;
+ − 1116
QTest::newRow( "data3" ) << QString("") << QString("") << 0;
+ − 1117
QTest::newRow( "data4" ) << QString() << QString("a") << -1;
+ − 1118
QTest::newRow( "data5" ) << QString() << QString("abcdefg") << -1;
+ − 1119
QTest::newRow( "data6" ) << QString("") << QString("a") << -1;
+ − 1120
QTest::newRow( "data7" ) << QString("") << QString("abcdefg") << -1;
+ − 1121
+ − 1122
QTest::newRow( "data8" ) << QString("a") << QString() << 0;
+ − 1123
QTest::newRow( "data9" ) << QString("a") << QString("") << 0;
+ − 1124
QTest::newRow( "data10" ) << QString("a") << QString("a") << 0;
+ − 1125
QTest::newRow( "data11" ) << QString("a") << QString("b") << -1;
+ − 1126
QTest::newRow( "data12" ) << QString("a") << QString("abcdefg") << -1;
+ − 1127
QTest::newRow( "data13" ) << QString("ab") << QString() << 0;
+ − 1128
QTest::newRow( "data14" ) << QString("ab") << QString("") << 0;
+ − 1129
QTest::newRow( "data15" ) << QString("ab") << QString("a") << 0;
+ − 1130
QTest::newRow( "data16" ) << QString("ab") << QString("b") << 1;
+ − 1131
QTest::newRow( "data17" ) << QString("ab") << QString("ab") << 0;
+ − 1132
QTest::newRow( "data18" ) << QString("ab") << QString("bc") << -1;
+ − 1133
QTest::newRow( "data19" ) << QString("ab") << QString("abcdefg") << -1;
+ − 1134
+ − 1135
QTest::newRow( "data30" ) << QString("abc") << QString("a") << 0;
+ − 1136
QTest::newRow( "data31" ) << QString("abc") << QString("b") << 1;
+ − 1137
QTest::newRow( "data32" ) << QString("abc") << QString("c") << 2;
+ − 1138
QTest::newRow( "data33" ) << QString("abc") << QString("d") << -1;
+ − 1139
QTest::newRow( "data34" ) << QString("abc") << QString("ab") << 0;
+ − 1140
QTest::newRow( "data35" ) << QString("abc") << QString("bc") << 1;
+ − 1141
QTest::newRow( "data36" ) << QString("abc") << QString("cd") << -1;
+ − 1142
QTest::newRow( "data37" ) << QString("abc") << QString("ac") << -1;
+ − 1143
+ − 1144
// sizeof(whale) > 32
+ − 1145
QString whale = "a5zby6cx7dw8evf9ug0th1si2rj3qkp4lomn";
+ − 1146
QString minnow = "zby";
+ − 1147
QTest::newRow( "data40" ) << whale << minnow << 2;
+ − 1148
QTest::newRow( "data41" ) << (whale + whale) << minnow << 2;
+ − 1149
QTest::newRow( "data42" ) << (minnow + whale) << minnow << 0;
+ − 1150
QTest::newRow( "data43" ) << whale << whale << 0;
+ − 1151
QTest::newRow( "data44" ) << (whale + whale) << whale << 0;
+ − 1152
QTest::newRow( "data45" ) << whale << (whale + whale) << -1;
+ − 1153
QTest::newRow( "data46" ) << (whale + whale) << (whale + whale) << 0;
+ − 1154
QTest::newRow( "data47" ) << (whale + whale) << (whale + minnow) << -1;
+ − 1155
QTest::newRow( "data48" ) << (minnow + whale) << whale << (int)minnow.length();
+ − 1156
}
+ − 1157
+ − 1158
void tst_QString::indexOf2()
+ − 1159
{
+ − 1160
QFETCH( QString, haystack );
+ − 1161
QFETCH( QString, needle );
+ − 1162
QFETCH( int, resultpos );
+ − 1163
+ − 1164
QByteArray chaystack = haystack.toLatin1();
+ − 1165
QByteArray cneedle = needle.toLatin1();
+ − 1166
int got;
+ − 1167
+ − 1168
QCOMPARE( haystack.indexOf(needle, 0, Qt::CaseSensitive), resultpos );
+ − 1169
QCOMPARE( QStringMatcher(needle, Qt::CaseSensitive).indexIn(haystack, 0), resultpos );
+ − 1170
QCOMPARE( haystack.indexOf(needle, 0, Qt::CaseInsensitive), resultpos );
+ − 1171
QCOMPARE( QStringMatcher(needle, Qt::CaseInsensitive).indexIn(haystack, 0), resultpos );
+ − 1172
if ( needle.length() > 0 ) {
+ − 1173
got = haystack.lastIndexOf( needle, -1, Qt::CaseSensitive );
+ − 1174
QVERIFY( got == resultpos || (resultpos >= 0 && got >= resultpos) );
+ − 1175
got = haystack.lastIndexOf( needle, -1, Qt::CaseInsensitive );
+ − 1176
QVERIFY( got == resultpos || (resultpos >= 0 && got >= resultpos) );
+ − 1177
}
+ − 1178
+ − 1179
QCOMPARE( chaystack.indexOf(cneedle, 0), resultpos );
+ − 1180
QCOMPARE( QByteArrayMatcher(cneedle).indexIn(chaystack, 0), resultpos );
+ − 1181
if ( cneedle.length() > 0 ) {
+ − 1182
got = chaystack.lastIndexOf(cneedle, -1);
+ − 1183
QVERIFY( got == resultpos || (resultpos >= 0 && got >= resultpos) );
+ − 1184
}
+ − 1185
}
+ − 1186
+ − 1187
void tst_QString::lastIndexOf_data()
+ − 1188
{
+ − 1189
QTest::addColumn<QString>("haystack" );
+ − 1190
QTest::addColumn<QString>("needle" );
+ − 1191
QTest::addColumn<int>("from" );
+ − 1192
QTest::addColumn<int>("expected" );
+ − 1193
QTest::addColumn<bool>("caseSensitive" );
+ − 1194
+ − 1195
QString a = "ABCDEFGHIEfGEFG";
+ − 1196
+ − 1197
QTest::newRow("-1") << a << "G" << a.size() - 1 << 14 << true;
+ − 1198
QTest::newRow("1") << a << "G" << - 1 << 14 << true;
+ − 1199
QTest::newRow("2") << a << "G" << -3 << 11 << true;
+ − 1200
QTest::newRow("3") << a << "G" << -5 << 6 << true;
+ − 1201
QTest::newRow("4") << a << "G" << 14 << 14 << true;
+ − 1202
QTest::newRow("5") << a << "G" << 13 << 11 << true;
+ − 1203
QTest::newRow("6") << a << "B" << a.size() - 1 << 1 << true;
+ − 1204
QTest::newRow("6") << a << "B" << - 1 << 1 << true;
+ − 1205
QTest::newRow("7") << a << "B" << 1 << 1 << true;
+ − 1206
QTest::newRow("8") << a << "B" << 0 << -1 << true;
+ − 1207
+ − 1208
QTest::newRow("9") << a << "G" << -1 << a.size()-1 << true;
+ − 1209
QTest::newRow("10") << a << "G" << a.size()-1 << a.size()-1 << true;
+ − 1210
QTest::newRow("11") << a << "G" << a.size() << -1 << true;
+ − 1211
QTest::newRow("12") << a << "A" << 0 << 0 << true;
+ − 1212
QTest::newRow("13") << a << "A" << -1*a.size() << 0 << true;
+ − 1213
+ − 1214
QTest::newRow("15") << a << "efg" << 0 << -1 << false;
+ − 1215
QTest::newRow("16") << a << "efg" << a.size() << -1 << false;
+ − 1216
QTest::newRow("17") << a << "efg" << -1 * a.size() << -1 << false;
+ − 1217
QTest::newRow("19") << a << "efg" << a.size() - 1 << 12 << false;
+ − 1218
QTest::newRow("20") << a << "efg" << 12 << 12 << false;
+ − 1219
QTest::newRow("21") << a << "efg" << -12 << -1 << false;
+ − 1220
QTest::newRow("22") << a << "efg" << 11 << 9 << false;
+ − 1221
+ − 1222
QTest::newRow("24") << "" << "asdf" << -1 << -1 << false;
+ − 1223
QTest::newRow("25") << "asd" << "asdf" << -1 << -1 << false;
+ − 1224
QTest::newRow("26") << "" << QString() << -1 << -1 << false;
+ − 1225
+ − 1226
QTest::newRow("27") << a << "" << a.size() << a.size() << false;
+ − 1227
QTest::newRow("28") << a << "" << a.size() + 10 << -1 << false;
+ − 1228
}
+ − 1229
+ − 1230
void tst_QString::lastIndexOf()
+ − 1231
{
+ − 1232
QFETCH(QString, haystack);
+ − 1233
QFETCH(QString, needle);
+ − 1234
QFETCH(int, from);
+ − 1235
QFETCH(int, expected);
+ − 1236
QFETCH(bool, caseSensitive);
+ − 1237
+ − 1238
Qt::CaseSensitivity cs = (caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
+ − 1239
+ − 1240
QCOMPARE(haystack.lastIndexOf(needle, from, cs), expected);
+ − 1241
QCOMPARE(haystack.lastIndexOf(needle.toLatin1(), from, cs), expected);
+ − 1242
QCOMPARE(haystack.lastIndexOf(needle.toLatin1().data(), from, cs), expected);
+ − 1243
+ − 1244
if (from >= -1 && from < haystack.size()) {
+ − 1245
// unfortunately, QString and QRegExp don't have the same out of bound semantics
+ − 1246
// I think QString is wrong -- See file log for contact information.
+ − 1247
{
+ − 1248
QRegExp rx1 = QRegExp(QRegExp::escape(needle), cs);
+ − 1249
QRegExp rx2 = QRegExp(needle, cs, QRegExp::FixedString);
+ − 1250
QCOMPARE(haystack.lastIndexOf(rx1, from), expected);
+ − 1251
QCOMPARE(haystack.lastIndexOf(rx2, from), expected);
+ − 1252
// our QRegExp mustn't have been modified
+ − 1253
QVERIFY(expected == -1 || rx1.matchedLength() > 0);
+ − 1254
QVERIFY(expected == -1 || rx2.matchedLength() > 0);
+ − 1255
}
+ − 1256
+ − 1257
{
+ − 1258
const QRegExp rx1 = QRegExp(QRegExp::escape(needle), cs);
+ − 1259
const QRegExp rx2 = QRegExp(needle, cs, QRegExp::FixedString);
+ − 1260
QCOMPARE(haystack.lastIndexOf(rx1, from), expected);
+ − 1261
QCOMPARE(haystack.lastIndexOf(rx2, from), expected);
+ − 1262
// our QRegExp mustn't have been modified
+ − 1263
QCOMPARE(rx1.matchedLength(), -1);
+ − 1264
QCOMPARE(rx2.matchedLength(), -1);
+ − 1265
}
+ − 1266
}
+ − 1267
+ − 1268
if (cs == Qt::CaseSensitive) {
+ − 1269
QCOMPARE(haystack.lastIndexOf(needle, from), expected);
+ − 1270
QCOMPARE(haystack.lastIndexOf(needle.toLatin1(), from), expected);
+ − 1271
QCOMPARE(haystack.lastIndexOf(needle.toLatin1().data(), from), expected);
+ − 1272
if (from == -1) {
+ − 1273
QCOMPARE(haystack.lastIndexOf(needle), expected);
+ − 1274
QCOMPARE(haystack.lastIndexOf(needle.toLatin1()), expected);
+ − 1275
QCOMPARE(haystack.lastIndexOf(needle.toLatin1().data()), expected);
+ − 1276
}
+ − 1277
}
+ − 1278
if (needle.size() == 1) {
+ − 1279
QCOMPARE(haystack.lastIndexOf(needle.at(0), from), expected);
+ − 1280
}
+ − 1281
}
+ − 1282
+ − 1283
void tst_QString::contains()
+ − 1284
{
+ − 1285
QString a;
+ − 1286
a="ABCDEFGHIEfGEFG"; // 15 chars
+ − 1287
QCOMPARE(a.count('A'),1);
+ − 1288
QCOMPARE(a.count('Z'),0);
+ − 1289
QCOMPARE(a.count('E'),3);
+ − 1290
QCOMPARE(a.count('F'),2);
+ − 1291
QCOMPARE(a.count('F',Qt::CaseInsensitive),3);
+ − 1292
QCOMPARE(a.count("FG"),2);
+ − 1293
QCOMPARE(a.count("FG",Qt::CaseInsensitive),3);
+ − 1294
QCOMPARE(a.count( QString(), Qt::CaseInsensitive), 16);
+ − 1295
QCOMPARE(a.count( "", Qt::CaseInsensitive), 16);
+ − 1296
QCOMPARE(a.count(QRegExp("[FG][HI]")),1);
+ − 1297
QCOMPARE(a.count(QRegExp("[G][HE]")),2);
+ − 1298
}
+ − 1299
+ − 1300
void tst_QString::left()
+ − 1301
{
+ − 1302
QString a;
+ − 1303
a="ABCDEFGHIEfGEFG"; // 15 chars
+ − 1304
QCOMPARE(a.left(3),(QString)"ABC");
+ − 1305
QVERIFY(!a.left(0).isNull());
+ − 1306
QCOMPARE(a.left(0),(QString)"");
+ − 1307
+ − 1308
QString n;
+ − 1309
QVERIFY(n.left(3).isNull());
+ − 1310
QVERIFY(n.left(0).isNull());
+ − 1311
QVERIFY(n.left(0).isNull());
+ − 1312
+ − 1313
QString l = "Left";
+ − 1314
QCOMPARE(l.left(-1), l);
+ − 1315
QCOMPARE(l.left(100), l);
+ − 1316
}
+ − 1317
+ − 1318
void tst_QString::leftRef()
+ − 1319
{
+ − 1320
QString a;
+ − 1321
a="ABCDEFGHIEfGEFG"; // 15 chars
+ − 1322
QCOMPARE(a.leftRef(3).toString(),(QString)"ABC");
+ − 1323
+ − 1324
QVERIFY(a.leftRef(0).toString().isEmpty());
+ − 1325
QCOMPARE(a.leftRef(0).toString(),(QString)"");
+ − 1326
+ − 1327
QString n;
+ − 1328
QVERIFY(n.leftRef(3).toString().isEmpty());
+ − 1329
QVERIFY(n.leftRef(0).toString().isEmpty());
+ − 1330
QVERIFY(n.leftRef(0).toString().isEmpty());
+ − 1331
+ − 1332
QString l = "Left";
+ − 1333
QCOMPARE(l.leftRef(-1).toString(), l);
+ − 1334
QCOMPARE(l.leftRef(100).toString(), l);
+ − 1335
}
+ − 1336
+ − 1337
void tst_QString::right()
+ − 1338
{
+ − 1339
QString a;
+ − 1340
a="ABCDEFGHIEfGEFG"; // 15 chars
+ − 1341
QCOMPARE(a.right(3),(QString)"EFG");
+ − 1342
QCOMPARE(a.right(0),(QString)"");
+ − 1343
+ − 1344
QString n;
+ − 1345
QVERIFY(n.right(3).isNull());
+ − 1346
QVERIFY(n.right(0).isNull());
+ − 1347
+ − 1348
QString r = "Right";
+ − 1349
QCOMPARE(r.right(-1), r);
+ − 1350
QCOMPARE(r.right(100), r);
+ − 1351
}
+ − 1352
+ − 1353
void tst_QString::rightRef()
+ − 1354
{
+ − 1355
QString a;
+ − 1356
a="ABCDEFGHIEfGEFG"; // 15 chars
+ − 1357
QCOMPARE(a.rightRef(3).toString(),(QString)"EFG");
+ − 1358
QCOMPARE(a.rightRef(0).toString(),(QString)"");
+ − 1359
+ − 1360
QString n;
+ − 1361
QVERIFY(n.rightRef(3).toString().isEmpty());
+ − 1362
QVERIFY(n.rightRef(0).toString().isEmpty());
+ − 1363
+ − 1364
QString r = "Right";
+ − 1365
QCOMPARE(r.rightRef(-1).toString(), r);
+ − 1366
QCOMPARE(r.rightRef(100).toString(), r);
+ − 1367
}
+ − 1368
+ − 1369
void tst_QString::mid()
+ − 1370
{
+ − 1371
QString a;
+ − 1372
a="ABCDEFGHIEfGEFG"; // 15 chars
+ − 1373
+ − 1374
QCOMPARE(a.mid(3,3),(QString)"DEF");
+ − 1375
QCOMPARE(a.mid(0,0),(QString)"");
+ − 1376
QVERIFY(a.mid(9999).isNull());
+ − 1377
QVERIFY(a.mid(9999,1).isNull());
+ − 1378
+ − 1379
QString n;
+ − 1380
QVERIFY(n.mid(3,3).isNull());
+ − 1381
QVERIFY(n.mid(0,0).isNull());
+ − 1382
QVERIFY(n.mid(9999,0).isNull());
+ − 1383
QVERIFY(n.mid(9999,1).isNull());
+ − 1384
+ − 1385
QString x = "Nine pineapples";
+ − 1386
QCOMPARE(x.mid(5, 4), QString("pine"));
+ − 1387
QCOMPARE(x.mid(5), QString("pineapples"));
+ − 1388
+ − 1389
}
+ − 1390
+ − 1391
void tst_QString::midRef()
+ − 1392
{
+ − 1393
QString a;
+ − 1394
a="ABCDEFGHIEfGEFG"; // 15 chars
+ − 1395
+ − 1396
QCOMPARE(a.midRef(3,3).toString(),(QString)"DEF");
+ − 1397
QCOMPARE(a.midRef(0,0).toString(),(QString)"");
+ − 1398
QVERIFY(a.midRef(9999).toString().isEmpty());
+ − 1399
QVERIFY(a.midRef(9999,1).toString().isEmpty());
+ − 1400
+ − 1401
QString n;
+ − 1402
QVERIFY(n.midRef(3,3).toString().isEmpty());
+ − 1403
QVERIFY(n.midRef(0,0).toString().isEmpty());
+ − 1404
QVERIFY(n.midRef(9999,0).toString().isEmpty());
+ − 1405
QVERIFY(n.midRef(9999,1).toString().isEmpty());
+ − 1406
+ − 1407
QString x = "Nine pineapples";
+ − 1408
QCOMPARE(x.midRef(5, 4).toString(), QString("pine"));
+ − 1409
QCOMPARE(x.midRef(5).toString(), QString("pineapples"));
+ − 1410
+ − 1411
}
+ − 1412
+ − 1413
void tst_QString::stringRef()
+ − 1414
{
+ − 1415
QString a;
+ − 1416
a="ABCDEFGHIEfGEFG"; // 15 chars
+ − 1417
+ − 1418
QVERIFY(QStringRef(&a, 0, 0) == (QString)"");
+ − 1419
+ − 1420
QVERIFY(QStringRef(&a, 3, 3) == (QString)"DEF");
+ − 1421
QVERIFY(QStringRef(&a, 3, 3) == QLatin1String("DEF"));
+ − 1422
QVERIFY(QStringRef(&a, 3, 3) == "DEF");
+ − 1423
QVERIFY((QString)"DEF" == QStringRef(&a, 3, 3));
+ − 1424
QVERIFY(QLatin1String("DEF") == QStringRef(&a, 3, 3));
+ − 1425
QVERIFY("DEF" == QStringRef(&a, 3, 3));
+ − 1426
+ − 1427
QVERIFY(QStringRef(&a, 3, 3) != (QString)"DE");
+ − 1428
QVERIFY(QStringRef(&a, 3, 3) != QLatin1String("DE"));
+ − 1429
QVERIFY(QStringRef(&a, 3, 3) != "DE");
+ − 1430
QVERIFY((QString)"DE" != QStringRef(&a, 3, 3));
+ − 1431
QVERIFY(QLatin1String("DE") != QStringRef(&a, 3, 3));
+ − 1432
QVERIFY("DE" != QStringRef(&a, 3, 3));
+ − 1433
+ − 1434
QString s_alpha("alpha");
+ − 1435
QString s_beta("beta");
+ − 1436
QStringRef alpha(&s_alpha);
+ − 1437
QStringRef beta(&s_beta);
+ − 1438
+ − 1439
QVERIFY(alpha < beta);
+ − 1440
QVERIFY(alpha <= beta);
+ − 1441
QVERIFY(alpha <= alpha);
+ − 1442
QVERIFY(beta > alpha);
+ − 1443
QVERIFY(beta >= alpha);
+ − 1444
QVERIFY(beta >= beta);
+ − 1445
+ − 1446
QString s_alpha2("alpha");
+ − 1447
+ − 1448
QMap<QStringRef, QString> map;
+ − 1449
map.insert(alpha, "alpha");
+ − 1450
map.insert(beta, "beta");
+ − 1451
QVERIFY(alpha == map.value(QStringRef(&s_alpha2)));
+ − 1452
+ − 1453
QHash<QStringRef, QString> hash;
+ − 1454
hash.insert(alpha, "alpha");
+ − 1455
hash.insert(beta, "beta");
+ − 1456
+ − 1457
QVERIFY(alpha == hash.value(QStringRef(&s_alpha2)));
+ − 1458
}
+ − 1459
+ − 1460
void tst_QString::leftJustified()
+ − 1461
{
+ − 1462
QString a;
+ − 1463
a="ABC";
+ − 1464
QCOMPARE(a.leftJustified(5,'-'),(QString)"ABC--");
+ − 1465
QCOMPARE(a.leftJustified(4,'-'),(QString)"ABC-");
+ − 1466
QCOMPARE(a.leftJustified(4),(QString)"ABC ");
+ − 1467
QCOMPARE(a.leftJustified(3),(QString)"ABC");
+ − 1468
QCOMPARE(a.leftJustified(2),(QString)"ABC");
+ − 1469
QCOMPARE(a.leftJustified(1),(QString)"ABC");
+ − 1470
QCOMPARE(a.leftJustified(0),(QString)"ABC");
+ − 1471
+ − 1472
QString n;
+ − 1473
QVERIFY(!n.leftJustified(3).isNull());
+ − 1474
QCOMPARE(a.leftJustified(4,' ',true),(QString)"ABC ");
+ − 1475
QCOMPARE(a.leftJustified(3,' ',true),(QString)"ABC");
+ − 1476
QCOMPARE(a.leftJustified(2,' ',true),(QString)"AB");
+ − 1477
QCOMPARE(a.leftJustified(1,' ',true),(QString)"A");
+ − 1478
QCOMPARE(a.leftJustified(0,' ',true),(QString)"");
+ − 1479
}
+ − 1480
+ − 1481
void tst_QString::rightJustified()
+ − 1482
{
+ − 1483
QString a;
+ − 1484
a="ABC";
+ − 1485
QCOMPARE(a.rightJustified(5,'-'),(QString)"--ABC");
+ − 1486
QCOMPARE(a.rightJustified(4,'-'),(QString)"-ABC");
+ − 1487
QCOMPARE(a.rightJustified(4),(QString)" ABC");
+ − 1488
QCOMPARE(a.rightJustified(3),(QString)"ABC");
+ − 1489
QCOMPARE(a.rightJustified(2),(QString)"ABC");
+ − 1490
QCOMPARE(a.rightJustified(1),(QString)"ABC");
+ − 1491
QCOMPARE(a.rightJustified(0),(QString)"ABC");
+ − 1492
+ − 1493
QString n;
+ − 1494
QVERIFY(!n.rightJustified(3).isNull());
+ − 1495
QCOMPARE(a.rightJustified(4,'-',true),(QString)"-ABC");
+ − 1496
QCOMPARE(a.rightJustified(4,' ',true),(QString)" ABC");
+ − 1497
QCOMPARE(a.rightJustified(3,' ',true),(QString)"ABC");
+ − 1498
QCOMPARE(a.rightJustified(2,' ',true),(QString)"AB");
+ − 1499
QCOMPARE(a.rightJustified(1,' ',true),(QString)"A");
+ − 1500
QCOMPARE(a.rightJustified(0,' ',true),(QString)"");
+ − 1501
QCOMPARE(a,(QString)"ABC");
+ − 1502
}
+ − 1503
+ − 1504
void tst_QString::toUpper()
+ − 1505
{
+ − 1506
QCOMPARE( QString().toUpper(), QString() );
+ − 1507
QCOMPARE( QString("").toUpper(), QString("") );
+ − 1508
QCOMPARE( QString("text").toUpper(), QString("TEXT") );
+ − 1509
QCOMPARE( QString("Text").toUpper(), QString("TEXT") );
+ − 1510
QCOMPARE( QString("tExt").toUpper(), QString("TEXT") );
+ − 1511
QCOMPARE( QString("teXt").toUpper(), QString("TEXT") );
+ − 1512
QCOMPARE( QString("texT").toUpper(), QString("TEXT") );
+ − 1513
QCOMPARE( QString("TExt").toUpper(), QString("TEXT") );
+ − 1514
QCOMPARE( QString("teXT").toUpper(), QString("TEXT") );
+ − 1515
QCOMPARE( QString("tEXt").toUpper(), QString("TEXT") );
+ − 1516
QCOMPARE( QString("tExT").toUpper(), QString("TEXT") );
+ − 1517
QCOMPARE( QString("TEXT").toUpper(), QString("TEXT") );
+ − 1518
QCOMPARE( QString("@ABYZ[").toUpper(), QString("@ABYZ["));
+ − 1519
QCOMPARE( QString("@abyz[").toUpper(), QString("@ABYZ["));
+ − 1520
QCOMPARE( QString("`ABYZ{").toUpper(), QString("`ABYZ{"));
+ − 1521
QCOMPARE( QString("`abyz{").toUpper(), QString("`ABYZ{"));
+ − 1522
+ − 1523
QCOMPARE( QString(1, QChar(0xdf)).toUpper(), QString("SS"));
+ − 1524
+ − 1525
QString lower;
+ − 1526
lower += QChar(QChar::highSurrogate(0x10428));
+ − 1527
lower += QChar(QChar::lowSurrogate(0x10428));
+ − 1528
QString upper;
+ − 1529
upper += QChar(QChar::highSurrogate(0x10400));
+ − 1530
upper += QChar(QChar::lowSurrogate(0x10400));
+ − 1531
QCOMPARE( lower.toUpper(), upper);
+ − 1532
+ − 1533
+ − 1534
for (int i = 0; i < 65536; ++i) {
+ − 1535
QString str(1, QChar(i));
+ − 1536
QString upper = str.toUpper();
+ − 1537
QVERIFY(upper.length() >= 1);
+ − 1538
if (upper.length() == 1)
+ − 1539
QVERIFY(upper == QString(1, QChar(i).toUpper()));
+ − 1540
}
+ − 1541
}
+ − 1542
+ − 1543
void tst_QString::toLower()
+ − 1544
{
+ − 1545
QCOMPARE( QString().toLower(), QString() );
+ − 1546
QCOMPARE( QString("").toLower(), QString("") );
+ − 1547
QCOMPARE( QString("text").toLower(), QString("text") );
+ − 1548
QCOMPARE( QString("Text").toLower(), QString("text") );
+ − 1549
QCOMPARE( QString("tExt").toLower(), QString("text") );
+ − 1550
QCOMPARE( QString("teXt").toLower(), QString("text") );
+ − 1551
QCOMPARE( QString("texT").toLower(), QString("text") );
+ − 1552
QCOMPARE( QString("TExt").toLower(), QString("text") );
+ − 1553
QCOMPARE( QString("teXT").toLower(), QString("text") );
+ − 1554
QCOMPARE( QString("tEXt").toLower(), QString("text") );
+ − 1555
QCOMPARE( QString("tExT").toLower(), QString("text") );
+ − 1556
QCOMPARE( QString("TEXT").toLower(), QString("text") );
+ − 1557
QCOMPARE( QString("@ABYZ[").toLower(), QString("@abyz["));
+ − 1558
QCOMPARE( QString("@abyz[").toLower(), QString("@abyz["));
+ − 1559
QCOMPARE( QString("`ABYZ{").toLower(), QString("`abyz{"));
+ − 1560
QCOMPARE( QString("`abyz{").toLower(), QString("`abyz{"));
+ − 1561
+ − 1562
QCOMPARE( QString(1, QChar(0x130)).toLower(), QString(1, QChar(0x69)) + QChar(0x307));
+ − 1563
+ − 1564
QString lower;
+ − 1565
lower += QChar(QChar::highSurrogate(0x10428));
+ − 1566
lower += QChar(QChar::lowSurrogate(0x10428));
+ − 1567
QString upper;
+ − 1568
upper += QChar(QChar::highSurrogate(0x10400));
+ − 1569
upper += QChar(QChar::lowSurrogate(0x10400));
+ − 1570
QCOMPARE( upper.toLower(), lower);
+ − 1571
+ − 1572
for (int i = 0; i < 65536; ++i) {
+ − 1573
QString str(1, QChar(i));
+ − 1574
QString lower = str.toLower();
+ − 1575
QVERIFY(lower.length() >= 1);
+ − 1576
if (lower.length() == 1)
+ − 1577
QVERIFY(str.toLower() == QString(1, QChar(i).toLower()));
+ − 1578
}
+ − 1579
}
+ − 1580
+ − 1581
void tst_QString::trimmed()
+ − 1582
{
+ − 1583
QString a;
+ − 1584
a="Text";
+ − 1585
QCOMPARE(a,(QString)"Text");
+ − 1586
QCOMPARE(a.trimmed(),(QString)"Text");
+ − 1587
QCOMPARE(a,(QString)"Text");
+ − 1588
a=" ";
+ − 1589
QCOMPARE(a.trimmed(),(QString)"");
+ − 1590
QCOMPARE(a,(QString)" ");
+ − 1591
a=" a ";
+ − 1592
QCOMPARE(a.trimmed(),(QString)"a");
+ − 1593
}
+ − 1594
+ − 1595
void tst_QString::simplified()
+ − 1596
{
+ − 1597
QString j;
+ − 1598
j.simplified();
+ − 1599
+ − 1600
QString a;
+ − 1601
a = "a ";
+ − 1602
QCOMPARE(a.simplified(),(QString)"a");
+ − 1603
a=" a b ";
+ − 1604
QCOMPARE(a.simplified(),(QString)"a b");
+ − 1605
}
+ − 1606
+ − 1607
void tst_QString::insert()
+ − 1608
{
+ − 1609
QString a;
+ − 1610
+ − 1611
a = "Ys";
+ − 1612
QCOMPARE(a.insert(1,'e'), QString("Yes"));
+ − 1613
QCOMPARE(a.insert(3,'!'), QString("Yes!"));
+ − 1614
QCOMPARE(a.insert(5,'?'), QString("Yes! ?"));
+ − 1615
+ − 1616
a = "ABC";
+ − 1617
QCOMPARE(a.insert(5,"DEF"), QString("ABC DEF"));
+ − 1618
+ − 1619
a = "ABC";
+ − 1620
QCOMPARE(a.insert(2, QString()), QString("ABC"));
+ − 1621
QCOMPARE(a.insert(0,"ABC"), QString("ABCABC"));
+ − 1622
QCOMPARE(a, QString("ABCABC"));
+ − 1623
QCOMPARE(a.insert(0,a), QString("ABCABCABCABC"));
+ − 1624
+ − 1625
QCOMPARE(a, QString("ABCABCABCABC"));
+ − 1626
QCOMPARE(a.insert(0,'<'), QString("<ABCABCABCABC"));
+ − 1627
QCOMPARE(a.insert(1,'>'), QString("<>ABCABCABCABC"));
+ − 1628
+ − 1629
a = "Meal";
+ − 1630
QCOMPARE(a.insert(1, QLatin1String("ontr")), QString("Montreal"));
+ − 1631
QCOMPARE(a.insert(4, ""), QString("Montreal"));
+ − 1632
QCOMPARE(a.insert(3, QLatin1String("")), QString("Montreal"));
+ − 1633
QCOMPARE(a.insert(3, QLatin1String(0)), QString("Montreal"));
+ − 1634
QCOMPARE(a.insert(3, static_cast<const char *>(0)), QString("Montreal"));
+ − 1635
QCOMPARE(a.insert(0, QLatin1String("a")), QString("aMontreal"));
+ − 1636
}
+ − 1637
+ − 1638
void tst_QString::append()
+ − 1639
{
+ − 1640
QString a;
+ − 1641
a = "<>ABCABCABCABC";
+ − 1642
QCOMPARE(a.append(">"),(QString)"<>ABCABCABCABC>");
+ − 1643
#if 0
+ − 1644
#if !defined(QT_NO_STL)
+ − 1645
/*
+ − 1646
The std::string support is fairly trivial in itself. The major
+ − 1647
problem is whether it compiles or not, because of the way
+ − 1648
different compilers choose an overload based on the type of the
+ − 1649
argument. If it compiles, we're happy.
+ − 1650
*/
+ − 1651
std::string stroustrup;
+ − 1652
a.append( stroustrup );
+ − 1653
a += stroustrup;
+ − 1654
#endif
+ − 1655
#endif
+ − 1656
}
+ − 1657
+ − 1658
void tst_QString::append_bytearray_data()
+ − 1659
{
+ − 1660
QTest::addColumn<QString>("str" );
+ − 1661
QTest::addColumn<QByteArray>("ba" );
+ − 1662
QTest::addColumn<QString>("res" );
+ − 1663
+ − 1664
QByteArray ba( 5, 0 );
+ − 1665
ba[0] = 'a';
+ − 1666
ba[1] = 'b';
+ − 1667
ba[2] = 'c';
+ − 1668
ba[3] = 'd';
+ − 1669
#if 0
+ − 1670
ba[4] = 0;
+ − 1671
+ − 1672
for ( int i=0; i<2; i++ ) {
+ − 1673
// i == 0: the byte array is exactly strlen+1
+ − 1674
// i == 1: the byte array is larger than strlen+1
+ − 1675
QTest::newRow( QString("nullTerminated_%1_0").arg(i) ) << QString() << ba << QString("abcd");
+ − 1676
QTest::newRow( QString("nullTerminated_%1_1").arg(i) ) << QString("") << ba << QString("abcd");
+ − 1677
QTest::newRow( QString("nullTerminated_%1_2").arg(i) ) << QString("foobar ") << ba << QString("foobar abcd");
+ − 1678
+ − 1679
ba.resize( 8 );
+ − 1680
}
+ − 1681
#endif
+ − 1682
// no 0 termination
+ − 1683
ba.resize( 4 );
+ − 1684
QTest::newRow( "notTerminated_0" ) << QString() << ba << QString("abcd");
+ − 1685
QTest::newRow( "notTerminated_1" ) << QString("") << ba << QString("abcd");
+ − 1686
QTest::newRow( "notTerminated_2" ) << QString("foobar ") << ba << QString("foobar abcd");
+ − 1687
+ − 1688
// byte array with only a 0
+ − 1689
ba.resize( 1 );
+ − 1690
ba[0] = 0;
+ − 1691
QByteArray ba2("foobar ");
+ − 1692
ba2.append('\0');
+ − 1693
QTest::newRow( "emptyString" ) << QString("foobar ") << ba << QString(ba2);
+ − 1694
+ − 1695
// empty byte array
+ − 1696
ba.resize( 0 );
+ − 1697
QTest::newRow( "emptyByteArray" ) << QString("foobar ") << ba << QString("foobar ");
+ − 1698
}
+ − 1699
+ − 1700
void tst_QString::append_bytearray()
+ − 1701
{
+ − 1702
{
+ − 1703
QFETCH( QString, str );
+ − 1704
QFETCH( QByteArray, ba );
+ − 1705
+ − 1706
str.append( ba );
+ − 1707
+ − 1708
QTEST( str, "res" );
+ − 1709
}
+ − 1710
{
+ − 1711
QFETCH( QString, str );
+ − 1712
QFETCH( QByteArray, ba );
+ − 1713
+ − 1714
QTextCodec::setCodecForCStrings( QTextCodec::codecForMib(4) ); // Latin 1
+ − 1715
str.append( ba );
+ − 1716
QTextCodec::setCodecForCStrings( 0 );
+ − 1717
+ − 1718
QTEST( str, "res" );
+ − 1719
}
+ − 1720
}
+ − 1721
+ − 1722
void tst_QString::operator_pluseq_bytearray_data()
+ − 1723
{
+ − 1724
append_bytearray_data();
+ − 1725
}
+ − 1726
+ − 1727
void tst_QString::operator_pluseq_bytearray()
+ − 1728
{
+ − 1729
{
+ − 1730
QFETCH( QString, str );
+ − 1731
QFETCH( QByteArray, ba );
+ − 1732
+ − 1733
str += ba;
+ − 1734
+ − 1735
QTEST( str, "res" );
+ − 1736
}
+ − 1737
{
+ − 1738
QFETCH( QString, str );
+ − 1739
QFETCH( QByteArray, ba );
+ − 1740
+ − 1741
QTextCodec::setCodecForCStrings( QTextCodec::codecForMib(4) ); // Latin 1
+ − 1742
str += ba;
+ − 1743
QTextCodec::setCodecForCStrings( 0 );
+ − 1744
+ − 1745
QTEST( str, "res" );
+ − 1746
}
+ − 1747
}
+ − 1748
+ − 1749
void tst_QString::prepend()
+ − 1750
{
+ − 1751
QString a;
+ − 1752
a = "<>ABCABCABCABC>";
+ − 1753
QCOMPARE(a.prepend("-"),(QString)"-<>ABCABCABCABC>");
+ − 1754
#if 0
+ − 1755
#if !defined(QT_NO_STL)
+ − 1756
std::string stroustrup;
+ − 1757
a.prepend( stroustrup );
+ − 1758
#endif
+ − 1759
#endif
+ − 1760
}
+ − 1761
+ − 1762
void tst_QString::prepend_bytearray_data()
+ − 1763
{
+ − 1764
QTest::addColumn<QString>("str" );
+ − 1765
QTest::addColumn<QByteArray>("ba" );
+ − 1766
QTest::addColumn<QString>("res" );
+ − 1767
+ − 1768
QByteArray ba( 5, 0 );
+ − 1769
ba[0] = 'a';
+ − 1770
ba[1] = 'b';
+ − 1771
ba[2] = 'c';
+ − 1772
ba[3] = 'd';
+ − 1773
#if 0
+ − 1774
ba[4] = 0;
+ − 1775
+ − 1776
for ( int i=0; i<2; i++ ) {
+ − 1777
// i == 0: the byte array is exactly strlen+1
+ − 1778
// i == 1: the byte array is larger than strlen+1
+ − 1779
QTest::newRow( QString("nullTerminated_%1_0").arg(i) ) << QString() << ba << QString("abcd");
+ − 1780
QTest::newRow( QString("nullTerminated_%1_1").arg(i) ) << QString("") << ba << QString("abcd");
+ − 1781
QTest::newRow( QString("nullTerminated_%1_2").arg(i) ) << QString(" foobar") << ba << QString("abcd foobar");
+ − 1782
+ − 1783
ba.resize( 8 );
+ − 1784
}
+ − 1785
// no 0 termination
+ − 1786
ba.resize( 4 );
+ − 1787
QTest::newRow( "notTerminated_0" ) << QString() << ba << QString("abcd");
+ − 1788
QTest::newRow( "notTerminated_1" ) << QString("") << ba << QString("abcd");
+ − 1789
QTest::newRow( "notTerminated_2" ) << QString(" foobar") << ba << QString("abcd foobar");
+ − 1790
#endif
+ − 1791
+ − 1792
// byte array with only a 0
+ − 1793
ba.resize( 1 );
+ − 1794
ba[0] = 0;
+ − 1795
QTest::newRow( "emptyString" ) << QString("foobar ") << ba << QString("foobar ");
+ − 1796
+ − 1797
// empty byte array
+ − 1798
ba.resize( 0 );
+ − 1799
QTest::newRow( "emptyByteArray" ) << QString(" foobar") << ba << QString(" foobar");
+ − 1800
}
+ − 1801
+ − 1802
void tst_QString::prepend_bytearray()
+ − 1803
{
+ − 1804
{
+ − 1805
QFETCH( QString, str );
+ − 1806
QFETCH( QByteArray, ba );
+ − 1807
+ − 1808
str.prepend( ba );
+ − 1809
+ − 1810
QFETCH( QString, res );
+ − 1811
QCOMPARE( str, res );
+ − 1812
}
+ − 1813
{
+ − 1814
QFETCH( QString, str );
+ − 1815
QFETCH( QByteArray, ba );
+ − 1816
+ − 1817
QTextCodec::setCodecForCStrings( QTextCodec::codecForMib(4) ); // Latin 1
+ − 1818
str.prepend( ba );
+ − 1819
QTextCodec::setCodecForCStrings( 0 );
+ − 1820
+ − 1821
QTEST( str, "res" );
+ − 1822
}
+ − 1823
}
+ − 1824
+ − 1825
void tst_QString::replace_uint_uint()
+ − 1826
{
+ − 1827
QFETCH( QString, string );
+ − 1828
QFETCH( int, index );
+ − 1829
QFETCH( int, len );
+ − 1830
QFETCH( QString, after );
+ − 1831
+ − 1832
QString s1 = string;
+ − 1833
s1.replace( (uint) index, (int) len, after );
+ − 1834
QTEST( s1, "result" );
+ − 1835
+ − 1836
QString s2 = string;
+ − 1837
s2.replace( (uint) index, (uint) len, after.unicode(), after.length() );
+ − 1838
QTEST( s2, "result" );
+ − 1839
+ − 1840
if ( after.length() == 1 ) {
+ − 1841
QString s3 = string;
+ − 1842
s3.replace( (uint) index, (uint) len, QChar(after[0]) );
+ − 1843
QTEST( s3, "result" );
+ − 1844
+ − 1845
QString s4 = string;
+ − 1846
s4.replace( (uint) index, (uint) len, QChar(after[0]).toLatin1() );
+ − 1847
QTEST( s4, "result" );
+ − 1848
}
+ − 1849
}
+ − 1850
+ − 1851
void tst_QString::replace_uint_uint_extra()
+ − 1852
{
+ − 1853
/*
+ − 1854
This test is designed to be extremely slow if QString::replace() doesn't optimize the case
+ − 1855
len == after.size().
+ − 1856
*/
+ − 1857
QString str("dsfkljfdsjklsdjsfjklfsdjkldfjslkjsdfkllkjdsfjklsfdkjsdflkjlsdfjklsdfkjldsflkjsddlkj");
+ − 1858
for (int j = 1; j < 12; ++j)
+ − 1859
str += str;
+ − 1860
+ − 1861
QString str2("aaaaaaaaaaaaaaaaaaaa");
+ − 1862
for (int i = 0; i < 2000000; ++i) {
+ − 1863
str.replace(10, 20, str2);
+ − 1864
}
+ − 1865
+ − 1866
/*
+ − 1867
Make sure that replacing with itself works.
+ − 1868
*/
+ − 1869
QString copy(str);
+ − 1870
copy.detach();
+ − 1871
str.replace(0, str.length(), str);
+ − 1872
QVERIFY(copy == str);
+ − 1873
+ − 1874
/*
+ − 1875
Make sure that replacing a part of oneself with itself works.
+ − 1876
*/
+ − 1877
QString str3("abcdefghij");
+ − 1878
str3.replace(0, 1, str3);
+ − 1879
QCOMPARE(str3, QString("abcdefghijbcdefghij"));
+ − 1880
+ − 1881
QString str4("abcdefghij");
+ − 1882
str4.replace(1, 3, str4);
+ − 1883
QCOMPARE(str4, QString("aabcdefghijefghij"));
+ − 1884
+ − 1885
QString str5("abcdefghij");
+ − 1886
str5.replace(8, 10, str5);
+ − 1887
QCOMPARE(str5, QString("abcdefghabcdefghij"));
+ − 1888
}
+ − 1889
+ − 1890
void tst_QString::replace_string()
+ − 1891
{
+ − 1892
QFETCH( QString, string );
+ − 1893
QFETCH( QString, before );
+ − 1894
QFETCH( QString, after );
+ − 1895
QFETCH( bool, bcs );
+ − 1896
+ − 1897
Qt::CaseSensitivity cs = bcs ? Qt::CaseSensitive : Qt::CaseInsensitive;
+ − 1898
+ − 1899
if ( before.length() == 1 ) {
+ − 1900
QChar ch = before.at( 0 );
+ − 1901
+ − 1902
QString s1 = string;
+ − 1903
s1.replace( ch, after, cs );
+ − 1904
QTEST( s1, "result" );
+ − 1905
+ − 1906
if ( QChar(ch.toLatin1()) == ch ) {
+ − 1907
QString s2 = string;
+ − 1908
s2.replace( ch.toLatin1(), after, cs );
+ − 1909
QTEST( s2, "result" );
+ − 1910
}
+ − 1911
}
+ − 1912
+ − 1913
QString s3 = string;
+ − 1914
s3.replace( before, after, cs );
+ − 1915
QTEST( s3, "result" );
+ − 1916
+ − 1917
QString s4 = string;
+ − 1918
s4.replace( QRegExp(QRegExp::escape(before), cs), after );
+ − 1919
QTEST( s4, "result" );
+ − 1920
+ − 1921
QString s5 = string;
+ − 1922
s5.replace(QRegExp(before, cs, QRegExp::FixedString), after);
+ − 1923
QTEST( s5, "result" );
+ − 1924
}
+ − 1925
+ − 1926
void tst_QString::replace_regexp()
+ − 1927
{
+ − 1928
QFETCH( QString, string );
+ − 1929
QFETCH( QString, regexp );
+ − 1930
QFETCH( QString, after );
+ − 1931
+ − 1932
QString s2 = string;
+ − 1933
s2.replace( QRegExp(regexp), after );
+ − 1934
QTEST( s2, "result" );
+ − 1935
}
+ − 1936
+ − 1937
void tst_QString::remove_uint_uint()
+ − 1938
{
+ − 1939
QFETCH( QString, string );
+ − 1940
QFETCH( int, index );
+ − 1941
QFETCH( int, len );
+ − 1942
QFETCH( QString, after );
+ − 1943
+ − 1944
if ( after.length() == 0 ) {
+ − 1945
QString s1 = string;
+ − 1946
s1.remove( (uint) index, (uint) len );
+ − 1947
QTEST( s1, "result" );
+ − 1948
} else
+ − 1949
QCOMPARE( 0, 0 ); // shut QtTest
+ − 1950
}
+ − 1951
+ − 1952
void tst_QString::remove_string()
+ − 1953
{
+ − 1954
QFETCH( QString, string );
+ − 1955
QFETCH( QString, before );
+ − 1956
QFETCH( QString, after );
+ − 1957
QFETCH( bool, bcs );
+ − 1958
+ − 1959
Qt::CaseSensitivity cs = bcs ? Qt::CaseSensitive : Qt::CaseInsensitive;
+ − 1960
+ − 1961
if ( after.length() == 0 ) {
+ − 1962
if ( before.length() == 1 && cs ) {
+ − 1963
QChar ch = before.at( 0 );
+ − 1964
+ − 1965
QString s1 = string;
+ − 1966
s1.remove( ch );
+ − 1967
QTEST( s1, "result" );
+ − 1968
+ − 1969
if ( QChar(ch.toLatin1()) == ch ) {
+ − 1970
QString s2 = string;
+ − 1971
s2.remove( ch );
+ − 1972
QTEST( s2, "result" );
+ − 1973
}
+ − 1974
}
+ − 1975
+ − 1976
QString s3 = string;
+ − 1977
s3.remove( before, cs );
+ − 1978
QTEST( s3, "result" );
+ − 1979
+ − 1980
QString s4 = string;
+ − 1981
s4.replace( QRegExp(QRegExp::escape(before), cs), after );
+ − 1982
QTEST( s4, "result" );
+ − 1983
+ − 1984
QString s5 = string;
+ − 1985
s5.replace( QRegExp(before, cs, QRegExp::FixedString), after );
+ − 1986
QTEST( s5, "result" );
+ − 1987
} else {
+ − 1988
QCOMPARE( 0, 0 ); // shut QtTest
+ − 1989
}
+ − 1990
}
+ − 1991
+ − 1992
void tst_QString::remove_regexp()
+ − 1993
{
+ − 1994
QFETCH( QString, string );
+ − 1995
QFETCH( QString, regexp );
+ − 1996
QFETCH( QString, after );
+ − 1997
+ − 1998
if ( after.length() == 0 ) {
+ − 1999
string.remove( QRegExp(regexp) );
+ − 2000
QTEST( string, "result" );
+ − 2001
} else {
+ − 2002
QCOMPARE( 0, 0 ); // shut QtTest
+ − 2003
}
+ − 2004
}
+ − 2005
+ − 2006
void tst_QString::toNum()
+ − 2007
{
+ − 2008
#if defined (Q_WS_WIN) && defined (Q_CC_MSVC)
+ − 2009
#define TEST_TO_INT(num, func) \
+ − 2010
a = #num; \
+ − 2011
QVERIFY2(a.func(&ok) == num ## i64 && ok, "Failed: num=" #num ", func=" #func);
+ − 2012
#else
+ − 2013
#define TEST_TO_INT(num, func) \
+ − 2014
a = #num; \
+ − 2015
QVERIFY2(a.func(&ok) == num ## LL && ok, "Failed: num=" #num ", func=" #func);
+ − 2016
#endif
+ − 2017
+ − 2018
QString a;
+ − 2019
bool ok = false;
+ − 2020
+ − 2021
TEST_TO_INT(0, toInt)
+ − 2022
TEST_TO_INT(-1, toInt)
+ − 2023
TEST_TO_INT(1, toInt)
+ − 2024
TEST_TO_INT(2147483647, toInt)
+ − 2025
TEST_TO_INT(-2147483648, toInt)
+ − 2026
+ − 2027
TEST_TO_INT(0, toShort)
+ − 2028
TEST_TO_INT(-1, toShort)
+ − 2029
TEST_TO_INT(1, toShort)
+ − 2030
TEST_TO_INT(32767, toShort)
+ − 2031
TEST_TO_INT(-32768, toShort)
+ − 2032
+ − 2033
TEST_TO_INT(0, toLong)
+ − 2034
TEST_TO_INT(-1, toLong)
+ − 2035
TEST_TO_INT(1, toLong)
+ − 2036
TEST_TO_INT(2147483647, toLong)
+ − 2037
TEST_TO_INT(-2147483648, toLong)
+ − 2038
TEST_TO_INT(0, toLongLong)
+ − 2039
TEST_TO_INT(-1, toLongLong)
+ − 2040
TEST_TO_INT(1, toLongLong)
+ − 2041
TEST_TO_INT(9223372036854775807, toLongLong)
+ − 2042
TEST_TO_INT(-9223372036854775807, toLongLong)
+ − 2043
+ − 2044
#undef TEST_TO_INT
+ − 2045
+ − 2046
#if defined (Q_WS_WIN) && defined (Q_CC_MSVC)
+ − 2047
#define TEST_TO_UINT(num, func) \
+ − 2048
a = #num; \
+ − 2049
QVERIFY2(a.func(&ok) == num ## i64 && ok, "Failed: num=" #num ", func=" #func);
+ − 2050
#else
+ − 2051
#define TEST_TO_UINT(num, func) \
+ − 2052
a = #num; \
+ − 2053
QVERIFY2(a.func(&ok) == num ## ULL && ok, "Failed: num=" #num ", func=" #func);
+ − 2054
#endif
+ − 2055
+ − 2056
TEST_TO_UINT(0, toUInt)
+ − 2057
TEST_TO_UINT(1, toUInt)
+ − 2058
TEST_TO_UINT(4294967295, toUInt)
+ − 2059
+ − 2060
TEST_TO_UINT(0, toUShort)
+ − 2061
TEST_TO_UINT(1, toUShort)
+ − 2062
TEST_TO_UINT(65535, toUShort)
+ − 2063
+ − 2064
TEST_TO_UINT(0, toULong)
+ − 2065
TEST_TO_UINT(1, toULong)
+ − 2066
TEST_TO_UINT(4294967295, toULong)
+ − 2067
+ − 2068
TEST_TO_UINT(0, toULongLong)
+ − 2069
TEST_TO_UINT(1, toULongLong)
+ − 2070
TEST_TO_UINT(18446744073709551615, toULongLong)
+ − 2071
#undef TEST_TO_UINT
+ − 2072
+ − 2073
+ − 2074
#define TEST_BASE(str, base, num) \
+ − 2075
a = str; \
+ − 2076
QVERIFY2(a.toInt(&ok, base) == num && ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toInt"); \
+ − 2077
QVERIFY2(a.toUInt(&ok, base) == num && ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toUInt"); \
+ − 2078
QVERIFY2(a.toShort(&ok, base) == num && ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toShort"); \
+ − 2079
QVERIFY2(a.toUShort(&ok, base) == num && ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toUShort"); \
+ − 2080
QVERIFY2(a.toLong(&ok, base) == num && ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toLong"); \
+ − 2081
QVERIFY2(a.toULong(&ok, base) == num && ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toULong"); \
+ − 2082
QVERIFY2(a.toLongLong(&ok, base) == num && ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toLongLong"); \
+ − 2083
QVERIFY2(a.toULongLong(&ok, base) == num && ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toULongLong");
+ − 2084
+ − 2085
TEST_BASE("FF", 16, 255)
+ − 2086
TEST_BASE("0xFF", 16, 255)
+ − 2087
TEST_BASE("77", 8, 63)
+ − 2088
TEST_BASE("077", 8, 63)
+ − 2089
+ − 2090
TEST_BASE("0xFF", 0, 255)
+ − 2091
TEST_BASE("077", 0, 63)
+ − 2092
TEST_BASE("255", 0, 255)
+ − 2093
+ − 2094
TEST_BASE(" FF", 16, 255)
+ − 2095
TEST_BASE(" 0xFF", 16, 255)
+ − 2096
TEST_BASE(" 77", 8, 63)
+ − 2097
TEST_BASE(" 077", 8, 63)
+ − 2098
+ − 2099
TEST_BASE(" 0xFF", 0, 255)
+ − 2100
TEST_BASE(" 077", 0, 63)
+ − 2101
TEST_BASE(" 255", 0, 255)
+ − 2102
+ − 2103
TEST_BASE("\tFF\t", 16, 255)
+ − 2104
TEST_BASE("\t0xFF ", 16, 255)
+ − 2105
TEST_BASE(" 77 ", 8, 63)
+ − 2106
TEST_BASE("77 ", 8, 63)
+ − 2107
+ − 2108
#undef TEST_BASE
+ − 2109
+ − 2110
#define TEST_NEG_BASE(str, base, num) \
+ − 2111
a = str; \
+ − 2112
QVERIFY2(a.toInt(&ok, base) == num && ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toInt"); \
+ − 2113
QVERIFY2(a.toShort(&ok, base) == num && ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toShort"); \
+ − 2114
QVERIFY2(a.toLong(&ok, base) == num && ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toLong"); \
+ − 2115
QVERIFY2(a.toLongLong(&ok, base) == num && ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toLongLong");
+ − 2116
+ − 2117
TEST_NEG_BASE("-FE", 16, -254)
+ − 2118
TEST_NEG_BASE("-0xFE", 16, -254)
+ − 2119
TEST_NEG_BASE("-77", 8, -63)
+ − 2120
TEST_NEG_BASE("-077", 8, -63)
+ − 2121
+ − 2122
TEST_NEG_BASE("-0xFE", 0, -254)
+ − 2123
TEST_NEG_BASE("-077", 0, -63)
+ − 2124
TEST_NEG_BASE("-254", 0, -254)
+ − 2125
+ − 2126
#undef TEST_NEG_BASE
+ − 2127
+ − 2128
#define TEST_DOUBLE(num, str) \
+ − 2129
a = str; \
+ − 2130
QCOMPARE(a.toDouble(&ok), num); \
+ − 2131
QVERIFY(ok);
+ − 2132
+ − 2133
TEST_DOUBLE(1.2345, "1.2345")
+ − 2134
TEST_DOUBLE(12.345, "1.2345e+01")
+ − 2135
TEST_DOUBLE(12.345, "1.2345E+01")
+ − 2136
TEST_DOUBLE(12345.6, "12345.6")
+ − 2137
+ − 2138
#undef TEST_DOUBLE
+ − 2139
+ − 2140
+ − 2141
#define TEST_BAD(str, func) \
+ − 2142
a = str; \
+ − 2143
a.func(&ok); \
+ − 2144
QVERIFY2(!ok, "Failed: str=" #str " func=" #func);
+ − 2145
+ − 2146
TEST_BAD("32768", toShort)
+ − 2147
TEST_BAD("-32769", toShort)
+ − 2148
TEST_BAD("65536", toUShort)
+ − 2149
TEST_BAD("2147483648", toInt)
+ − 2150
TEST_BAD("-2147483649", toInt)
+ − 2151
TEST_BAD("4294967296", toUInt)
+ − 2152
if (sizeof(long) == 4) {
+ − 2153
TEST_BAD("2147483648", toLong)
+ − 2154
TEST_BAD("-2147483649", toLong)
+ − 2155
TEST_BAD("4294967296", toULong)
+ − 2156
}
+ − 2157
TEST_BAD("9223372036854775808", toLongLong)
+ − 2158
TEST_BAD("-9223372036854775809", toLongLong)
+ − 2159
TEST_BAD("18446744073709551616", toULongLong)
+ − 2160
TEST_BAD("-1", toUShort)
+ − 2161
TEST_BAD("-1", toUInt)
+ − 2162
TEST_BAD("-1", toULong)
+ − 2163
TEST_BAD("-1", toULongLong)
+ − 2164
#undef TEST_BAD
+ − 2165
+ − 2166
#define TEST_BAD_ALL(str) \
+ − 2167
a = str; \
+ − 2168
a.toShort(&ok); \
+ − 2169
QVERIFY2(!ok, "Failed: str=" #str); \
+ − 2170
a.toUShort(&ok); \
+ − 2171
QVERIFY2(!ok, "Failed: str=" #str); \
+ − 2172
a.toInt(&ok); \
+ − 2173
QVERIFY2(!ok, "Failed: str=" #str); \
+ − 2174
a.toUInt(&ok); \
+ − 2175
QVERIFY2(!ok, "Failed: str=" #str); \
+ − 2176
a.toLong(&ok); \
+ − 2177
QVERIFY2(!ok, "Failed: str=" #str); \
+ − 2178
a.toULong(&ok); \
+ − 2179
QVERIFY2(!ok, "Failed: str=" #str); \
+ − 2180
a.toLongLong(&ok); \
+ − 2181
QVERIFY2(!ok, "Failed: str=" #str); \
+ − 2182
a.toULongLong(&ok); \
+ − 2183
QVERIFY2(!ok, "Failed: str=" #str); \
+ − 2184
a.toFloat(&ok); \
+ − 2185
QVERIFY2(!ok, "Failed: str=" #str); \
+ − 2186
a.toDouble(&ok); \
+ − 2187
QVERIFY2(!ok, "Failed: str=" #str);
+ − 2188
+ − 2189
TEST_BAD_ALL((const char*)0);
+ − 2190
TEST_BAD_ALL("");
+ − 2191
TEST_BAD_ALL(" ");
+ − 2192
TEST_BAD_ALL(".");
+ − 2193
TEST_BAD_ALL("-");
+ − 2194
TEST_BAD_ALL("hello");
+ − 2195
TEST_BAD_ALL("1.2.3");
+ − 2196
TEST_BAD_ALL("0x0x0x");
+ − 2197
TEST_BAD_ALL("123-^~<");
+ − 2198
TEST_BAD_ALL("123ThisIsNotANumber");
+ − 2199
+ − 2200
#undef TEST_BAD_ALL
+ − 2201
+ − 2202
a = "FF";
+ − 2203
a.toULongLong(&ok, 10);
+ − 2204
QVERIFY(!ok);
+ − 2205
+ − 2206
a = "FF";
+ − 2207
a.toULongLong(&ok, 0);
+ − 2208
QVERIFY(!ok);
+ − 2209
+ − 2210
#ifdef QT_NO_FPU
+ − 2211
double d = 3.40282346638528e+38; // slightly off FLT_MAX when using hardfloats
+ − 2212
#else
+ − 2213
double d = 3.4028234663852886e+38; // FLT_MAX
+ − 2214
#endif
+ − 2215
QString::number(d, 'e', 17).toFloat(&ok);
+ − 2216
QVERIFY(ok);
+ − 2217
QString::number(d + 1e32, 'e', 17).toFloat(&ok);
+ − 2218
QVERIFY(!ok);
+ − 2219
QString::number(-d, 'e', 17).toFloat(&ok);
+ − 2220
QVERIFY(ok);
+ − 2221
QString::number(-d - 1e32, 'e', 17).toFloat(&ok);
+ − 2222
QVERIFY(!ok);
+ − 2223
QString::number(d + 1e32, 'e', 17).toDouble(&ok);
+ − 2224
QVERIFY(ok);
+ − 2225
QString::number(-d - 1e32, 'e', 17).toDouble(&ok);
+ − 2226
QVERIFY(ok);
+ − 2227
}
+ − 2228
+ − 2229
void tst_QString::toUShort()
+ − 2230
{
+ − 2231
QString a;
+ − 2232
bool ok;
+ − 2233
QCOMPARE(a.toUShort(),(ushort)0);
+ − 2234
QCOMPARE(a.toUShort(&ok),(ushort)0);
+ − 2235
QVERIFY(!ok);
+ − 2236
+ − 2237
a="";
+ − 2238
QCOMPARE(a.toUShort(),(ushort)0);
+ − 2239
QCOMPARE(a.toUShort(&ok),(ushort)0);
+ − 2240
QVERIFY(!ok);
+ − 2241
+ − 2242
a="COMPARE";
+ − 2243
QCOMPARE(a.toUShort(),(ushort)0);
+ − 2244
QCOMPARE(a.toUShort(&ok),(ushort)0);
+ − 2245
QVERIFY(!ok);
+ − 2246
+ − 2247
a="123";
+ − 2248
QCOMPARE(a.toUShort(),(ushort)123);
+ − 2249
QCOMPARE(a.toUShort(&ok),(ushort)123);
+ − 2250
QVERIFY(ok);
+ − 2251
+ − 2252
a="123A";
+ − 2253
QCOMPARE(a.toUShort(),(ushort)0);
+ − 2254
QCOMPARE(a.toUShort(&ok),(ushort)0);
+ − 2255
QVERIFY(!ok);
+ − 2256
+ − 2257
a="1234567";
+ − 2258
QCOMPARE(a.toUShort(),(ushort)0);
+ − 2259
QCOMPARE(a.toUShort(&ok),(ushort)0);
+ − 2260
QVERIFY(!ok);
+ − 2261
+ − 2262
a = "aaa123aaa";
+ − 2263
QCOMPARE(a.toUShort(),(ushort)0);
+ − 2264
QCOMPARE(a.toUShort(&ok),(ushort)0);
+ − 2265
QVERIFY(!ok);
+ − 2266
+ − 2267
a = "aaa123";
+ − 2268
QCOMPARE(a.toUShort(),(ushort)0);
+ − 2269
QCOMPARE(a.toUShort(&ok),(ushort)0);
+ − 2270
QVERIFY(!ok);
+ − 2271
+ − 2272
a = "123aaa";
+ − 2273
QCOMPARE(a.toUShort(),(ushort)0);
+ − 2274
QCOMPARE(a.toUShort(&ok),(ushort)0);
+ − 2275
QVERIFY(!ok);
+ − 2276
+ − 2277
a = "32767";
+ − 2278
QCOMPARE(a.toUShort(),(ushort)32767);
+ − 2279
QCOMPARE(a.toUShort(&ok),(ushort)32767);
+ − 2280
QVERIFY(ok);
+ − 2281
+ − 2282
a = "-32767";
+ − 2283
QCOMPARE(a.toUShort(),(ushort)0);
+ − 2284
QCOMPARE(a.toUShort(&ok),(ushort)0);
+ − 2285
QVERIFY(!ok);
+ − 2286
+ − 2287
a = "65535";
+ − 2288
QCOMPARE(a.toUShort(),(ushort)65535);
+ − 2289
QCOMPARE(a.toUShort(&ok),(ushort)65535);
+ − 2290
QVERIFY(ok);
+ − 2291
+ − 2292
if (sizeof(short) == 2) {
+ − 2293
a = "65536";
+ − 2294
QCOMPARE(a.toUShort(),(ushort)0);
+ − 2295
QCOMPARE(a.toUShort(&ok),(ushort)0);
+ − 2296
QVERIFY(!ok);
+ − 2297
+ − 2298
a = "123456";
+ − 2299
QCOMPARE(a.toUShort(),(ushort)0);
+ − 2300
QCOMPARE(a.toUShort(&ok),(ushort)0);
+ − 2301
QVERIFY(!ok);
+ − 2302
}
+ − 2303
}
+ − 2304
+ − 2305
void tst_QString::toShort()
+ − 2306
{
+ − 2307
QString a;
+ − 2308
bool ok;
+ − 2309
QCOMPARE(a.toShort(),(short)0);
+ − 2310
QCOMPARE(a.toShort(&ok),(short)0);
+ − 2311
QVERIFY(!ok);
+ − 2312
+ − 2313
a="";
+ − 2314
QCOMPARE(a.toShort(),(short)0);
+ − 2315
QCOMPARE(a.toShort(&ok),(short)0);
+ − 2316
QVERIFY(!ok);
+ − 2317
+ − 2318
a="COMPARE";
+ − 2319
QCOMPARE(a.toShort(),(short)0);
+ − 2320
QCOMPARE(a.toShort(&ok),(short)0);
+ − 2321
QVERIFY(!ok);
+ − 2322
+ − 2323
a="123";
+ − 2324
QCOMPARE(a.toShort(),(short)123);
+ − 2325
QCOMPARE(a.toShort(&ok),(short)123);
+ − 2326
QVERIFY(ok);
+ − 2327
+ − 2328
a="123A";
+ − 2329
QCOMPARE(a.toShort(),(short)0);
+ − 2330
QCOMPARE(a.toShort(&ok),(short)0);
+ − 2331
QVERIFY(!ok);
+ − 2332
+ − 2333
a="1234567";
+ − 2334
QCOMPARE(a.toShort(),(short)0);
+ − 2335
QCOMPARE(a.toShort(&ok),(short)0);
+ − 2336
QVERIFY(!ok);
+ − 2337
+ − 2338
a = "aaa123aaa";
+ − 2339
QCOMPARE(a.toShort(),(short)0);
+ − 2340
QCOMPARE(a.toShort(&ok),(short)0);
+ − 2341
QVERIFY(!ok);
+ − 2342
+ − 2343
a = "aaa123";
+ − 2344
QCOMPARE(a.toShort(),(short)0);
+ − 2345
QCOMPARE(a.toShort(&ok),(short)0);
+ − 2346
QVERIFY(!ok);
+ − 2347
+ − 2348
a = "123aaa";
+ − 2349
QCOMPARE(a.toShort(),(short)0);
+ − 2350
QCOMPARE(a.toShort(&ok),(short)0);
+ − 2351
QVERIFY(!ok);
+ − 2352
+ − 2353
a = "32767";
+ − 2354
QCOMPARE(a.toShort(),(short)32767);
+ − 2355
QCOMPARE(a.toShort(&ok),(short)32767);
+ − 2356
QVERIFY(ok);
+ − 2357
+ − 2358
a = "-32767";
+ − 2359
QCOMPARE(a.toShort(),(short)-32767);
+ − 2360
QCOMPARE(a.toShort(&ok),(short)-32767);
+ − 2361
QVERIFY(ok);
+ − 2362
+ − 2363
a = "-32768";
+ − 2364
QCOMPARE(a.toShort(),(short)-32768);
+ − 2365
QCOMPARE(a.toShort(&ok),(short)-32768);
+ − 2366
QVERIFY(ok);
+ − 2367
+ − 2368
if (sizeof(short) == 2) {
+ − 2369
a = "32768";
+ − 2370
QCOMPARE(a.toShort(),(short)0);
+ − 2371
QCOMPARE(a.toShort(&ok),(short)0);
+ − 2372
QVERIFY(!ok);
+ − 2373
+ − 2374
a = "-32769";
+ − 2375
QCOMPARE(a.toShort(),(short)0);
+ − 2376
QCOMPARE(a.toShort(&ok),(short)0);
+ − 2377
QVERIFY(!ok);
+ − 2378
}
+ − 2379
}
+ − 2380
+ − 2381
void tst_QString::toInt()
+ − 2382
{
+ − 2383
QString a;
+ − 2384
bool ok;
+ − 2385
QCOMPARE(a.toInt(),0);
+ − 2386
QCOMPARE(a.toInt(&ok),0);
+ − 2387
QVERIFY(!ok);
+ − 2388
+ − 2389
a = "";
+ − 2390
QCOMPARE(a.toInt(),0);
+ − 2391
QCOMPARE(a.toInt(&ok),0);
+ − 2392
QVERIFY(!ok);
+ − 2393
+ − 2394
a="COMPARE";
+ − 2395
QCOMPARE(a.toInt(),0);
+ − 2396
QCOMPARE(a.toInt(&ok),0);
+ − 2397
QVERIFY(!ok);
+ − 2398
+ − 2399
a="123";
+ − 2400
QCOMPARE(a.toInt(),123);
+ − 2401
QCOMPARE(a.toInt(&ok),123);
+ − 2402
QVERIFY(ok);
+ − 2403
+ − 2404
a="123A";
+ − 2405
QCOMPARE(a.toInt(),0);
+ − 2406
QCOMPARE(a.toInt(&ok),0);
+ − 2407
QVERIFY(!ok);
+ − 2408
+ − 2409
a="1234567";
+ − 2410
QCOMPARE(a.toInt(),1234567);
+ − 2411
QCOMPARE(a.toInt(&ok),1234567);
+ − 2412
QVERIFY(ok);
+ − 2413
+ − 2414
a="12345678901234";
+ − 2415
QCOMPARE(a.toInt(),0);
+ − 2416
QCOMPARE(a.toInt(&ok),0);
+ − 2417
QVERIFY(!ok);
+ − 2418
+ − 2419
a="3234567890";
+ − 2420
QCOMPARE(a.toInt(),0);
+ − 2421
QCOMPARE(a.toInt(&ok),0);
+ − 2422
QVERIFY(!ok);
+ − 2423
+ − 2424
a = "aaa12345aaa";
+ − 2425
QCOMPARE(a.toInt(),0);
+ − 2426
QCOMPARE(a.toInt(&ok),0);
+ − 2427
QVERIFY(!ok);
+ − 2428
+ − 2429
a = "aaa12345";
+ − 2430
QCOMPARE(a.toInt(),0);
+ − 2431
QCOMPARE(a.toInt(&ok),0);
+ − 2432
QVERIFY(!ok);
+ − 2433
+ − 2434
a = "12345aaa";
+ − 2435
QCOMPARE(a.toInt(),0);
+ − 2436
QCOMPARE(a.toInt(&ok),0);
+ − 2437
QVERIFY(!ok);
+ − 2438
+ − 2439
a = "2147483647"; // 2**31 - 1
+ − 2440
QCOMPARE(a.toInt(),2147483647);
+ − 2441
QCOMPARE(a.toInt(&ok),2147483647);
+ − 2442
QVERIFY(ok);
+ − 2443
+ − 2444
if (sizeof(int) == 4) {
+ − 2445
a = "-2147483647"; // -(2**31 - 1)
+ − 2446
QCOMPARE(a.toInt(),-2147483647);
+ − 2447
QCOMPARE(a.toInt(&ok),-2147483647);
+ − 2448
QVERIFY(ok);
+ − 2449
+ − 2450
a = "2147483648"; // 2**31
+ − 2451
QCOMPARE(a.toInt(),0);
+ − 2452
QCOMPARE(a.toInt(&ok),0);
+ − 2453
QVERIFY(!ok);
+ − 2454
+ − 2455
a = "-2147483648"; // -2**31
+ − 2456
QCOMPARE(a.toInt(),-2147483647 - 1);
+ − 2457
QCOMPARE(a.toInt(&ok),-2147483647 - 1);
+ − 2458
QVERIFY(ok);
+ − 2459
+ − 2460
a = "2147483649"; // 2**31 + 1
+ − 2461
QCOMPARE(a.toInt(),0);
+ − 2462
QCOMPARE(a.toInt(&ok),0);
+ − 2463
QVERIFY(!ok);
+ − 2464
}
+ − 2465
}
+ − 2466
+ − 2467
void tst_QString::toUInt()
+ − 2468
{
+ − 2469
bool ok;
+ − 2470
QString a;
+ − 2471
a="3234567890";
+ − 2472
QCOMPARE(a.toUInt(&ok),3234567890u);
+ − 2473
QVERIFY(ok);
+ − 2474
+ − 2475
a = "-50";
+ − 2476
QCOMPARE(a.toUInt(),0u);
+ − 2477
QCOMPARE(a.toUInt(&ok),0u);
+ − 2478
QVERIFY(!ok);
+ − 2479
+ − 2480
a = "4294967295"; // 2**32 - 1
+ − 2481
QCOMPARE(a.toUInt(),4294967295u);
+ − 2482
QCOMPARE(a.toUInt(&ok),4294967295u);
+ − 2483
QVERIFY(ok);
+ − 2484
+ − 2485
if (sizeof(int) == 4) {
+ − 2486
a = "4294967296"; // 2**32
+ − 2487
QCOMPARE(a.toUInt(),0u);
+ − 2488
QCOMPARE(a.toUInt(&ok),0u);
+ − 2489
QVERIFY(!ok);
+ − 2490
}
+ − 2491
}
+ − 2492
+ − 2493
///////////////////////////// to*Long //////////////////////////////////////
+ − 2494
+ − 2495
void tst_QString::toULong_data()
+ − 2496
{
+ − 2497
QTest::addColumn<QString>("str" );
+ − 2498
QTest::addColumn<int>("base" );
+ − 2499
QTest::addColumn<ulong>("result" );
+ − 2500
QTest::addColumn<bool>("ok" );
+ − 2501
+ − 2502
QTest::newRow( "default" ) << QString() << 10 << 0UL << false;
+ − 2503
QTest::newRow( "empty" ) << QString("") << 10 << 0UL << false;
+ − 2504
QTest::newRow( "ulong1" ) << QString("3234567890") << 10 << 3234567890UL << true;
+ − 2505
QTest::newRow( "ulong2" ) << QString("fFFfFfFf") << 16 << 0xFFFFFFFFUL << true;
+ − 2506
}
+ − 2507
+ − 2508
void tst_QString::toULong()
+ − 2509
{
+ − 2510
QFETCH( QString, str );
+ − 2511
QFETCH( int, base );
+ − 2512
QFETCH( ulong, result );
+ − 2513
QFETCH( bool, ok );
+ − 2514
+ − 2515
bool b;
+ − 2516
QCOMPARE( str.toULong( 0, base ), result );
+ − 2517
QCOMPARE( str.toULong( &b, base ), result );
+ − 2518
QCOMPARE( b, ok );
+ − 2519
}
+ − 2520
+ − 2521
void tst_QString::toLong_data()
+ − 2522
{
+ − 2523
QTest::addColumn<QString>("str" );
+ − 2524
QTest::addColumn<int>("base" );
+ − 2525
QTest::addColumn<long>("result" );
+ − 2526
QTest::addColumn<bool>("ok" );
+ − 2527
+ − 2528
QTest::newRow( "default" ) << QString() << 10 << 0L << false;
+ − 2529
QTest::newRow( "empty" ) << QString("") << 10 << 0L << false;
+ − 2530
QTest::newRow( "normal" ) << QString("7fFFfFFf") << 16 << 0x7fFFfFFfL << true;
+ − 2531
QTest::newRow( "long_max" ) << QString("2147483647") << 10 << 2147483647L << true;
+ − 2532
if (sizeof(long) == 4) {
+ − 2533
QTest::newRow( "long_max+1" ) << QString("2147483648") << 10 << 0L << false;
+ − 2534
QTest::newRow( "long_min-1" ) << QString("-80000001") << 16 << 0L << false;
+ − 2535
}
+ − 2536
QTest::newRow( "negative" ) << QString("-7fffffff") << 16 << -0x7fffffffL << true;
+ − 2537
// QTest::newRow( "long_min" ) << QString("-80000000") << 16 << 0x80000000uL << true;
+ − 2538
}
+ − 2539
+ − 2540
void tst_QString::toLong()
+ − 2541
{
+ − 2542
QFETCH( QString, str );
+ − 2543
QFETCH( int, base );
+ − 2544
QFETCH( long, result );
+ − 2545
QFETCH( bool, ok );
+ − 2546
+ − 2547
bool b;
+ − 2548
QCOMPARE( str.toLong( 0, base ), result );
+ − 2549
QCOMPARE( str.toLong( &b, base ), result );
+ − 2550
QCOMPARE( b, ok );
+ − 2551
}
+ − 2552
+ − 2553
+ − 2554
////////////////////////// to*LongLong //////////////////////////////////////
+ − 2555
+ − 2556
void tst_QString::toULongLong()
+ − 2557
{
+ − 2558
QString str;
+ − 2559
bool ok;
+ − 2560
str = "18446744073709551615"; // ULLONG_MAX
+ − 2561
QCOMPARE( str.toULongLong( 0 ), Q_UINT64_C(18446744073709551615) );
+ − 2562
QCOMPARE( str.toULongLong( &ok ), Q_UINT64_C(18446744073709551615) );
+ − 2563
QVERIFY( ok );
+ − 2564
+ − 2565
str = "18446744073709551616"; // ULLONG_MAX + 1
+ − 2566
QCOMPARE( str.toULongLong( 0 ), Q_UINT64_C(0) );
+ − 2567
QCOMPARE( str.toULongLong( &ok ), Q_UINT64_C(0) );
+ − 2568
QVERIFY( !ok );
+ − 2569
+ − 2570
str = "-150";
+ − 2571
QCOMPARE( str.toULongLong( 0 ), Q_UINT64_C(0) );
+ − 2572
QCOMPARE( str.toULongLong( &ok ), Q_UINT64_C(0) );
+ − 2573
QVERIFY( !ok );
+ − 2574
}
+ − 2575
+ − 2576
void tst_QString::toLongLong()
+ − 2577
{
+ − 2578
QString str;
+ − 2579
bool ok;
+ − 2580
+ − 2581
str = "9223372036854775807"; // LLONG_MAX
+ − 2582
QCOMPARE( str.toLongLong( 0 ), Q_INT64_C(9223372036854775807) );
+ − 2583
QCOMPARE( str.toLongLong( &ok ), Q_INT64_C(9223372036854775807) );
+ − 2584
QVERIFY( ok );
+ − 2585
+ − 2586
str = "-9223372036854775808"; // LLONG_MIN
+ − 2587
QCOMPARE( str.toLongLong( 0 ),
+ − 2588
-Q_INT64_C(9223372036854775807) - Q_INT64_C(1) );
+ − 2589
QCOMPARE( str.toLongLong( &ok ),
+ − 2590
-Q_INT64_C(9223372036854775807) - Q_INT64_C(1) );
+ − 2591
QVERIFY( ok );
+ − 2592
+ − 2593
str = "aaaa9223372036854775807aaaa";
+ − 2594
QCOMPARE( str.toLongLong( 0 ), Q_INT64_C(0) );
+ − 2595
QCOMPARE( str.toLongLong( &ok ), Q_INT64_C(0) );
+ − 2596
QVERIFY( !ok );
+ − 2597
+ − 2598
str = "9223372036854775807aaaa";
+ − 2599
QCOMPARE( str.toLongLong( 0 ), Q_INT64_C(0) );
+ − 2600
QCOMPARE( str.toLongLong( &ok ), Q_INT64_C(0) );
+ − 2601
QVERIFY( !ok );
+ − 2602
+ − 2603
str = "aaaa9223372036854775807";
+ − 2604
QCOMPARE( str.toLongLong( 0 ), Q_INT64_C(0) );
+ − 2605
QCOMPARE( str.toLongLong( &ok ), Q_INT64_C(0) );
+ − 2606
QVERIFY( !ok );
+ − 2607
+ − 2608
static char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ − 2609
+ − 2610
for (int i = 0; i < 36; ++i) {
+ − 2611
for (int j = 0; j < 36; ++j) {
+ − 2612
for (int k = 0; k < 36; ++k) {
+ − 2613
QString str;
+ − 2614
str += QChar(digits[i]);
+ − 2615
str += QChar(digits[j]);
+ − 2616
str += QChar(digits[k]);
+ − 2617
qlonglong value = (((i * 36) + j) * 36) + k;
+ − 2618
QVERIFY(str.toLongLong(0, 36) == value);
+ − 2619
}
+ − 2620
}
+ − 2621
}
+ − 2622
}
+ − 2623
+ − 2624
////////////////////////////////////////////////////////////////////////////
+ − 2625
+ − 2626
void tst_QString::toFloat()
+ − 2627
{
+ − 2628
QString a;
+ − 2629
bool ok;
+ − 2630
a="0.000000000931322574615478515625";
+ − 2631
QCOMPARE(a.toFloat(&ok),(float)(0.000000000931322574615478515625));
+ − 2632
QVERIFY(ok);
+ − 2633
}
+ − 2634
+ − 2635
void tst_QString::toDouble_data()
+ − 2636
{
+ − 2637
QTest::addColumn<QString>("str" );
+ − 2638
QTest::addColumn<double>("result" );
+ − 2639
QTest::addColumn<bool>("result_ok" );
+ − 2640
+ − 2641
QTest::newRow( "ok00" ) << QString("0.000000000931322574615478515625") << 0.000000000931322574615478515625 << true;
+ − 2642
QTest::newRow( "ok01" ) << QString(" 123.45") << 123.45 << true;
+ − 2643
+ − 2644
QTest::newRow( "ok02" ) << QString("0.1e10") << 0.1e10 << true;
+ − 2645
QTest::newRow( "ok03" ) << QString("0.1e-10") << 0.1e-10 << true;
+ − 2646
+ − 2647
QTest::newRow( "ok04" ) << QString("1e10") << 1.0e10 << true;
+ − 2648
QTest::newRow( "ok05" ) << QString("1e+10") << 1.0e10 << true;
+ − 2649
QTest::newRow( "ok06" ) << QString("1e-10") << 1.0e-10 << true;
+ − 2650
+ − 2651
QTest::newRow( "ok07" ) << QString(" 1e10") << 1.0e10 << true;
+ − 2652
QTest::newRow( "ok08" ) << QString(" 1e+10") << 1.0e10 << true;
+ − 2653
QTest::newRow( "ok09" ) << QString(" 1e-10") << 1.0e-10 << true;
+ − 2654
+ − 2655
QTest::newRow( "ok10" ) << QString("1.") << 1.0 << true;
+ − 2656
QTest::newRow( "ok11" ) << QString(".1") << 0.1 << true;
+ − 2657
+ − 2658
QTest::newRow( "wrong00" ) << QString("123.45 ") << 123.45 << true;
+ − 2659
QTest::newRow( "wrong01" ) << QString(" 123.45 ") << 123.45 << true;
+ − 2660
+ − 2661
QTest::newRow( "wrong02" ) << QString("aa123.45aa") << 0.0 << false;
+ − 2662
QTest::newRow( "wrong03" ) << QString("123.45aa") << 0.0 << false;
+ − 2663
QTest::newRow( "wrong04" ) << QString("123erf") << 0.0 << false;
+ − 2664
+ − 2665
QTest::newRow( "wrong05" ) << QString("abc") << 0.0 << false;
+ − 2666
QTest::newRow( "wrong06" ) << QString() << 0.0 << false;
+ − 2667
QTest::newRow( "wrong07" ) << QString("") << 0.0 << false;
+ − 2668
}
+ − 2669
+ − 2670
void tst_QString::toDouble()
+ − 2671
{
+ − 2672
QFETCH( QString, str );
+ − 2673
QFETCH( bool, result_ok );
+ − 2674
bool ok;
+ − 2675
double d = str.toDouble( &ok );
+ − 2676
if ( result_ok ) {
+ − 2677
QTEST( d, "result" );
+ − 2678
QVERIFY( ok );
+ − 2679
} else {
+ − 2680
QVERIFY( !ok );
+ − 2681
}
+ − 2682
}
+ − 2683
+ − 2684
void tst_QString::setNum()
+ − 2685
{
+ − 2686
QString a;
+ − 2687
QCOMPARE(a.setNum(123),(QString)"123");
+ − 2688
QCOMPARE(a.setNum(-123),(QString)"-123");
+ − 2689
QCOMPARE(a.setNum(0x123,16),(QString)"123");
+ − 2690
QCOMPARE(a.setNum((short)123),(QString)"123");
+ − 2691
QCOMPARE(a.setNum(123L),(QString)"123");
+ − 2692
QCOMPARE(a.setNum(123UL),(QString)"123");
+ − 2693
QCOMPARE(a.setNum(2147483647L), QString("2147483647")); // 32 bit LONG_MAX
+ − 2694
QCOMPARE(a.setNum(-2147483647L), QString("-2147483647")); // LONG_MIN + 1
+ − 2695
QCOMPARE(a.setNum(-2147483647L-1L), QString("-2147483648")); // LONG_MIN
+ − 2696
QCOMPARE(a.setNum(1.23), QString("1.23"));
+ − 2697
QCOMPARE(a.setNum(1.234567), QString("1.23457"));
+ − 2698
#if defined(LONG_MAX) && defined(LLONG_MAX) && LONG_MAX == LLONG_MAX
+ − 2699
// LONG_MAX and LONG_MIN on 64 bit systems
+ − 2700
QCOMPARE(a.setNum(9223372036854775807L), QString("9223372036854775807"));
+ − 2701
QCOMPARE(a.setNum(-9223372036854775807L-1L), QString("-9223372036854775808"));
+ − 2702
QCOMPARE(a.setNum(18446744073709551615UL), QString("18446744073709551615"));
+ − 2703
#endif
+ − 2704
QCOMPARE(a.setNum(Q_INT64_C(123)), QString("123"));
+ − 2705
// 2^40 == 1099511627776
+ − 2706
QCOMPARE(a.setNum(Q_INT64_C(-1099511627776)), QString("-1099511627776"));
+ − 2707
QCOMPARE(a.setNum(Q_UINT64_C(1099511627776)), QString("1099511627776"));
+ − 2708
QCOMPARE(a.setNum(Q_INT64_C(9223372036854775807)), // LLONG_MAX
+ − 2709
QString("9223372036854775807"));
+ − 2710
QCOMPARE(a.setNum(-Q_INT64_C(9223372036854775807) - Q_INT64_C(1)),
+ − 2711
QString("-9223372036854775808"));
+ − 2712
QCOMPARE(a.setNum(Q_UINT64_C(18446744073709551615)), // ULLONG_MAX
+ − 2713
QString("18446744073709551615"));
+ − 2714
QCOMPARE(a.setNum(0.000000000931322574615478515625),QString("9.31323e-10"));
+ − 2715
+ − 2716
// QCOMPARE(a.setNum(0.000000000931322574615478515625,'g',30),(QString)"9.31322574615478515625e-010");
+ − 2717
// QCOMPARE(a.setNum(0.000000000931322574615478515625,'f',30),(QString)"0.00000000093132257461547852");
+ − 2718
}
+ − 2719
+ − 2720
void tst_QString::startsWith()
+ − 2721
{
+ − 2722
QString a;
+ − 2723
a = "AB";
+ − 2724
QVERIFY( a.startsWith("A") );
+ − 2725
QVERIFY( a.startsWith("AB") );
+ − 2726
QVERIFY( !a.startsWith("C") );
+ − 2727
QVERIFY( !a.startsWith("ABCDEF") );
+ − 2728
QVERIFY( a.startsWith("") );
+ − 2729
QVERIFY( a.startsWith(QString::null) );
+ − 2730
QVERIFY( a.startsWith('A') );
+ − 2731
QVERIFY( a.startsWith(QLatin1Char('A')) );
+ − 2732
QVERIFY( a.startsWith(QChar('A')) );
+ − 2733
QVERIFY( !a.startsWith('C') );
+ − 2734
QVERIFY( !a.startsWith(QChar()) );
+ − 2735
QVERIFY( !a.startsWith(QLatin1Char(0)) );
+ − 2736
+ − 2737
QVERIFY( a.startsWith(QLatin1String("A")) );
+ − 2738
QVERIFY( a.startsWith(QLatin1String("AB")) );
+ − 2739
QVERIFY( !a.startsWith(QLatin1String("C")) );
+ − 2740
QVERIFY( !a.startsWith(QLatin1String("ABCDEF")) );
+ − 2741
QVERIFY( a.startsWith(QLatin1String("")) );
+ − 2742
QVERIFY( a.startsWith(QLatin1String(0)) );
+ − 2743
+ − 2744
QVERIFY( a.startsWith("A", Qt::CaseSensitive) );
+ − 2745
QVERIFY( a.startsWith("A", Qt::CaseInsensitive) );
+ − 2746
QVERIFY( !a.startsWith("a", Qt::CaseSensitive) );
+ − 2747
QVERIFY( a.startsWith("a", Qt::CaseInsensitive) );
+ − 2748
QVERIFY( !a.startsWith("aB", Qt::CaseSensitive) );
+ − 2749
QVERIFY( a.startsWith("aB", Qt::CaseInsensitive) );
+ − 2750
QVERIFY( !a.startsWith("C", Qt::CaseSensitive) );
+ − 2751
QVERIFY( !a.startsWith("C", Qt::CaseInsensitive) );
+ − 2752
QVERIFY( !a.startsWith("c", Qt::CaseSensitive) );
+ − 2753
QVERIFY( !a.startsWith("c", Qt::CaseInsensitive) );
+ − 2754
QVERIFY( !a.startsWith("abcdef", Qt::CaseInsensitive) );
+ − 2755
QVERIFY( a.startsWith("", Qt::CaseInsensitive) );
+ − 2756
QVERIFY( a.startsWith(QString::null, Qt::CaseInsensitive) );
+ − 2757
QVERIFY( a.startsWith('a', Qt::CaseInsensitive) );
+ − 2758
QVERIFY( a.startsWith('A', Qt::CaseInsensitive) );
+ − 2759
QVERIFY( a.startsWith(QLatin1Char('a'), Qt::CaseInsensitive) );
+ − 2760
QVERIFY( a.startsWith(QChar('a'), Qt::CaseInsensitive) );
+ − 2761
QVERIFY( !a.startsWith('c', Qt::CaseInsensitive) );
+ − 2762
QVERIFY( !a.startsWith(QChar(), Qt::CaseInsensitive) );
+ − 2763
QVERIFY( !a.startsWith(QLatin1Char(0), Qt::CaseInsensitive) );
+ − 2764
+ − 2765
QVERIFY( a.startsWith(QLatin1String("A"), Qt::CaseSensitive) );
+ − 2766
QVERIFY( a.startsWith(QLatin1String("A"), Qt::CaseInsensitive) );
+ − 2767
QVERIFY( !a.startsWith(QLatin1String("a"), Qt::CaseSensitive) );
+ − 2768
QVERIFY( a.startsWith(QLatin1String("a"), Qt::CaseInsensitive) );
+ − 2769
QVERIFY( !a.startsWith(QLatin1String("aB"), Qt::CaseSensitive) );
+ − 2770
QVERIFY( a.startsWith(QLatin1String("aB"), Qt::CaseInsensitive) );
+ − 2771
QVERIFY( !a.startsWith(QLatin1String("C"), Qt::CaseSensitive) );
+ − 2772
QVERIFY( !a.startsWith(QLatin1String("C"), Qt::CaseInsensitive) );
+ − 2773
QVERIFY( !a.startsWith(QLatin1String("c"), Qt::CaseSensitive) );
+ − 2774
QVERIFY( !a.startsWith(QLatin1String("c"), Qt::CaseInsensitive) );
+ − 2775
QVERIFY( !a.startsWith(QLatin1String("abcdef"), Qt::CaseInsensitive) );
+ − 2776
QVERIFY( a.startsWith(QLatin1String(""), Qt::CaseInsensitive) );
+ − 2777
QVERIFY( a.startsWith(QLatin1String(0), Qt::CaseInsensitive) );
+ − 2778
QVERIFY( a.startsWith('A', Qt::CaseSensitive) );
+ − 2779
QVERIFY( a.startsWith(QLatin1Char('A'), Qt::CaseSensitive) );
+ − 2780
QVERIFY( a.startsWith(QChar('A'), Qt::CaseSensitive) );
+ − 2781
QVERIFY( !a.startsWith('a', Qt::CaseSensitive) );
+ − 2782
QVERIFY( !a.startsWith(QChar(), Qt::CaseSensitive) );
+ − 2783
QVERIFY( !a.startsWith(QLatin1Char(0), Qt::CaseSensitive) );
+ − 2784
+ − 2785
a = "";
+ − 2786
QVERIFY( a.startsWith("") );
+ − 2787
QVERIFY( a.startsWith(QString::null) );
+ − 2788
QVERIFY( !a.startsWith("ABC") );
+ − 2789
+ − 2790
QVERIFY( a.startsWith(QLatin1String("")) );
+ − 2791
QVERIFY( a.startsWith(QLatin1String(0)) );
+ − 2792
QVERIFY( !a.startsWith(QLatin1String("ABC")) );
+ − 2793
+ − 2794
QVERIFY( !a.startsWith(QLatin1Char(0)) );
+ − 2795
QVERIFY( !a.startsWith(QLatin1Char('x')) );
+ − 2796
QVERIFY( !a.startsWith(QChar()) );
+ − 2797
+ − 2798
a = QString::null;
+ − 2799
QVERIFY( !a.startsWith("") );
+ − 2800
QVERIFY( a.startsWith(QString::null) );
+ − 2801
QVERIFY( !a.startsWith("ABC") );
+ − 2802
+ − 2803
QVERIFY( !a.startsWith(QLatin1String("")) );
+ − 2804
QVERIFY( a.startsWith(QLatin1String(0)) );
+ − 2805
QVERIFY( !a.startsWith(QLatin1String("ABC")) );
+ − 2806
+ − 2807
QVERIFY( !a.startsWith(QLatin1Char(0)) );
+ − 2808
QVERIFY( !a.startsWith(QLatin1Char('x')) );
+ − 2809
QVERIFY( !a.startsWith(QChar()) );
+ − 2810
}
+ − 2811
+ − 2812
void tst_QString::endsWith()
+ − 2813
{
+ − 2814
QString a;
+ − 2815
a = "AB";
+ − 2816
QVERIFY( a.endsWith("B") );
+ − 2817
QVERIFY( a.endsWith("AB") );
+ − 2818
QVERIFY( !a.endsWith("C") );
+ − 2819
QVERIFY( !a.endsWith("ABCDEF") );
+ − 2820
QVERIFY( a.endsWith("") );
+ − 2821
QVERIFY( a.endsWith(QString::null) );
+ − 2822
QVERIFY( a.endsWith('B') );
+ − 2823
QVERIFY( a.endsWith(QLatin1Char('B')) );
+ − 2824
QVERIFY( a.endsWith(QChar('B')) );
+ − 2825
QVERIFY( !a.endsWith('C') );
+ − 2826
QVERIFY( !a.endsWith(QChar()) );
+ − 2827
QVERIFY( !a.endsWith(QLatin1Char(0)) );
+ − 2828
+ − 2829
QVERIFY( a.endsWith(QLatin1String("B")) );
+ − 2830
QVERIFY( a.endsWith(QLatin1String("AB")) );
+ − 2831
QVERIFY( !a.endsWith(QLatin1String("C")) );
+ − 2832
QVERIFY( !a.endsWith(QLatin1String("ABCDEF")) );
+ − 2833
QVERIFY( a.endsWith(QLatin1String("")) );
+ − 2834
QVERIFY( a.endsWith(QLatin1String(0)) );
+ − 2835
+ − 2836
QVERIFY( a.endsWith("B", Qt::CaseSensitive) );
+ − 2837
QVERIFY( a.endsWith("B", Qt::CaseInsensitive) );
+ − 2838
QVERIFY( !a.endsWith("b", Qt::CaseSensitive) );
+ − 2839
QVERIFY( a.endsWith("b", Qt::CaseInsensitive) );
+ − 2840
QVERIFY( !a.endsWith("aB", Qt::CaseSensitive) );
+ − 2841
QVERIFY( a.endsWith("aB", Qt::CaseInsensitive) );
+ − 2842
QVERIFY( !a.endsWith("C", Qt::CaseSensitive) );
+ − 2843
QVERIFY( !a.endsWith("C", Qt::CaseInsensitive) );
+ − 2844
QVERIFY( !a.endsWith("c", Qt::CaseSensitive) );
+ − 2845
QVERIFY( !a.endsWith("c", Qt::CaseInsensitive) );
+ − 2846
QVERIFY( !a.endsWith("abcdef", Qt::CaseInsensitive) );
+ − 2847
QVERIFY( a.endsWith("", Qt::CaseInsensitive) );
+ − 2848
QVERIFY( a.endsWith(QString::null, Qt::CaseInsensitive) );
+ − 2849
QVERIFY( a.endsWith('b', Qt::CaseInsensitive) );
+ − 2850
QVERIFY( a.endsWith('B', Qt::CaseInsensitive) );
+ − 2851
QVERIFY( a.endsWith(QLatin1Char('b'), Qt::CaseInsensitive) );
+ − 2852
QVERIFY( a.endsWith(QChar('b'), Qt::CaseInsensitive) );
+ − 2853
QVERIFY( !a.endsWith('c', Qt::CaseInsensitive) );
+ − 2854
QVERIFY( !a.endsWith(QChar(), Qt::CaseInsensitive) );
+ − 2855
QVERIFY( !a.endsWith(QLatin1Char(0), Qt::CaseInsensitive) );
+ − 2856
+ − 2857
QVERIFY( a.endsWith(QLatin1String("B"), Qt::CaseSensitive) );
+ − 2858
QVERIFY( a.endsWith(QLatin1String("B"), Qt::CaseInsensitive) );
+ − 2859
QVERIFY( !a.endsWith(QLatin1String("b"), Qt::CaseSensitive) );
+ − 2860
QVERIFY( a.endsWith(QLatin1String("b"), Qt::CaseInsensitive) );
+ − 2861
QVERIFY( !a.endsWith(QLatin1String("aB"), Qt::CaseSensitive) );
+ − 2862
QVERIFY( a.endsWith(QLatin1String("aB"), Qt::CaseInsensitive) );
+ − 2863
QVERIFY( !a.endsWith(QLatin1String("C"), Qt::CaseSensitive) );
+ − 2864
QVERIFY( !a.endsWith(QLatin1String("C"), Qt::CaseInsensitive) );
+ − 2865
QVERIFY( !a.endsWith(QLatin1String("c"), Qt::CaseSensitive) );
+ − 2866
QVERIFY( !a.endsWith(QLatin1String("c"), Qt::CaseInsensitive) );
+ − 2867
QVERIFY( !a.endsWith(QLatin1String("abcdef"), Qt::CaseInsensitive) );
+ − 2868
QVERIFY( a.endsWith(QLatin1String(""), Qt::CaseInsensitive) );
+ − 2869
QVERIFY( a.endsWith(QLatin1String(0), Qt::CaseInsensitive) );
+ − 2870
QVERIFY( a.endsWith('B', Qt::CaseSensitive) );
+ − 2871
QVERIFY( a.endsWith(QLatin1Char('B'), Qt::CaseSensitive) );
+ − 2872
QVERIFY( a.endsWith(QChar('B'), Qt::CaseSensitive) );
+ − 2873
QVERIFY( !a.endsWith('b', Qt::CaseSensitive) );
+ − 2874
QVERIFY( !a.endsWith(QChar(), Qt::CaseSensitive) );
+ − 2875
QVERIFY( !a.endsWith(QLatin1Char(0), Qt::CaseSensitive) );
+ − 2876
+ − 2877
a = "";
+ − 2878
QVERIFY( a.endsWith("") );
+ − 2879
QVERIFY( a.endsWith(QString::null) );
+ − 2880
QVERIFY( !a.endsWith("ABC") );
+ − 2881
QVERIFY( !a.endsWith(QLatin1Char(0)) );
+ − 2882
QVERIFY( !a.endsWith(QLatin1Char('x')) );
+ − 2883
QVERIFY( !a.endsWith(QChar()) );
+ − 2884
+ − 2885
QVERIFY( a.endsWith(QLatin1String("")) );
+ − 2886
QVERIFY( a.endsWith(QLatin1String(0)) );
+ − 2887
QVERIFY( !a.endsWith(QLatin1String("ABC")) );
+ − 2888
+ − 2889
a = QString::null;
+ − 2890
QVERIFY( !a.endsWith("") );
+ − 2891
QVERIFY( a.endsWith(QString::null) );
+ − 2892
QVERIFY( !a.endsWith("ABC") );
+ − 2893
+ − 2894
QVERIFY( !a.endsWith(QLatin1String("")) );
+ − 2895
QVERIFY( a.endsWith(QLatin1String(0)) );
+ − 2896
QVERIFY( !a.endsWith(QLatin1String("ABC")) );
+ − 2897
+ − 2898
QVERIFY( !a.endsWith(QLatin1Char(0)) );
+ − 2899
QVERIFY( !a.endsWith(QLatin1Char('x')) );
+ − 2900
QVERIFY( !a.endsWith(QChar()) );
+ − 2901
}
+ − 2902
+ − 2903
void tst_QString::check_QDataStream()
+ − 2904
{
+ − 2905
QString a;
+ − 2906
QByteArray ar;
+ − 2907
{
+ − 2908
QDataStream out(&ar,QIODevice::WriteOnly);
+ − 2909
out << QString("COMPARE Text");
+ − 2910
}
+ − 2911
{
+ − 2912
QDataStream in(&ar,QIODevice::ReadOnly);
+ − 2913
in >> a;
+ − 2914
QCOMPARE(a,(QString)"COMPARE Text");
+ − 2915
}
+ − 2916
}
+ − 2917
+ − 2918
void tst_QString::check_QTextStream()
+ − 2919
{
+ − 2920
QString a;
+ − 2921
QByteArray ar;
+ − 2922
{
+ − 2923
QTextStream out(&ar,QIODevice::WriteOnly);
+ − 2924
out << QString("This is COMPARE Text");
+ − 2925
}
+ − 2926
{
+ − 2927
QTextStream in(&ar,QIODevice::ReadOnly);
+ − 2928
in >> a;
+ − 2929
QCOMPARE(a,(QString)"This");
+ − 2930
}
+ − 2931
}
+ − 2932
+ − 2933
void tst_QString::check_QTextIOStream()
+ − 2934
{
+ − 2935
QString a;
+ − 2936
{
+ − 2937
a="";
+ − 2938
QTextStream ts(&a);
+ − 2939
ts << "pi \261= " << 3.125;
+ − 2940
QCOMPARE(a,(QString)"pi \261= 3.125");
+ − 2941
}
+ − 2942
{
+ − 2943
a="123 456";
+ − 2944
int x,y;
+ − 2945
QTextStream(&a) >> x >> y;
+ − 2946
QCOMPARE(x,123);
+ − 2947
QCOMPARE(y,456);
+ − 2948
}
+ − 2949
}
+ − 2950
+ − 2951
void tst_QString::fromRawData()
+ − 2952
{
+ − 2953
const QChar ptr[] = { 0x1234, 0x0000 };
+ − 2954
QString cstr = QString::fromRawData(ptr, 1);
+ − 2955
QVERIFY(cstr.constData() == ptr);
+ − 2956
cstr.squeeze();
+ − 2957
QVERIFY(cstr.constData() == ptr);
+ − 2958
cstr.detach();
+ − 2959
QVERIFY(cstr.size() == 1);
+ − 2960
QVERIFY(cstr.capacity() == 1);
+ − 2961
QVERIFY(cstr.constData() != ptr);
+ − 2962
QVERIFY(cstr.constData()[0] == QChar(0x1234));
+ − 2963
QVERIFY(cstr.constData()[1] == QChar(0x0000));
+ − 2964
}
+ − 2965
+ − 2966
void tst_QString::fromStdString()
+ − 2967
{
+ − 2968
#ifdef Q_CC_HPACC
+ − 2969
QSKIP("This test crashes on HP-UX with aCC", SkipSingle);
+ − 2970
#endif
+ − 2971
#if !defined(QT_NO_STL)
+ − 2972
std::string stroustrup = "foo";
+ − 2973
QString eng = QString::fromStdString( stroustrup );
+ − 2974
QCOMPARE( eng, QString("foo") );
+ − 2975
const char cnull[] = "Embedded\0null\0character!";
+ − 2976
std::string stdnull( cnull, sizeof(cnull)-1 );
+ − 2977
QString qtnull = QString::fromStdString( stdnull );
+ − 2978
QCOMPARE( qtnull.size(), int(stdnull.size()) );
+ − 2979
#endif
+ − 2980
}
+ − 2981
+ − 2982
void tst_QString::toStdString()
+ − 2983
{
+ − 2984
#ifdef Q_CC_HPACC
+ − 2985
QSKIP("This test crashes on HP-UX with aCC", SkipSingle);
+ − 2986
#endif
+ − 2987
#if !defined(QT_NO_STL)
+ − 2988
QString nord = "foo";
+ − 2989
std::string stroustrup1 = nord.toStdString();
+ − 2990
QVERIFY( qstrcmp(stroustrup1.c_str(), "foo") == 0 );
+ − 2991
// For now, most QString constructors are also broken with respect
+ − 2992
// to embedded null characters, had to find one that works...
+ − 2993
const QChar qcnull[] = {
+ − 2994
'E', 'm', 'b', 'e', 'd', 'd', 'e', 'd', '\0',
+ − 2995
'n', 'u', 'l', 'l', '\0',
+ − 2996
'c', 'h', 'a', 'r', 'a', 'c', 't', 'e', 'r', '!'
+ − 2997
};
+ − 2998
QString qtnull( qcnull, sizeof(qcnull)/sizeof(QChar) );
+ − 2999
std::string stdnull = qtnull.toStdString();
+ − 3000
QCOMPARE( int(stdnull.size()), qtnull.size() );
+ − 3001
#endif
+ − 3002
}
+ − 3003
+ − 3004
void tst_QString::utf8()
+ − 3005
{
+ − 3006
QFETCH( QByteArray, utf8 );
+ − 3007
QFETCH( QString, res );
+ − 3008
+ − 3009
QCOMPARE( utf8, QByteArray(res.toUtf8()) );
+ − 3010
}
+ − 3011
+ − 3012
// copied to tst_QTextCodec::utf8Codec_data()
+ − 3013
void tst_QString::fromUtf8_data()
+ − 3014
{
+ − 3015
QTest::addColumn<QByteArray>("utf8");
+ − 3016
QTest::addColumn<QString>("res");
+ − 3017
QTest::addColumn<int>("len");
+ − 3018
QString str;
+ − 3019
+ − 3020
QTest::newRow("str0") << QByteArray("abcdefgh") << QString("abcdefgh") << -1;
+ − 3021
QTest::newRow("str0-len") << QByteArray("abcdefgh") << QString("abc") << 3;
+ − 3022
QTest::newRow("str1") << QByteArray("\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205") << QString("\366\344\374\326\304\334\370\346\345\330\306\305") << -1;
+ − 3023
QTest::newRow("str1-len") << QByteArray("\303\266\303\244\303\274\303\226\303\204\303\234\303\270\303\246\303\245\303\230\303\206\303\205") << QString("\366\344\374\326\304") << 10;
+ − 3024
+ − 3025
str += QChar(0x05e9);
+ − 3026
str += QChar(0x05d3);
+ − 3027
str += QChar(0x05d2);
+ − 3028
QTest::newRow("str2") << QByteArray("\327\251\327\223\327\222") << str << -1;
+ − 3029
+ − 3030
str = QChar(0x05e9);
+ − 3031
QTest::newRow("str2-len") << QByteArray("\327\251\327\223\327\222") << str << 2;
+ − 3032
+ − 3033
str = QChar(0x20ac);
+ − 3034
str += " some text";
+ − 3035
QTest::newRow("str3") << QByteArray("\342\202\254 some text") << str << -1;
+ − 3036
+ − 3037
str = QChar(0x20ac);
+ − 3038
str += " some ";
+ − 3039
QTest::newRow("str3-len") << QByteArray("\342\202\254 some text") << str << 9;
+ − 3040
+ − 3041
str = "hello";
+ − 3042
str += QChar::ReplacementCharacter;
+ − 3043
str += QChar(0x68);
+ − 3044
str += QChar::ReplacementCharacter;
+ − 3045
str += QChar::ReplacementCharacter;
+ − 3046
str += QChar::ReplacementCharacter;
+ − 3047
str += QChar::ReplacementCharacter;
+ − 3048
str += QChar(0x61);
+ − 3049
str += QChar::ReplacementCharacter;
+ − 3050
QTest::newRow("invalid utf8") << QByteArray("hello\344h\344\344\366\344a\304") << str << -1;
+ − 3051
QTest::newRow("invalid utf8-len") << QByteArray("hello\344h\344\344\366\344a\304") << QString("hello") << 5;
+ − 3052
+ − 3053
str = "Prohl";
+ − 3054
str += QChar::ReplacementCharacter;
+ − 3055
str += QChar::ReplacementCharacter;
+ − 3056
str += "e";
+ − 3057
str += QChar::ReplacementCharacter;
+ − 3058
str += " plugin";
+ − 3059
str += QChar::ReplacementCharacter;
+ − 3060
str += " Netscape";
+ − 3061
+ − 3062
QTest::newRow("task28417") << QByteArray("Prohl\355\276e\350 plugin\371 Netscape") << str << -1;
+ − 3063
QTest::newRow("task28417-len") << QByteArray("Prohl\355\276e\350 plugin\371 Netscape") << QString("") << 0;
+ − 3064
+ − 3065
QTest::newRow("null-1") << QByteArray() << QString() << -1;
+ − 3066
QTest::newRow("null0") << QByteArray() << QString() << 0;
+ − 3067
QTest::newRow("null5") << QByteArray() << QString() << 5;
+ − 3068
QTest::newRow("empty-1") << QByteArray("\0abcd", 5) << QString() << -1;
+ − 3069
QTest::newRow("empty0") << QByteArray() << QString() << 0;
+ − 3070
QTest::newRow("empty5") << QByteArray("\0abcd", 5) << QString::fromAscii("\0abcd", 5) << 5;
+ − 3071
QTest::newRow("other-1") << QByteArray("ab\0cd", 5) << QString::fromAscii("ab") << -1;
+ − 3072
QTest::newRow("other5") << QByteArray("ab\0cd", 5) << QString::fromAscii("ab\0cd", 5) << 5;
+ − 3073
+ − 3074
str = "Old Italic: ";
+ − 3075
str += QChar(0xd800);
+ − 3076
str += QChar(0xdf00);
+ − 3077
str += QChar(0xd800);
+ − 3078
str += QChar(0xdf01);
+ − 3079
str += QChar(0xd800);
+ − 3080
str += QChar(0xdf02);
+ − 3081
str += QChar(0xd800);
+ − 3082
str += QChar(0xdf03);
+ − 3083
str += QChar(0xd800);
+ − 3084
str += QChar(0xdf04);
+ − 3085
QTest::newRow("surrogate") << QByteArray("Old Italic: \360\220\214\200\360\220\214\201\360\220\214\202\360\220\214\203\360\220\214\204") << str << -1;
+ − 3086
+ − 3087
QTest::newRow("surrogate-len") << QByteArray("Old Italic: \360\220\214\200\360\220\214\201\360\220\214\202\360\220\214\203\360\220\214\204") << str.left(16) << 20;
+ − 3088
+ − 3089
}
+ − 3090
+ − 3091
void tst_QString::fromUtf8()
+ − 3092
{
+ − 3093
QFETCH(QByteArray, utf8);
+ − 3094
QFETCH(QString, res);
+ − 3095
QFETCH(int, len);
+ − 3096
+ − 3097
QCOMPARE(QString::fromUtf8(utf8.isNull() ? 0 : utf8.data(), len), res);
+ − 3098
}
+ − 3099
+ − 3100
void tst_QString::nullFromUtf8()
+ − 3101
{
+ − 3102
QString a;
+ − 3103
a = QString::fromUtf8(0);
+ − 3104
QVERIFY(a.isNull());
+ − 3105
QVERIFY(a.isEmpty());
+ − 3106
a = QString::fromUtf8("");
+ − 3107
QVERIFY(!a.isNull());
+ − 3108
QVERIFY(a.isEmpty());
+ − 3109
}
+ − 3110
+ − 3111
void tst_QString::fromLocal8Bit_data()
+ − 3112
{
+ − 3113
QTest::addColumn<QByteArray>("local8Bit");
+ − 3114
QTest::addColumn<int>("len");
+ − 3115
QTest::addColumn<QString>("result");
+ − 3116
+ − 3117
//QTest::newRow("nullString") << QByteArray() << -1 << QString();
+ − 3118
//QTest::newRow("emptyString") << QByteArray("") << -1 << QString("");
+ − 3119
//QTest::newRow("string") << QByteArray("test") << -1 << QString("test");
+ − 3120
//QTest::newRow("stringlen0") << QByteArray("test") << 0 << QString("");
+ − 3121
//QTest::newRow("stringlen3") << QByteArray("test") << 3 << QString("tes");
+ − 3122
QTest::newRow("stringlen99") << QByteArray("test\0foo", 8) << 8 << QString::fromLatin1("test\0foo", 8);
+ − 3123
+ − 3124
QByteArray longQByteArray;
+ − 3125
QString longQString;
+ − 3126
+ − 3127
for (int l=0;l<111;l++) {
+ − 3128
longQByteArray = longQByteArray + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+ − 3129
longQString += "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+ − 3130
}
+ − 3131
+ − 3132
//QTest::newRow("longString") << longQByteArray << -1 << longQString;
+ − 3133
//QTest::newRow("longStringlen0") << longQByteArray << 0 << QString("");
+ − 3134
//QTest::newRow("longStringlen3") << longQByteArray << 3 << QString("aaa");
+ − 3135
//QTest::newRow("someNonAlphaChars") << QByteArray("d:/this/is/a/test.h") << -1 << QString("d:/this/is/a/test.h");
+ − 3136
+ − 3137
//QTest::newRow("null-1") << QByteArray() << -1 << QString();
+ − 3138
//QTest::newRow("null0") << QByteArray() << 0 << QString();
+ − 3139
//QTest::newRow("null5") << QByteArray() << 5 << QString();
+ − 3140
//QTest::newRow("empty-1") << QByteArray("\0abcd", 5) << -1 << QString();
+ − 3141
//QTest::newRow("empty0") << QByteArray() << 0 << QString();
+ − 3142
//QTest::newRow("empty5") << QByteArray("\0abcd", 5) << 5 << QString::fromAscii("\0abcd", 5);
+ − 3143
//QTest::newRow("other-1") << QByteArray("ab\0cd", 5) << -1 << QString::fromAscii("ab");
+ − 3144
//QTest::newRow("other5") << QByteArray("ab\0cd", 5) << 5 << QString::fromAscii("ab\0cd", 5);
+ − 3145
}
+ − 3146
+ − 3147
void tst_QString::fromLocal8Bit()
+ − 3148
{
+ − 3149
QFETCH(QByteArray, local8Bit);
+ − 3150
QFETCH(int, len);
+ − 3151
QFETCH(QString, result);
+ − 3152
+ − 3153
QCOMPARE(QString::fromLocal8Bit(local8Bit.isNull() ? 0 : local8Bit.data(), len).length(),
+ − 3154
result.length());
+ − 3155
QCOMPARE(QString::fromLocal8Bit(local8Bit.isNull() ? 0 : local8Bit.data(), len), result);
+ − 3156
}
+ − 3157
+ − 3158
void tst_QString::local8Bit_data()
+ − 3159
{
+ − 3160
QTest::addColumn<QString>("local8Bit");
+ − 3161
QTest::addColumn<QByteArray>("result");
+ − 3162
+ − 3163
/*
+ − 3164
QString::local8Bit() called on a null QString returns an _empty_
+ − 3165
QByteArray. This is the correct behavior since Qt 3.1.
+ − 3166
*/
+ − 3167
QTest::newRow("nullString") << QString() << QByteArray("");
+ − 3168
QTest::newRow("emptyString") << QString("") << QByteArray("");
+ − 3169
QTest::newRow("string") << QString("test") << QByteArray("test");
+ − 3170
+ − 3171
QByteArray longQByteArray;
+ − 3172
QString longQString;
+ − 3173
+ − 3174
for (int l=0;l<111;l++) {
+ − 3175
longQByteArray = longQByteArray + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+ − 3176
longQString += "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+ − 3177
}
+ − 3178
+ − 3179
QTest::newRow("longString") << longQString << longQByteArray;
+ − 3180
QTest::newRow("someNonAlphaChars") << QString("d:/this/is/a/test.h") << QByteArray("d:/this/is/a/test.h");
+ − 3181
}
+ − 3182
+ − 3183
void tst_QString::local8Bit()
+ − 3184
{
+ − 3185
QFETCH(QString, local8Bit);
+ − 3186
QFETCH(QByteArray, result);
+ − 3187
+ − 3188
QCOMPARE(local8Bit.toLocal8Bit(), QByteArray(result));
+ − 3189
}
+ − 3190
+ − 3191
void tst_QString::fromLatin1()
+ − 3192
{
+ − 3193
QString a;
+ − 3194
a = QString::fromLatin1( 0 );
+ − 3195
QVERIFY( a.isNull() );
+ − 3196
QVERIFY( a.isEmpty() );
+ − 3197
a = QString::fromLatin1( "" );
+ − 3198
QVERIFY( !a.isNull() );
+ − 3199
QVERIFY( a.isEmpty() );
+ − 3200
+ − 3201
a = QString::fromLatin1(0, 0);
+ − 3202
QVERIFY(a.isNull());
+ − 3203
a = QString::fromLatin1(0, 5);
+ − 3204
QVERIFY(a.isNull());
+ − 3205
a = QString::fromLatin1("\0abcd", 0);
+ − 3206
QVERIFY(!a.isNull());
+ − 3207
QVERIFY(a.isEmpty());
+ − 3208
a = QString::fromLatin1("\0abcd", 5);
+ − 3209
QVERIFY(a.size() == 5);
+ − 3210
}
+ − 3211
+ − 3212
void tst_QString::fromAscii()
+ − 3213
{
+ − 3214
QString a;
+ − 3215
a = QString::fromAscii( 0 );
+ − 3216
QVERIFY( a.isNull() );
+ − 3217
QVERIFY( a.isEmpty() );
+ − 3218
a = QString::fromAscii( "" );
+ − 3219
QVERIFY( !a.isNull() );
+ − 3220
QVERIFY( a.isEmpty() );
+ − 3221
+ − 3222
a = QString::fromAscii(0, 0);
+ − 3223
QVERIFY(a.isNull());
+ − 3224
a = QString::fromAscii(0, 5);
+ − 3225
QVERIFY(a.isNull());
+ − 3226
a = QString::fromAscii("\0abcd", 0);
+ − 3227
QVERIFY(!a.isNull());
+ − 3228
QVERIFY(a.isEmpty());
+ − 3229
a = QString::fromAscii("\0abcd", 5);
+ − 3230
QVERIFY(a.size() == 5);
+ − 3231
}
+ − 3232
+ − 3233
void tst_QString::arg()
+ − 3234
{
+ − 3235
/*
+ − 3236
Warning: If any of these test fails, the warning given by QtTest
+ − 3237
is all messed up, because QtTest itself uses QString::arg().
+ − 3238
*/
+ − 3239
+ − 3240
QLocale::setDefault(QString("de_DE"));
+ − 3241
+ − 3242
QString s4( "[%0]" );
+ − 3243
QString s5( "[%1]" );
+ − 3244
QString s6( "[%3]" );
+ − 3245
QString s7( "[%9]" );
+ − 3246
QString s8( "[%0 %1]" );
+ − 3247
QString s9( "[%0 %3]" );
+ − 3248
QString s10( "[%1 %2 %3]" );
+ − 3249
QString s11( "[%9 %3 %0]" );
+ − 3250
QString s12( "[%9 %1 %3 %9 %0 %8]" );
+ − 3251
QString s13( "%1% %x%c%2 %d%2-%" );
+ − 3252
QString s14( "%1%2%3" );
+ − 3253
+ − 3254
QCOMPARE( s4.arg("foo"), QString("[foo]") );
+ − 3255
QCOMPARE( s5.arg("foo"), QString("[foo]") );
+ − 3256
QCOMPARE( s6.arg("foo"), QString("[foo]") );
+ − 3257
QCOMPARE( s7.arg("foo"), QString("[foo]") );
+ − 3258
QCOMPARE( s8.arg("foo"), QString("[foo %1]") );
+ − 3259
QCOMPARE( s8.arg("foo").arg("bar"), QString("[foo bar]") );
+ − 3260
QCOMPARE( s8.arg("foo", "bar"), QString("[foo bar]") );
+ − 3261
QCOMPARE( s9.arg("foo"), QString("[foo %3]") );
+ − 3262
QCOMPARE( s9.arg("foo").arg("bar"), QString("[foo bar]") );
+ − 3263
QCOMPARE( s9.arg("foo", "bar"), QString("[foo bar]") );
+ − 3264
QCOMPARE( s10.arg("foo"), QString("[foo %2 %3]") );
+ − 3265
QCOMPARE( s10.arg("foo").arg("bar"), QString("[foo bar %3]") );
+ − 3266
QCOMPARE( s10.arg("foo", "bar"), QString("[foo bar %3]") );
+ − 3267
QCOMPARE( s10.arg("foo").arg("bar").arg("baz"), QString("[foo bar baz]") );
+ − 3268
QCOMPARE( s10.arg("foo", "bar", "baz"), QString("[foo bar baz]") );
+ − 3269
QCOMPARE( s11.arg("foo"), QString("[%9 %3 foo]") );
+ − 3270
QCOMPARE( s11.arg("foo").arg("bar"), QString("[%9 bar foo]") );
+ − 3271
QCOMPARE( s11.arg("foo", "bar"), QString("[%9 bar foo]") );
+ − 3272
QCOMPARE( s11.arg("foo").arg("bar").arg("baz"), QString("[baz bar foo]") );
+ − 3273
QCOMPARE( s11.arg("foo", "bar", "baz"), QString("[baz bar foo]") );
+ − 3274
QCOMPARE( s12.arg("a").arg("b").arg("c").arg("d").arg("e"),
+ − 3275
QString("[e b c e a d]") );
+ − 3276
QCOMPARE( s12.arg("a", "b", "c", "d").arg("e"), QString("[e b c e a d]") );
+ − 3277
QCOMPARE( s12.arg("a").arg("b", "c", "d", "e"), QString("[e b c e a d]") );
+ − 3278
QCOMPARE( s13.arg("alpha").arg("beta"),
+ − 3279
QString("alpha% %x%cbeta %dbeta-%") );
+ − 3280
QCOMPARE( s13.arg("alpha", "beta"), QString("alpha% %x%cbeta %dbeta-%") );
+ − 3281
QCOMPARE( s14.arg("a", "b", "c"), QString("abc") );
+ − 3282
QCOMPARE( s8.arg("%1").arg("foo"), QString("[foo foo]") );
+ − 3283
QCOMPARE( s8.arg("%1", "foo"), QString("[%1 foo]") );
+ − 3284
QCOMPARE( s4.arg("foo", 2), QString("[foo]") );
+ − 3285
QCOMPARE( s4.arg("foo", -2), QString("[foo]") );
+ − 3286
QCOMPARE( s4.arg("foo", 10), QString("[ foo]") );
+ − 3287
QCOMPARE( s4.arg("foo", -10), QString("[foo ]") );
+ − 3288
+ − 3289
QString firstName( "James" );
+ − 3290
QString lastName( "Bond" );
+ − 3291
QString fullName = QString( "My name is %2, %1 %2" )
+ − 3292
.arg( firstName ).arg( lastName );
+ − 3293
QCOMPARE( fullName, QString("My name is Bond, James Bond") );
+ − 3294
+ − 3295
// number overloads
+ − 3296
QCOMPARE( s4.arg(0), QString("[0]") );
+ − 3297
QCOMPARE( s4.arg(-1), QString("[-1]") );
+ − 3298
QCOMPARE( s4.arg(4294967295UL), QString("[4294967295]") ); // ULONG_MAX 32
+ − 3299
QCOMPARE( s4.arg(Q_INT64_C(9223372036854775807)), // LLONG_MAX
+ − 3300
QString("[9223372036854775807]") );
+ − 3301
+ − 3302
QCOMPARE( QString().arg(0), QString() );
+ − 3303
QCOMPARE( QString("").arg(0), QString("") );
+ − 3304
QCOMPARE( QString(" ").arg(0), QString(" ") );
+ − 3305
QCOMPARE( QString("%").arg(0), QString("%") );
+ − 3306
QCOMPARE( QString("%%").arg(0), QString("%%") );
+ − 3307
QCOMPARE( QString("%%%").arg(0), QString("%%%") );
+ − 3308
QCOMPARE( QString("%%%1%%%2").arg("foo").arg("bar"), QString("%%foo%%bar") );
+ − 3309
+ − 3310
QCOMPARE( QString("%1").arg("hello", -10), QString("hello ") );
+ − 3311
QCOMPARE( QString("%1").arg("hello", -5), QString("hello") );
+ − 3312
QCOMPARE( QString("%1").arg("hello", -2), QString("hello") );
+ − 3313
QCOMPARE( QString("%1").arg("hello", 0), QString("hello") );
+ − 3314
QCOMPARE( QString("%1").arg("hello", 2), QString("hello") );
+ − 3315
QCOMPARE( QString("%1").arg("hello", 5), QString("hello") );
+ − 3316
QCOMPARE( QString("%1").arg("hello", 10), QString(" hello") );
+ − 3317
QCOMPARE( QString("%1%1").arg("hello"), QString("hellohello") );
+ − 3318
QCOMPARE( QString("%2%1").arg("hello"), QString("%2hello") );
+ − 3319
QCOMPARE( QString("%1%1").arg(QString::null), QString("") );
+ − 3320
QCOMPARE( QString("%2%1").arg(""), QString("%2") );
+ − 3321
+ − 3322
QCOMPARE( QString("%2 %L1").arg(12345.6789).arg(12345.6789),
+ − 3323
QString("12345.7 12.345,7") );
+ − 3324
QCOMPARE( QString("%2 %L1").arg(123456789).arg(123456789),
+ − 3325
QString("123456789 123.456.789") );
+ − 3326
QCOMPARE( QString("%L2 %L1 %3").arg(12345.7).arg(123456789).arg('c'),
+ − 3327
QString("123.456.789 12.345,7 c") );
+ − 3328
+ − 3329
// multi-digit replacement
+ − 3330
QString input("%%%L0 %1 %02 %3 %4 %5 %L6 %7 %8 %%% %090 %10 %11 %L12 %14 %L9888 %9999 %%%%%%%L");
+ − 3331
input = input.arg("A").arg("B").arg("C")
+ − 3332
.arg("D").arg("E").arg("f")
+ − 3333
.arg("g").arg("h").arg("i").arg("j")
+ − 3334
.arg("k").arg("l").arg("m")
+ − 3335
.arg("n").arg("o").arg("p");
+ − 3336
+ − 3337
QCOMPARE(input, QString("%%A B C D E f g h i %%% j0 k l m n o88 p99 %%%%%%%L"));
+ − 3338
+ − 3339
QString str("%1 %2 %3 %4 %5 %6 %7 %8 %9 foo %10 %11 bar");
+ − 3340
str = str.arg("one", "2", "3", "4", "5", "6", "7", "8", "9");
+ − 3341
str = str.arg("ahoy", "there");
+ − 3342
QCOMPARE(str, QString("one 2 3 4 5 6 7 8 9 foo ahoy there bar"));
+ − 3343
+ − 3344
QString str2("%123 %234 %345 %456 %567 %999 %1000 %1230");
+ − 3345
str2 = str2.arg("A", "B", "C", "D", "E", "F");
+ − 3346
QCOMPARE(str2, QString("A B C D E F %1000 %1230"));
+ − 3347
+ − 3348
// task 201185
+ − 3349
QCOMPARE(QString("%1").arg(-1, 3, 10, QChar('0')), QString("-01"));
+ − 3350
QCOMPARE(QString("%1").arg(-100, 3, 10, QChar('0')), QString("-100"));
+ − 3351
QCOMPARE(QString("%1").arg(-1, 3, 10, QChar(' ')), QString(" -1"));
+ − 3352
QCOMPARE(QString("%1").arg(-100, 3, 10, QChar(' ')), QString("-100"));
+ − 3353
QCOMPARE(QString("%1").arg(1U, 3, 10, QChar(' ')), QString(" 1"));
+ − 3354
QCOMPARE(QString("%1").arg(1000U, 3, 10, QChar(' ')), QString("1000"));
+ − 3355
QCOMPARE(QString("%1").arg(-1, 3, 10, QChar('x')), QString("x-1"));
+ − 3356
QCOMPARE(QString("%1").arg(-100, 3, 10, QChar('x')), QString("-100"));
+ − 3357
QCOMPARE(QString("%1").arg(1U, 3, 10, QChar('x')), QString("xx1"));
+ − 3358
QCOMPARE(QString("%1").arg(1000U, 3, 10, QChar('x')), QString("1000"));
+ − 3359
+ − 3360
QCOMPARE(QString("%1").arg(-1., 3, 'g', -1, QChar('0')), QString("-01"));
+ − 3361
QCOMPARE(QString("%1").arg(-100., 3, 'g', -1, QChar('0')), QString("-100"));
+ − 3362
QCOMPARE(QString("%1").arg(-1., 3, 'g', -1, QChar(' ')), QString(" -1"));
+ − 3363
QCOMPARE(QString("%1").arg(-100., 3, 'g', -1, QChar(' ')), QString("-100"));
+ − 3364
QCOMPARE(QString("%1").arg(1., 3, 'g', -1, QChar('x')), QString("xx1"));
+ − 3365
QCOMPARE(QString("%1").arg(1000., 3, 'g', -1, QChar('x')), QString("1000"));
+ − 3366
QCOMPARE(QString("%1").arg(-1., 3, 'g', -1, QChar('x')), QString("x-1"));
+ − 3367
QCOMPARE(QString("%1").arg(-100., 3, 'g', -1, QChar('x')), QString("-100"));
+ − 3368
}
+ − 3369
+ − 3370
void tst_QString::number()
+ − 3371
{
+ − 3372
QCOMPARE( QString::number(int(0)), QString("0") );
+ − 3373
QCOMPARE( QString::number((unsigned int)(11)), QString("11") );
+ − 3374
QCOMPARE( QString::number(-22L), QString("-22") );
+ − 3375
QCOMPARE( QString::number(333UL), QString("333") );
+ − 3376
QCOMPARE( QString::number(4.4), QString("4.4") );
+ − 3377
QCOMPARE( QString::number(Q_INT64_C(-555)), QString("-555") );
+ − 3378
QCOMPARE( QString::number(Q_UINT64_C(6666)), QString("6666") );
+ − 3379
}
+ − 3380
+ − 3381
void tst_QString::capacity_data()
+ − 3382
{
+ − 3383
length_data();
+ − 3384
}
+ − 3385
+ − 3386
void tst_QString::capacity()
+ − 3387
{
+ − 3388
QFETCH( QString, s1 );
+ − 3389
QFETCH( int, res );
+ − 3390
+ − 3391
QString s2( s1 );
+ − 3392
s2.reserve( res );
+ − 3393
QVERIFY( (int)s2.capacity() >= res );
+ − 3394
QCOMPARE( s2, s1 );
+ − 3395
+ − 3396
s2.reserve( res * 2 );
+ − 3397
QVERIFY( (int)s2.capacity() >= res * 2 );
+ − 3398
QCOMPARE( s2, s1 );
+ − 3399
+ − 3400
s2.squeeze();
+ − 3401
QVERIFY( (int)s2.capacity() == res );
+ − 3402
QCOMPARE( s2, s1 );
+ − 3403
+ − 3404
}
+ − 3405
+ − 3406
void tst_QString::section_data()
+ − 3407
{
+ − 3408
QTest::addColumn<QString>("wholeString" );
+ − 3409
QTest::addColumn<QString>("sep" );
+ − 3410
QTest::addColumn<int>("start" );
+ − 3411
QTest::addColumn<int>("end" );
+ − 3412
QTest::addColumn<int>("flags" );
+ − 3413
QTest::addColumn<QString>("sectionString" );
+ − 3414
QTest::addColumn<bool>("regexp" );
+ − 3415
+ − 3416
QTest::newRow( "data0" ) << QString("forename,middlename,surname,phone") << QString(",") << 2 << 2 << int(QString::SectionDefault) << QString("surname") << false;
+ − 3417
QTest::newRow( "data1" ) << QString("/usr/local/bin/myapp") << QString("/") << 3 << 4 << int(QString::SectionDefault) << QString("bin/myapp") << false;
+ − 3418
QTest::newRow( "data2" ) << QString("/usr/local/bin/myapp") << QString("/") << 3 << 3 << int(QString::SectionSkipEmpty) << QString("myapp") << false;
+ − 3419
QTest::newRow( "data3" ) << QString("forename**middlename**surname**phone") << QString("**") << 2 << 2 << int(QString::SectionDefault) << QString("surname") << false;
+ − 3420
QTest::newRow( "data4" ) << QString("forename**middlename**surname**phone") << QString("**") << -3 << -2 << int(QString::SectionDefault) << QString("middlename**surname") << false;
+ − 3421
QTest::newRow( "task-21749-1" ) << QString("##Datt######wollen######wir######mal######sehen##") << QString("#") << 0 << 0 << int(QString::SectionSkipEmpty) << QString("Datt") << false;
+ − 3422
QTest::newRow( "task-21749-2" ) << QString("##Datt######wollen######wir######mal######sehen##") << QString("#") << 1 << 1 << int(QString::SectionSkipEmpty) << QString("wollen") << false;
+ − 3423
QTest::newRow( "task-21749-3" ) << QString("##Datt######wollen######wir######mal######sehen##") << QString("#") << 2 << 2 << int(QString::SectionSkipEmpty) << QString("wir") << false;
+ − 3424
QTest::newRow( "task-21749-4" ) << QString("##Datt######wollen######wir######mal######sehen##") << QString("#") << 3 << 3 << int(QString::SectionSkipEmpty) << QString("mal") << false;
+ − 3425
QTest::newRow( "task-21749-5" ) << QString("##Datt######wollen######wir######mal######sehen##") << QString("#") << 4 << 4 << int(QString::SectionSkipEmpty) << QString("sehen") << false;
+ − 3426
// not fixed for 3.1
+ − 3427
QTest::newRow( "task-27269" ) << QString("a/b/c/d") << QString("/") << 1 << -1 << int(QString::SectionIncludeLeadingSep | QString::SectionIncludeTrailingSep) << QString("/b/c/d") << false;
+ − 3428
QTest::newRow( "task-43641" ) << QString("aoLoboLocolod") << QString("olo") << -1 << -1 << int(QString::SectionCaseInsensitiveSeps) << QString("d") << false;
+ − 3429
QTest::newRow( "task-27593" ) << QString("F0") << QString("F") << 0 << 0 << int(QString::SectionSkipEmpty) << QString("0") << false;
+ − 3430
QTest::newRow( "foo1" ) << QString("foo;foo;") << QString(";") << 0 << 0
+ − 3431
<< int(QString::SectionIncludeLeadingSep) << QString("foo") << false;
+ − 3432
QTest::newRow( "foo2" ) << QString("foo;foo;") << QString(";") << 1 << 1
+ − 3433
<< int(QString::SectionIncludeLeadingSep) << QString(";foo") << false;
+ − 3434
QTest::newRow( "foo3" ) << QString("foo;foo;") << QString(";") << 2 << 2
+ − 3435
<< int(QString::SectionIncludeLeadingSep) << QString(";") << false;
+ − 3436
QTest::newRow( "foo1rx" ) << QString("foo;foo;") << QString(";") << 0 << 0
+ − 3437
<< int(QString::SectionIncludeLeadingSep) << QString("foo") << true;
+ − 3438
QTest::newRow( "foo2rx" ) << QString("foo;foo;") << QString(";") << 1 << 1
+ − 3439
<< int(QString::SectionIncludeLeadingSep) << QString(";foo") << true;
+ − 3440
QTest::newRow( "foo3rx" ) << QString("foo;foo;") << QString(";") << 2 << 2
+ − 3441
<< int(QString::SectionIncludeLeadingSep) << QString(";") << true;
+ − 3442
+ − 3443
QTest::newRow( "qmake_path" ) << QString("/Users/sam/troll/qt4.0/src/corelib/QtCore_debug.xcode/")
+ − 3444
<< QString("/") << 0 << -2 << int(QString::SectionDefault)
+ − 3445
<< QString("/Users/sam/troll/qt4.0/src/corelib/QtCore_debug.xcode") << false;
+ − 3446
QTest::newRow( "qmake_pathrx" ) << QString("/Users/sam/troll/qt4.0/src/corelib/QtCore_debug.xcode/")
+ − 3447
<< QString("/") << 0 << -2 << int(QString::SectionDefault)
+ − 3448
<< QString("/Users/sam/troll/qt4.0/src/corelib/QtCore_debug.xcode") << true;
+ − 3449
QTest::newRow( "task72972" ) << QString("||2|3|||")
+ − 3450
<< QString("|") << 0 << 1 << int(QString::SectionIncludeLeadingSep|QString::SectionIncludeTrailingSep)
+ − 3451
<< QString("||") << false;
+ − 3452
QTest::newRow( "task72972rx" ) << QString("||2|3|||")
+ − 3453
<< QString("\\|") << 0 << 1 << int(QString::SectionIncludeLeadingSep|QString::SectionIncludeTrailingSep)
+ − 3454
<< QString("||") << true;
+ − 3455
QTest::newRow( "task72972-2" ) << QString("|1|2|")
+ − 3456
<< QString("|") << 0 << 1 << int(QString::SectionIncludeLeadingSep|QString::SectionIncludeTrailingSep)
+ − 3457
<< QString("|1|") << false;
+ − 3458
QTest::newRow( "task72972-2rx" ) << QString("|1|2|")
+ − 3459
<< QString("\\|") << 0 << 1
+ − 3460
<< int(QString::SectionIncludeLeadingSep|QString::SectionIncludeTrailingSep)
+ − 3461
<< QString("|1|") << true;
+ − 3462
QTest::newRow( "normal1" ) << QString("o1o2o")
+ − 3463
<< QString("o") << 0 << 0
+ − 3464
<< int(QString::SectionIncludeLeadingSep|QString::SectionIncludeTrailingSep)
+ − 3465
<< QString("o") << false;
+ − 3466
QTest::newRow( "normal2" ) << QString("o1o2o")
+ − 3467
<< QString("o") << 1 << 1
+ − 3468
<< int(QString::SectionIncludeLeadingSep|QString::SectionIncludeTrailingSep)
+ − 3469
<< QString("o1o") << false;
+ − 3470
QTest::newRow( "normal3" ) << QString("o1o2o")
+ − 3471
<< QString("o") << 2 << 2
+ − 3472
<< int(QString::SectionIncludeLeadingSep|QString::SectionIncludeTrailingSep)
+ − 3473
<< QString("o2o") << false;
+ − 3474
QTest::newRow( "normal4" ) << QString("o1o2o")
+ − 3475
<< QString("o") << 2 << 3
+ − 3476
<< int(QString::SectionIncludeLeadingSep|QString::SectionIncludeTrailingSep)
+ − 3477
<< QString("o2o") << false;
+ − 3478
QTest::newRow( "normal5" ) << QString("o1o2o")
+ − 3479
<< QString("o") << 1 << 2
+ − 3480
<< int(QString::SectionIncludeLeadingSep|QString::SectionIncludeTrailingSep)
+ − 3481
<< QString("o1o2o") << false;
+ − 3482
QTest::newRow( "rx1" ) << QString("o1o2o")
+ − 3483
<< QString("[a-z]") << 0 << 0
+ − 3484
<< int(QString::SectionIncludeLeadingSep|QString::SectionIncludeTrailingSep)
+ − 3485
<< QString("o") << true;
+ − 3486
QTest::newRow( "rx2" ) << QString("o1o2o")
+ − 3487
<< QString("[a-z]") << 1 << 1
+ − 3488
<< int(QString::SectionIncludeLeadingSep|QString::SectionIncludeTrailingSep)
+ − 3489
<< QString("o1o") << true;
+ − 3490
QTest::newRow( "rx3" ) << QString("o1o2o")
+ − 3491
<< QString("[a-z]") << 2 << 2
+ − 3492
<< int(QString::SectionIncludeLeadingSep|QString::SectionIncludeTrailingSep)
+ − 3493
<< QString("o2o") << true;
+ − 3494
QTest::newRow( "rx4" ) << QString("o1o2o")
+ − 3495
<< QString("[a-z]") << 2 << 3
+ − 3496
<< int(QString::SectionIncludeLeadingSep|QString::SectionIncludeTrailingSep)
+ − 3497
<< QString("o2o") << true;
+ − 3498
QTest::newRow( "rx5" ) << QString("o1o2o")
+ − 3499
<< QString("[a-z]") << 1 << 2
+ − 3500
<< int(QString::SectionIncludeLeadingSep|QString::SectionIncludeTrailingSep)
+ − 3501
<< QString("o1o2o") << true;
+ − 3502
QTest::newRow( "task45855-rx" ) << QString("This is a story, a small story")
+ − 3503
<< QString("\\b") << 3 << 3
+ − 3504
<< int(QString::SectionDefault)
+ − 3505
<< QString("is") << true;
+ − 3506
+ − 3507
}
+ − 3508
+ − 3509
void tst_QString::section()
+ − 3510
{
+ − 3511
QFETCH( QString, wholeString );
+ − 3512
QFETCH( QString, sep );
+ − 3513
QFETCH( int, start );
+ − 3514
QFETCH( int, end );
+ − 3515
QFETCH( int, flags );
+ − 3516
QFETCH( QString, sectionString );
+ − 3517
QFETCH( bool, regexp );
+ − 3518
if (regexp) {
+ − 3519
QCOMPARE( wholeString.section( QRegExp(sep), start, end, QString::SectionFlag(flags) ), sectionString );
+ − 3520
} else {
+ − 3521
QCOMPARE( wholeString.section( sep, start, end, QString::SectionFlag(flags) ), sectionString );
+ − 3522
}
+ − 3523
}
+ − 3524
+ − 3525
+ − 3526
void tst_QString::operator_eqeq_nullstring()
+ − 3527
{
+ − 3528
/* Some of these might not be all that logical but it's the behaviour we've had since 3.0.0
+ − 3529
so we should probably stick with it. */
+ − 3530
+ − 3531
QVERIFY( QString() == "" );
+ − 3532
QVERIFY( "" == QString() );
+ − 3533
+ − 3534
QVERIFY( QString("") == "" );
+ − 3535
QVERIFY( "" == QString("") );
+ − 3536
+ − 3537
QVERIFY( QString().size() == 0 );
+ − 3538
+ − 3539
QVERIFY( QString("").size() == 0 );
+ − 3540
+ − 3541
QVERIFY( QString() == QString("") );
+ − 3542
QVERIFY( QString("") == QString() );
+ − 3543
}
+ − 3544
+ − 3545
void tst_QString::operator_smaller()
+ − 3546
{
+ − 3547
QString null;
+ − 3548
QString empty("");
+ − 3549
QString foo("foo");
+ − 3550
+ − 3551
QVERIFY( !(null < QString()) );
+ − 3552
QVERIFY( !(null > QString()) );
+ − 3553
+ − 3554
QVERIFY( !(empty < QString("")) );
+ − 3555
QVERIFY( !(empty > QString("")) );
+ − 3556
+ − 3557
QVERIFY( !(null < empty) );
+ − 3558
QVERIFY( !(null > empty) );
+ − 3559
+ − 3560
QVERIFY( null < foo );
+ − 3561
QVERIFY( !(null > foo) );
+ − 3562
QVERIFY( foo > null );
+ − 3563
QVERIFY( !(foo < null) );
+ − 3564
+ − 3565
QVERIFY( empty < foo );
+ − 3566
QVERIFY( !(empty > foo) );
+ − 3567
QVERIFY( foo > empty );
+ − 3568
QVERIFY( !(foo < empty) );
+ − 3569
+ − 3570
QVERIFY( !(null < QLatin1String(0)) );
+ − 3571
QVERIFY( !(null > QLatin1String(0)) );
+ − 3572
QVERIFY( !(null < QLatin1String("")) );
+ − 3573
QVERIFY( !(null > QLatin1String("")) );
+ − 3574
+ − 3575
QVERIFY( !(null < QLatin1String("")) );
+ − 3576
QVERIFY( !(null > QLatin1String("")) );
+ − 3577
QVERIFY( !(empty < QLatin1String("")) );
+ − 3578
QVERIFY( !(empty > QLatin1String("")) );
+ − 3579
+ − 3580
QVERIFY( !(QLatin1String(0) < null) );
+ − 3581
QVERIFY( !(QLatin1String(0) > null) );
+ − 3582
QVERIFY( !(QLatin1String("") < null) );
+ − 3583
QVERIFY( !(QLatin1String("") > null) );
+ − 3584
+ − 3585
QVERIFY( !(QLatin1String(0) < empty) );
+ − 3586
QVERIFY( !(QLatin1String(0) > empty) );
+ − 3587
QVERIFY( !(QLatin1String("") < empty) );
+ − 3588
QVERIFY( !(QLatin1String("") > empty) );
+ − 3589
+ − 3590
QVERIFY( QLatin1String(0) < foo );
+ − 3591
QVERIFY( !(QLatin1String(0) > foo) );
+ − 3592
QVERIFY( QLatin1String("") < foo );
+ − 3593
QVERIFY( !(QLatin1String("") > foo) );
+ − 3594
+ − 3595
QVERIFY( foo > QLatin1String(0) );
+ − 3596
QVERIFY( !(foo < QLatin1String(0)) );
+ − 3597
QVERIFY( foo > QLatin1String("") );
+ − 3598
QVERIFY( !(foo < QLatin1String("")) );
+ − 3599
+ − 3600
QVERIFY( QLatin1String(0) == empty);
+ − 3601
QVERIFY( QLatin1String(0) == null);
+ − 3602
QVERIFY( QLatin1String("") == empty);
+ − 3603
QVERIFY( QLatin1String("") == null);
+ − 3604
+ − 3605
QVERIFY( !(foo < QLatin1String("foo")));
+ − 3606
QVERIFY( !(foo > QLatin1String("foo")));
+ − 3607
QVERIFY( !(QLatin1String("foo") < foo));
+ − 3608
QVERIFY( !(QLatin1String("foo") > foo));
+ − 3609
+ − 3610
QVERIFY( !(foo < QLatin1String("a")));
+ − 3611
QVERIFY( (foo > QLatin1String("a")));
+ − 3612
QVERIFY( (QLatin1String("a") < foo));
+ − 3613
QVERIFY( !(QLatin1String("a") > foo));
+ − 3614
+ − 3615
QVERIFY( (foo < QLatin1String("z")));
+ − 3616
QVERIFY( !(foo > QLatin1String("z")));
+ − 3617
QVERIFY( !(QLatin1String("z") < foo));
+ − 3618
QVERIFY( (QLatin1String("z") > foo));
+ − 3619
}
+ − 3620
+ − 3621
void tst_QString::integer_conversion_data()
+ − 3622
{
+ − 3623
QTest::addColumn<QString>("locale_name");
+ − 3624
QTest::addColumn<QString>("num_str");
+ − 3625
QTest::addColumn<int>("base");
+ − 3626
QTest::addColumn<bool>("good");
+ − 3627
QTest::addColumn<qlonglong>("num");
+ − 3628
+ − 3629
QTest::newRow("C empty 0") << QString("C") << QString("") << 0 << false << (qlonglong)0;
+ − 3630
QTest::newRow("C empty 8") << QString("C") << QString("") << 8 << false << (qlonglong)0;
+ − 3631
QTest::newRow("C empty 10") << QString("C") << QString("") << 10 << false << (qlonglong)0;
+ − 3632
QTest::newRow("C empty 16") << QString("C") << QString("") << 16 << false << (qlonglong)0;
+ − 3633
+ − 3634
QTest::newRow("C null 0") << QString("C") << QString() << 0 << false << (qlonglong)0;
+ − 3635
QTest::newRow("C null 8") << QString("C") << QString() << 8 << false << (qlonglong)0;
+ − 3636
QTest::newRow("C null 10") << QString("C") << QString() << 10 << false << (qlonglong)0;
+ − 3637
QTest::newRow("C null 16") << QString("C") << QString() << 16 << false << (qlonglong)0;
+ − 3638
+ − 3639
QTest::newRow("C -0xf 0") << QString("C") << QString(" -0xf") << 0 << true << (qlonglong)-15;
+ − 3640
QTest::newRow("C -0xf 0") << QString("C") << QString("-0xf ") << 0 << true << (qlonglong)-15;
+ − 3641
QTest::newRow("C \t0xf\t 0") << QString("C") << QString("\t0xf\t") << 0 << true << (qlonglong)15;
+ − 3642
QTest::newRow("C -010 0") << QString("C") << QString(" -010") << 0 << true << (qlonglong)-8;
+ − 3643
QTest::newRow("C 010 0") << QString("C") << QString("010 ") << 0 << true << (qlonglong)8;
+ − 3644
QTest::newRow("C \t-010\t 0") << QString("C") << QString("\t-010\t") << 0 << true << (qlonglong)-8;
+ − 3645
QTest::newRow("C 123 10") << QString("C") << QString(" 123") << 10 << true << (qlonglong)123;
+ − 3646
QTest::newRow("C 123 10") << QString("C") << QString("123 ") << 10 << true << (qlonglong)123;
+ − 3647
QTest::newRow("C \t123\t 10") << QString("C") << QString("\t123\t") << 10 << true << (qlonglong)123;
+ − 3648
QTest::newRow("C -0xf 16") << QString("C") << QString(" -0xf") << 16 << true << (qlonglong)-15;
+ − 3649
QTest::newRow("C -0xf 16") << QString("C") << QString("-0xf ") << 16 << true << (qlonglong)-15;
+ − 3650
QTest::newRow("C \t0xf\t 16") << QString("C") << QString("\t0xf\t") << 16 << true << (qlonglong)15;
+ − 3651
+ − 3652
QTest::newRow("C -0 0") << QString("C") << QString("-0") << 0 << true << (qlonglong)0;
+ − 3653
QTest::newRow("C -0 8") << QString("C") << QString("-0") << 8 << true << (qlonglong)0;
+ − 3654
QTest::newRow("C -0 10") << QString("C") << QString("-0") << 10 << true << (qlonglong)0;
+ − 3655
QTest::newRow("C -0 16") << QString("C") << QString("-0") << 16 << true << (qlonglong)0;
+ − 3656
+ − 3657
QTest::newRow("C 1.234 10") << QString("C") << QString("1.234") << 10 << false << (qlonglong)0;
+ − 3658
QTest::newRow("C 1,234 10") << QString("C") << QString("1,234") << 10 << false << (qlonglong)0;
+ − 3659
QTest::newRow("de_DE 1.234 10") << QString("de_DE") << QString("1.234") << 10 << false << (qlonglong)0;
+ − 3660
QTest::newRow("de_DE 1,234 10") << QString("de_DE") << QString("1,234") << 10 << false << (qlonglong)0;
+ − 3661
+ − 3662
QTest::newRow("C 0x 0") << QString("C") << QString("0x") << 0 << false << (qlonglong)0;
+ − 3663
QTest::newRow("C 0x 16") << QString("C") << QString("0x") << 16 << false << (qlonglong)0;
+ − 3664
+ − 3665
QTest::newRow("C 10 0") << QString("C") << QString("10") << 0 << true << (qlonglong)10;
+ − 3666
QTest::newRow("C 010 0") << QString("C") << QString("010") << 0 << true << (qlonglong)8;
+ − 3667
QTest::newRow("C 0x10 0") << QString("C") << QString("0x10") << 0 << true << (qlonglong)16;
+ − 3668
QTest::newRow("C 10 8") << QString("C") << QString("10") << 8 << true << (qlonglong)8;
+ − 3669
QTest::newRow("C 010 8") << QString("C") << QString("010") << 8 << true << (qlonglong)8;
+ − 3670
QTest::newRow("C 0x10 8") << QString("C") << QString("0x10") << 8 << false << (qlonglong)0;
+ − 3671
QTest::newRow("C 10 10") << QString("C") << QString("10") << 10 << true << (qlonglong)10;
+ − 3672
QTest::newRow("C 010 10") << QString("C") << QString("010") << 10 << true << (qlonglong)10;
+ − 3673
QTest::newRow("C 0x10 10") << QString("C") << QString("0x10") << 10 << false << (qlonglong)0;
+ − 3674
QTest::newRow("C 10 16") << QString("C") << QString("10") << 16 << true << (qlonglong)16;
+ − 3675
QTest::newRow("C 010 16") << QString("C") << QString("010") << 16 << true << (qlonglong)16;
+ − 3676
QTest::newRow("C 0x10 16") << QString("C") << QString("0x10") << 16 << true << (qlonglong)16;
+ − 3677
+ − 3678
QTest::newRow("de_DE 10 0") << QString("de_DE") << QString("10") << 0 << true << (qlonglong)10;
+ − 3679
QTest::newRow("de_DE 010 0") << QString("de_DE") << QString("010") << 0 << true << (qlonglong)8;
+ − 3680
QTest::newRow("de_DE 0x10 0") << QString("de_DE") << QString("0x10") << 0 << true << (qlonglong)16;
+ − 3681
QTest::newRow("de_DE 10 8") << QString("de_DE") << QString("10") << 8 << true << (qlonglong)8;
+ − 3682
QTest::newRow("de_DE 010 8") << QString("de_DE") << QString("010") << 8 << true << (qlonglong)8;
+ − 3683
QTest::newRow("de_DE 0x10 8") << QString("de_DE") << QString("0x10") << 8 << false << (qlonglong)0;
+ − 3684
QTest::newRow("de_DE 10 10") << QString("de_DE") << QString("10") << 10 << true << (qlonglong)10;
+ − 3685
QTest::newRow("de_DE 010 10") << QString("de_DE") << QString("010") << 10 << true << (qlonglong)10;
+ − 3686
QTest::newRow("de_DE 0x10 10") << QString("de_DE") << QString("0x10") << 10 << false << (qlonglong)0;
+ − 3687
QTest::newRow("de_DE 10 16") << QString("de_DE") << QString("10") << 16 << true << (qlonglong)16;
+ − 3688
QTest::newRow("de_DE 010 16") << QString("de_DE") << QString("010") << 16 << true << (qlonglong)16;
+ − 3689
QTest::newRow("de_DE 0x10 16") << QString("de_DE") << QString("0x10") << 16 << true << (qlonglong)16;
+ − 3690
+ − 3691
QTest::newRow("C -10 0") << QString("C") << QString("-10") << 0 << true << (qlonglong)-10;
+ − 3692
QTest::newRow("C -010 0") << QString("C") << QString("-010") << 0 << true << (qlonglong)-8;
+ − 3693
QTest::newRow("C -0x10 0") << QString("C") << QString("-0x10") << 0 << true << (qlonglong)-16;
+ − 3694
QTest::newRow("C -10 8") << QString("C") << QString("-10") << 8 << true << (qlonglong)-8;
+ − 3695
QTest::newRow("C -010 8") << QString("C") << QString("-010") << 8 << true << (qlonglong)-8;
+ − 3696
QTest::newRow("C -0x10 8") << QString("C") << QString("-0x10") << 8 << false << (qlonglong)0;
+ − 3697
QTest::newRow("C -10 10") << QString("C") << QString("-10") << 10 << true << (qlonglong)-10;
+ − 3698
QTest::newRow("C -010 10") << QString("C") << QString("-010") << 10 << true << (qlonglong)-10;
+ − 3699
QTest::newRow("C -0x10 10") << QString("C") << QString("-0x10") << 10 << false << (qlonglong)0;
+ − 3700
QTest::newRow("C -10 16") << QString("C") << QString("-10") << 16 << true << (qlonglong)-16;
+ − 3701
QTest::newRow("C -010 16") << QString("C") << QString("-010") << 16 << true << (qlonglong)-16;
+ − 3702
QTest::newRow("C -0x10 16") << QString("C") << QString("-0x10") << 16 << true << (qlonglong)-16;
+ − 3703
+ − 3704
// Let's try some Arabic
+ − 3705
const quint16 arabic_str[] = { 0x0661, 0x0662, 0x0663, 0x0664, 0x0000 }; // "1234"
+ − 3706
QTest::newRow("ar_SA 1234 0") << QString("ar_SA") << QString::fromUtf16(arabic_str) << 0 << true << (qlonglong)1234;
+ − 3707
QTest::newRow("ar_SA 1234 8") << QString("ar_SA") << QString::fromUtf16(arabic_str) << 8 << true << (qlonglong)668;
+ − 3708
QTest::newRow("ar_SA 1234 10") << QString("ar_SA") << QString::fromUtf16(arabic_str) << 10 << true << (qlonglong)1234;
+ − 3709
QTest::newRow("ar_SA 1234 16") << QString("ar_SA") << QString::fromUtf16(arabic_str) << 16 << true << (qlonglong)4660;
+ − 3710
}
+ − 3711
+ − 3712
void tst_QString::integer_conversion()
+ − 3713
{
+ − 3714
QFETCH(QString, locale_name);
+ − 3715
QFETCH(QString, num_str);
+ − 3716
QFETCH(int, base);
+ − 3717
QFETCH(bool, good);
+ − 3718
QFETCH(qlonglong, num);
+ − 3719
+ − 3720
+ − 3721
QLocale::setDefault(locale_name);
+ − 3722
QCOMPARE(QLocale().name(), locale_name);
+ − 3723
+ − 3724
bool ok;
+ − 3725
qlonglong d = num_str.toLongLong(&ok, base);
+ − 3726
QCOMPARE(ok, good);
+ − 3727
+ − 3728
if (ok) {
+ − 3729
QCOMPARE(d, num);
+ − 3730
}
+ − 3731
+ − 3732
QLocale::setDefault(QLocale::C);
+ − 3733
}
+ − 3734
+ − 3735
void tst_QString::double_conversion_data()
+ − 3736
{
+ − 3737
QTest::addColumn<QString>("locale_name");
+ − 3738
QTest::addColumn<QString>("num_str");
+ − 3739
QTest::addColumn<bool>("good");
+ − 3740
QTest::addColumn<double>("num");
+ − 3741
/*
+ − 3742
// The good...
+ − 3743
+ − 3744
QTest::newRow("C 1") << QString("C") << QString("1") << true << 1.0;
+ − 3745
QTest::newRow("C 1.0") << QString("C") << QString("1.0") << true << 1.0;
+ − 3746
QTest::newRow("C 1.234") << QString("C") << QString("1.234") << true << 1.234;
+ − 3747
QTest::newRow("C 1.234e-10") << QString("C") << QString("1.234e-10") << true << 1.234e-10;
+ − 3748
QTest::newRow("C 1.234E10") << QString("C") << QString("1.234E10") << true << 1.234e10;
+ − 3749
QTest::newRow("C 1e10") << QString("C") << QString("1e10") << true << 1.0e10;
+ − 3750
+ − 3751
// The bad...
+ − 3752
+ − 3753
QTest::newRow("C empty") << QString("C") << QString("") << false << 0.0;
+ − 3754
QTest::newRow("C null") << QString("C") << QString() << false << 0.0;
+ − 3755
QTest::newRow("C .") << QString("C") << QString(".") << false << 0.0;
+ − 3756
QTest::newRow("C 1e") << QString("C") << QString("1e") << false << 0.0;
+ − 3757
QTest::newRow("C 1,") << QString("C") << QString("1,") << false << 0.0;
+ − 3758
QTest::newRow("C 1,0") << QString("C") << QString("1,0") << false << 0.0;
+ − 3759
QTest::newRow("C 1,000") << QString("C") << QString("1,000") << false << 0.0;
+ − 3760
QTest::newRow("C 1e1.0") << QString("C") << QString("1e1.0") << false << 0.0;
+ − 3761
QTest::newRow("C 1e+") << QString("C") << QString("1e+") << false << 0.0;
+ − 3762
QTest::newRow("C 1e-") << QString("C") << QString("1e-") << false << 0.0;
+ − 3763
+ − 3764
// And the ugly...
+ − 3765
+ − 3766
QTest::newRow("C .1") << QString("C") << QString(".1") << true << 0.1;
+ − 3767
QTest::newRow("C -.1") << QString("C") << QString("-.1") << true << -0.1;
+ − 3768
QTest::newRow("C 1.") << QString("C") << QString("1.") << true << 1.0;
+ − 3769
QTest::newRow("C 1.E10") << QString("C") << QString("1.E10") << true << 1.0e10;
+ − 3770
QTest::newRow("C 1e+10") << QString("C") << QString("1e+10") << true << 1.0e+10;
+ − 3771
+ − 3772
QTest::newRow("de_DE 1") << QString("de_DE") << QString("1") << true << 1.0;
+ − 3773
QTest::newRow("de_DE 1.0") << QString("de_DE") << QString("1.0") << true << 1.0;
+ − 3774
QTest::newRow("de_DE 1.234") << QString("de_DE") << QString("1.234") << true << 1.234;
+ − 3775
QTest::newRow("de_DE 1.234e-10") << QString("de_DE") << QString("1.234e-10") << true << 1.234e-10;
+ − 3776
QTest::newRow("de_DE 1.234E10") << QString("de_DE") << QString("1.234E10") << true << 1.234e10;
+ − 3777
QTest::newRow("de_DE 1e10") << QString("de_DE") << QString("1e10") << true << 1.0e10;
+ − 3778
QTest::newRow("de_DE .1") << QString("de_DE") << QString(".1") << true << 0.1;
+ − 3779
QTest::newRow("de_DE -.1") << QString("de_DE") << QString("-.1") << true << -0.1;
+ − 3780
QTest::newRow("de_DE 1.") << QString("de_DE") << QString("1.") << true << 1.0;
+ − 3781
QTest::newRow("de_DE 1.E10") << QString("de_DE") << QString("1.E10") << true << 1.0e10;
+ − 3782
QTest::newRow("de_DE 1e+10") << QString("de_DE") << QString("1e+10") << true << 1.0e+10;
+ − 3783
+ − 3784
QTest::newRow("de_DE 1,0") << QString("de_DE") << QString("1,0") << true << 1.0;
+ − 3785
QTest::newRow("de_DE 1,234") << QString("de_DE") << QString("1,234") << true << 1.234;
+ − 3786
QTest::newRow("de_DE 1,234e-10") << QString("de_DE") << QString("1,234e-10") << true << 1.234e-10;
+ − 3787
QTest::newRow("de_DE 1,234E10") << QString("de_DE") << QString("1,234E10") << true << 1.234e10;
+ − 3788
QTest::newRow("de_DE ,1") << QString("de_DE") << QString(",1") << true << 0.1;
+ − 3789
QTest::newRow("de_DE -,1") << QString("de_DE") << QString("-,1") << true << -0.1;
+ − 3790
QTest::newRow("de_DE 1,") << QString("de_DE") << QString("1,") << true << 1.0;
+ − 3791
QTest::newRow("de_DE 1,E10") << QString("de_DE") << QString("1,E10") << true << 1.0e10;
+ − 3792
+ − 3793
QTest::newRow("de_DE empty") << QString("de_DE") << QString("") << false << 0.0;
+ − 3794
QTest::newRow("de_DE null") << QString("de_DE") << QString() << false << 0.0;
+ − 3795
QTest::newRow("de_DE .") << QString("de_DE") << QString(".") << false << 0.0;
+ − 3796
QTest::newRow("de_DE 1e") << QString("de_DE") << QString("1e") << false << 0.0;
+ − 3797
QTest::newRow("de_DE 1e1.0") << QString("de_DE") << QString("1e1.0") << false << 0.0;
+ − 3798
QTest::newRow("de_DE 1e+") << QString("de_DE") << QString("1e+") << false << 0.0;
+ − 3799
QTest::newRow("de_DE 1e-") << QString("de_DE") << QString("1e-") << false << 0.0;
+ − 3800
+ − 3801
QTest::newRow("C 1") << QString("C") << QString(" 1") << true << 1.0;
+ − 3802
QTest::newRow("C 1 ") << QString("C") << QString("1 ") << true << 1.0;
+ − 3803
QTest::newRow("de_DE 1") << QString("de_DE") << QString(" 1") << true << 1.0;
+ − 3804
QTest::newRow("de_DE 1 ") << QString("de_DE") << QString("1 ") << true << 1.0;
+ − 3805
*/
+ − 3806
// Let's try some Arabic
+ − 3807
const quint16 arabic_str[] = { 0x0660, 0x066B, 0x0661, 0x0662,
+ − 3808
0x0663, 0x0664, 0x0065, 0x0662,
+ − 3809
0x0000 }; // "0.1234e2"
+ − 3810
QTest::newRow("ar_SA") << QString("ar_SA") << QString::fromUtf16(arabic_str) << true << 0.1234e2;
+ − 3811
}
+ − 3812
+ − 3813
void tst_QString::double_conversion()
+ − 3814
{
+ − 3815
#define MY_DOUBLE_EPSILON (2.22045e-16)
+ − 3816
+ − 3817
QFETCH(QString, locale_name);
+ − 3818
QFETCH(QString, num_str);
+ − 3819
QFETCH(bool, good);
+ − 3820
QFETCH(double, num);
+ − 3821
+ − 3822
QLocale::setDefault(locale_name);
+ − 3823
QCOMPARE(QLocale().name(), locale_name);
+ − 3824
+ − 3825
bool ok;
+ − 3826
double d = num_str.toDouble(&ok);
+ − 3827
QCOMPARE(ok, good);
+ − 3828
+ − 3829
if (ok) {
+ − 3830
double diff = d - num;
+ − 3831
if (diff < 0)
+ − 3832
diff = -diff;
+ − 3833
QVERIFY(diff <= MY_DOUBLE_EPSILON);
+ − 3834
}
+ − 3835
+ − 3836
QLocale::setDefault(QLocale::C);
+ − 3837
}
+ − 3838
+ − 3839
#ifndef Q_MOC_RUN
+ − 3840
#include "double_data.h"
+ − 3841
#endif
+ − 3842
+ − 3843
void tst_QString::tortureSprintfDouble()
+ − 3844
{
+ − 3845
const SprintfDoubleData *data = g_sprintf_double_data;
+ − 3846
+ − 3847
QString s;
+ − 3848
+ − 3849
for (; data->fmt != 0; ++data) {
+ − 3850
double d;
+ − 3851
char *buff = (char *)&d;
+ − 3852
# ifndef Q_BYTE_ORDER
+ − 3853
# error "Q_BYTE_ORDER not defined"
+ − 3854
# endif
+ − 3855
+ − 3856
# ifdef QT_ARMFPA
+ − 3857
buff[0] = data->bytes[4];
+ − 3858
buff[1] = data->bytes[5];
+ − 3859
buff[2] = data->bytes[6];
+ − 3860
buff[3] = data->bytes[7];
+ − 3861
buff[4] = data->bytes[0];
+ − 3862
buff[5] = data->bytes[1];
+ − 3863
buff[6] = data->bytes[2];
+ − 3864
buff[7] = data->bytes[3];
+ − 3865
# elif Q_BYTE_ORDER == Q_LITTLE_ENDIAN
+ − 3866
for (uint i = 0; i < 8; ++i)
+ − 3867
buff[i] = data->bytes[i];
+ − 3868
# else
+ − 3869
for (uint i = 0; i < 8; ++i)
+ − 3870
buff[7 - i] = data->bytes[i];
+ − 3871
# endif
+ − 3872
s.sprintf(data->fmt, d);
+ − 3873
#ifdef QT_NO_FPU // reduced precision when running with hardfloats in qemu
+ − 3874
if (d - 0.1 < 1e12)
+ − 3875
QSKIP("clib sprintf doesn't fill with 0's on this platform",
+ − 3876
SkipSingle);
+ − 3877
QCOMPARE(s.left(16), QString(data->expected).left(16));
+ − 3878
#else
+ − 3879
QCOMPARE(s, QString(data->expected));
+ − 3880
#endif
+ − 3881
}
+ − 3882
}
+ − 3883
+ − 3884
#include <locale.h>
+ − 3885
+ − 3886
void tst_QString::localeAwareCompare_data()
+ − 3887
{
+ − 3888
#ifdef Q_OS_WIN
+ − 3889
QTest::addColumn<ulong>("locale");
+ − 3890
#else
+ − 3891
QTest::addColumn<QString>("locale");
+ − 3892
#endif
+ − 3893
QTest::addColumn<QString>("s1");
+ − 3894
QTest::addColumn<QString>("s2");
+ − 3895
QTest::addColumn<int>("result");
+ − 3896
+ − 3897
/*
+ − 3898
The C locale performs pure byte comparisons for
+ − 3899
Latin-1-specific characters (I think). Compare with Swedish
+ − 3900
below.
+ − 3901
*/
+ − 3902
#ifdef Q_OS_WIN // assume c locale to be english
+ − 3903
QTest::newRow("c1") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString("\xe5") << QString("\xe4") << 1;
+ − 3904
QTest::newRow("c2") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString("\xe4") << QString("\xf6") << -1;
+ − 3905
QTest::newRow("c3") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString("\xe5") << QString("\xf6") << -1;
+ − 3906
#else
+ − 3907
QTest::newRow("c1") << QString("C") << QString("\xe5") << QString("\xe4") << 1;
+ − 3908
QTest::newRow("c2") << QString("C") << QString("\xe4") << QString("\xf6") << -1;
+ − 3909
QTest::newRow("c3") << QString("C") << QString("\xe5") << QString("\xf6") << -1;
+ − 3910
#endif
+ − 3911
+ − 3912
/*
+ − 3913
It's hard to test English, because it's treated differently
+ − 3914
on different platforms. For example, on Linux, it uses the
+ − 3915
iso14651_t1 template file, which happens to provide good
+ − 3916
defaults for Swedish. Mac OS X seems to do a pure bytewise
+ − 3917
comparison of Latin-1 values, although I'm not sure. So I
+ − 3918
just test digits to make sure that it's not totally broken.
+ − 3919
*/
+ − 3920
#ifdef Q_OS_WIN
+ − 3921
QTest::newRow("english1") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString("5") << QString("4") << 1;
+ − 3922
QTest::newRow("english2") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString("4") << QString("6") << -1;
+ − 3923
QTest::newRow("english3") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString("5") << QString("6") << -1;
+ − 3924
#else
+ − 3925
QTest::newRow("english1") << QString("en_US") << QString("5") << QString("4") << 1;
+ − 3926
QTest::newRow("english2") << QString("en_US") << QString("4") << QString("6") << -1;
+ − 3927
QTest::newRow("english3") << QString("en_US") << QString("5") << QString("6") << -1;
+ − 3928
#endif
+ − 3929
/*
+ − 3930
In Swedish, a with ring above (E5) comes before a with
+ − 3931
diaresis (E4), which comes before o diaresis (F6), which
+ − 3932
all come after z.
+ − 3933
*/
+ − 3934
#ifdef Q_OS_MAC
+ − 3935
QTest::newRow("swedish1") << QString("sv_SE.ISO8859-1") << QString("\xe5") << QString("\xe4") << -1;
+ − 3936
QTest::newRow("swedish2") << QString("sv_SE.ISO8859-1") << QString("\xe4") << QString("\xf6") << -1;
+ − 3937
QTest::newRow("swedish3") << QString("sv_SE.ISO8859-1") << QString("\xe5") << QString("\xf6") << -1;
+ − 3938
QTest::newRow("swedish4") << QString("sv_SE.ISO8859-1") << QString("z") << QString("\xe5") << -1;
+ − 3939
#elif defined(Q_OS_WIN)
+ − 3940
QTest::newRow("swedish1") << MAKELCID(MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH), SORT_DEFAULT) << QString("\xe5") << QString("\xe4") << -1;
+ − 3941
QTest::newRow("swedish2") << MAKELCID(MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH), SORT_DEFAULT) << QString("\xe4") << QString("\xf6") << -1;
+ − 3942
QTest::newRow("swedish3") << MAKELCID(MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH), SORT_DEFAULT) << QString("\xe5") << QString("\xf6") << -1;
+ − 3943
QTest::newRow("swedish4") << MAKELCID(MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH), SORT_DEFAULT) << QString("z") << QString("\xe5") << -1;
+ − 3944
#else
+ − 3945
QTest::newRow("swedish1") << QString("sv_SE") << QString("\xe5") << QString("\xe4") << -1;
+ − 3946
QTest::newRow("swedish2") << QString("sv_SE") << QString("\xe4") << QString("\xf6") << -1;
+ − 3947
QTest::newRow("swedish3") << QString("sv_SE") << QString("\xe5") << QString("\xf6") << -1;
+ − 3948
QTest::newRow("swedish4") << QString("sv_SE") << QString("z") << QString("\xe5") << -1;
+ − 3949
#endif
+ − 3950
+ − 3951
#if 0
+ − 3952
/*
+ − 3953
In Norwegian, ae (E6) comes before o with stroke (D8), which
+ − 3954
comes before a with ring above (E5).
+ − 3955
*/
+ − 3956
QTest::newRow("norwegian1") << QString("no_NO") << QString("\xe6") << QString("\xd8") << -1;
+ − 3957
QTest::newRow("norwegian2") << QString("no_NO") << QString("\xd8") << QString("\xe5") << -1;
+ − 3958
QTest::newRow("norwegian3") << QString("no_NO") << QString("\xe6") << QString("\xe5") << -1;
+ − 3959
#endif
+ − 3960
+ − 3961
/*
+ − 3962
In German, z comes *after* a with diaresis (E4),
+ − 3963
which comes before o diaresis (F6).
+ − 3964
*/
+ − 3965
#ifdef Q_OS_MAC
+ − 3966
QTest::newRow("german1") << QString("de_DE.ISO8859-1") << QString("z") << QString("\xe4") << 1;
+ − 3967
QTest::newRow("german2") << QString("de_DE.ISO8859-1") << QString("\xe4") << QString("\xf6") << -1;
+ − 3968
QTest::newRow("german3") << QString("de_DE.ISO8859-1") << QString("z") << QString("\xf6") << 1;
+ − 3969
#elif defined(Q_OS_WIN)
+ − 3970
QTest::newRow("german1") << MAKELCID(MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), SORT_DEFAULT) << QString("z") << QString("\xe4") << 1;
+ − 3971
QTest::newRow("german2") << MAKELCID(MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), SORT_DEFAULT) << QString("\xe4") << QString("\xf6") << -1;
+ − 3972
QTest::newRow("german3") << MAKELCID(MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), SORT_DEFAULT) << QString("z") << QString("\xf6") << 1;
+ − 3973
#else
+ − 3974
QTest::newRow("german1") << QString("de_DE") << QString("z") << QString("\xe4") << 1;
+ − 3975
QTest::newRow("german2") << QString("de_DE") << QString("\xe4") << QString("\xf6") << -1;
+ − 3976
QTest::newRow("german3") << QString("de_DE") << QString("z") << QString("\xf6") << 1;
+ − 3977
#endif
+ − 3978
}
+ − 3979
+ − 3980
void tst_QString::localeAwareCompare()
+ − 3981
{
+ − 3982
#ifdef Q_OS_WIN
+ − 3983
# ifndef Q_OS_WINCE
+ − 3984
QSKIP("On others than Win CE, we cannot set the system or user locale.", SkipAll);
+ − 3985
# endif
+ − 3986
QFETCH(ulong, locale);
+ − 3987
#else
+ − 3988
QFETCH(QString, locale);
+ − 3989
#endif
+ − 3990
QFETCH(QString, s1);
+ − 3991
QFETCH(QString, s2);
+ − 3992
QFETCH(int, result);
+ − 3993
+ − 3994
QStringRef r1(&s1, 0, s1.length());
+ − 3995
QStringRef r2(&s2, 0, s2.length());
+ − 3996
+ − 3997
#ifdef Q_OS_WIN
+ − 3998
# if defined(Q_OS_WINCE)
+ − 3999
DWORD oldLcid = GetUserDefaultLCID();
+ − 4000
SetUserDefaultLCID(locale);
+ − 4001
+ − 4002
QCOMPARE(locale, GetUserDefaultLCID());
+ − 4003
# else
+ − 4004
DWORD oldLcid = GetThreadLocale();
+ − 4005
SetThreadLocale(locale);
+ − 4006
+ − 4007
QCOMPARE(locale, GetThreadLocale());
+ − 4008
# endif
+ − 4009
+ − 4010
#elif defined (Q_WS_MAC)
+ − 4011
QSKIP("Setting the locale is not supported on OS X (you can set the C locale, but that won't affect CFStringCompare which is used to compare strings)", SkipAll);
+ − 4012
#else
+ − 4013
if (!locale.isEmpty()) {
+ − 4014
const char *newLocale = setlocale(LC_ALL, locale.toLatin1());
+ − 4015
if (!newLocale) {
+ − 4016
setlocale(LC_ALL, "");
+ − 4017
QSKIP("Please install the proper locale on this machine to test properly", SkipSingle);
+ − 4018
return;
+ − 4019
}
+ − 4020
}
+ − 4021
#endif
+ − 4022
+ − 4023
int testres = QString::localeAwareCompare(s1, s2);
+ − 4024
if (result < 0) {
+ − 4025
QVERIFY(testres < 0);
+ − 4026
} else if (result > 0) {
+ − 4027
QVERIFY(testres > 0);
+ − 4028
} else {
+ − 4029
QVERIFY(testres == 0);
+ − 4030
}
+ − 4031
+ − 4032
testres = QString::localeAwareCompare(s2, s1);
+ − 4033
if (result > 0) {
+ − 4034
QVERIFY(testres < 0);
+ − 4035
} else if (result < 0) {
+ − 4036
QVERIFY(testres > 0);
+ − 4037
} else {
+ − 4038
QVERIFY(testres == 0);
+ − 4039
}
+ − 4040
+ − 4041
testres = QString::localeAwareCompare(s1, r2);
+ − 4042
if (result < 0) {
+ − 4043
QVERIFY(testres < 0);
+ − 4044
} else if (result > 0) {
+ − 4045
QVERIFY(testres > 0);
+ − 4046
} else {
+ − 4047
QVERIFY(testres == 0);
+ − 4048
}
+ − 4049
+ − 4050
testres = QStringRef::localeAwareCompare(r1, r2);
+ − 4051
if (result < 0) {
+ − 4052
QVERIFY(testres < 0);
+ − 4053
} else if (result > 0) {
+ − 4054
QVERIFY(testres > 0);
+ − 4055
} else {
+ − 4056
QVERIFY(testres == 0);
+ − 4057
}
+ − 4058
+ − 4059
testres = QStringRef::localeAwareCompare(r2, r1);
+ − 4060
if (result > 0) {
+ − 4061
QVERIFY(testres < 0);
+ − 4062
} else if (result < 0) {
+ − 4063
QVERIFY(testres > 0);
+ − 4064
} else {
+ − 4065
QVERIFY(testres == 0);
+ − 4066
}
+ − 4067
+ − 4068
#ifdef Q_OS_WIN
+ − 4069
# if defined(Q_OS_WINCE)
+ − 4070
SetUserDefaultLCID(oldLcid);
+ − 4071
# else
+ − 4072
SetThreadLocale(oldLcid);
+ − 4073
# endif
+ − 4074
+ − 4075
#else
+ − 4076
if (!locale.isEmpty())
+ − 4077
setlocale(LC_ALL, "");
+ − 4078
#endif
+ − 4079
}
+ − 4080
+ − 4081
void tst_QString::split_data()
+ − 4082
{
+ − 4083
QTest::addColumn<QString>("str");
+ − 4084
QTest::addColumn<QString>("sep");
+ − 4085
QTest::addColumn<QStringList>("result");
+ − 4086
+ − 4087
QTest::newRow("1") << "a,b,c" << "," << (QStringList() << "a" << "b" << "c");
+ − 4088
QTest::newRow("2") << QString("-rw-r--r-- 1 0 0 519240 Jul 9 2002 bigfile")
+ − 4089
<< " "
+ − 4090
<< (QStringList() << "-rw-r--r--" << "" << "1" << "0" << "" << "0" << ""
+ − 4091
<< "519240" << "Jul" << "" << "9" << "" << "2002" << "bigfile");
+ − 4092
QTest::newRow("one-empty") << "" << " " << (QStringList() << "");
+ − 4093
QTest::newRow("two-empty") << " " << " " << (QStringList() << "" << "");
+ − 4094
QTest::newRow("three-empty") << " " << " " << (QStringList() << "" << "" << "");
+ − 4095
+ − 4096
QTest::newRow("all-empty") << "" << "" << (QStringList() << "" << "");
+ − 4097
QTest::newRow("sep-empty") << "abc" << "" << (QStringList() << "" << "a" << "b" << "c" << "");
+ − 4098
}
+ − 4099
+ − 4100
void tst_QString::split()
+ − 4101
{
+ − 4102
QFETCH(QString, str);
+ − 4103
QFETCH(QString, sep);
+ − 4104
QFETCH(QStringList, result);
+ − 4105
+ − 4106
QRegExp rx = QRegExp(QRegExp::escape(sep));
+ − 4107
+ − 4108
QStringList list;
+ − 4109
+ − 4110
list = str.split(sep);
+ − 4111
QVERIFY(list == result);
+ − 4112
list = str.split(rx);
+ − 4113
QVERIFY(list == result);
+ − 4114
if (sep.size() == 1) {
+ − 4115
list = str.split(sep.at(0));
+ − 4116
QVERIFY(list == result);
+ − 4117
}
+ − 4118
+ − 4119
list = str.split(sep, QString::KeepEmptyParts);
+ − 4120
QVERIFY(list == result);
+ − 4121
list = str.split(rx, QString::KeepEmptyParts);
+ − 4122
QVERIFY(list == result);
+ − 4123
if (sep.size() == 1) {
+ − 4124
list = str.split(sep.at(0), QString::KeepEmptyParts);
+ − 4125
QVERIFY(list == result);
+ − 4126
}
+ − 4127
+ − 4128
result.removeAll("");
+ − 4129
list = str.split(sep, QString::SkipEmptyParts);
+ − 4130
QVERIFY(list == result);
+ − 4131
list = str.split(rx, QString::SkipEmptyParts);
+ − 4132
QVERIFY(list == result);
+ − 4133
if (sep.size() == 1) {
+ − 4134
list = str.split(sep.at(0), QString::SkipEmptyParts);
+ − 4135
QVERIFY(list == result);
+ − 4136
}
+ − 4137
}
+ − 4138
+ − 4139
void tst_QString::split_regexp()
+ − 4140
{
+ − 4141
QString str1 = "Some text\n\twith strange whitespace.";
+ − 4142
QStringList list1 = str1.split(QRegExp("\\s+"));
+ − 4143
QStringList result1;
+ − 4144
result1 << "Some" << "text" << "with" << "strange" << "whitespace.";
+ − 4145
QVERIFY(list1 == result1);
+ − 4146
list1 = str1.split(QRegExp("\\s"), QString::SkipEmptyParts);
+ − 4147
QVERIFY(list1 == result1);
+ − 4148
+ − 4149
QString str2 = "This time, a normal English sentence.";
+ − 4150
QStringList list2 = str2.split(QRegExp("\\W+"));
+ − 4151
QStringList result2;
+ − 4152
result2 << "This" << "time" << "a" << "normal" << "English" << "sentence" << "";
+ − 4153
QVERIFY(list2 == result2);
+ − 4154
list2 = str2.split(QRegExp("\\W"), QString::SkipEmptyParts);
+ − 4155
result2.removeAll(QString());
+ − 4156
QVERIFY(list2 == result2);
+ − 4157
+ − 4158
QString str3 = "Now: this sentence fragment.";
+ − 4159
QStringList list3 = str3.split(QRegExp("\\b"));
+ − 4160
QStringList result3;
+ − 4161
result3 << "" << "Now" << ": " << "this" << " " << "sentence" << " " << "fragment" << ".";
+ − 4162
QVERIFY(list3 == result3);
+ − 4163
list3 = str3.split(QRegExp("\\b"), QString::SkipEmptyParts);
+ − 4164
result3.removeAll(QString());
+ − 4165
QVERIFY(list3 == result3);
+ − 4166
}
+ − 4167
+ − 4168
void tst_QString::fromUtf16_data()
+ − 4169
{
+ − 4170
QTest::addColumn<QString>("ucs2");
+ − 4171
QTest::addColumn<QString>("res");
+ − 4172
QTest::addColumn<int>("len");
+ − 4173
+ − 4174
QTest::newRow("str0") << QString("abcdefgh") << QString("abcdefgh") << -1;
+ − 4175
QTest::newRow("str0-len") << QString("abcdefgh") << QString("abc") << 3;
+ − 4176
}
+ − 4177
+ − 4178
void tst_QString::fromUtf16()
+ − 4179
{
+ − 4180
QFETCH(QString, ucs2);
+ − 4181
QFETCH(QString, res);
+ − 4182
QFETCH(int, len);
+ − 4183
+ − 4184
QCOMPARE(QString::fromUtf16(ucs2.utf16(), len), res);
+ − 4185
}
+ − 4186
+ − 4187
+ − 4188
void tst_QString::latin1String()
+ − 4189
{
+ − 4190
QString s("Hello");
+ − 4191
+ − 4192
QVERIFY(s == QLatin1String("Hello"));
+ − 4193
QVERIFY(s != QLatin1String("Hello World"));
+ − 4194
QVERIFY(s < QLatin1String("Helloa"));
+ − 4195
QVERIFY(!(s > QLatin1String("Helloa")));
+ − 4196
QVERIFY(s > QLatin1String("Helln"));
+ − 4197
QVERIFY(s > QLatin1String("Hell"));
+ − 4198
QVERIFY(!(s < QLatin1String("Helln")));
+ − 4199
QVERIFY(!(s < QLatin1String("Hell")));
+ − 4200
}
+ − 4201
+ − 4202
void tst_QString::nanAndInf()
+ − 4203
{
+ − 4204
bool ok;
+ − 4205
double d;
+ − 4206
+ − 4207
#define CHECK_DOUBLE(str, expected_ok, expected_inf) \
+ − 4208
d = QString(str).toDouble(&ok); \
+ − 4209
QVERIFY(ok == expected_ok); \
+ − 4210
QVERIFY((d == INFINITY) == expected_inf);
+ − 4211
+ − 4212
CHECK_DOUBLE("inf", true, true)
+ − 4213
CHECK_DOUBLE("INF", true, true)
+ − 4214
CHECK_DOUBLE("inf ", true, true)
+ − 4215
CHECK_DOUBLE("+inf", true, true)
+ − 4216
CHECK_DOUBLE("\t +INF", true, true)
+ − 4217
CHECK_DOUBLE("\t INF", true, true)
+ − 4218
CHECK_DOUBLE("inF ", true, true)
+ − 4219
CHECK_DOUBLE("+iNf", true, true)
+ − 4220
CHECK_DOUBLE("INFe-10", false, false)
+ − 4221
CHECK_DOUBLE("0xINF", false, false)
+ − 4222
CHECK_DOUBLE("- INF", false, false)
+ − 4223
CHECK_DOUBLE("+ INF", false, false)
+ − 4224
CHECK_DOUBLE("-- INF", false, false)
+ − 4225
CHECK_DOUBLE("inf0", false, false)
+ − 4226
CHECK_DOUBLE("--INF", false, false)
+ − 4227
CHECK_DOUBLE("++INF", false, false)
+ − 4228
CHECK_DOUBLE("INF++", false, false)
+ − 4229
CHECK_DOUBLE("INF--", false, false)
+ − 4230
CHECK_DOUBLE("INF +", false, false)
+ − 4231
CHECK_DOUBLE("INF -", false, false)
+ − 4232
CHECK_DOUBLE("0INF", false, false)
+ − 4233
#undef CHECK_INF
+ − 4234
+ − 4235
#define CHECK_NAN(str, expected_ok, expected_nan) \
+ − 4236
d = QString(str).toDouble(&ok); \
+ − 4237
QVERIFY(ok == expected_ok); \
+ − 4238
QVERIFY((bool)isnan(d) == expected_nan); \
+ − 4239
+ − 4240
CHECK_NAN("nan", true, true)
+ − 4241
CHECK_NAN("NAN", true, true)
+ − 4242
CHECK_NAN("nan ", true, true)
+ − 4243
CHECK_NAN("\t NAN", true, true)
+ − 4244
CHECK_NAN("\t NAN ", true, true)
+ − 4245
CHECK_NAN("-nan", false, false)
+ − 4246
CHECK_NAN("+NAN", false, false)
+ − 4247
CHECK_NAN("NaN", true, true)
+ − 4248
CHECK_NAN("nAn", true, true)
+ − 4249
CHECK_NAN("NANe-10", false, false)
+ − 4250
CHECK_NAN("0xNAN", false, false)
+ − 4251
CHECK_NAN("0NAN", false, false)
+ − 4252
#undef CHECK_NAN
+ − 4253
+ − 4254
d = QString("-INF").toDouble(&ok);
+ − 4255
QVERIFY(ok);
+ − 4256
QVERIFY(d == -INFINITY);
+ − 4257
+ − 4258
long l;
+ − 4259
l = QString("INF").toLong(&ok);
+ − 4260
QVERIFY(!ok);
+ − 4261
+ − 4262
l = QString("INF").toLong(&ok, 36);
+ − 4263
QVERIFY(ok);
+ − 4264
+ − 4265
l = QString("INF0").toLong(&ok, 36);
+ − 4266
QVERIFY(ok);
+ − 4267
+ − 4268
l = QString("0INF0").toLong(&ok, 36);
+ − 4269
QVERIFY(ok);
+ − 4270
}
+ − 4271
+ − 4272
void tst_QString::arg_fillChar_data()
+ − 4273
{
+ − 4274
QTest::addColumn<QString>("pattern");
+ − 4275
QTest::addColumn<QList<QVariant> >("replaceValues");
+ − 4276
QTest::addColumn<IntList>("widths");
+ − 4277
QTest::addColumn<QString>("fillChars");
+ − 4278
QTest::addColumn<QString>("expected");
+ − 4279
+ − 4280
QList<QVariant> replaceValues;
+ − 4281
IntList widths;
+ − 4282
QString fillChars;
+ − 4283
+ − 4284
replaceValues << QVariant((int)5) << QVariant(QString("f")) << QVariant((int)0);
+ − 4285
widths << 3 << 2 << 5;
+ − 4286
QTest::newRow("str0") << QString("%1%2%3") << replaceValues << widths << QString("abc") << QString("aa5bfcccc0");
+ − 4287
+ − 4288
replaceValues.clear();
+ − 4289
widths.clear();
+ − 4290
replaceValues << QVariant((int)5.5) << QVariant(QString("foo")) << QVariant((qulonglong)INT_MAX);
+ − 4291
widths << 10 << 2 << 5;
+ − 4292
QTest::newRow("str1") << QString("%3.%1.%3.%2") << replaceValues << widths << QString("0 c")
+ − 4293
<< QString("2147483647.0000000005.2147483647.foo");
+ − 4294
+ − 4295
replaceValues.clear();
+ − 4296
widths.clear();
+ − 4297
replaceValues << QVariant(QString("fisk"));
+ − 4298
widths << 100;
+ − 4299
QTest::newRow("str2") << QString("%9 og poteter") << replaceValues << widths << QString("f")
+ − 4300
<< QString("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffisk og poteter");
+ − 4301
}
+ − 4302
+ − 4303
void tst_QString::arg_fillChar()
+ − 4304
{
+ − 4305
static const int base = 10;
+ − 4306
static const char fmt = 'g';
+ − 4307
static const int prec = -1;
+ − 4308
+ − 4309
QFETCH(QString, pattern);
+ − 4310
QFETCH(QList<QVariant>, replaceValues);
+ − 4311
QFETCH(IntList, widths);
+ − 4312
QFETCH(QString, fillChars);
+ − 4313
QFETCH(QString, expected);
+ − 4314
QCOMPARE(replaceValues.count(), fillChars.count());
+ − 4315
QCOMPARE(replaceValues.count(), widths.count());
+ − 4316
+ − 4317
QString actual = pattern;
+ − 4318
for (int i=0; i<replaceValues.count(); ++i) {
+ − 4319
const QVariant &var = replaceValues.at(i);
+ − 4320
const int width = widths.at(i);
+ − 4321
const QChar &fillChar = fillChars.at(i);
+ − 4322
switch (var.type()) {
+ − 4323
case QVariant::String: actual = actual.arg(var.toString(), width, fillChar); break;
+ − 4324
case QVariant::Int: actual = actual.arg(var.toInt(), width, base, fillChar); break;
+ − 4325
case QVariant::UInt: actual = actual.arg(var.toUInt(), width, base, fillChar); break;
+ − 4326
case QVariant::Double: actual = actual.arg(var.toDouble(), width, fmt, prec, fillChar); break;
+ − 4327
case QVariant::LongLong: actual = actual.arg(var.toLongLong(), width, base, fillChar); break;
+ − 4328
case QVariant::ULongLong: actual = actual.arg(var.toULongLong(), width, base, fillChar); break;
+ − 4329
default: QVERIFY(0); break;
+ − 4330
}
+ − 4331
}
+ − 4332
+ − 4333
QCOMPARE(actual, expected);
+ − 4334
}
+ − 4335
+ − 4336
static inline int sign(int x)
+ − 4337
{
+ − 4338
return x == 0 ? 0 : (x < 0 ? -1 : 1);
+ − 4339
}
+ − 4340
+ − 4341
void tst_QString::compare_data()
+ − 4342
{
+ − 4343
QTest::addColumn<QString>("s1");
+ − 4344
QTest::addColumn<QString>("s2");
+ − 4345
QTest::addColumn<int>("csr"); // case sensitive result
+ − 4346
QTest::addColumn<int>("cir"); // case insensitive result
+ − 4347
+ − 4348
+ − 4349
// null strings
+ − 4350
QTest::newRow("data0") << QString("") << QString("") << 0 << 0;
+ − 4351
QTest::newRow("data1") << QString("a") << QString("") << 1 << 1;
+ − 4352
QTest::newRow("data2") << QString("") << QString("a") << -1 << -1;
+ − 4353
+ − 4354
// equal length
+ − 4355
QTest::newRow("data3") << QString("abc") << QString("abc") << 0 << 0;
+ − 4356
QTest::newRow("data4") << QString("abC") << QString("abc") << -1 << 0;
+ − 4357
QTest::newRow("data5") << QString("abc") << QString("abC") << 1 << 0;
+ − 4358
+ − 4359
// different length
+ − 4360
QTest::newRow("data6") << QString("abcdef") << QString("abc") << 1 << 1;
+ − 4361
QTest::newRow("data6") << QString("abCdef") << QString("abc") << -1 << 1;
+ − 4362
QTest::newRow("data7") << QString("abc") << QString("abcdef") << -1 << -1;
+ − 4363
+ − 4364
QString upper;
+ − 4365
upper += QChar(QChar::highSurrogate(0x10400));
+ − 4366
upper += QChar(QChar::lowSurrogate(0x10400));
+ − 4367
QString lower;
+ − 4368
lower += QChar(QChar::highSurrogate(0x10428));
+ − 4369
lower += QChar(QChar::lowSurrogate(0x10428));
+ − 4370
QTest::newRow("data8") << upper << lower << -1 << 0;
+ − 4371
+ − 4372
// embedded nulls
+ − 4373
// These dont work as of now. Its OK that these dont work since \0 is not a valid unicode
+ − 4374
/*QTest::newRow("data9") << QString(QByteArray("\0", 1)) << QString(QByteArray("\0", 1)) << 0 << 0;
+ − 4375
QTest::newRow("data10") << QString(QByteArray("\0", 1)) << QString("") << 1 << 1;
+ − 4376
QTest::newRow("data11") << QString("") << QString(QByteArray("\0", 1)) << -1 << -1;
+ − 4377
QTest::newRow("data12") << QString("ab\0c") << QString(QByteArray("ab\0c", 4)) << 0 << 0;
+ − 4378
QTest::newRow("data13") << QString(QByteArray("ab\0c", 4)) << QString("abc") << -1 << -1;
+ − 4379
QTest::newRow("data14") << QString("abc") << QString(QByteArray("ab\0c", 4)) << 1 << 1;*/
+ − 4380
}
+ − 4381
+ − 4382
static bool isLatin(const QString &s)
+ − 4383
{
+ − 4384
for (int i = 0; i < s.length(); ++i)
+ − 4385
if (s.at(i).unicode() > 0xff)
+ − 4386
return false;
+ − 4387
return true;
+ − 4388
}
+ − 4389
+ − 4390
void tst_QString::compare()
+ − 4391
{
+ − 4392
QFETCH(QString, s1);
+ − 4393
QFETCH(QString, s2);
+ − 4394
QFETCH(int, csr);
+ − 4395
QFETCH(int, cir);
+ − 4396
+ − 4397
QStringRef r1(&s1, 0, s1.length());
+ − 4398
QStringRef r2(&s2, 0, s2.length());
+ − 4399
+ − 4400
QCOMPARE(sign(QString::compare(s1, s2)), csr);
+ − 4401
QCOMPARE(sign(QStringRef::compare(r1, r2)), csr);
+ − 4402
QCOMPARE(sign(s1.compare(s2)), csr);
+ − 4403
QCOMPARE(sign(s1.compare(r2)), csr);
+ − 4404
QCOMPARE(sign(r1.compare(r2)), csr);
+ − 4405
+ − 4406
QCOMPARE(sign(s1.compare(s2, Qt::CaseSensitive)), csr);
+ − 4407
QCOMPARE(sign(s1.compare(s2, Qt::CaseInsensitive)), cir);
+ − 4408
QCOMPARE(sign(s1.compare(r2, Qt::CaseSensitive)), csr);
+ − 4409
QCOMPARE(sign(s1.compare(r2, Qt::CaseInsensitive)), cir);
+ − 4410
QCOMPARE(sign(r1.compare(r2, Qt::CaseSensitive)), csr);
+ − 4411
QCOMPARE(sign(r1.compare(r2, Qt::CaseInsensitive)), cir);
+ − 4412
+ − 4413
QCOMPARE(sign(QString::compare(s1, s2, Qt::CaseSensitive)), csr);
+ − 4414
QCOMPARE(sign(QString::compare(s1, s2, Qt::CaseInsensitive)), cir);
+ − 4415
QCOMPARE(sign(QString::compare(s1, r2, Qt::CaseSensitive)), csr);
+ − 4416
QCOMPARE(sign(QString::compare(s1, r2, Qt::CaseInsensitive)), cir);
+ − 4417
QCOMPARE(sign(QStringRef::compare(r1, r2, Qt::CaseSensitive)), csr);
+ − 4418
QCOMPARE(sign(QStringRef::compare(r1, r2, Qt::CaseInsensitive)), cir);
+ − 4419
+ − 4420
if (!cir) {
+ − 4421
QCOMPARE(s1.toCaseFolded(), s2.toCaseFolded());
+ − 4422
}
+ − 4423
+ − 4424
if (isLatin(s2)) {
+ − 4425
QCOMPARE(sign(QString::compare(s1, QLatin1String(s2.toLatin1()))), csr);
+ − 4426
QCOMPARE(sign(QString::compare(s1, QLatin1String(s2.toLatin1()), Qt::CaseInsensitive)), cir);
+ − 4427
QCOMPARE(sign(QStringRef::compare(r1, QLatin1String(s2.toLatin1()))), csr);
+ − 4428
QCOMPARE(sign(QStringRef::compare(r1, QLatin1String(s2.toLatin1()), Qt::CaseInsensitive)), cir);
+ − 4429
}
+ − 4430
+ − 4431
if (isLatin(s1)) {
+ − 4432
QCOMPARE(sign(QString::compare(QLatin1String(s1.toLatin1()), s2)), csr);
+ − 4433
QCOMPARE(sign(QString::compare(QLatin1String(s1.toLatin1()), s2, Qt::CaseInsensitive)), cir);
+ − 4434
}
+ − 4435
}
+ − 4436
+ − 4437
void tst_QString::resizeAfterFromRawData()
+ − 4438
{
+ − 4439
QString buffer("hello world");
+ − 4440
+ − 4441
QString array = QString::fromRawData(buffer.constData(), buffer.size());
+ − 4442
QVERIFY(array.constData() == buffer.constData());
+ − 4443
array.resize(5);
+ − 4444
QVERIFY(array.constData() == buffer.constData());
+ − 4445
}
+ − 4446
+ − 4447
void tst_QString::resizeAfterReserve()
+ − 4448
{
+ − 4449
+ − 4450
QString s;
+ − 4451
s.reserve(100);
+ − 4452
+ − 4453
s += "hello world";
+ − 4454
+ − 4455
// resize should not affect capacity
+ − 4456
s.resize(s.size());
+ − 4457
QVERIFY(s.capacity() == 100);
+ − 4458
+ − 4459
// but squeeze does
+ − 4460
s.squeeze();
+ − 4461
QVERIFY(s.capacity() == s.size());
+ − 4462
+ − 4463
// clear does too
+ − 4464
s.clear();
+ − 4465
QVERIFY(s.capacity() == 0);
+ − 4466
+ − 4467
// test resize(0) border case
+ − 4468
s.reserve(100);
+ − 4469
s += "hello world";
+ − 4470
s.resize(0);
+ − 4471
QVERIFY(s.capacity() == 100);
+ − 4472
}
+ − 4473
+ − 4474
void tst_QString::resizeWithNegative() const
+ − 4475
{
+ − 4476
{
+ − 4477
QString string(QLatin1String("input"));
+ − 4478
string.resize(-1);
+ − 4479
QCOMPARE(string, QString());
+ − 4480
}
+ − 4481
+ − 4482
{
+ − 4483
QString string(QLatin1String("input"));
+ − 4484
string.resize(-9099);
+ − 4485
QCOMPARE(string, QString());
+ − 4486
}
+ − 4487
+ − 4488
{
+ − 4489
/* Example code from customer. */
+ − 4490
QString s(QLatin1String("hola"));
+ − 4491
s.reserve(1);
+ − 4492
s.resize(-1);
+ − 4493
QCOMPARE(s, QString());
+ − 4494
}
+ − 4495
}
+ − 4496
+ − 4497
void tst_QString::truncateWithNegative() const
+ − 4498
{
+ − 4499
{
+ − 4500
QString string(QLatin1String("input"));
+ − 4501
string.truncate(-1);
+ − 4502
QCOMPARE(string, QString());
+ − 4503
}
+ − 4504
+ − 4505
{
+ − 4506
QString string(QLatin1String("input"));
+ − 4507
string.truncate(-9099);
+ − 4508
QCOMPARE(string, QString());
+ − 4509
}
+ − 4510
+ − 4511
{
+ − 4512
/* Example code from customer. */
+ − 4513
QString test(QLatin1String("c"));
+ − 4514
+ − 4515
test.replace(QRegExp(QLatin1String("c")), QLatin1String("z"));
+ − 4516
test.truncate(-1);
+ − 4517
QCOMPARE(test, QString());
+ − 4518
}
+ − 4519
}
+ − 4520
+ − 4521
void tst_QString::QCharRefMutableUnicode() const
+ − 4522
{
+ − 4523
QString str;
+ − 4524
str.resize(3);
+ − 4525
str[0].unicode() = 115;
+ − 4526
str[1].unicode() = 116;
+ − 4527
str[2].unicode() = 114;
+ − 4528
+ − 4529
QCOMPARE(str, QString::fromLatin1("str"));
+ − 4530
}
+ − 4531
+ − 4532
void tst_QString::QCharRefDetaching() const
+ − 4533
{
+ − 4534
{
+ − 4535
QString str = QString::fromLatin1("str");
+ − 4536
QString copy;
+ − 4537
copy[0] = QLatin1Char('S');
+ − 4538
+ − 4539
QCOMPARE(str, QString::fromLatin1("str"));
+ − 4540
}
+ − 4541
+ − 4542
{
+ − 4543
ushort buf[] = { 's', 't', 'r' };
+ − 4544
QString str = QString::fromRawData((const QChar *)buf, 3);
+ − 4545
str[0] = QLatin1Char('S');
+ − 4546
+ − 4547
QCOMPARE(buf[0], ushort('s'));
+ − 4548
}
+ − 4549
+ − 4550
{
+ − 4551
static const ushort buf[] = { 's', 't', 'r' };
+ − 4552
QString str = QString::fromRawData((const QChar *)buf, 3);
+ − 4553
+ − 4554
// this causes a crash in most systems if the detaching doesn't work
+ − 4555
str[0] = QLatin1Char('S');
+ − 4556
+ − 4557
QCOMPARE(buf[0], ushort('s'));
+ − 4558
}
+ − 4559
}
+ − 4560
+ − 4561
void tst_QString::sprintfZU() const
+ − 4562
{
+ − 4563
{
+ − 4564
QString string;
+ − 4565
size_t s = 6;
+ − 4566
string.sprintf("%zu", s);
+ − 4567
QCOMPARE(string, QString::fromLatin1("6"));
+ − 4568
}
+ − 4569
+ − 4570
{
+ − 4571
QString string;
+ − 4572
string.sprintf("%s\n", "foo");
+ − 4573
QCOMPARE(string, QString::fromLatin1("foo\n"));
+ − 4574
}
+ − 4575
+ − 4576
{
+ − 4577
/* This code crashed. I don't know how to reduce it further. In other words,
+ − 4578
* both %zu and %s needs to be present. */
+ − 4579
size_t s = 6;
+ − 4580
QString string;
+ − 4581
string.sprintf("%zu%s", s, "foo");
+ − 4582
QCOMPARE(string, QString::fromLatin1("6foo"));
+ − 4583
}
+ − 4584
+ − 4585
{
+ − 4586
size_t s = 6;
+ − 4587
QString string;
+ − 4588
string.sprintf("%zu %s\n", s, "foo");
+ − 4589
QCOMPARE(string, QString::fromLatin1("6 foo\n"));
+ − 4590
}
+ − 4591
}
+ − 4592
+ − 4593
void tst_QString::repeatedSignature() const
+ − 4594
{
+ − 4595
/* repated() should be a const member. */
+ − 4596
const QString string;
+ − 4597
string.repeated(3);
+ − 4598
}
+ − 4599
+ − 4600
void tst_QString::repeated() const
+ − 4601
{
+ − 4602
QFETCH(QString, string);
+ − 4603
QFETCH(QString, expected);
+ − 4604
QFETCH(int, count);
+ − 4605
+ − 4606
QCOMPARE(string.repeated(count), expected);
+ − 4607
}
+ − 4608
+ − 4609
void tst_QString::repeated_data() const
+ − 4610
{
+ − 4611
QTest::addColumn<QString>("string" );
+ − 4612
QTest::addColumn<QString>("expected" );
+ − 4613
QTest::addColumn<int>("count" );
+ − 4614
+ − 4615
/* Empty strings. */
+ − 4616
QTest::newRow("")
+ − 4617
<< QString()
+ − 4618
<< QString()
+ − 4619
<< 0;
+ − 4620
+ − 4621
QTest::newRow("")
+ − 4622
<< QString()
+ − 4623
<< QString()
+ − 4624
<< -1004;
+ − 4625
+ − 4626
QTest::newRow("")
+ − 4627
<< QString()
+ − 4628
<< QString()
+ − 4629
<< 1;
+ − 4630
+ − 4631
QTest::newRow("")
+ − 4632
<< QString()
+ − 4633
<< QString()
+ − 4634
<< 5;
+ − 4635
+ − 4636
/* On simple string. */
+ − 4637
QTest::newRow("")
+ − 4638
<< QString(QLatin1String("abc"))
+ − 4639
<< QString()
+ − 4640
<< -1004;
+ − 4641
+ − 4642
QTest::newRow("")
+ − 4643
<< QString(QLatin1String("abc"))
+ − 4644
<< QString()
+ − 4645
<< -1;
+ − 4646
+ − 4647
QTest::newRow("")
+ − 4648
<< QString(QLatin1String("abc"))
+ − 4649
<< QString()
+ − 4650
<< 0;
+ − 4651
+ − 4652
QTest::newRow("")
+ − 4653
<< QString(QLatin1String("abc"))
+ − 4654
<< QString(QLatin1String("abc"))
+ − 4655
<< 1;
+ − 4656
+ − 4657
QTest::newRow("")
+ − 4658
<< QString(QLatin1String("abc"))
+ − 4659
<< QString(QLatin1String("abcabc"))
+ − 4660
<< 2;
+ − 4661
+ − 4662
QTest::newRow("")
+ − 4663
<< QString(QLatin1String("abc"))
+ − 4664
<< QString(QLatin1String("abcabcabc"))
+ − 4665
<< 3;
+ − 4666
+ − 4667
QTest::newRow("")
+ − 4668
<< QString(QLatin1String("abc"))
+ − 4669
<< QString(QLatin1String("abcabcabcabc"))
+ − 4670
<< 4;
+ − 4671
}
+ − 4672
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 4673
void tst_QString::task262677remove()
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 4674
{
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 4675
QString driveName = QLatin1String("V:\\blahblah\\more_blahblah\\");
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 4676
driveName.remove(2, INT_MAX); // should be "V:" - instead, it's "V::\\blahblah\\more_blahblah\\"
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 4677
QVERIFY(driveName == QLatin1String("V:"));
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 4678
}
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 4679
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
+ − 4680
0
+ − 4681
QTEST_APPLESS_MAIN(tst_QString)
+ − 4682
+ − 4683
#include "tst_qstring.moc"