tests/qtp/qtp_addressbook/autotest.cpp
changeset 3 41300fa6a67c
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
       
     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 examples 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 "mainwindow.h"
       
    44 #include "addresswidget.h"
       
    45 #include "adddialog.h"
       
    46 #include "newaddresstab.h"
       
    47 #include "tablemodel.h"
       
    48 #include "autotest.h"
       
    49 
       
    50 void autoTest::initTestCase()
       
    51 {
       
    52 }
       
    53 
       
    54 void autoTest::testDefaults()
       
    55 {
       
    56 	MainWindow mw;
       
    57 	mw.show();
       
    58 
       
    59 	// Test default values for widget properties
       
    60 	QCOMPARE( mw.acceptDrops(), false );
       
    61 	QCOMPARE( mw.hasEditFocus(), false );
       
    62 	QCOMPARE( mw.hasFocus(), false );
       
    63 	QCOMPARE( mw.hasMouseTracking(), false );
       
    64 	QCOMPARE( mw.isActiveWindow(), true );
       
    65 	QCOMPARE( mw.isEnabled(), true );
       
    66 	QCOMPARE( mw.isFullScreen(), false );
       
    67 	QCOMPARE( mw.isHidden(), false );
       
    68 	QCOMPARE( mw.isMaximized(), false );
       
    69 	QCOMPARE( mw.isMinimized(), false );
       
    70 	QCOMPARE( mw.isModal(), false );
       
    71 	QCOMPARE( mw.isVisible(), true );
       
    72 	QCOMPARE( mw.isWindow(), true );
       
    73 	QCOMPARE( mw.isWindowModified(), false );
       
    74 	QCOMPARE( mw.underMouse(), false );
       
    75 	QCOMPARE( mw.updatesEnabled(), true );
       
    76 
       
    77 	mw.hide();
       
    78 }
       
    79 
       
    80 void autoTest::testMainWindow()
       
    81 {
       
    82     MainWindow mw;
       
    83     mw.show();
       
    84 
       
    85     QTest::qWait(1000);
       
    86 
       
    87     QAction *openAction = NULL;
       
    88     QAction *saveAction = NULL;
       
    89     QList<QAction *> allActions = mw.findChildren<QAction *>();
       
    90     QVERIFY( allActions.count() > 0 );
       
    91 
       
    92     for ( int i = 0; i < allActions.count(); i++ )
       
    93     {
       
    94         if ( allActions.at(i)->text() == QString("&Open..."))
       
    95         {
       
    96             openAction = allActions.at(i);
       
    97         }
       
    98         else if ( allActions.at(i)->text() == QString("&Save As..."))
       
    99         {
       
   100             saveAction = allActions.at(i);
       
   101         }
       
   102         else
       
   103         {
       
   104             // not currently tested by this autotest
       
   105         }
       
   106     }
       
   107 
       
   108     // verifies that these items exist, but no further testing is currently possible
       
   109     // due to limitations of event sending in kernel space between different threads.
       
   110     QVERIFY( openAction );
       
   111     QVERIFY( saveAction );
       
   112 
       
   113     QTest::qWait(1000);
       
   114 }
       
   115 
       
   116 void autoTest::testAddressWidget()
       
   117 {
       
   118     QString name;
       
   119     QString address;
       
   120 
       
   121     MainWindow mw;
       
   122     mw.show();
       
   123 
       
   124     QTest::qWait(500);
       
   125 
       
   126     QList<AddressWidget *> allAddrWidgets = mw.findChildren<AddressWidget *>();
       
   127     QVERIFY( allAddrWidgets.count() == 1 );
       
   128     AddressWidget *wg = allAddrWidgets.at(0);
       
   129 
       
   130     // Some sanity checks for AddressWidget
       
   131     QVERIFY( wg != 0 );
       
   132 	  
       
   133     QVERIFY( wg->width() > 0 );
       
   134     QVERIFY( wg->height() > 0 );
       
   135     QVERIFY( wg->width() <= mw.width() );
       
   136     QVERIFY( wg->height() <= mw.height() );   
       
   137     
       
   138     // Testing adding items to data fields
       
   139     QList<TableModel *> allTables = wg->findChildren<TableModel *>();
       
   140     QVERIFY( allTables.count() == 1 );
       
   141     TableModel *tm = allTables.at(0);
       
   142     QVERIFY( tm != 0 );
       
   143 
       
   144     QCOMPARE( tm->rowCount( QModelIndex()), 0 );
       
   145     QCOMPARE( tm->columnCount( QModelIndex()), 2 );
       
   146 
       
   147     name = "asdf";
       
   148     address = "0xD34DB33F";
       
   149     wg->addEntry( name, address );
       
   150 
       
   151     name = "qwerty";
       
   152     address = "usb1:0";
       
   153     wg->addEntry( name, address );
       
   154 
       
   155     name = "john";
       
   156     address = "doestreet";
       
   157     wg->addEntry( name, address );
       
   158 
       
   159     QCOMPARE( tm->rowCount( QModelIndex()), 3 );
       
   160     QCOMPARE( tm->columnCount( QModelIndex()), 2 );
       
   161 
       
   162     QTest::qWait(1000);
       
   163 
       
   164     // Testing removing items to data fields
       
   165     QTableView *tmp = static_cast<QTableView*>(wg->currentWidget());
       
   166     QVERIFY( tmp );
       
   167     tmp->selectRow(0);
       
   168     QTest::qWait(1000);
       
   169 
       
   170     wg->removeEntry();
       
   171     QTest::qWait(200);
       
   172     QCOMPARE( tm->rowCount( QModelIndex()), 2 );
       
   173     QCOMPARE( tm->columnCount( QModelIndex()), 2 );
       
   174 
       
   175     QTest::qWait(1000);
       
   176 
       
   177     mw.hide();
       
   178 }
       
   179 
       
   180 void autoTest::testAddDialog()
       
   181 {
       
   182     MainWindow mw;
       
   183     mw.show();
       
   184 
       
   185     QTest::qWait(500);
       
   186 
       
   187     mw.hide();
       
   188 }
       
   189 
       
   190 void autoTest::testNewAddressTab()
       
   191 {
       
   192     MainWindow mw;
       
   193     mw.show();
       
   194 
       
   195     QTest::qWait(500);
       
   196 
       
   197     QList<AddressWidget *> allAddrWidgets = mw.findChildren<AddressWidget *>();
       
   198     QVERIFY( allAddrWidgets.count() == 1 );
       
   199     AddressWidget *wg = allAddrWidgets.at(0);
       
   200     QVERIFY( wg != 0 );
       
   201 
       
   202     QList<NewAddressTab *> allNewWidgets = wg->findChildren<NewAddressTab *>();
       
   203     QVERIFY( allNewWidgets.count() == 1 );
       
   204     NewAddressTab *nat = allNewWidgets.at(0);
       
   205     QVERIFY( nat != 0 );
       
   206 
       
   207     QTableView *tmp = static_cast<QTableView*>(wg->currentWidget());
       
   208     QVERIFY( tmp );
       
   209 
       
   210     for (int i = 0; i < wg->count(); i++)
       
   211     {
       
   212         wg->setCurrentIndex(i);
       
   213         QTest::qWait(500);
       
   214     }
       
   215     wg->setCurrentIndex(0);
       
   216 
       
   217     QTest::keyClick ( wg, Qt::Key_Tab, Qt::NoModifier, 500 );
       
   218     QTest::keyClick ( wg, Qt::Key_Tab, Qt::NoModifier, 500 );
       
   219 
       
   220     mw.hide();
       
   221 }
       
   222 
       
   223 void autoTest::testTableModel()
       
   224 {
       
   225     MainWindow mw;
       
   226     mw.show();
       
   227 
       
   228     QTest::qWait(500);
       
   229 
       
   230     QList<AddressWidget *> allAddrWidgets = mw.findChildren<AddressWidget *>();
       
   231     QVERIFY( allAddrWidgets.count() == 1 );
       
   232     AddressWidget *wg = allAddrWidgets.at(0);
       
   233     QVERIFY( wg != 0 );
       
   234 
       
   235     QList<TableModel *> allTables = wg->findChildren<TableModel *>();
       
   236     QVERIFY( allTables.count() == 1 );
       
   237     TableModel *tm = allTables.at(0);
       
   238     QVERIFY( tm != 0 );
       
   239     
       
   240     mw.hide();
       
   241 }