wlanutilities/wlanqtutilities/tsrc/testwlanqtutils.cpp
changeset 31 e8f4211554fb
child 39 7b3e49e4608a
equal deleted inserted replaced
30:ab513c8439db 31:e8f4211554fb
       
     1 /*
       
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * This is the source file for testing Wlan Qt Utilities library.
       
    16 */
       
    17 
       
    18 #include <QApplication>
       
    19 #include <QtCore>
       
    20 #include <QTest>
       
    21 #include <QSignalSpy>
       
    22 #include <QSharedPointer>
       
    23 #include <rconnmon.h>
       
    24 #include <nifvar.h>
       
    25 #include <cmmanagerdefines_shim.h>
       
    26 
       
    27 #include "wlanqtutilsap.h"
       
    28 #include "wlanqtutilsiap.h"
       
    29 #include "wlanqtutils.h"
       
    30 #include "wlanqtutils_p.h"
       
    31 #include "wlanqtutilsconmonwrapper.h"
       
    32 #include "wlanqtutilsconmonwrapperinfo_s60_p.h"
       
    33 #include "wlanqtutilsconntestwrapper.h"
       
    34 #include "wlanqtutilsconntestwrapper_s60_p.h"
       
    35 #include "testwlanqtutils.h"
       
    36 #include "wlanqtutilstestcontext.h"
       
    37 
       
    38 WlanQtUtilsTestContext testContext;
       
    39 
       
    40 const QString TestWlanQtUtils::commsDatDefault_ = "default.cre";
       
    41 
       
    42 // ---------------------------------------------------------
       
    43 // FRAMEWORK FUNCTIONS
       
    44 // ---------------------------------------------------------
       
    45 
       
    46 /**
       
    47  * Test main function. Runs all test cases.
       
    48  */
       
    49 int main(int argc, char *argv[])
       
    50 {
       
    51     QApplication app(argc, argv);
       
    52     
       
    53     char *pass[3];
       
    54     pass[0] = argv[0];
       
    55     pass[1] = "-o"; 
       
    56     pass[2] = "c:\\data\\wlanqtutils_qtest_log.txt";
       
    57  
       
    58     TestWlanQtUtils tc;
       
    59     int res = QTest::qExec(&tc, 3, pass);
       
    60  
       
    61     return res;
       
    62 }
       
    63 
       
    64 /**
       
    65  * This function will be called before the first test function is executed.
       
    66  */
       
    67 void TestWlanQtUtils::initTestCase()
       
    68 {
       
    69     wlanQtUtils_ = NULL;
       
    70     signalScanReady_ = NULL;
       
    71     signalWlanNetworkOpened_ = NULL;
       
    72     signalWlanNetworkClosed_ = NULL;
       
    73     signalIctResult_ = NULL;
       
    74 
       
    75     //If Active scheduler exists then don't install a new one as it will cause panic
       
    76     if (CActiveScheduler::Current() == NULL) {
       
    77         CActiveScheduler *scheduler = new CActiveScheduler();
       
    78         CActiveScheduler::Install(scheduler);
       
    79     }
       
    80 }
       
    81 
       
    82 /**
       
    83  * This function will be called after the last test function was executed.
       
    84  */
       
    85 void TestWlanQtUtils::cleanupTestCase()
       
    86 {
       
    87     // CommsDat file is initialized.
       
    88     subTestLoadCommsDatFile(commsDatDefault_);
       
    89 }
       
    90 
       
    91 /**
       
    92  * This function will be called before each test function is executed.
       
    93  */
       
    94 void TestWlanQtUtils::init()
       
    95 {
       
    96     // CommsDat file is initialized.
       
    97     subTestLoadCommsDatFile(commsDatDefault_);
       
    98 
       
    99     testContext.initialize();
       
   100 
       
   101     QVERIFY(wlanQtUtils_ == NULL);
       
   102     QVERIFY(signalScanReady_ == NULL);
       
   103     QVERIFY(signalWlanNetworkOpened_ == NULL);
       
   104     QVERIFY(signalWlanNetworkClosed_ == NULL);
       
   105     QVERIFY(signalIctResult_ == NULL);
       
   106     subTestNewWlanQtUtils();
       
   107 }
       
   108 
       
   109 /**
       
   110  * This function will be called after each test function is executed.
       
   111  */
       
   112 void TestWlanQtUtils::cleanup()
       
   113 {
       
   114     delete wlanQtUtils_;
       
   115     wlanQtUtils_ = NULL;
       
   116 
       
   117     QCOMPARE(signalScanReady_->count(), 0);
       
   118     delete signalScanReady_;
       
   119     signalScanReady_ = NULL;
       
   120 
       
   121     QCOMPARE(signalWlanNetworkOpened_->count(), 0);
       
   122     delete signalWlanNetworkOpened_;
       
   123     signalWlanNetworkOpened_ = NULL;
       
   124 
       
   125     QCOMPARE(signalWlanNetworkClosed_->count(), 0);
       
   126     delete signalWlanNetworkClosed_;
       
   127     signalWlanNetworkClosed_ = NULL;
       
   128 
       
   129     QCOMPARE(signalIctResult_->count(), 0);
       
   130     delete signalIctResult_;
       
   131     signalIctResult_ = NULL;
       
   132 }
       
   133 
       
   134 // ---------------------------------------------------------
       
   135 // TEST CASES
       
   136 // ---------------------------------------------------------
       
   137 
       
   138 /**
       
   139  * Test available WLAN APs when scan is triggered by client.
       
   140  */
       
   141 void TestWlanQtUtils::testAvailableWlan()
       
   142 {
       
   143     testContext.connMon_.wlanScanResult_.createDefaultWlanScanResultList(4);
       
   144     
       
   145     // Request a scan to get result signal
       
   146     wlanQtUtils_->scanWlans();
       
   147     
       
   148     // Let active object run and verify signal.
       
   149     subTestSignalWaitAndTake(signalScanReady_, NULL);
       
   150 
       
   151     // Get and verify the list of available WLAN APs.
       
   152     QList< QSharedPointer<WlanQtUtilsIap> > iaps;
       
   153     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   154     wlanQtUtils_->availableWlans(iaps, aps);
       
   155 
       
   156     testContext.connMon_.wlanScanResult_.verifyWlanScanResultList(aps);
       
   157     QCOMPARE(iaps.count(), 0);
       
   158     aps.clear();
       
   159 }
       
   160 
       
   161 /**
       
   162  * Test available WLAN APs when scan is triggered by client.
       
   163  * Two scan results have the same SSID and the latter one of those will be removed.
       
   164  * Two scan results have the same SSID but different security mode
       
   165  * Two scan results have the same SSID and security mode but different WpaPsk value
       
   166  * and both are included in the results.
       
   167  */
       
   168 void TestWlanQtUtils::testAvailableWlanDuplicates()
       
   169 {
       
   170     testContext.connMon_.wlanScanResult_.createDefaultWlanScanResultList(10);
       
   171     testContext.connMon_.wlanScanResult_.wlanScanResultList_[0]->setValue(WlanQtUtilsAp::ConfIdSsid, "Same SSID");
       
   172     testContext.connMon_.wlanScanResult_.wlanScanResultList_[2]->setValue(WlanQtUtilsAp::ConfIdSsid, "Same SSID");
       
   173     testContext.connMon_.wlanScanResult_.wlanScanResultList_[5]->setValue(WlanQtUtilsAp::ConfIdSsid, "Same SSID, different SecMode");
       
   174     testContext.connMon_.wlanScanResult_.wlanScanResultList_[5]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWpa);
       
   175     testContext.connMon_.wlanScanResult_.wlanScanResultList_[6]->setValue(WlanQtUtilsAp::ConfIdSsid, "Same SSID, different SecMode");
       
   176     testContext.connMon_.wlanScanResult_.wlanScanResultList_[6]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeOpen);
       
   177     testContext.connMon_.wlanScanResult_.wlanScanResultList_[7]->setValue(WlanQtUtilsAp::ConfIdSsid, "Same SSID & SecMode diff Psk");
       
   178     testContext.connMon_.wlanScanResult_.wlanScanResultList_[7]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWpa2);
       
   179     testContext.connMon_.wlanScanResult_.wlanScanResultList_[9]->setValue(WlanQtUtilsAp::ConfIdSsid, "Same SSID & SecMode diff Psk");
       
   180     testContext.connMon_.wlanScanResult_.wlanScanResultList_[9]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWpa2);
       
   181     testContext.connMon_.wlanScanResult_.wlanScanResultList_[9]->setValue(WlanQtUtilsAp::ConfIdWpaPskUse,true);
       
   182 
       
   183     // Request a scan to get result signal
       
   184     wlanQtUtils_->scanWlans();
       
   185     
       
   186     // Let active object run and verify signal.
       
   187     subTestSignalWaitAndTake(signalScanReady_, NULL);
       
   188 
       
   189     // Get and verify the list of available WLAN APs.
       
   190     QList< QSharedPointer<WlanQtUtilsIap> > iaps;
       
   191     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   192     wlanQtUtils_->availableWlans(iaps, aps);
       
   193 
       
   194     // First remove AP that has duplicate SSID.
       
   195     testContext.connMon_.wlanScanResult_.wlanScanResultList_.removeAt(2);
       
   196     testContext.connMon_.wlanScanResult_.verifyWlanScanResultList(aps);
       
   197     QCOMPARE(iaps.count(), 0);
       
   198     aps.clear();
       
   199 }
       
   200 
       
   201 /**
       
   202  * Test available WLAN APs when scan is triggered by client.
       
   203  * Include all supported security modes.
       
   204  */
       
   205 void TestWlanQtUtils::testAvailableWlanSecModes()
       
   206 {
       
   207     testContext.connMon_.wlanScanResult_.createDefaultWlanScanResultList(9);
       
   208     testContext.connMon_.wlanScanResult_.wlanScanResultList_[0]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeOpen);
       
   209     testContext.connMon_.wlanScanResult_.wlanScanResultList_[0]->setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Adhoc);
       
   210     testContext.connMon_.wlanScanResult_.wlanScanResultList_[1]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWep);
       
   211     testContext.connMon_.wlanScanResult_.wlanScanResultList_[2]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecMode802_1x);
       
   212     testContext.connMon_.wlanScanResult_.wlanScanResultList_[3]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWpa);
       
   213     testContext.connMon_.wlanScanResult_.wlanScanResultList_[4]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWpa);
       
   214     testContext.connMon_.wlanScanResult_.wlanScanResultList_[4]->setValue(WlanQtUtilsAp::ConfIdWpaPskUse,true);
       
   215     testContext.connMon_.wlanScanResult_.wlanScanResultList_[5]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWpa2);
       
   216     testContext.connMon_.wlanScanResult_.wlanScanResultList_[6]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWpa2);
       
   217     testContext.connMon_.wlanScanResult_.wlanScanResultList_[6]->setValue(WlanQtUtilsAp::ConfIdWpaPskUse,true);
       
   218     testContext.connMon_.wlanScanResult_.wlanScanResultList_[7]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWapi);
       
   219     testContext.connMon_.wlanScanResult_.wlanScanResultList_[8]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWapi);
       
   220     // Let's trick the stub to return WapiPsk by putting WpaPskUse on *
       
   221     testContext.connMon_.wlanScanResult_.wlanScanResultList_[8]->setValue(WlanQtUtilsAp::ConfIdWpaPskUse,true);
       
   222 
       
   223     // Request a scan to get result signal
       
   224     wlanQtUtils_->scanWlans();
       
   225     
       
   226     // Let active object run and verify signal.
       
   227     subTestSignalWaitAndTake(signalScanReady_, NULL);
       
   228 
       
   229     // Get and verify the list of available WLAN APs.
       
   230     QList< QSharedPointer<WlanQtUtilsIap> > iaps;
       
   231     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   232     wlanQtUtils_->availableWlans(iaps, aps);
       
   233 
       
   234     // Remove the trick *. WapiPsk and Wapi both map to just Wapi
       
   235     testContext.connMon_.wlanScanResult_.wlanScanResultList_[8]->setValue(WlanQtUtilsAp::ConfIdWpaPskUse,false);
       
   236     testContext.connMon_.wlanScanResult_.verifyWlanScanResultList(aps);
       
   237     QCOMPARE(iaps.count(), 0);
       
   238     aps.clear();
       
   239 }
       
   240 
       
   241 /**
       
   242  * Test available WLAN APs when scan is triggered by client.
       
   243  * Include some exotic ssids.
       
   244  */
       
   245 void TestWlanQtUtils::testAvailableWlanSsids()
       
   246 {
       
   247     testContext.connMon_.wlanScanResult_.createDefaultWlanScanResultList(6);
       
   248     testContext.connMon_.wlanScanResult_.wlanScanResultList_[1]->setValue(WlanQtUtilsAp::ConfIdSsid, "           ");
       
   249     testContext.connMon_.wlanScanResult_.wlanScanResultList_[2]->setValue(WlanQtUtilsAp::ConfIdSsid, "    whitespace around ssid  ");
       
   250     testContext.connMon_.wlanScanResult_.wlanScanResultList_[3]->setValue(WlanQtUtilsAp::ConfIdSsid, QString(QChar()));
       
   251     testContext.connMon_.wlanScanResult_.wlanScanResultList_[4]->setValue(WlanQtUtilsAp::ConfIdSsid, "maximum length ssid that is 32 c");
       
   252     testContext.connMon_.wlanScanResult_.wlanScanResultList_[5]->setValue(WlanQtUtilsAp::ConfIdSsid, "A");
       
   253 
       
   254     // Request a scan to get result signal
       
   255     wlanQtUtils_->scanWlans();
       
   256     
       
   257     // Let active object run and verify signal.
       
   258     subTestSignalWaitAndTake(signalScanReady_, NULL);
       
   259 
       
   260     // Get and verify the list of available WLAN APs.
       
   261     QList< QSharedPointer<WlanQtUtilsIap> > iaps;
       
   262     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   263     wlanQtUtils_->availableWlans(iaps, aps);
       
   264 
       
   265     // Empty ssids are removed from results
       
   266     testContext.connMon_.wlanScanResult_.wlanScanResultList_.removeAt(3);
       
   267     testContext.connMon_.wlanScanResult_.wlanScanResultList_.removeAt(1);
       
   268     testContext.connMon_.wlanScanResult_.verifyWlanScanResultList(aps);
       
   269     QCOMPARE(iaps.count(), 0);
       
   270     aps.clear();
       
   271 }
       
   272 
       
   273 /**
       
   274  * Test available WLAN APs when there are also WLAN IAPs available.
       
   275  */
       
   276 void TestWlanQtUtils::testAvailableWlanWithIaps()
       
   277 {
       
   278     testContext.connMon_.wlanScanResult_.createDefaultWlanScanResultList(7);
       
   279     testContext.connMon_.wlanScanResult_.wlanScanResultList_[1]->setValue(WlanQtUtilsAp::ConfIdSsid, "WLAN IAP 3");
       
   280     testContext.connMon_.wlanScanResult_.wlanScanResultList_[1]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWpa);    
       
   281     testContext.connMon_.wlanScanResult_.wlanScanResultList_[1]->setValue(WlanQtUtilsAp::ConfIdWpaPskUse,true);    
       
   282     testContext.connMon_.wlanScanResult_.wlanScanResultList_[5]->setValue(WlanQtUtilsAp::ConfIdSsid, "WLAN IAP 1");
       
   283     // SSID is found in Internet Snap, but security mode does not match:
       
   284     testContext.connMon_.wlanScanResult_.wlanScanResultList_[6]->setValue(WlanQtUtilsAp::ConfIdSsid, "WLAN IAP 2");
       
   285     testContext.connMon_.wlanScanResult_.wlanScanResultList_[6]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWpa);
       
   286     
       
   287     // Request a scan to get result signal
       
   288     wlanQtUtils_->scanWlans();
       
   289     
       
   290     // Let active object run and verify signal.
       
   291     subTestSignalWaitAndTake(signalScanReady_, NULL);
       
   292 
       
   293     // Get and verify the list of available WLAN APs.
       
   294     QList< QSharedPointer<WlanQtUtilsIap> > iaps;
       
   295     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   296     wlanQtUtils_->availableWlans(iaps, aps);
       
   297 
       
   298     // Verify WLAN AP list. First, remove scan results that will not appear
       
   299     // because they are WLAN IAPs.
       
   300     testContext.connMon_.wlanScanResult_.wlanScanResultList_.removeAt(5);
       
   301     testContext.connMon_.wlanScanResult_.wlanScanResultList_.removeAt(1);
       
   302     testContext.connMon_.wlanScanResult_.verifyWlanScanResultList(aps);
       
   303 
       
   304     // Verify WLAN IAP list
       
   305     QCOMPARE(iaps.count(), 2);
       
   306     QCOMPARE(iaps[0]->value(WlanQtUtilsIap::ConfIdIapId).toInt(), 5);
       
   307     QCOMPARE(iaps[0]->value(WlanQtUtilsIap::ConfIdName).toString(), QString("WLAN IAP 1"));
       
   308     QCOMPARE(iaps[0]->value(WlanQtUtilsAp::ConfIdSsid).toString(), QString("WLAN IAP 1"));
       
   309     QCOMPARE(iaps[1]->value(WlanQtUtilsIap::ConfIdIapId).toInt(), 7);
       
   310     QCOMPARE(iaps[1]->value(WlanQtUtilsIap::ConfIdName).toString(), QString("WLAN IAP 3"));
       
   311     QCOMPARE(iaps[1]->value(WlanQtUtilsAp::ConfIdSsid).toString(), QString("WLAN IAP 3"));
       
   312     iaps.clear();
       
   313     aps.clear();
       
   314 }
       
   315 
       
   316 /**
       
   317  * Test refereshing of WLAN APs when client requests sequential scans.
       
   318  */
       
   319 void TestWlanQtUtils::testAvailableWlanSequence()
       
   320 {
       
   321     // **************** Before 1st scan ********************
       
   322     QList< QSharedPointer<WlanQtUtilsIap> > iaps;
       
   323     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   324     wlanQtUtils_->availableWlans(iaps, aps);
       
   325     // Verify we have no results
       
   326     QCOMPARE(aps.count(), 0);
       
   327     QCOMPARE(iaps.count(), 0);
       
   328     
       
   329     // **************** 1st scan ********************
       
   330     // 6 APs are required for this scan
       
   331     testContext.connMon_.wlanScanResult_.createDefaultWlanScanResultList(6);
       
   332 
       
   333     wlanQtUtils_->scanWlans();
       
   334     subTestSignalWaitAndTake(signalScanReady_, NULL);
       
   335 
       
   336     // Get the results for the 1st scan
       
   337     wlanQtUtils_->availableWlans(iaps, aps);
       
   338     // Verify the results for the scan
       
   339     testContext.connMon_.wlanScanResult_.verifyWlanScanResultList(aps);
       
   340     QCOMPARE(iaps.count(), 0);
       
   341     aps.clear();
       
   342 
       
   343     // **************** 2nd scan ********************
       
   344     // 2 APs are required for this scan
       
   345     testContext.connMon_.wlanScanResult_.createDefaultWlanScanResultList(2);
       
   346 
       
   347     wlanQtUtils_->scanWlans();
       
   348     subTestSignalWaitAndTake(signalScanReady_, NULL);
       
   349 
       
   350     // Get the results for the 2nd scan
       
   351     wlanQtUtils_->availableWlans(iaps, aps);
       
   352     // Verify the results for the scan
       
   353     testContext.connMon_.wlanScanResult_.verifyWlanScanResultList(aps);
       
   354     QCOMPARE(iaps.count(), 0);
       
   355     aps.clear();
       
   356 
       
   357     // **************** 3rd scan ********************
       
   358     // 4 APs are required for the 3rd scan
       
   359     testContext.connMon_.wlanScanResult_.createDefaultWlanScanResultList(4);
       
   360 
       
   361     wlanQtUtils_->scanWlans();
       
   362     subTestSignalWaitAndTake(signalScanReady_, NULL);
       
   363     
       
   364     // Get the results for the 3rd scan
       
   365     wlanQtUtils_->availableWlans(iaps, aps);
       
   366     // Verify the results for the scan
       
   367     testContext.connMon_.wlanScanResult_.verifyWlanScanResultList(aps);
       
   368     QCOMPARE(iaps.count(), 0);
       
   369     aps.clear();
       
   370 }
       
   371 
       
   372 /**
       
   373  * This function tests creation of WLAN IAP in a succesful manner.
       
   374  * - WLAN scan is made because otherwise we cannot verify that IAP creation is successful.
       
   375  * - Check that there are no available WLAN IAPs.
       
   376  * - Fetch SNAP list.
       
   377  * - Create WLAN IAP.
       
   378  * - Check that WLAN IAP has been created and that this IAP is not in WLAN AP scan results.
       
   379  */
       
   380 void TestWlanQtUtils::testCreateIapOk()
       
   381 {
       
   382     testContext.connMon_.wlanScanResult_.createDefaultWlanScanResultList(1);
       
   383     testContext.connMon_.wlanScanResult_.wlanScanResultList_[0]->setValue(WlanQtUtilsAp::ConfIdSsid, "testCreateIapOk");
       
   384     testContext.connMon_.wlanScanResult_.wlanScanResultList_[0]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWpa);
       
   385     testContext.connMon_.wlanScanResult_.wlanScanResultList_[0]->setValue(WlanQtUtilsAp::ConfIdWpaPskUse,true);
       
   386 
       
   387     // Request a scan to get result signal
       
   388     wlanQtUtils_->scanWlans();
       
   389     
       
   390     // Let active object run and verify signal.
       
   391     subTestSignalWaitAndTake(signalScanReady_, NULL);
       
   392 
       
   393     // Ensure there are no WLAN IAPs but there is one scan result.
       
   394     QList< QSharedPointer<WlanQtUtilsIap> > iaps;
       
   395     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   396     wlanQtUtils_->availableWlans(iaps, aps);
       
   397 
       
   398     QCOMPARE(iaps.count(), 0);
       
   399     testContext.connMon_.wlanScanResult_.verifyWlanScanResultList(aps);
       
   400 
       
   401     // Execute createIap() function
       
   402     WlanQtUtilsAp wlanAp;
       
   403     wlanAp.setValue(WlanQtUtilsAp::ConfIdSsid, "testCreateIapOk");
       
   404     wlanAp.setValue(WlanQtUtilsAp::ConfIdSignalStrength, 90 );
       
   405     wlanAp.setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
       
   406     wlanAp.setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa);
       
   407     wlanAp.setValue(WlanQtUtilsAp::ConfIdWpaPskUse, true);
       
   408     wlanAp.setValue(WlanQtUtilsAp::ConfIdWpaPsk, "100euronlounas");
       
   409     int iapId = wlanQtUtils_->createIap(&wlanAp);
       
   410     QVERIFY(iapId != WlanQtUtils::IapIdNone);
       
   411 
       
   412     // Verify that created IAP is in the IAP list and AP list is empty.
       
   413     wlanQtUtils_->availableWlans(iaps, aps);
       
   414     QCOMPARE(iaps.count(), 1);
       
   415     QCOMPARE(iaps[0]->value(WlanQtUtilsIap::ConfIdIapId).toInt(), iapId);
       
   416     QCOMPARE(iaps[0]->value(WlanQtUtilsIap::ConfIdName).toString(), QString("testCreateIapOk"));
       
   417     QCOMPARE(iaps[0]->value(WlanQtUtilsAp::ConfIdSsid).toString(), QString("testCreateIapOk"));
       
   418     QCOMPARE(iaps[0]->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(), (int)(CMManagerShim::WlanSecModeWpa));
       
   419     QCOMPARE(iaps[0]->value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool(), true);
       
   420     QCOMPARE(aps.count(), 0);
       
   421     iaps.clear();
       
   422 }
       
   423 
       
   424 /**
       
   425  * This function tests creation of WLAN IAP in unsuccesful manner.
       
   426  */
       
   427 void TestWlanQtUtils::testCreateIapErr()
       
   428 {
       
   429     // Execute createIap() function with invalid parameters
       
   430     WlanQtUtilsAp wlanAp;
       
   431     wlanAp.setValue(WlanQtUtilsAp::ConfIdSsid, "testCreateIapErr");
       
   432     wlanAp.setValue(WlanQtUtilsAp::ConfIdSignalStrength, 90 );
       
   433     wlanAp.setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
       
   434     wlanAp.setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false);
       
   435     // Invalid security mode -> exception
       
   436     wlanAp.setValue(
       
   437         WlanQtUtilsAp::ConfIdSecurityMode,
       
   438         CMManager::EWlanSecModeWAPI + 1111);
       
   439     int iapId = wlanQtUtils_->createIap(&wlanAp);
       
   440     QVERIFY(iapId == WlanQtUtils::IapIdNone);
       
   441 }
       
   442 
       
   443 /**
       
   444  * This function tests creation of WLAN IAPs with different WEP keys.
       
   445  */
       
   446 void TestWlanQtUtils::testCreateIapWepKeys()
       
   447 {
       
   448     // Create the IAPs with different kind of WEP keys
       
   449     WlanQtUtilsAp wlanAp;
       
   450     wlanAp.setValue(WlanQtUtilsAp::ConfIdSsid, "testCreateIapWepKeys");
       
   451     wlanAp.setValue(WlanQtUtilsAp::ConfIdSignalStrength, 90);
       
   452     wlanAp.setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
       
   453     wlanAp.setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWep);
       
   454     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepDefaultIndex, 1);
       
   455     // All keys in HEX format
       
   456     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey1, "1234567891");
       
   457     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey2, "1234567891");
       
   458     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey3, "1234567891");
       
   459     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey4, "1234567891");
       
   460     wlanAp.setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false);
       
   461 
       
   462     int iapId = wlanQtUtils_->createIap(&wlanAp);
       
   463     QVERIFY(iapId != WlanQtUtils::IapIdNone);
       
   464     
       
   465     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepDefaultIndex, 2);
       
   466     // All keys in ASCII format
       
   467     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey1, "12345");
       
   468     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey2, "12345");
       
   469     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey3, "12345");
       
   470     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey4, "12345");
       
   471 
       
   472     iapId = wlanQtUtils_->createIap(&wlanAp);
       
   473     QVERIFY(iapId != WlanQtUtils::IapIdNone);
       
   474 
       
   475     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepDefaultIndex, 3);
       
   476     // Different keys, including a missing one
       
   477     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey1, "");
       
   478     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey2, "12345678911234567892123456");
       
   479     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey3, "12345");
       
   480     wlanAp.setValue(WlanQtUtilsAp::ConfIdWepKey4, "1234567891123");
       
   481 
       
   482     iapId = wlanQtUtils_->createIap(&wlanAp);
       
   483     QVERIFY(iapId != WlanQtUtils::IapIdNone);
       
   484 }
       
   485 
       
   486 /**
       
   487  * This function tests updating of WLAN IAP in a succesful manner.
       
   488  */
       
   489 void TestWlanQtUtils::testUpdateIapOk()
       
   490 {
       
   491     // Create an IAP that can be updated
       
   492     WlanQtUtilsAp wlanAp;
       
   493     wlanAp.setValue(WlanQtUtilsAp::ConfIdSsid, "testUpdateIapOk");
       
   494     wlanAp.setValue(WlanQtUtilsAp::ConfIdSignalStrength, 90);
       
   495     wlanAp.setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
       
   496     wlanAp.setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeOpen);
       
   497     wlanAp.setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false);
       
   498     int iapId = wlanQtUtils_->createIap(&wlanAp);
       
   499 
       
   500     // Update the name and verify it changed
       
   501     wlanAp.setValue(WlanQtUtilsAp::ConfIdSsid, "UPDATED_testUpdateIapOk");
       
   502 
       
   503     bool success = wlanQtUtils_->updateIap(iapId, &wlanAp);
       
   504     QVERIFY(success == true);
       
   505     QString name = wlanQtUtils_->iapName(iapId);
       
   506     QCOMPARE(name, QString("UPDATED_testUpdateIapOk"));
       
   507 }
       
   508 
       
   509 /**
       
   510  * This function tests updating of WLAN IAP in unsuccesful manner.
       
   511  */
       
   512 void TestWlanQtUtils::testUpdateIapErr()
       
   513 {
       
   514     // Try to update a non-existing IAP
       
   515     WlanQtUtilsAp wlanAp;
       
   516     bool success = wlanQtUtils_->updateIap(200, &wlanAp);
       
   517     QVERIFY(success == false);
       
   518 }
       
   519 
       
   520 /**
       
   521  * This function tests deletion of WLAN IAP in a succesful manner.
       
   522  */
       
   523 void TestWlanQtUtils::testDeleteIapOk()
       
   524 {
       
   525     // Create an IAP that can be deleted
       
   526     WlanQtUtilsAp wlanAp;
       
   527     wlanAp.setValue(WlanQtUtilsAp::ConfIdSsid, "testDeleteIapOk");
       
   528     wlanAp.setValue(WlanQtUtilsAp::ConfIdSignalStrength, 90 );
       
   529     wlanAp.setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
       
   530     wlanAp.setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeOpen);
       
   531     wlanAp.setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false);
       
   532     int iapId = wlanQtUtils_->createIap(&wlanAp);
       
   533 
       
   534     // Check that IAP now exists
       
   535     QString name = wlanQtUtils_->iapName(iapId);
       
   536     QCOMPARE(name, QString("testDeleteIapOk"));
       
   537     
       
   538     // Delete it and verify it does not exist anymore
       
   539     wlanQtUtils_->deleteIap(iapId);
       
   540     name = wlanQtUtils_->iapName(iapId);
       
   541     QVERIFY(name.isEmpty());
       
   542 }
       
   543 
       
   544 /**
       
   545  * This function tests deletion of WLAN IAP in unsuccesful manner.
       
   546  */
       
   547 void TestWlanQtUtils::testDeleteIapErr()
       
   548 {
       
   549     // Try to delete a non-existing IAP
       
   550     wlanQtUtils_->deleteIap(200);
       
   551 
       
   552     // No signals or return values to verify
       
   553 }
       
   554 
       
   555 /**
       
   556  * This function tests connecting to IAP in a succesful manner.
       
   557  */
       
   558 void TestWlanQtUtils::testConnectIapOk()
       
   559 {
       
   560     testContext.esock_.startRetValue_ = KErrNone;
       
   561 
       
   562     // Esock stub completes connection creation immediately
       
   563     wlanQtUtils_->connectIap(5);
       
   564 
       
   565     // Connection creation in ConnMon interface
       
   566     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 5);
       
   567     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
   568         EConnMonCreateConnection,
       
   569         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
   570 
       
   571     // Connection status change in ConnMon interface
       
   572     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   573         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   574         0,
       
   575         KConnectionOpen));
       
   576     
       
   577     // Receive signal for connection opening (caused by connectIap, which completed immediately)
       
   578     QList<QVariant> arguments;
       
   579     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); 
       
   580     QCOMPARE(arguments.at(0).toInt(), 5); 
       
   581 
       
   582     // Connection status change to opened in ConnMon interface. Sub test cases between test
       
   583     // cases check that no extra signals are sent
       
   584     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   585         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   586         0,
       
   587         KLinkLayerOpen));
       
   588 }
       
   589 
       
   590 /**
       
   591  * This function tests connecting to IAP in unsuccesful manner.
       
   592  */
       
   593 void TestWlanQtUtils::testConnectIapErr()
       
   594 {
       
   595     testContext.esock_.startRetValue_ = KErrGeneral;
       
   596 
       
   597     wlanQtUtils_->connectIap(7);
       
   598 
       
   599     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 7);
       
   600     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
   601             EConnMonCreateConnection,
       
   602             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
   603     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   604         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   605         0,
       
   606         KConnectionOpen));
       
   607     
       
   608     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
   609             EConnMonDeleteConnection,
       
   610             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
   611     
       
   612     QList<QVariant> arguments;
       
   613     subTestSignalWaitAndTake(signalWlanNetworkClosed_, &arguments); 
       
   614     QCOMPARE(arguments.at(0).toInt(), 7);
       
   615     QCOMPARE(arguments.at(1).toInt(), KErrGeneral);
       
   616 }
       
   617 
       
   618 // TODO: testDisconnectFail cases are needed when fail branches are
       
   619 // implemented into the connmon wrapper
       
   620 /**
       
   621  * This function tests IAP disconnecting functionality.
       
   622  */
       
   623 void TestWlanQtUtils::testDisconnectIapOk()
       
   624 {
       
   625     // Create and connect an IAP we can then disconnect
       
   626     WlanQtUtilsAp wlanAp;
       
   627     wlanAp.setValue(WlanQtUtilsAp::ConfIdSsid, "testDisconnectIapOk");
       
   628     wlanAp.setValue(WlanQtUtilsAp::ConfIdSignalStrength, 90 );
       
   629     wlanAp.setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
       
   630     wlanAp.setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa);
       
   631     wlanAp.setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false);
       
   632 
       
   633     int iapId = wlanQtUtils_->createIap(&wlanAp);
       
   634     testContext.esock_.startRetValue_ = KErrNone;
       
   635     wlanQtUtils_->connectIap(iapId);
       
   636     QList<QVariant> arguments;
       
   637     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); 
       
   638     QCOMPARE(arguments.at(0).toInt(), iapId); 
       
   639     
       
   640     // Make sure there is the newly created connection active and also
       
   641     // another one to gain coverage
       
   642     testContext.connMon_.activeConnections_.createDefaultActiveConnList(2, iapId - 1);
       
   643     // The disconnect function does not have any return values or
       
   644     // signals related to the disconnection, thus plain
       
   645     // function call is done for the test.
       
   646     wlanQtUtils_->disconnectIap(iapId);
       
   647 }
       
   648 
       
   649 /**
       
   650  * This function tests IAP disconnecting functionality when there is no
       
   651  * IAP to disconnect.
       
   652  */
       
   653 void TestWlanQtUtils::testDisconnectIapIgnored()
       
   654 {
       
   655     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 150);
       
   656     wlanQtUtils_->disconnectIap(200);
       
   657     wlanQtUtils_->disconnectIap(WlanQtUtils::IapIdNone);
       
   658 }
       
   659 
       
   660 /**
       
   661  * This function tests connection status getter.
       
   662  */
       
   663 void TestWlanQtUtils::testConnectionStatus()
       
   664 {
       
   665     // Request status when there is no connection
       
   666     WlanQtUtils::ConnStatus status = wlanQtUtils_->connectionStatus();
       
   667     QCOMPARE(status, WlanQtUtils::ConnStatusDisconnected);
       
   668     
       
   669     // Make a connection and request its status
       
   670     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 5);
       
   671     // Send event for connection creation.
       
   672     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
   673             EConnMonCreateConnection,
       
   674             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
   675     // Send events for connection status change -> connecting
       
   676     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   677         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   678         0,
       
   679         KStartingConnection));
       
   680 
       
   681     // Request status when there is connection in connecting state
       
   682     status = wlanQtUtils_->connectionStatus();
       
   683     QCOMPARE(status, WlanQtUtils::ConnStatusConnecting);
       
   684 
       
   685     // Send events for connection status change -> connected
       
   686     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   687         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   688         0,
       
   689         KLinkLayerOpen));
       
   690 
       
   691     QList<QVariant> arguments;
       
   692     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments);
       
   693     QCOMPARE(arguments.at(0).toInt(), 5);
       
   694 
       
   695     // Request status when there is connection in connected state
       
   696     status = wlanQtUtils_->connectionStatus();
       
   697     QCOMPARE(status, WlanQtUtils::ConnStatusConnected);
       
   698 }
       
   699 
       
   700 /**
       
   701  * This function tests IAP name getter with existing IAP ID.
       
   702  */
       
   703 void TestWlanQtUtils::testIapNameFound()
       
   704 {
       
   705     // Create the IAP we want to find with the getter
       
   706     WlanQtUtilsAp wlanAp;
       
   707     wlanAp.setValue(WlanQtUtilsAp::ConfIdSsid, "testIapFound");
       
   708     wlanAp.setValue(WlanQtUtilsAp::ConfIdSignalStrength, 90 );
       
   709     wlanAp.setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
       
   710     wlanAp.setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa2);
       
   711     wlanAp.setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false);
       
   712 
       
   713     int iapId = wlanQtUtils_->createIap(&wlanAp);
       
   714     
       
   715     // Execute the function under test and check that we got the correct name
       
   716     QString name = wlanQtUtils_->iapName(iapId);
       
   717     QCOMPARE(name, QString("testIapFound"));
       
   718 }
       
   719 
       
   720 /**
       
   721  * This function tests IAP name getter with non-existing IAP ID.
       
   722  */
       
   723 void TestWlanQtUtils::testIapNameNotFound()
       
   724 {
       
   725     // Execute the function under test and check that we get no name as result
       
   726     QString name = wlanQtUtils_->iapName(200); // id in valid range, but not found -> KErrNotFound
       
   727     QVERIFY(name.isEmpty());
       
   728 
       
   729     name = wlanQtUtils_->iapName(1000); // id not in valid range -> KErrArgument
       
   730     QVERIFY(name.isEmpty());
       
   731 
       
   732     name = wlanQtUtils_->iapName(3); // id of cellular IAP -> discarded
       
   733     QVERIFY(name.isEmpty());
       
   734 }
       
   735 
       
   736 /**
       
   737  * This function tests active WLAN IAP getter with existing connection.
       
   738  */
       
   739 void TestWlanQtUtils::testActiveIapFound()
       
   740 {
       
   741     // Create the IAP we want to find with the getter
       
   742     WlanQtUtilsAp wlanAp;
       
   743     wlanAp.setValue(WlanQtUtilsAp::ConfIdSsid, "testConnectedWlanIdFound");
       
   744     wlanAp.setValue(WlanQtUtilsAp::ConfIdSignalStrength, 90 );
       
   745     wlanAp.setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
       
   746     wlanAp.setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa);
       
   747     wlanAp.setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false);
       
   748 
       
   749     int iapId = wlanQtUtils_->createIap(&wlanAp);
       
   750     
       
   751     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, iapId);
       
   752 
       
   753     // Send event for connection creation.
       
   754     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
   755             EConnMonCreateConnection,
       
   756             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
   757 
       
   758     // Send events for connection status change -> opened.
       
   759     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   760         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   761         0,
       
   762         KStartingConnection));
       
   763     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   764         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   765         0,
       
   766         KLinkLayerOpen));
       
   767 
       
   768     QList<QVariant> arguments;
       
   769     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments);
       
   770     QCOMPARE(arguments.at(0).toInt(), iapId);
       
   771         
       
   772     // Execute the function under test and check that we get valid ID as result
       
   773     int id = wlanQtUtils_->activeIap();
       
   774     QCOMPARE(id, iapId);
       
   775 }
       
   776 
       
   777 /**
       
   778  * This function tests active WLAN IAP getter with connection existing already during dll construction.
       
   779  */
       
   780 void TestWlanQtUtils::testActiveIapFoundConstructor()
       
   781 {
       
   782     // IAP IDs 4 and 5 exist in default commsdat file, 4 is GPRS, 5 is WLAN
       
   783     testContext.connMon_.activeConnections_.createDefaultActiveConnList(2, 4);
       
   784     testContext.connMon_.activeConnections_.activeConnList_[0]->connMonBearerType_ = EBearerGPRS;
       
   785 
       
   786     // Create a new instance in order to test functionality triggered in constructor.
       
   787     WlanQtUtils *utils = new WlanQtUtils();
       
   788 
       
   789     // Execute the function under test and check that we get valid ID as result
       
   790     int id = utils->activeIap();
       
   791     QCOMPARE(id, 5);
       
   792 
       
   793     delete utils;
       
   794 }
       
   795 
       
   796 /**
       
   797  * This function tests active WLAN IAP getter without existing connection.
       
   798  */
       
   799 void TestWlanQtUtils::testActiveIapNotFound()
       
   800 {
       
   801     // Execute the function under test and check that we get invalid ID as result
       
   802     int id = wlanQtUtils_->activeIap();
       
   803     QCOMPARE(id, WlanQtUtils::IapIdNone);
       
   804 }
       
   805 
       
   806 /**
       
   807  * Test WLAN scan triggering interface.
       
   808  */
       
   809 void TestWlanQtUtils::testScanWlans()
       
   810 {
       
   811     // Execute function under test
       
   812     wlanQtUtils_->scanWlans();
       
   813 
       
   814     // No need to verify scan results here, testAvailableWlan* test cases
       
   815     // are for that. Just make sure the result signal is received.
       
   816     subTestSignalWaitAndTake(signalScanReady_, NULL);
       
   817 }
       
   818 
       
   819 /**
       
   820  * Test WLAN scan triggering interface with two consecutive requests.
       
   821  */
       
   822 void TestWlanQtUtils::testScanWlansIgnored()
       
   823 {
       
   824     // Do not complete scan request immediately
       
   825     testContext.connMon_.wlanScanResult_.completeWlanScan_ = false;
       
   826     
       
   827     // Execute function under test
       
   828     wlanQtUtils_->scanWlans();
       
   829 
       
   830     // Execute function under test again -> this one is ignored
       
   831     wlanQtUtils_->scanWlans();
       
   832     
       
   833     // Ongoing scan is cancelled in destructors
       
   834 }
       
   835 
       
   836 /**
       
   837  * Test WLAN scan stopping interface when scan is active.
       
   838  */
       
   839 void TestWlanQtUtils::testStopWlanScanOk()
       
   840 {
       
   841     // Do not complete scan request immediately
       
   842     testContext.connMon_.wlanScanResult_.completeWlanScan_ = false;
       
   843     // Start a scan
       
   844     wlanQtUtils_->scanWlans();
       
   845     // Execute function under test
       
   846     wlanQtUtils_->stopWlanScan();
       
   847     
       
   848     // No return values or signals to verify
       
   849 }
       
   850 
       
   851 /**
       
   852  * Test WLAN scan stopping interface when no scan is ongoing.
       
   853  */
       
   854 void TestWlanQtUtils::testStopWlanScanIgnored()
       
   855 {
       
   856     // Execute function under test
       
   857     wlanQtUtils_->stopWlanScan();
       
   858     
       
   859     // No return values or signals to verify
       
   860 }
       
   861 
       
   862 /**
       
   863  * This function tests Wlan network opening signal when network is not opened by the dll.
       
   864  */
       
   865 void TestWlanQtUtils::testWlanNetworkOpened()
       
   866 {
       
   867     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 5);
       
   868 
       
   869     // Send event for connection creation.
       
   870     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
   871             EConnMonCreateConnection,
       
   872             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
   873 
       
   874     // Send events for connection status change -> opened.
       
   875     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   876         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   877         0,
       
   878         KConnectionOpen));
       
   879     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   880         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   881         0,
       
   882         KConfigDaemonFinishedRegistration));
       
   883     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   884         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   885         0,
       
   886         KLinkLayerOpen));
       
   887 
       
   888     QList<QVariant> arguments;
       
   889     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments);
       
   890     QCOMPARE(arguments.at(0).toInt(), 5);
       
   891 
       
   892     // Send uninteresting event to gain coverage
       
   893     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
   894         EConnMonNetworkStatusChange,
       
   895         10));
       
   896 }
       
   897 
       
   898 /**
       
   899  * This function tests Wlan network closing signal when network is not closed by the dll.
       
   900  */
       
   901 void TestWlanQtUtils::testWlanNetworkClosed()
       
   902 {
       
   903     // First create a connection
       
   904     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 5);
       
   905 
       
   906     // Send event for connection creation.
       
   907     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
   908             EConnMonCreateConnection,
       
   909             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
   910 
       
   911     // Send events for connection status change -> opened.
       
   912     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   913         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   914         0,
       
   915         KConnectionOpen));
       
   916     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   917         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   918         0,
       
   919         KLinkLayerOpen));
       
   920 
       
   921     QList<QVariant> arguments;
       
   922     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments);
       
   923     QCOMPARE(arguments.at(0).toInt(), 5);
       
   924 
       
   925     // Send event for connection status change -> closed.
       
   926     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   927         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   928         0,
       
   929         KLinkLayerClosed));
       
   930 
       
   931     // Send event for connection deletion.
       
   932     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
   933             EConnMonDeleteConnection,
       
   934             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
   935 
       
   936     subTestSignalWaitAndTake(signalWlanNetworkClosed_, &arguments);
       
   937     QCOMPARE(arguments.at(0).toInt(), 5);
       
   938     QCOMPARE(arguments.at(1).toInt(), KErrNone);
       
   939 }
       
   940 
       
   941 /**
       
   942  * This function tests WlanQtUtilsAp copy constructor.
       
   943  */
       
   944 void TestWlanQtUtils::testApCopyConstructor()
       
   945 {
       
   946     WlanQtUtilsAp firstAp;
       
   947     firstAp.setValue(WlanQtUtilsAp::ConfIdSsid, "testApCopyConstructor");
       
   948     firstAp.setValue(WlanQtUtilsAp::ConfIdSignalStrength, 90 );
       
   949     firstAp.setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
       
   950     firstAp.setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa);
       
   951     firstAp.setValue(WlanQtUtilsAp::ConfIdWpaPskUse, true);    
       
   952     firstAp.setValue(WlanQtUtilsAp::ConfIdWpaPsk, "100euronlounas");
       
   953     
       
   954     // Create the copy AP
       
   955     WlanQtUtilsAp secondAp(firstAp);
       
   956     QCOMPARE(secondAp.value(WlanQtUtilsAp::ConfIdSsid).toString(), QString("testApCopyConstructor"));
       
   957     QCOMPARE(secondAp.value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(), (int)(CMManagerShim::WlanSecModeWpa));
       
   958     QCOMPARE(secondAp.value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool(), true);
       
   959     QCOMPARE(secondAp.value(WlanQtUtilsAp::ConfIdSignalStrength).toInt(), 90);
       
   960     QCOMPARE(secondAp.value(WlanQtUtilsAp::ConfIdConnectionMode).toInt(), (int)(CMManagerShim::Infra));
       
   961     QCOMPARE(secondAp.value(WlanQtUtilsAp::ConfIdWpaPsk).toString(), QString("100euronlounas"));
       
   962 }
       
   963 
       
   964 /**
       
   965  * This function tests ICT when connection test passes.
       
   966  */
       
   967 void TestWlanQtUtils::testConnectionTestOk()
       
   968 {
       
   969     // Create new IAP to test
       
   970     WlanQtUtilsAp wlanAp;
       
   971     wlanAp.setValue(WlanQtUtilsAp::ConfIdSsid, "testConnectionTestOk");
       
   972     wlanAp.setValue(WlanQtUtilsAp::ConfIdSignalStrength, 90 );
       
   973     wlanAp.setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
       
   974     wlanAp.setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeOpen);
       
   975     wlanAp.setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false);
       
   976     int iapId = wlanQtUtils_->createIap(&wlanAp);
       
   977     QVERIFY(iapId != WlanQtUtils::IapIdNone);
       
   978 
       
   979     testContext.esock_.startRetValue_ = KErrNone;
       
   980 
       
   981     // Esock stub completes connection creation immediately
       
   982     wlanQtUtils_->connectIap(iapId, true);
       
   983 
       
   984     // Connection creation in ConnMon interface
       
   985     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, iapId);
       
   986     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
   987             EConnMonCreateConnection,
       
   988             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
   989 
       
   990     // Connection status change in ConnMon interface
       
   991     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   992         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   993         0,
       
   994         KConnectionOpen));
       
   995     
       
   996     // Receive signal for connection opening (caused by connectIap, which completed immediately)
       
   997     QList<QVariant> arguments;
       
   998     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); 
       
   999     QCOMPARE(arguments.at(0).toInt(), iapId); 
       
  1000 
       
  1001     // Connection status change to opened in ConnMon interface. Sub test cases between test
       
  1002     // cases check that no extra signals are sent
       
  1003     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1004         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1005         0,
       
  1006         KLinkLayerOpen));
       
  1007 
       
  1008     // Connection test automatically started at this point. Call result function explicitly
       
  1009     // No interface exists that we could check that the IAP is moved to Internet SNAP correctly
       
  1010     TBuf<5> string;
       
  1011     wlanQtUtils_->d_ptr->mConnTestWrapper->d_ptr_->ConnectivityObserver(EConnectionOk, string);
       
  1012 
       
  1013     subTestSignalWaitAndTake(signalIctResult_, &arguments); 
       
  1014     QCOMPARE(arguments.at(0).toInt(), iapId); 
       
  1015     QCOMPARE(arguments.at(1).toBool(), true);
       
  1016 }
       
  1017 
       
  1018 /**
       
  1019  * This function tests ICT when connection test fails.
       
  1020  */
       
  1021 void TestWlanQtUtils::testConnectionTestErr()
       
  1022 {
       
  1023     // Create and connect an IAP and request ICT to be run
       
  1024     WlanQtUtilsAp wlanAp;
       
  1025     wlanAp.setValue(WlanQtUtilsAp::ConfIdSsid, "testConnectionTestErr");
       
  1026     wlanAp.setValue(WlanQtUtilsAp::ConfIdSignalStrength, 90 );
       
  1027     wlanAp.setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
       
  1028     wlanAp.setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa);
       
  1029     wlanAp.setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false);
       
  1030     
       
  1031     int iapId = wlanQtUtils_->createIap(&wlanAp);
       
  1032     wlanQtUtils_->connectIap(iapId, true);
       
  1033 
       
  1034     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, iapId);
       
  1035     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
  1036             EConnMonCreateConnection,
       
  1037             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
  1038     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1039         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1040         0,
       
  1041         KConnectionOpen));
       
  1042     QList<QVariant> arguments;
       
  1043     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); 
       
  1044     QCOMPARE(arguments.at(0).toInt(), iapId); 
       
  1045 
       
  1046     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1047         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1048         0,
       
  1049         KLinkLayerOpen));
       
  1050 
       
  1051     // Connection test automatically started at this point. Call result function explicitly
       
  1052     // No interface exists that we could check that IAP is not moved to another SNAP
       
  1053     TBuf<5> string;
       
  1054     wlanQtUtils_->d_ptr->mConnTestWrapper->d_ptr_->ConnectivityObserver(EHttpAuthenticationNeeded, string);
       
  1055 
       
  1056     subTestSignalWaitAndTake(signalIctResult_, &arguments); 
       
  1057     QCOMPARE(arguments.at(0).toInt(), iapId); 
       
  1058     QCOMPARE(arguments.at(1).toBool(), false);
       
  1059 }
       
  1060 
       
  1061 /**
       
  1062  * This function tests that Gprs connection events are ignored.
       
  1063  */
       
  1064 void TestWlanQtUtils::testConnMonEventGprs()
       
  1065 {
       
  1066     // First create a connection
       
  1067     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 4);
       
  1068     testContext.connMon_.activeConnections_.activeConnList_[0]->connMonBearerType_ = EBearerGPRS;
       
  1069     
       
  1070     // Send event for connection creation.
       
  1071     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
  1072             EConnMonCreateConnection,
       
  1073             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
  1074 
       
  1075     // Send events for connection status change -> opened.
       
  1076     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1077         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1078         0,
       
  1079         KConnectionOpen));
       
  1080     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1081         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1082         0,
       
  1083         KLinkLayerOpen));
       
  1084 
       
  1085     // Send event for connection status change -> closed.
       
  1086     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1087         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1088         0,
       
  1089         KLinkLayerClosed));
       
  1090 
       
  1091     // Send event for connection deletion.
       
  1092     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
  1093             EConnMonDeleteConnection,
       
  1094             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
  1095 }
       
  1096 
       
  1097 /**
       
  1098  * This function tests ConnMon event handling with connection existing already during dll construction.
       
  1099  */
       
  1100 void TestWlanQtUtils::testConnMonEventCreatedBeforeConstructor()
       
  1101 {
       
  1102     // IAP ID 5 exists in default commsdat file
       
  1103     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 5);
       
  1104 
       
  1105     // Create a new instance in order to test functionality triggered in constructor.
       
  1106     WlanQtUtils *utils = new WlanQtUtils();
       
  1107 
       
  1108     QSignalSpy *signalWlanNetworkOpened = new QSignalSpy(utils, SIGNAL(wlanNetworkOpened(int)));
       
  1109     QVERIFY(signalWlanNetworkOpened->isValid() == true);
       
  1110     QSignalSpy *signalWlanNetworkClosed = new QSignalSpy(utils, SIGNAL(wlanNetworkClosed(int, int)));
       
  1111     QVERIFY(signalWlanNetworkClosed->isValid() == true);
       
  1112     
       
  1113     // Send events for connection status change -> opened.
       
  1114     utils->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1115         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1116         0,
       
  1117         KConnectionOpen));
       
  1118     utils->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1119         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1120         0,
       
  1121         KLinkLayerOpen));
       
  1122 
       
  1123     QList<QVariant> arguments;
       
  1124     subTestSignalWaitAndTake(signalWlanNetworkOpened, &arguments);
       
  1125     QCOMPARE(arguments.at(0).toInt(), 5);
       
  1126 
       
  1127     // Send event for connection status change -> closed.
       
  1128     utils->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1129         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1130         0,
       
  1131         KLinkLayerClosed));
       
  1132 
       
  1133     // Send event for connection deletion.
       
  1134     utils->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
  1135             EConnMonDeleteConnection,
       
  1136             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
  1137 
       
  1138     subTestSignalWaitAndTake(signalWlanNetworkClosed, &arguments);
       
  1139     QCOMPARE(arguments.at(0).toInt(), 5);
       
  1140     QCOMPARE(arguments.at(1).toInt(), KErrNone);
       
  1141     
       
  1142     delete signalWlanNetworkOpened;
       
  1143     delete signalWlanNetworkClosed;
       
  1144     delete utils;
       
  1145 }
       
  1146 
       
  1147 // ---------------------------------------------------------
       
  1148 // SUB TEST CASES
       
  1149 // ---------------------------------------------------------
       
  1150 
       
  1151 /**
       
  1152  * This function waits for active objects to get time to run, takes the arguments of the
       
  1153  * first signal and returns them from the given signal spy.
       
  1154  * This function also verifies that the number of signals is 1.
       
  1155  * 
       
  1156  * @param[in] spy Signal spy.
       
  1157  * @param[out] arguments Arguments of the first signal in the given signal spy. NULL if arguments not needed.
       
  1158  */
       
  1159 void TestWlanQtUtils::subTestSignalWaitAndTake(QSignalSpy* spy, QList<QVariant>* arguments)
       
  1160 {
       
  1161     QTest::qWait(1);
       
  1162     QCOMPARE(spy->count(), 1);
       
  1163     QList<QVariant> arguments_tmp = spy->takeFirst();
       
  1164     if (arguments != NULL) {
       
  1165         *arguments = arguments_tmp;
       
  1166     }
       
  1167 }
       
  1168 
       
  1169 /**
       
  1170  * This function loads given CommsDat file, replacing current one.
       
  1171  * If CommsDat file doesn't exist, it can be re-created by commanding WST script.
       
  1172  * Using help switch is a quick way:
       
  1173  *     run_wst HELP
       
  1174  * 
       
  1175  * @param newCommsdatFilename Filename of the new CommsDat to be loaded. 
       
  1176  */
       
  1177 void TestWlanQtUtils::subTestLoadCommsDatFile(QString newCommsdatFilename)
       
  1178 {
       
  1179     // EPOC's CommsDat filename   
       
  1180     const QString epocCommsdatFilename("cccccc00.cre");
       
  1181     // EPOC's directory for CommsDat file
       
  1182     const QString commsdatDir("c:\\private\\10202be9\\persists\\");
       
  1183     // Created backup directory under EPOC for CommsDat files
       
  1184     const QString storeDir("c:\\private\\10202be9\\persists\\backup\\");
       
  1185     QString nameOld = commsdatDir + epocCommsdatFilename;
       
  1186     QString nameDefault = storeDir + newCommsdatFilename;
       
  1187 
       
  1188     // First remove the old CommsDat file.
       
  1189     Q_ASSERT(QFile::remove(nameOld) == TRUE);
       
  1190     
       
  1191     // Copy the stored default CommsDat file.
       
  1192     Q_ASSERT(QFile::copy(nameDefault, nameOld) == TRUE);
       
  1193 }
       
  1194 
       
  1195 /**
       
  1196  * 
       
  1197  */
       
  1198 void TestWlanQtUtils::subTestNewWlanQtUtils()
       
  1199 {
       
  1200     if (wlanQtUtils_ != NULL) {
       
  1201         delete wlanQtUtils_;
       
  1202     }
       
  1203     wlanQtUtils_ = new WlanQtUtils();
       
  1204 
       
  1205     if (signalScanReady_ != NULL) {
       
  1206         delete signalScanReady_;
       
  1207     }
       
  1208     signalScanReady_ = new QSignalSpy(wlanQtUtils_, SIGNAL(wlanScanReady()));
       
  1209     QVERIFY(signalScanReady_->isValid() == true);
       
  1210 
       
  1211     if (signalWlanNetworkOpened_ != NULL) {
       
  1212         delete signalWlanNetworkOpened_;
       
  1213     }
       
  1214     signalWlanNetworkOpened_ = new QSignalSpy(wlanQtUtils_, SIGNAL(wlanNetworkOpened(int)));
       
  1215     QVERIFY(signalWlanNetworkOpened_->isValid() == true);
       
  1216     
       
  1217     if (signalWlanNetworkClosed_ != NULL) {
       
  1218         delete signalWlanNetworkClosed_;
       
  1219     }
       
  1220     signalWlanNetworkClosed_ = new QSignalSpy(wlanQtUtils_, SIGNAL(wlanNetworkClosed(int, int)));
       
  1221     QVERIFY(signalWlanNetworkClosed_->isValid() == true);
       
  1222     
       
  1223     if (signalIctResult_ != NULL) {
       
  1224         delete signalIctResult_;
       
  1225     }
       
  1226     signalIctResult_ = new QSignalSpy(wlanQtUtils_, SIGNAL(ictResult(int, bool)));
       
  1227     QVERIFY(signalIctResult_->isValid() == true);
       
  1228 }