tests/auto/qstringbuilder1/stringbuilder.cpp
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     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 // This is included in various .cpp files as a compile test for various scenarios
       
    43 // depending on NO_CAST_*  and  QT_USE_FAST_OPERATOR_PLUS and QT_USE_FAST_CONCATENATION
       
    44 
       
    45 #if SCENARIO == 1
       
    46 // this is the "no harm done" version. Only operator% is active,
       
    47 // with NO_CAST * defined
       
    48 #define P %
       
    49 #undef QT_USE_FAST_OPERATOR_PLUS
       
    50 #undef QT_USE_FAST_CONCATENATION
       
    51 #define QT_NO_CAST_FROM_ASCII
       
    52 #define QT_NO_CAST_TO_ASCII
       
    53 #endif
       
    54 
       
    55 
       
    56 #if SCENARIO == 2
       
    57 // this is the "full" version. Operator+ is replaced by a QStringBuilder
       
    58 // based version
       
    59 // with NO_CAST * defined
       
    60 #define P +
       
    61 #define QT_USE_FAST_OPERATOR_PLUS
       
    62 #define QT_USE_FAST_CONCATENATION
       
    63 #define QT_NO_CAST_FROM_ASCII
       
    64 #define QT_NO_CAST_TO_ASCII
       
    65 #endif
       
    66 
       
    67 #if SCENARIO == 3
       
    68 // this is the "no harm done" version. Only operator% is active,
       
    69 // with NO_CAST * _not_ defined
       
    70 #define P %
       
    71 #undef QT_USE_FAST_OPERATOR_PLUS
       
    72 #undef QT_USE_FAST_CONCATENATION
       
    73 #undef QT_NO_CAST_FROM_ASCII
       
    74 #undef QT_NO_CAST_TO_ASCII
       
    75 #endif
       
    76 
       
    77 #if SCENARIO == 4
       
    78 // this is the "full" version. Operator+ is replaced by a QStringBuilder
       
    79 // based version
       
    80 // with NO_CAST * _not_ defined
       
    81 #define P +
       
    82 #define QT_USE_FAST_OPERATOR_PLUS
       
    83 #define QT_USE_FAST_CONCATENATION
       
    84 #undef QT_NO_CAST_FROM_ASCII
       
    85 #undef QT_NO_CAST_TO_ASCII
       
    86 #endif
       
    87 
       
    88 #include <QtTest/QtTest>
       
    89 #include "stringbuilder.h"
       
    90 
       
    91 //TESTED_CLASS=QStringBuilder
       
    92 //TESTED_FILES=qstringbuilder.cpp
       
    93 
       
    94 #define LITERAL "some literal"
       
    95 
       
    96 void tst_QStringBuilder::scenario()
       
    97 {
       
    98     QLatin1Literal l1literal(LITERAL);
       
    99     QLatin1String l1string(LITERAL);
       
   100     QString string(l1string);
       
   101     QStringRef stringref(&string, 2, 10);
       
   102     QLatin1Char achar('c');
       
   103     QString r2(QLatin1String(LITERAL LITERAL));
       
   104     QString r;
       
   105     QByteArray ba(LITERAL);
       
   106 
       
   107     r = l1literal P l1literal;
       
   108     QCOMPARE(r, r2);
       
   109     r = string P string;
       
   110     QCOMPARE(r, r2);
       
   111     r = stringref P stringref;
       
   112     QCOMPARE(r, QString(stringref.toString() + stringref.toString()));
       
   113     r = string P l1literal;
       
   114     QCOMPARE(r, r2);
       
   115     r = string P l1string;
       
   116     QCOMPARE(r, r2);
       
   117     r = string + achar;
       
   118     QCOMPARE(r, QString(string P achar));
       
   119     r = achar + string;
       
   120     QCOMPARE(r, QString(achar P string));
       
   121 #ifndef QT_NO_CAST_FROM_ASCII
       
   122     r = string P LITERAL;
       
   123     QCOMPARE(r, r2);
       
   124     r = LITERAL P string;
       
   125     QCOMPARE(r, r2);
       
   126     r = ba P string;
       
   127     QCOMPARE(r, r2);
       
   128     r = string P ba;
       
   129     QCOMPARE(r, r2);
       
   130 #endif
       
   131 }
       
   132 
       
   133 QTEST_APPLESS_MAIN(tst_QStringBuilder)