tests/auto/qtokenautomaton/tst_qtokenautomaton.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
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 
       
    43 #include <QtTest/QtTest>
       
    44 
       
    45 #include "tokenizers/basic/basic.h"
       
    46 #include "tokenizers/basicNamespace/basicNamespace.h"
       
    47 #include "tokenizers/boilerplate/boilerplate.h"
       
    48 #include "tokenizers/noToString/noToString.h"
       
    49 
       
    50 /*!
       
    51  \class tst_QTokenAutomaton
       
    52  \internal
       
    53  \brief Tests the QTokenAutomaton generator.
       
    54 
       
    55 TODO:
       
    56     - Verify high Unicode codepoints
       
    57     - Verify that signatures are static.
       
    58  */
       
    59 class tst_QTokenAutomaton : public QObject
       
    60 {
       
    61     Q_OBJECT
       
    62 
       
    63 private Q_SLOTS:
       
    64     void tokenizerBasic() const;
       
    65 };
       
    66 
       
    67 void tst_QTokenAutomaton::tokenizerBasic() const
       
    68 {
       
    69     typedef QPair<Basic::Token, QString> TokenPair;
       
    70     typedef QList<TokenPair> TokenPairList;
       
    71 
       
    72     /* Tokenizer basic. */
       
    73     {
       
    74         /* All the tokens matching tokens. */
       
    75         {
       
    76             TokenPairList tokens;
       
    77             tokens.append(qMakePair(Basic::_, QString::fromLatin1("abc")));
       
    78             tokens.append(qMakePair(Basic::_111, QString::fromLatin1("def")));
       
    79             tokens.append(qMakePair(Basic::wobbly, QString::fromLatin1("ghi")));
       
    80             tokens.append(qMakePair(Basic::FFFF, QString::fromLatin1("FFFF")));
       
    81             tokens.append(qMakePair(Basic::FFFG, QString::fromLatin1("FFFG")));
       
    82             tokens.append(qMakePair(Basic::FFGG, QString::fromLatin1("FFGG")));
       
    83             tokens.append(qMakePair(Basic::FFGF, QString::fromLatin1("FFGF")));
       
    84             tokens.append(qMakePair(Basic::FFLM, QString::fromLatin1("FFLM")));
       
    85             tokens.append(qMakePair(Basic::AReallyLongTokenIFreakinMeanItUKnowUKnowKnow, QString::fromLatin1("aReallyLongTokenIFreakinMeanItUKnowUKnowKnow")));
       
    86             tokens.append(qMakePair(Basic::WeHaveDashes, QString::fromLatin1("we-have-dashes")));
       
    87             tokens.append(qMakePair(Basic::WeHaveDashes2, QString::fromLatin1("we-have-dashes-")));
       
    88 
       
    89             /* toToken(). */
       
    90             for(int i = 0; i < tokens.count(); ++i)
       
    91             {
       
    92                 const TokenPair &at = tokens.at(i);
       
    93                 /* QString. */
       
    94                 QCOMPARE(Basic::toToken(at.second), at.first);
       
    95 
       
    96                 /* const QChar *, int. */
       
    97                 QCOMPARE(Basic::toToken(at.second.constData(), at.second.length()), at.first);
       
    98 
       
    99                 /* QStringRef. */
       
   100                 const QStringRef ref(&at.second);
       
   101                 QCOMPARE(Basic::toToken(ref), at.first);
       
   102             }
       
   103 
       
   104             /* toString(). */
       
   105             for(int i = 0; i < tokens.count(); ++i)
       
   106             {
       
   107                 const TokenPair &at = tokens.at(i);
       
   108                 QCOMPARE(Basic::toString(at.first), at.second);
       
   109             }
       
   110         }
       
   111 
       
   112         /* Tokens that we don't recognize. */
       
   113         {
       
   114             QStringList tokens;
       
   115             tokens.append(QLatin1String("NO-MATCH"));
       
   116             tokens.append(QLatin1String("NoKeyword"));
       
   117             tokens.append(QString());
       
   118 
       
   119             for(int i = 0; i < tokens.count(); ++i)
       
   120                 QCOMPARE(Basic::toToken(tokens.at(i)), Basic::NoKeyword);
       
   121         }
       
   122 
       
   123         /* Weird values for toToken(). */
       
   124         {
       
   125             QCOMPARE(Basic::toString(Basic::Token(5000)), QString());
       
   126             QCOMPARE(Basic::toString(Basic::NoKeyword), QString());
       
   127         }
       
   128 
       
   129     }
       
   130 }
       
   131 
       
   132 QTEST_MAIN(tst_QTokenAutomaton)
       
   133 
       
   134 #include "tst_qtokenautomaton.moc"