tests/auto/qxmlitem/tst_qxmlitem.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 #ifdef QTEST_XMLPATTERNS
       
    46 
       
    47 #include <QXmlItem>
       
    48 
       
    49 /*!
       
    50  \class tst_QXmlItem
       
    51  \internal
       
    52  \since 4.4
       
    53  \brief Tests class QXmlItem.
       
    54  */
       
    55 class tst_QXmlItem : public QObject
       
    56 {
       
    57     Q_OBJECT
       
    58 
       
    59 private Q_SLOTS:
       
    60     void defaultConstructor() const;
       
    61     void copyConstructor() const;
       
    62     void copyConstructorFromQVariant() const;
       
    63     void copyConstructorFromQXmlNodeModelIndex() const;
       
    64     void assignmentOperator() const;
       
    65     void isNull() const;
       
    66     void isNode() const;
       
    67     void isAtomicValue() const;
       
    68     void toAtomicValue() const;
       
    69     void toNodeModelIndex() const;
       
    70 
       
    71     void objectSize() const;
       
    72     void constCorrectness() const;
       
    73     void withinQVariant() const;
       
    74 };
       
    75 
       
    76 void tst_QXmlItem::defaultConstructor() const
       
    77 {
       
    78     {
       
    79         QXmlItem();
       
    80     }
       
    81 
       
    82     {
       
    83         QXmlItem();
       
    84         QXmlItem();
       
    85     }
       
    86 
       
    87     {
       
    88         QXmlItem();
       
    89         QXmlItem();
       
    90         QXmlItem();
       
    91     }
       
    92 }
       
    93 
       
    94 void tst_QXmlItem::copyConstructor() const
       
    95 {
       
    96     /* Check that we can copy from a const reference. */
       
    97     {
       
    98         const QXmlItem item;
       
    99         const QXmlItem copy(item);
       
   100     }
       
   101 
       
   102     /* On a QXmlItem constructed from a null QVariant. */
       
   103     {
       
   104         const QXmlItem item((QVariant()));
       
   105         const QXmlItem copy(item);
       
   106     }
       
   107 
       
   108     /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */
       
   109     {
       
   110         const QXmlItem item((QXmlNodeModelIndex()));
       
   111         const QXmlItem copy(item);
       
   112     }
       
   113 }
       
   114 
       
   115 void tst_QXmlItem::copyConstructorFromQVariant() const
       
   116 {
       
   117     /* Construct & destruct a single value. */
       
   118     {
       
   119         const QXmlItem item(QVariant(QString::fromLatin1("dummy")));
       
   120     }
       
   121 
       
   122     /* Copy a null QVariant. */
       
   123     {
       
   124         const QXmlItem item((QVariant()));
       
   125         QVERIFY(item.isNull());
       
   126     }
       
   127 
       
   128 }
       
   129 
       
   130 void tst_QXmlItem::copyConstructorFromQXmlNodeModelIndex() const
       
   131 {
       
   132     // TODO copy a valid model index.
       
   133 
       
   134     /* Construct from a null QXmlNodeModelIndex. */
       
   135     {
       
   136         const QXmlItem item((QXmlNodeModelIndex()));
       
   137         QVERIFY(item.isNull());
       
   138     }
       
   139 }
       
   140 
       
   141 void tst_QXmlItem::assignmentOperator() const
       
   142 {
       
   143     /* Assign to self. */
       
   144     {
       
   145         /* With null value. */
       
   146         {
       
   147             QXmlItem item;
       
   148             item = item;
       
   149             item = item;
       
   150             item = item;
       
   151             item = item;
       
   152             item = item;
       
   153         }
       
   154 
       
   155         /* With the same atomic value. */
       
   156         {
       
   157             QXmlItem item(QVariant(QString::fromLatin1("dummy")));
       
   158             item = item;
       
   159             item = item;
       
   160             item = item;
       
   161             item = item;
       
   162             item = item;
       
   163         }
       
   164 
       
   165         /* With the same node. */
       
   166         {
       
   167             // TODO
       
   168         }
       
   169 
       
   170         /* With a QXmlItem constructed from a null QVariant. */
       
   171         {
       
   172             QXmlItem item((QVariant()));
       
   173             item = item;
       
   174             item = item;
       
   175             item = item;
       
   176             item = item;
       
   177             item = item;
       
   178         }
       
   179 
       
   180         /* With a QXmlItem constructed from a null QXmlNodeModelIndex. */
       
   181         {
       
   182             QXmlItem item((QXmlNodeModelIndex()));
       
   183             item = item;
       
   184             item = item;
       
   185             item = item;
       
   186             item = item;
       
   187             item = item;
       
   188         }
       
   189     }
       
   190 }
       
   191 
       
   192 void tst_QXmlItem::isNull() const
       
   193 {
       
   194     /* Check default value. */
       
   195     {
       
   196         const QXmlItem item;
       
   197         QVERIFY(item.isNull());
       
   198     }
       
   199 
       
   200     /* On atomic value. */
       
   201     {
       
   202         const QXmlItem item(QVariant(3));
       
   203         QVERIFY(!item.isNull());
       
   204     }
       
   205 
       
   206     /* On a QXmlItem constructed from a null QVariant. */
       
   207     {
       
   208         const QXmlItem item((QVariant()));
       
   209         QVERIFY(item.isNull());
       
   210     }
       
   211 
       
   212     /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */
       
   213     {
       
   214         const QXmlItem item((QXmlNodeModelIndex()));
       
   215         QVERIFY(item.isNull());
       
   216     }
       
   217 }
       
   218 
       
   219 void tst_QXmlItem::isNode() const
       
   220 {
       
   221     /* Check default value. */
       
   222     {
       
   223         const QXmlItem item;
       
   224         QVERIFY(!item.isNode());
       
   225     }
       
   226 
       
   227     /* On atomic value. */
       
   228     {
       
   229         const QXmlItem item(QVariant(3));
       
   230         QVERIFY(!item.isNode());
       
   231     }
       
   232     // TODO on valid node index
       
   233 
       
   234     /* On a QXmlItem constructed from a null QVariant. */
       
   235     {
       
   236         const QXmlItem item((QVariant()));
       
   237         QVERIFY(!item.isNode());
       
   238     }
       
   239 
       
   240     /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */
       
   241     {
       
   242         const QXmlItem item((QXmlNodeModelIndex()));
       
   243         QVERIFY(!item.isNode());
       
   244     }
       
   245 }
       
   246 
       
   247 void tst_QXmlItem::isAtomicValue() const
       
   248 {
       
   249     /* Check default value. */
       
   250     {
       
   251         const QXmlItem item;
       
   252         QVERIFY(!item.isAtomicValue());
       
   253     }
       
   254 
       
   255     /* On valid atomic value. */
       
   256     {
       
   257         const QXmlItem item(QVariant(3));
       
   258         QVERIFY(item.isAtomicValue());
       
   259     }
       
   260 
       
   261     // TODO on valid node index
       
   262 
       
   263     /* On a QXmlItem constructed from a null QVariant. */
       
   264     {
       
   265         const QXmlItem item((QVariant()));
       
   266         QVERIFY(!item.isAtomicValue());
       
   267     }
       
   268 
       
   269     /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */
       
   270     {
       
   271         const QXmlItem item((QXmlNodeModelIndex()));
       
   272         QVERIFY(!item.isAtomicValue());
       
   273     }
       
   274 }
       
   275 
       
   276 void tst_QXmlItem::toAtomicValue() const
       
   277 {
       
   278     /* Check default value. */
       
   279     {
       
   280         const QXmlItem item;
       
   281         QVERIFY(item.toAtomicValue().isNull());
       
   282     }
       
   283 
       
   284     /* On atomic value. */
       
   285     {
       
   286         const QXmlItem item(QVariant(3));
       
   287         QCOMPARE(item.toAtomicValue(), QVariant(3));
       
   288     }
       
   289 
       
   290     /* On a QXmlItem constructed from a null QVariant. */
       
   291     {
       
   292         const QXmlItem item((QVariant()));
       
   293         QVERIFY(item.toAtomicValue().isNull());
       
   294     }
       
   295 
       
   296     /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */
       
   297     {
       
   298         const QXmlItem item((QXmlNodeModelIndex()));
       
   299         QVERIFY(item.toAtomicValue().isNull());
       
   300     }
       
   301 }
       
   302 
       
   303 void tst_QXmlItem::toNodeModelIndex() const
       
   304 {
       
   305     /* Check default value. */
       
   306     {
       
   307         const QXmlItem item;
       
   308         QVERIFY(item.toNodeModelIndex().isNull());
       
   309     }
       
   310 
       
   311     /* On valid atomic value. */
       
   312     {
       
   313         const QXmlItem item(QVariant(3));
       
   314         QVERIFY(item.toNodeModelIndex().isNull());
       
   315     }
       
   316 
       
   317     /* On a QXmlItem constructed from a null QVariant. */
       
   318     {
       
   319         const QXmlItem item((QVariant()));
       
   320         QVERIFY(item.isNull());
       
   321     }
       
   322 
       
   323     /* On a QXmlItem constructed from a null QXmlNodeModelIndex. */
       
   324     {
       
   325         const QXmlItem item((QXmlNodeModelIndex()));
       
   326         QVERIFY(item.isNull());
       
   327     }
       
   328 }
       
   329 
       
   330 void tst_QXmlItem::objectSize() const
       
   331 {
       
   332     /* We can't currently test this in portable way,
       
   333      * so disable it. */
       
   334     return;
       
   335 
       
   336     QCOMPARE(sizeof(QPatternist::NodeIndexStorage), sizeof(QXmlItem));
       
   337 
       
   338     /* Data, additional data, and pointer to model. We test for two, such that we
       
   339      * account for the padding that MSVC do. */
       
   340     QVERIFY(sizeof(QXmlItem) == sizeof(qint64) * 2 + sizeof(QAbstractXmlNodeModel *) * 2
       
   341             || sizeof(QXmlItem) == sizeof(qint64) * 2 + sizeof(QAbstractXmlNodeModel *) * 2);
       
   342 }
       
   343 
       
   344 /*!
       
   345   Check that the functions that should be const, are.
       
   346  */
       
   347 void tst_QXmlItem::constCorrectness() const
       
   348 {
       
   349     const QXmlItem item;
       
   350     item.isNull();
       
   351     item.isNode();
       
   352     item.isAtomicValue();
       
   353 
       
   354     item.toAtomicValue();
       
   355     item.toNodeModelIndex();
       
   356 }
       
   357 
       
   358 /*!
       
   359   Check that QXmlItem can be used inside QVariant.
       
   360  */
       
   361 void tst_QXmlItem::withinQVariant() const
       
   362 {
       
   363     QXmlItem val;
       
   364     const QVariant variant(qVariantFromValue(val));
       
   365     QXmlItem val2(qVariantValue<QXmlItem>(variant));
       
   366 }
       
   367 
       
   368 QTEST_MAIN(tst_QXmlItem)
       
   369 
       
   370 #include "tst_qxmlitem.moc"
       
   371 #else //QTEST_XMLPATTERNS
       
   372 QTEST_NOOP_MAIN
       
   373 #endif