/**************************************************************************** ** ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and Digia. For licensing terms and ** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional ** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include #include #include #include //TESTED_CLASS= //TESTED_FILES= class tst_Q3CString : public QObject { Q_OBJECT public: tst_Q3CString(); virtual ~tst_Q3CString(); public slots: void init(); void cleanup(); private slots: void setExpand(); void check_QTextStream(); void check_QDataStream(); void replace_uint_uint_data(); void replace_uint_uint(); void replace_string_data(); void replace_string(); void remove_uint_uint_data(); void remove_uint_uint(); void prepend(); void append(); void insert(); void simplifyWhiteSpace(); void stripWhiteSpace(); void lower(); void upper(); void rightJustify(); void leftJustify(); void mid(); void right(); void left(); void contains(); void findRev(); void find(); void sprintf(); void copy(); void fill(); void truncate(); void constructor(); void isEmpty(); void isNull(); void acc_01(); void length_data(); void length(); // testfunctions? void remove_string_data(); void remove_regexp_data(); }; Q_DECLARE_METATYPE(Q3CString) tst_Q3CString::tst_Q3CString() { } tst_Q3CString::~tst_Q3CString() { } void tst_Q3CString::init() { } void tst_Q3CString::cleanup() { } void tst_Q3CString::remove_uint_uint_data() { replace_uint_uint_data(); } void tst_Q3CString::remove_string_data() { replace_string_data(); } void tst_Q3CString::length_data() { QTest::addColumn("s1"); QTest::addColumn("res"); QTest::newRow( "data0" ) << Q3CString("Test") << 4; QTest::newRow( "data1" ) << Q3CString("The quick brown fox jumps over the lazy dog") << 43; QTest::newRow( "data2" ) << Q3CString(0) << 0; QTest::newRow( "data3" ) << Q3CString("A") << 1; QTest::newRow( "data4" ) << Q3CString("AB") << 2; QTest::newRow( "data5" ) << Q3CString("AB\n") << 3; QTest::newRow( "data6" ) << Q3CString("AB\nC") << 4; QTest::newRow( "data7" ) << Q3CString("\n") << 1; QTest::newRow( "data8" ) << Q3CString("\nA") << 2; QTest::newRow( "data9" ) << Q3CString("\nAB") << 3; QTest::newRow( "data10" ) << Q3CString("\nAB\nCDE") << 7; QTest::newRow( "data11" ) << Q3CString("shdnftrheid fhgnt gjvnfmd chfugkh bnfhg thgjf vnghturkf chfnguh bjgnfhvygh hnbhgutjfv dhdnjds dcjs d") << 100; } void tst_Q3CString::replace_uint_uint_data() { QTest::addColumn("string"); QTest::addColumn("index"); QTest::addColumn("len"); QTest::addColumn("after"); QTest::addColumn("result"); QTest::newRow( "rem00" ) << Q3CString("-<>ABCABCABCABC>") << 0 << 3 << Q3CString("") << Q3CString("ABCABCABCABC>"); QTest::newRow( "rem01" ) << Q3CString("ABCABCABCABC>") << 1 << 4 <"); QTest::newRow( "rem02" ) << Q3CString("ACABCABC>") << 999 << 4 << Q3CString("") << Q3CString("ACABCABC>"); QTest::newRow( "rem03" ) << Q3CString("ACABCABC>") << 9 << 4 << Q3CString("") << Q3CString("ACABCABC>"); QTest::newRow( "rem04" ) << Q3CString("ACABCABC>") << 8 << 4 << Q3CString("") << Q3CString("ACABCABC"); QTest::newRow( "rem05" ) << Q3CString("ACABCABC") << 7 << 1 << Q3CString("") << Q3CString("ACABCAB"); QTest::newRow( "rem06" ) << Q3CString("ACABCAB") << 4 << 0 << Q3CString("") << Q3CString("ACABCAB"); QTest::newRow( "rep00" ) << Q3CString("ACABCAB") << 4 << 0 << Q3CString("X") << Q3CString("ACABXCAB"); QTest::newRow( "rep01" ) << Q3CString("ACABXCAB") << 4 << 1 << Q3CString("Y") << Q3CString("ACABYCAB"); QTest::newRow( "rep02" ) << Q3CString("ACABYCAB") << 4 << 1 << Q3CString("") << Q3CString("ACABCAB"); QTest::newRow( "rep03" ) << Q3CString("ACABCAB") << 0 << 9999 << Q3CString("XX") << Q3CString("XX"); QTest::newRow( "rep04" ) << Q3CString("XX") << 0 << 9999 << Q3CString("") << Q3CString(""); } void tst_Q3CString::replace_string_data() { QTest::addColumn("string"); QTest::addColumn("before"); QTest::addColumn("after"); QTest::addColumn("result"); QTest::newRow( "rem00" ) << Q3CString("") << Q3CString("") << Q3CString("") << Q3CString(""); QTest::newRow( "rem01" ) << Q3CString("A") << Q3CString("") << Q3CString("") << Q3CString("A"); QTest::newRow( "rem02" ) << Q3CString("A") << Q3CString("A") << Q3CString("") << Q3CString(""); QTest::newRow( "rem03" ) << Q3CString("A") << Q3CString("B") << Q3CString("") << Q3CString("A"); QTest::newRow( "rem04" ) << Q3CString("AA") << Q3CString("A") << Q3CString("") << Q3CString(""); QTest::newRow( "rem05" ) << Q3CString("AB") << Q3CString("A") << Q3CString("") << Q3CString("B"); QTest::newRow( "rem06" ) << Q3CString("AB") << Q3CString("B") << Q3CString("") << Q3CString("A"); QTest::newRow( "rem07" ) << Q3CString("AB") << Q3CString("C") << Q3CString("") << Q3CString("AB"); QTest::newRow( "rem08" ) << Q3CString("ABA") << Q3CString("A") << Q3CString("") << Q3CString("B"); QTest::newRow( "rem09" ) << Q3CString("ABA") << Q3CString("B") << Q3CString("") << Q3CString("AA"); QTest::newRow( "rem10" ) << Q3CString("ABA") << Q3CString("C") << Q3CString("") << Q3CString("ABA"); QTest::newRow( "rem11" ) << Q3CString("banana") << Q3CString("an") << Q3CString("") << Q3CString("ba"); QTest::newRow( "rem12" ) << Q3CString("") << Q3CString("A") << Q3CString("") << Q3CString(""); QTest::newRow( "rem13" ) << Q3CString("") << Q3CString("A") << Q3CString(0) << Q3CString(""); QTest::newRow( "rem14" ) << Q3CString(0) << Q3CString("A") << Q3CString("") << Q3CString(0); QTest::newRow( "rem15" ) << Q3CString(0) << Q3CString("A") << Q3CString(0) << Q3CString(0); QTest::newRow( "rem17" ) << Q3CString(0) << Q3CString("") << Q3CString("") << Q3CString(0); // ### how should the one below behave in Q3CString???? // QTest::newRow( "rem18" ) << Q3CString("") << Q3CString(0) << Q3CString("A") << Q3CString("A"); QTest::newRow( "rem19" ) << Q3CString("") << Q3CString(0) << Q3CString("") << Q3CString(""); QTest::newRow( "rep00" ) << Q3CString("ABC") << Q3CString("B") << Q3CString("-") << Q3CString("A-C"); QTest::newRow( "rep01" ) << Q3CString("$()*+.?[\\]^{|}") << Q3CString("$()*+.?[\\]^{|}") << Q3CString("X") << Q3CString("X"); QTest::newRow( "rep02" ) << Q3CString("ABCDEF") << Q3CString("") << Q3CString("X") << Q3CString("XAXBXCXDXEXFX"); QTest::newRow( "rep03" ) << Q3CString("") << Q3CString("") << Q3CString("X") << Q3CString("X"); } void tst_Q3CString::remove_regexp_data() { QTest::addColumn("string"); QTest::addColumn("regexp"); QTest::addColumn("after"); QTest::addColumn("result"); QTest::newRow( "rem00" ) << Q3CString("alpha") << Q3CString("a+") << Q3CString("") << Q3CString("lph"); QTest::newRow( "rem01" ) << Q3CString("banana") << Q3CString("^.a") << Q3CString("") << Q3CString("nana"); QTest::newRow( "rem02" ) << Q3CString("") << Q3CString("^.a") << Q3CString("") << Q3CString(""); QTest::newRow( "rem03" ) << Q3CString("") << Q3CString("^.a") << Q3CString(0) << Q3CString(""); QTest::newRow( "rem04" ) << Q3CString(0) << Q3CString("^.a") << Q3CString("") << Q3CString(0); QTest::newRow( "rem05" ) << Q3CString(0) << Q3CString("^.a") << Q3CString(0) << Q3CString(0); QTest::newRow( "rep00" ) << Q3CString("A bon mot.") << Q3CString("([^<]*)") << Q3CString("\\emph{\\1}") << Q3CString("A \\emph{bon mot}."); QTest::newRow( "rep01" ) << Q3CString("banana") << Q3CString("^.a()") << Q3CString("\\1") << Q3CString("nana"); QTest::newRow( "rep02" ) << Q3CString("banana") << Q3CString("(ba)") << Q3CString("\\1X\\1") << Q3CString("baXbanana"); QTest::newRow( "rep03" ) << Q3CString("banana") << Q3CString("(ba)(na)na") << Q3CString("\\2X\\1") << Q3CString("naXba"); } void tst_Q3CString::length() { QFETCH( Q3CString, s1 ); QTEST( (int)s1.length(), "res" ); } #include void tst_Q3CString::acc_01() { Q3CString a; Q3CString b; //b(10); Q3CString bb; //bb((int)0); Q3CString c("String C"); char tmp[10]; tmp[0] = 'S'; tmp[1] = 't'; tmp[2] = 'r'; tmp[3] = 'i'; tmp[4] = 'n'; tmp[5] = 'g'; tmp[6] = ' '; tmp[7] = 'D'; tmp[8] = 'X'; tmp[9] = '\0'; Q3CString d(tmp,8); Q3CString ca(a); Q3CString cb(b); Q3CString cc(c); Q3CString n; Q3CString e("String E"); Q3CString f; f = e; f.detach(); f[7]='F'; QCOMPARE(e,(Q3CString)"String E"); char text[]="String f"; f = text; text[7]='!'; QCOMPARE(f,(Q3CString)"String f"); f[7]='F'; QCOMPARE(text[7],'!'); #if 0 a=""; a[0]='A'; Q3CString res = "A"; QCOMPARE(a,res); QCOMPARE(a.length(),(uint)1); compare(a.length(),(uint)1); a[1]='B'; QCOMPARE(a,(Q3CString)"AB"); QCOMPARE(a.length(),(uint)2); a[2]='C'; QCOMPARE(a,(Q3CString)"ABC"); QCOMPARE(a.length(),(uint)3); a = Q3CString(); QVERIFY(a.isNull()); a[0]='A'; QCOMPARE(a,(Q3CString)"A"); QCOMPARE(a.length(),(uint)1); a[1]='B'; QCOMPARE(a,(Q3CString)"AB"); QCOMPARE(a.length(),(uint)2); a[2]='C'; QCOMPARE(a,(Q3CString)"ABC"); QCOMPARE(a.length(),(uint)3); #endif a="123"; b="456"; a[0]=a[1]; QCOMPARE(a,(Q3CString)"223"); a[1]=b[1]; QCOMPARE(b,(Q3CString)"456"); QCOMPARE(a,(Q3CString)"253"); char t[]="TEXT"; a="A"; a=t; QCOMPARE(a,(Q3CString)"TEXT"); QCOMPARE(a,(Q3CString)t); a[0]='X'; QCOMPARE(a,(Q3CString)"XEXT"); QCOMPARE(t[0],'T'); t[0]='Z'; QCOMPARE(a,(Q3CString)"XEXT"); a="ABC"; QCOMPARE(((const char*)a)[1],'B'); QCOMPARE(strcmp(a,(Q3CString)"ABC"),0); a += "DEF"; QCOMPARE(a, (Q3CString)"ABCDEF"); a += 'G'; QCOMPARE(a, (Q3CString)"ABCDEFG"); a += ((const char*)(0)); QCOMPARE(a, (Q3CString)"ABCDEFG"); // non-member operators a="ABC"; b="ABC"; c="ACB"; d="ABCD"; QVERIFY(a==b); QVERIFY(!(a==d)); QVERIFY(!(a!=b)); QVERIFY(a!=d); QVERIFY(!(a'),res ); } void tst_Q3CString::append() { Q3CString a; a = "<>ABCABCABCABC"; QCOMPARE(a.append(">"),(Q3CString)"<>ABCABCABCABC>"); } void tst_Q3CString::prepend() { Q3CString a; a = "<>ABCABCABCABC>"; QCOMPARE(a.prepend("-"),(Q3CString)"-<>ABCABCABCABC>"); } void tst_Q3CString::replace_uint_uint() { QFETCH( Q3CString, string ); QFETCH( int, index ); QFETCH( int, len ); QFETCH( Q3CString, after ); Q3CString s1 = string; s1.replace( (uint) index, (int) len, after ); QFETCH( Q3CString, result ); QVERIFY( s1 == result ); Q3CString s2 = string; s2.replace( (uint) index, (uint) len, after ); QVERIFY( s2 == result ); } void tst_Q3CString::replace_string() { QFETCH( Q3CString, string ); QFETCH( Q3CString, before ); QFETCH( Q3CString, after ); QFETCH( Q3CString, result ); if ( before.length() == 1 ) { char ch = before[0]; Q3CString s1 = string; s1.replace( ch, after ); QCOMPARE( s1, result ); } Q3CString s3 = string; s3.replace( before, after ); QCOMPARE( s3, result ); } void tst_Q3CString::remove_uint_uint() { QFETCH( Q3CString, string ); QFETCH( int, index ); QFETCH( int, len ); QFETCH( Q3CString, after ); QFETCH( Q3CString, result ); if ( after.length() == 0 ) { Q3CString s1 = string; s1.remove( (uint) index, (uint) len ); QVERIFY( s1 == result ); } else { QSKIP("Test data applies only to replace_uint_uint(), not remove_uint_uint()", SkipSingle); } } void tst_Q3CString::check_QDataStream() { Q3CString a; QByteArray ar; { QDataStream out(&ar,QIODevice::WriteOnly); out << Q3CString("COMPARE Text"); } { QDataStream in(&ar,QIODevice::ReadOnly); in >> a; QCOMPARE(a,(Q3CString)"COMPARE Text"); } } void tst_Q3CString::check_QTextStream() { Q3CString a; QByteArray ar; { QTextStream out(&ar,QIODevice::WriteOnly); out << Q3CString("This is COMPARE Text"); } { QTextStream in(&ar,QIODevice::ReadOnly); in >> a; QCOMPARE(a,(Q3CString)"This"); } } void tst_Q3CString::setExpand() { Q3CString a; a="ABC"; a.setExpand(0,'X'); QCOMPARE(a,(Q3CString)"XBC"); a.setExpand(4,'Z'); QCOMPARE(a,(Q3CString)"XBC Z"); a.setExpand(3,'Y'); QCOMPARE(a,(Q3CString)"XBCYZ"); } QTEST_APPLESS_MAIN(tst_Q3CString) #include "tst_q3cstring.moc"