wlanutilities/wlanqtutilities/tsrc/testwlanqtutils.cpp
branchRCL_3
changeset 25 f28ada11abbf
parent 24 63be7eb3fc78
equal deleted inserted replaced
24:63be7eb3fc78 25:f28ada11abbf
     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_symbian.h"
       
    33 #include "testwlanqtutils.h"
       
    34 #include "wlanqtutilstestcontext.h"
       
    35 
       
    36 WlanQtUtilsTestContext testContext;
       
    37 
       
    38 const QString TestWlanQtUtils::commsDatDefault_ = "default.cre";
       
    39 
       
    40 // ---------------------------------------------------------
       
    41 // FRAMEWORK FUNCTIONS
       
    42 // ---------------------------------------------------------
       
    43 
       
    44 /**
       
    45  * Test main function. Runs all test cases.
       
    46  */
       
    47 int main(int argc, char *argv[])
       
    48 {
       
    49     QApplication app(argc, argv);
       
    50     
       
    51     char *pass[3];
       
    52     pass[0] = argv[0];
       
    53     pass[1] = "-o"; 
       
    54     pass[2] = "c:\\data\\wlanqtutils_qtest_log.txt";
       
    55  
       
    56     TestWlanQtUtils tc;
       
    57     int res = QTest::qExec(&tc, 3, pass);
       
    58  
       
    59     return res;
       
    60 }
       
    61 
       
    62 /**
       
    63  * This function will be called before the first test function is executed.
       
    64  */
       
    65 void TestWlanQtUtils::initTestCase()
       
    66 {
       
    67     wlanQtUtils_ = NULL;
       
    68     mSignalScanReady = NULL;
       
    69     mSignalScanApReady = NULL;
       
    70     mSignalScanDirectReady = 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(mSignalScanReady == NULL);
       
   103     QVERIFY(mSignalScanApReady == NULL);
       
   104     QVERIFY(mSignalScanDirectReady == NULL);
       
   105     QVERIFY(signalWlanNetworkOpened_ == NULL);
       
   106     QVERIFY(signalWlanNetworkClosed_ == NULL);
       
   107     QVERIFY(signalIctResult_ == NULL);
       
   108     subTestNewWlanQtUtils();
       
   109 }
       
   110 
       
   111 /**
       
   112  * This function will be called after each test function is executed.
       
   113  */
       
   114 void TestWlanQtUtils::cleanup()
       
   115 {
       
   116     delete wlanQtUtils_;
       
   117     wlanQtUtils_ = NULL;
       
   118 
       
   119     QCOMPARE(mSignalScanReady->count(), 0);
       
   120     delete mSignalScanReady;
       
   121     mSignalScanReady = NULL;
       
   122 
       
   123     QCOMPARE(mSignalScanApReady->count(), 0);
       
   124     delete mSignalScanApReady;
       
   125     mSignalScanApReady = NULL;
       
   126 
       
   127     QCOMPARE(mSignalScanDirectReady->count(), 0);
       
   128     delete mSignalScanDirectReady;
       
   129     mSignalScanDirectReady = NULL;
       
   130 
       
   131     QCOMPARE(signalWlanNetworkOpened_->count(), 0);
       
   132     delete signalWlanNetworkOpened_;
       
   133     signalWlanNetworkOpened_ = NULL;
       
   134 
       
   135     QCOMPARE(signalWlanNetworkClosed_->count(), 0);
       
   136     delete signalWlanNetworkClosed_;
       
   137     signalWlanNetworkClosed_ = NULL;
       
   138 
       
   139     QCOMPARE(signalIctResult_->count(), 0);
       
   140     delete signalIctResult_;
       
   141     signalIctResult_ = NULL;
       
   142 }
       
   143 
       
   144 // ---------------------------------------------------------
       
   145 // TEST CASES
       
   146 // ---------------------------------------------------------
       
   147 
       
   148 /**
       
   149  * Test available WLAN APs when scan is triggered by client.
       
   150  */
       
   151 void TestWlanQtUtils::testAvailableWlan()
       
   152 {
       
   153     testContext.mScan.createDefaultWlanScanApResultList(4);
       
   154     
       
   155     // Request a scan to get result signal
       
   156     wlanQtUtils_->scanWlans();
       
   157     
       
   158     // Let active object run and verify signal.
       
   159     subTestScanResultSignal(mSignalScanReady, WlanQtUtils::ScanStatusOk);
       
   160 
       
   161     // Get and verify the list of available WLAN APs.
       
   162     QList< QSharedPointer<WlanQtUtilsIap> > iaps;
       
   163     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   164     wlanQtUtils_->availableWlans(iaps, aps);
       
   165 
       
   166     testContext.mScan.verifyWlanScanApResultList(aps);
       
   167     QCOMPARE(iaps.count(), 0);
       
   168     aps.clear();
       
   169 }
       
   170 
       
   171 /**
       
   172  * Test available WLAN APs when scan is triggered by client.
       
   173  * Two scan results have the same SSID and the latter one of those will be removed.
       
   174  * Two scan results have the same SSID but different security mode
       
   175  * Two scan results have the same SSID and security mode but different WpaPsk value
       
   176  * and both are included in the results.
       
   177  * Two scan results have the same SSID but different connection mode
       
   178  */
       
   179 void TestWlanQtUtils::testAvailableWlanDuplicates()
       
   180 {
       
   181     testContext.mScan.createDefaultWlanScanApResultList(11);
       
   182     testContext.mScan.mWlanScanApResultList[0]->setValue(WlanQtUtilsAp::ConfIdSsid, "Same SSID");
       
   183     testContext.mScan.mWlanScanApResultList[2]->setValue(WlanQtUtilsAp::ConfIdSsid, "Same SSID");
       
   184     testContext.mScan.mWlanScanApResultList[5]->setValue(WlanQtUtilsAp::ConfIdSsid, "Same SSID, different SecMode");
       
   185     testContext.mScan.mWlanScanApResultList[5]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWpa);
       
   186     testContext.mScan.mWlanScanApResultList[6]->setValue(WlanQtUtilsAp::ConfIdSsid, "Same SSID, different SecMode");
       
   187     testContext.mScan.mWlanScanApResultList[6]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeOpen);
       
   188     testContext.mScan.mWlanScanApResultList[7]->setValue(WlanQtUtilsAp::ConfIdSsid, "Same SSID & SecMode diff Psk");
       
   189     testContext.mScan.mWlanScanApResultList[7]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWpa2);
       
   190     testContext.mScan.mWlanScanApResultList[9]->setValue(WlanQtUtilsAp::ConfIdSsid, "Same SSID & SecMode diff Psk");
       
   191     testContext.mScan.mWlanScanApResultList[9]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWpa2);
       
   192     testContext.mScan.mWlanScanApResultList[9]->setValue(WlanQtUtilsAp::ConfIdWpaPskUse,true);
       
   193     testContext.mScan.mWlanScanApResultList[10]->setValue(WlanQtUtilsAp::ConfIdSsid, "Same SSID");
       
   194     testContext.mScan.mWlanScanApResultList[10]->setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Adhoc);
       
   195 
       
   196     // Request a scan to get result signal
       
   197     wlanQtUtils_->scanWlans();
       
   198     
       
   199     // Let active object run and verify signal.
       
   200     subTestScanResultSignal(mSignalScanReady, WlanQtUtils::ScanStatusOk);
       
   201 
       
   202     // Get and verify the list of available WLAN APs.
       
   203     QList< QSharedPointer<WlanQtUtilsIap> > iaps;
       
   204     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   205     wlanQtUtils_->availableWlans(iaps, aps);
       
   206 
       
   207     // First remove AP that has duplicate SSID.
       
   208     testContext.mScan.mWlanScanApResultList.removeAt(2);
       
   209     testContext.mScan.verifyWlanScanApResultList(aps);
       
   210     QCOMPARE(iaps.count(), 0);
       
   211     aps.clear();
       
   212 }
       
   213 
       
   214 /**
       
   215  * Test available WLAN APs when scan is triggered by client.
       
   216  * Include all supported security modes.
       
   217  */
       
   218 void TestWlanQtUtils::testAvailableWlanSecModes()
       
   219 {
       
   220     testContext.mScan.createDefaultWlanScanApResultList(11);
       
   221     testContext.mScan.mWlanScanApResultList[0]->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeOpen);
       
   222     testContext.mScan.mWlanScanApResultList[0]->setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Adhoc);
       
   223     testContext.mScan.mWlanScanApResultList[1]->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWep);
       
   224     testContext.mScan.mWlanScanApResultList[2]->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWep);
       
   225     testContext.mScan.mWlanScanApResultList[3]->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecMode802_1x);
       
   226     testContext.mScan.mWlanScanApResultList[4]->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa);
       
   227     testContext.mScan.mWlanScanApResultList[5]->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa);
       
   228     testContext.mScan.mWlanScanApResultList[5]->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, true);
       
   229     testContext.mScan.mWlanScanApResultList[6]->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa2);
       
   230     testContext.mScan.mWlanScanApResultList[7]->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa2);
       
   231     testContext.mScan.mWlanScanApResultList[7]->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, true);
       
   232     testContext.mScan.mWlanScanApResultList[8]->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWapi);
       
   233     testContext.mScan.mWlanScanApResultList[9]->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWapi);
       
   234     // Let's trick the stub to return WapiPsk by putting WpaPskUse on *
       
   235     testContext.mScan.mWlanScanApResultList[9]->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, true);
       
   236     testContext.mScan.mWlanScanApResultList[10]->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa2);
       
   237     testContext.mScan.mWlanScanApResultList[10]->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, true);
       
   238     testContext.mScan.mWlanScanApResultList[10]->setValue(WlanQtUtilsAp::ConfIdWpsSupported, true);
       
   239 
       
   240     // Request a scan to get result signal
       
   241     wlanQtUtils_->scanWlans();
       
   242     
       
   243     // Let active object run and verify signal.
       
   244     subTestScanResultSignal(mSignalScanReady, WlanQtUtils::ScanStatusOk);
       
   245 
       
   246     // Get and verify the list of available WLAN APs.
       
   247     QList< QSharedPointer<WlanQtUtilsIap> > iaps;
       
   248     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   249     wlanQtUtils_->availableWlans(iaps, aps);
       
   250 
       
   251     // Remove the trick *. WapiPsk and Wapi both map to just Wapi
       
   252     testContext.mScan.mWlanScanApResultList[9]->setValue(WlanQtUtilsAp::ConfIdWpaPskUse,false);
       
   253     testContext.mScan.verifyWlanScanApResultList(aps);
       
   254     QCOMPARE(iaps.count(), 0);
       
   255     aps.clear();
       
   256 }
       
   257 
       
   258 /**
       
   259  * Test available WLAN APs when scan is triggered by client.
       
   260  * Include some exotic ssids.
       
   261  */
       
   262 void TestWlanQtUtils::testAvailableWlanSsids()
       
   263 {
       
   264     testContext.mScan.createDefaultWlanScanApResultList(6);
       
   265     testContext.mScan.mWlanScanApResultList[1]->setValue(WlanQtUtilsAp::ConfIdSsid, "           ");
       
   266     testContext.mScan.mWlanScanApResultList[2]->setValue(WlanQtUtilsAp::ConfIdSsid, "    whitespace around ssid  ");
       
   267     testContext.mScan.mWlanScanApResultList[3]->setValue(WlanQtUtilsAp::ConfIdSsid, QString(QChar()));
       
   268     testContext.mScan.mWlanScanApResultList[4]->setValue(WlanQtUtilsAp::ConfIdSsid, "maximum length ssid that is 32 c");
       
   269     testContext.mScan.mWlanScanApResultList[5]->setValue(WlanQtUtilsAp::ConfIdSsid, "A");
       
   270 
       
   271     // Request a scan to get result signal
       
   272     wlanQtUtils_->scanWlans();
       
   273     
       
   274     // Let active object run and verify signal.
       
   275     subTestScanResultSignal(mSignalScanReady, WlanQtUtils::ScanStatusOk);
       
   276 
       
   277     // Get and verify the list of available WLAN APs.
       
   278     QList< QSharedPointer<WlanQtUtilsIap> > iaps;
       
   279     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   280     wlanQtUtils_->availableWlans(iaps, aps);
       
   281 
       
   282     // Empty ssids are removed from results
       
   283     testContext.mScan.mWlanScanApResultList.removeAt(3);
       
   284     testContext.mScan.mWlanScanApResultList.removeAt(1);
       
   285     testContext.mScan.verifyWlanScanApResultList(aps);
       
   286     QCOMPARE(iaps.count(), 0);
       
   287 }
       
   288 
       
   289 /**
       
   290  * Test available WLAN APs when there are also WLAN IAPs available.
       
   291  */
       
   292 void TestWlanQtUtils::testAvailableWlanWithIaps()
       
   293 {
       
   294     // Form WLAN IAP scan result list
       
   295     testContext.mScan.createDefaultWlanScanIapResultList(3);
       
   296     testContext.mScan.mWlanScanIapResultList.removeAt(1);
       
   297     testContext.mScan.mWlanScanIapResultList[0]->setValue(WlanQtUtilsIap::ConfIdIapId, 5);
       
   298     testContext.mScan.mWlanScanIapResultList[1]->setValue(WlanQtUtilsIap::ConfIdIapId, 7);
       
   299     
       
   300     // Form WLAN AP scan result list
       
   301     testContext.mScan.createDefaultWlanScanApResultList(7);
       
   302     testContext.mScan.mWlanScanApResultList[1]->setValue(WlanQtUtilsAp::ConfIdSsid, "WLAN IAP 3");
       
   303     testContext.mScan.mWlanScanApResultList[1]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWpa);    
       
   304     testContext.mScan.mWlanScanApResultList[1]->setValue(WlanQtUtilsAp::ConfIdWpaPskUse,true);    
       
   305     testContext.mScan.mWlanScanApResultList[5]->setValue(WlanQtUtilsAp::ConfIdSsid, "WLAN IAP 1");
       
   306     // SSID is found in Internet Snap, but security mode does not match:
       
   307     testContext.mScan.mWlanScanApResultList[6]->setValue(WlanQtUtilsAp::ConfIdSsid, "WLAN IAP 2");
       
   308     testContext.mScan.mWlanScanApResultList[6]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWpa);
       
   309 
       
   310     // Request a scan to get result signal
       
   311     wlanQtUtils_->scanWlans();
       
   312     
       
   313     // Let active object run and verify signal.
       
   314     subTestScanResultSignal(mSignalScanReady, WlanQtUtils::ScanStatusOk);
       
   315 
       
   316     // Get and verify the list of available WLAN APs.
       
   317     QList< QSharedPointer<WlanQtUtilsIap> > iaps;
       
   318     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   319     wlanQtUtils_->availableWlans(iaps, aps);
       
   320 
       
   321     // Verify WLAN IAP list
       
   322     testContext.mScan.verifyWlanScanIapResultList(iaps);
       
   323 
       
   324     // Verify WLAN AP list. First, remove scan results that will not appear
       
   325     // because they are WLAN IAPs.
       
   326     testContext.mScan.mWlanScanApResultList.removeAt(5);
       
   327     testContext.mScan.mWlanScanApResultList.removeAt(1);
       
   328     testContext.mScan.verifyWlanScanApResultList(aps);
       
   329     
       
   330     iaps.clear();
       
   331     aps.clear();
       
   332 }
       
   333 
       
   334 /**
       
   335  * Test refereshing of WLAN APs when client requests sequential scans.
       
   336  */
       
   337 void TestWlanQtUtils::testAvailableWlanSequence()
       
   338 {
       
   339     // **************** Before 1st scan ********************
       
   340     QList< QSharedPointer<WlanQtUtilsIap> > iaps;
       
   341     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   342     wlanQtUtils_->availableWlans(iaps, aps);
       
   343     // Verify we have no results
       
   344     QCOMPARE(aps.count(), 0);
       
   345     QCOMPARE(iaps.count(), 0);
       
   346     
       
   347     // **************** 1st scan ********************
       
   348     // 6 APs are required for this scan
       
   349     testContext.mScan.createDefaultWlanScanApResultList(6);
       
   350 
       
   351     wlanQtUtils_->scanWlans();
       
   352     subTestScanResultSignal(mSignalScanReady, WlanQtUtils::ScanStatusOk);
       
   353 
       
   354     // Get the results for the 1st scan
       
   355     wlanQtUtils_->availableWlans(iaps, aps);
       
   356     // Verify the results for the scan
       
   357     testContext.mScan.verifyWlanScanApResultList(aps);
       
   358     QCOMPARE(iaps.count(), 0);
       
   359     aps.clear();
       
   360 
       
   361     // **************** 2nd scan ********************
       
   362     // 2 APs are required for this scan
       
   363     testContext.mScan.createDefaultWlanScanApResultList(2);
       
   364 
       
   365     wlanQtUtils_->scanWlans();
       
   366     subTestScanResultSignal(mSignalScanReady, WlanQtUtils::ScanStatusOk);
       
   367 
       
   368     // Get the results for the 2nd scan
       
   369     wlanQtUtils_->availableWlans(iaps, aps);
       
   370     // Verify the results for the scan
       
   371     testContext.mScan.verifyWlanScanApResultList(aps);
       
   372     QCOMPARE(iaps.count(), 0);
       
   373     aps.clear();
       
   374 
       
   375     // **************** 3rd scan ********************
       
   376     // 4 APs are required for the 3rd scan
       
   377     testContext.mScan.createDefaultWlanScanApResultList(4);
       
   378 
       
   379     wlanQtUtils_->scanWlans();
       
   380     subTestScanResultSignal(mSignalScanReady, WlanQtUtils::ScanStatusOk);
       
   381     
       
   382     // Get the results for the 3rd scan
       
   383     wlanQtUtils_->availableWlans(iaps, aps);
       
   384     // Verify the results for the scan
       
   385     testContext.mScan.verifyWlanScanApResultList(aps);
       
   386     QCOMPARE(iaps.count(), 0);
       
   387     aps.clear();
       
   388 }
       
   389 
       
   390 /**
       
   391  * Test availability scan that finds nothing.
       
   392  */
       
   393 void TestWlanQtUtils::testAvailableWlanScanEmpty()
       
   394 {
       
   395     // Form result list
       
   396     testContext.mScan.createDefaultWlanScanApResultList(0);
       
   397 
       
   398     // Request a direct scan to get result signal
       
   399     wlanQtUtils_->scanWlans();
       
   400     
       
   401     // Let active object run and verify signal.
       
   402     subTestScanResultSignal(mSignalScanReady, WlanQtUtils::ScanStatusOk);
       
   403 
       
   404     // Get and verify the list of available WLAN APs.
       
   405     QList< QSharedPointer<WlanQtUtilsIap> > iaps;
       
   406     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   407     wlanQtUtils_->availableWlans(iaps, aps);
       
   408     testContext.mScan.verifyWlanScanApResultList(aps);
       
   409     QCOMPARE(iaps.count(), 0);
       
   410 }
       
   411 
       
   412 /**
       
   413  * Test WLAN availability scan failure.
       
   414  */
       
   415 void TestWlanQtUtils::testAvailableWlanScanError()
       
   416 {
       
   417     // Set the scan to fail
       
   418     testContext.mScan.mApScanRetValue = KErrGeneral;
       
   419     
       
   420     // Start the scan
       
   421     wlanQtUtils_->scanWlans();
       
   422 
       
   423     // Catch & check the scan result signal
       
   424     subTestScanResultSignal(mSignalScanReady, WlanQtUtils::ScanStatusError);
       
   425 }
       
   426 
       
   427 /**
       
   428  * Test available WLAN APs when scan is triggered by client.
       
   429  */
       
   430 void TestWlanQtUtils::testAvailableWlanAps()
       
   431 {
       
   432     testContext.mScan.createDefaultWlanScanApResultList(4);
       
   433     
       
   434     // Request a scan to get result signal
       
   435     wlanQtUtils_->scanWlanAps();
       
   436     
       
   437     // Let active object run and verify signal.
       
   438     subTestScanResultSignal(mSignalScanApReady, WlanQtUtils::ScanStatusOk);
       
   439 
       
   440     // Get and verify the list of available WLAN APs.
       
   441     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   442     wlanQtUtils_->availableWlanAps(aps);
       
   443 
       
   444     testContext.mScan.verifyWlanScanApResultList(aps);
       
   445     aps.clear();
       
   446 }
       
   447 
       
   448 /**
       
   449  * Test a direct scan that finds nothing.
       
   450  */
       
   451 void TestWlanQtUtils::testAvailableWlanApsScanEmpty()
       
   452 {
       
   453     // Form result list
       
   454     testContext.mScan.createDefaultWlanScanApResultList(0);
       
   455 
       
   456     // Request a direct scan to get result signal
       
   457     wlanQtUtils_->scanWlanAps();
       
   458     
       
   459     // Let active object run and verify signal.
       
   460     subTestScanResultSignal(mSignalScanApReady, WlanQtUtils::ScanStatusOk);
       
   461 
       
   462     // Get and verify the list of available WLAN APs.
       
   463     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   464     wlanQtUtils_->availableWlanAps(aps);
       
   465     testContext.mScan.verifyWlanScanApResultList(aps);
       
   466 }
       
   467 
       
   468 /**
       
   469  * Test cancellation of WLAN AP scan.
       
   470  */
       
   471 void TestWlanQtUtils::testStopWlanApScan()
       
   472 {
       
   473     // Do not complete scan request immediately
       
   474     testContext.mScan.mCompleteWlanApScan = false;
       
   475     
       
   476     // Start the scan
       
   477     wlanQtUtils_->scanWlanAps();
       
   478     // Cancel the scan
       
   479     wlanQtUtils_->stopWlanScan();
       
   480 
       
   481     // Catch & check the scan result signal
       
   482     subTestScanResultSignal(mSignalScanApReady, WlanQtUtils::ScanStatusCancelled);
       
   483 }
       
   484 
       
   485 /**
       
   486  * Test WLAN AP scan failure.
       
   487  */
       
   488 void TestWlanQtUtils::testWlanApScanError()
       
   489 {
       
   490     // Set the scan to fail
       
   491     testContext.mScan.mApScanRetValue = KErrGeneral;
       
   492     
       
   493     // Start the scan
       
   494     wlanQtUtils_->scanWlanAps();
       
   495 
       
   496     // Catch & check the scan result signal
       
   497     subTestScanResultSignal(mSignalScanApReady, WlanQtUtils::ScanStatusError);
       
   498 }
       
   499 
       
   500 /**
       
   501  * Test WLAN AP scan with special characters.
       
   502  */
       
   503 void TestWlanQtUtils::testAvailableWlanApsSpecialChars()
       
   504 {
       
   505     testContext.mScan.createDefaultWlanScanApResultList(3);
       
   506     // Set SSID's to include special characters
       
   507     testContext.mScan.mWlanScanApResultList[0]->setValue(
       
   508         WlanQtUtilsAp::ConfIdSsid,
       
   509         "\x57\x41\x50\x49\xBD\xA7\xA4\xE4\xF6");
       
   510     testContext.mScan.mWlanScanApResultList[1]->setValue(
       
   511         WlanQtUtilsAp::ConfIdSsid,
       
   512         "\x01\x02\x03\xAB\x43\x52\x41\x50\xBB\xA7\xA4\xFE\xFF");
       
   513     testContext.mScan.mWlanScanApResultList[2]->setValue(
       
   514         WlanQtUtilsAp::ConfIdSsid,
       
   515         "12345678901234567890123456789012");  // Maximum SSID length of 32 bytes
       
   516 
       
   517     // Request a scan to get result signal
       
   518     wlanQtUtils_->scanWlanAps();
       
   519     
       
   520     // Let active object run and verify signal.
       
   521     subTestScanResultSignal(mSignalScanApReady, WlanQtUtils::ScanStatusOk);
       
   522 
       
   523     // Get and verify the list of available WLAN APs.
       
   524     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   525     wlanQtUtils_->availableWlanAps(aps);
       
   526 
       
   527     testContext.mScan.verifyWlanScanApResultList(aps);
       
   528     aps.clear();
       
   529 }
       
   530 
       
   531 /**
       
   532  * Test a basic direct scan.
       
   533  */
       
   534 void TestWlanQtUtils::testDirectScanBasic()
       
   535 {
       
   536     // Form result list
       
   537     testContext.mScan.createDefaultWlanScanApResultList(2);
       
   538     testContext.mScan.mWlanScanApResultList[0]->setValue(WlanQtUtilsAp::ConfIdSsid, "testssid");
       
   539     testContext.mScan.mWlanScanApResultList[0]->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeOpen);
       
   540     testContext.mScan.mWlanScanApResultList[1]->setValue(WlanQtUtilsAp::ConfIdSsid, "testssid");
       
   541     testContext.mScan.mWlanScanApResultList[1]->setValue(WlanQtUtilsAp::ConfIdBssid, "654321");
       
   542     testContext.mScan.mWlanScanApResultList[1]->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa);
       
   543 
       
   544     // Request a direct scan to get result signal
       
   545     wlanQtUtils_->scanWlanDirect(QString("testssid"));
       
   546     
       
   547     // Let active object run and verify signal.
       
   548     subTestScanResultSignal(mSignalScanDirectReady, WlanQtUtils::ScanStatusOk);
       
   549 
       
   550     // Get and verify the list of available WLAN APs.
       
   551     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   552     wlanQtUtils_->availableWlanAps(aps);
       
   553 
       
   554     testContext.mScan.verifyWlanScanApResultList(aps);
       
   555     aps.clear();
       
   556 }
       
   557 
       
   558 /**
       
   559  * Test a direct scan that finds nothing.
       
   560  */
       
   561 void TestWlanQtUtils::testDirectScanEmpty()
       
   562 {
       
   563     // Form result list
       
   564     testContext.mScan.createDefaultWlanScanApResultList(0);
       
   565 
       
   566     // Request a direct scan to get result signal
       
   567     wlanQtUtils_->scanWlanDirect(QString("notavailable"));
       
   568     
       
   569     // Let active object run and verify signal.
       
   570     subTestScanResultSignal(mSignalScanDirectReady, WlanQtUtils::ScanStatusOk);
       
   571 
       
   572     // Get and verify the list of available WLAN APs.
       
   573     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   574     wlanQtUtils_->availableWlanAps(aps);
       
   575     testContext.mScan.verifyWlanScanApResultList(aps);
       
   576 }
       
   577 
       
   578 /**
       
   579  * Test cancellation of direct scan.
       
   580  */
       
   581 void TestWlanQtUtils::testDirectScanStop()
       
   582 {
       
   583     // Do not complete scan request immediately
       
   584     testContext.mScan.mCompleteWlanApScan = false;
       
   585     
       
   586     // Start the scan
       
   587     wlanQtUtils_->scanWlanDirect(QString("testssid"));
       
   588     // Cancel the scan
       
   589     wlanQtUtils_->stopWlanScan();
       
   590 
       
   591     // Catch & check the scan result signal
       
   592     subTestScanResultSignal(mSignalScanDirectReady, WlanQtUtils::ScanStatusCancelled);
       
   593 }
       
   594 
       
   595 /**
       
   596  * Test direct scan failure.
       
   597  */
       
   598 void TestWlanQtUtils::testDirectScanError()
       
   599 {
       
   600     // Set the scan to fail
       
   601     testContext.mScan.mApScanRetValue = KErrGeneral;
       
   602     
       
   603     // Start the scan
       
   604     wlanQtUtils_->scanWlanDirect(QString("boundtofail"));
       
   605 
       
   606     // Catch & check the scan result signal
       
   607     subTestScanResultSignal(mSignalScanDirectReady, WlanQtUtils::ScanStatusError);
       
   608 }
       
   609 
       
   610 /**
       
   611  * This function tests creation of WLAN IAP in a succesful manner.
       
   612  * - WLAN scan is made because otherwise we cannot verify that IAP creation is successful.
       
   613  * - Check that there are no available WLAN IAPs.
       
   614  * - Fetch SNAP list.
       
   615  * - Create WLAN IAP.
       
   616  * - Check that WLAN IAP has been created and that this IAP is not in WLAN AP scan results.
       
   617  */
       
   618 void TestWlanQtUtils::testCreateIapOk()
       
   619 {
       
   620     // Form WLAN AP scan result list
       
   621     testContext.mScan.createDefaultWlanScanApResultList(1);
       
   622     testContext.mScan.mWlanScanApResultList[0]->setValue(WlanQtUtilsAp::ConfIdSsid, "testCreateIapOk");
       
   623     testContext.mScan.mWlanScanApResultList[0]->setValue(WlanQtUtilsAp::ConfIdSecurityMode,CMManagerShim::WlanSecModeWpa);
       
   624     testContext.mScan.mWlanScanApResultList[0]->setValue(WlanQtUtilsAp::ConfIdWpaPskUse,true);
       
   625 
       
   626     // Form WLAN IAP scan result list
       
   627     testContext.mScan.createDefaultWlanScanIapResultList(0);
       
   628 
       
   629     // Request a scan to get result signal
       
   630     wlanQtUtils_->scanWlans();
       
   631 
       
   632     // Let active object run and verify signal.
       
   633     subTestScanResultSignal(mSignalScanReady, WlanQtUtils::ScanStatusOk);
       
   634 
       
   635     // Ensure there are no WLAN IAPs but there is one scan result.
       
   636     QList< QSharedPointer<WlanQtUtilsIap> > iaps;
       
   637     QList< QSharedPointer<WlanQtUtilsAp> > aps;
       
   638     wlanQtUtils_->availableWlans(iaps, aps);
       
   639 
       
   640     QCOMPARE(iaps.count(), 0);
       
   641     testContext.mScan.verifyWlanScanApResultList(aps);
       
   642 
       
   643     // Execute createIap() function
       
   644     QScopedPointer<WlanQtUtilsAp> wlanAp(subTestNewAp());
       
   645     wlanAp->setValue(WlanQtUtilsAp::ConfIdSsid, "testCreateIapOk");
       
   646     wlanAp->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa);
       
   647     wlanAp->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, true);
       
   648     wlanAp->setValue(WlanQtUtilsAp::ConfIdWpaPsk, "100euronlounas");
       
   649     int iapId = wlanQtUtils_->createIap(wlanAp.data());
       
   650     QVERIFY(iapId != WlanQtUtils::IapIdNone);
       
   651 
       
   652     // Form WLAN IAP scan result list
       
   653     testContext.mScan.createDefaultWlanScanIapResultList(1);
       
   654     testContext.mScan.mWlanScanIapResultList[0]->setValue(WlanQtUtilsIap::ConfIdIapId, iapId);
       
   655     testContext.mScan.mWlanScanIapResultList[0]->setValue(WlanQtUtilsIap::ConfIdName, QString("testCreateIapOk"));
       
   656     testContext.mScan.mWlanScanIapResultList[0]->setValue(WlanQtUtilsIap::ConfIdSsid, QString("testCreateIapOk"));
       
   657     testContext.mScan.mWlanScanIapResultList[0]->setValue(WlanQtUtilsIap::ConfIdSecurityMode, (int)(CMManagerShim::WlanSecModeWpa));
       
   658     testContext.mScan.mWlanScanIapResultList[0]->setValue(WlanQtUtilsIap::ConfIdWpaPskUse, true);
       
   659 
       
   660     // Re-execute the scan so that scan lists get updated due to the IAP creation
       
   661     wlanQtUtils_->scanWlans();
       
   662     subTestScanResultSignal(mSignalScanReady, WlanQtUtils::ScanStatusOk);
       
   663 
       
   664     // Verify that created IAP is in the IAP list and AP list is empty.
       
   665     wlanQtUtils_->availableWlans(iaps, aps);
       
   666     testContext.mScan.verifyWlanScanIapResultList(iaps);
       
   667     QCOMPARE(aps.count(), 0);
       
   668 }
       
   669 
       
   670 /**
       
   671  * This function tests creation of WLAN IAP in unsuccesful manner.
       
   672  */
       
   673 void TestWlanQtUtils::testCreateIapErr()
       
   674 {
       
   675     // Execute createIap() function with invalid parameters
       
   676     QScopedPointer<WlanQtUtilsAp> wlanAp(subTestNewAp());
       
   677     wlanAp->setValue(WlanQtUtilsAp::ConfIdSsid, "testCreateIapErr");
       
   678     wlanAp->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false);
       
   679     // Invalid security mode -> exception
       
   680     wlanAp->setValue(
       
   681         WlanQtUtilsAp::ConfIdSecurityMode,
       
   682         CMManager::EWlanSecModeWAPI + 1111);
       
   683     int iapId = wlanQtUtils_->createIap(wlanAp.data());
       
   684     QVERIFY(iapId == WlanQtUtils::IapIdNone);
       
   685 }
       
   686 
       
   687 /**
       
   688  * This function tests creation of WLAN IAPs with different WEP keys.
       
   689  */
       
   690 void TestWlanQtUtils::testCreateIapWepKeys()
       
   691 {
       
   692     // Create the IAPs with different kind of WEP keys
       
   693     QScopedPointer<WlanQtUtilsAp> wlanAp(subTestNewAp());
       
   694     wlanAp->setValue(WlanQtUtilsAp::ConfIdSsid, "testCreateIapWepKeys");
       
   695     wlanAp->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWep);
       
   696     wlanAp->setValue(WlanQtUtilsAp::ConfIdWepDefaultIndex, CMManagerShim::WepKeyIndex2);
       
   697     // All keys in HEX format
       
   698     wlanAp->setValue(WlanQtUtilsAp::ConfIdWepKey1, "1234567891");
       
   699     wlanAp->setValue(WlanQtUtilsAp::ConfIdWepKey2, "1234567891");
       
   700     wlanAp->setValue(WlanQtUtilsAp::ConfIdWepKey3, "1234567891");
       
   701     wlanAp->setValue(WlanQtUtilsAp::ConfIdWepKey4, "1234567891");
       
   702 
       
   703     int iapId = wlanQtUtils_->createIap(wlanAp.data());
       
   704     QVERIFY(iapId != WlanQtUtils::IapIdNone);
       
   705     
       
   706     wlanAp->setValue(WlanQtUtilsAp::ConfIdWepDefaultIndex, CMManagerShim::WepKeyIndex3);
       
   707     // All keys in ASCII format
       
   708     wlanAp->setValue(WlanQtUtilsAp::ConfIdWepKey1, "12345");
       
   709     wlanAp->setValue(WlanQtUtilsAp::ConfIdWepKey2, "12345");
       
   710     wlanAp->setValue(WlanQtUtilsAp::ConfIdWepKey3, "12345");
       
   711     wlanAp->setValue(WlanQtUtilsAp::ConfIdWepKey4, "12345");
       
   712 
       
   713     iapId = wlanQtUtils_->createIap(wlanAp.data());
       
   714     QVERIFY(iapId != WlanQtUtils::IapIdNone);
       
   715 
       
   716     wlanAp->setValue(WlanQtUtilsAp::ConfIdWepDefaultIndex, CMManagerShim::WepKeyIndex4);
       
   717     // Different keys, including a missing one
       
   718     wlanAp->setValue(WlanQtUtilsAp::ConfIdWepKey1, "");
       
   719     wlanAp->setValue(WlanQtUtilsAp::ConfIdWepKey2, "12345678911234567892123456");
       
   720     wlanAp->setValue(WlanQtUtilsAp::ConfIdWepKey3, "12345");
       
   721     wlanAp->setValue(WlanQtUtilsAp::ConfIdWepKey4, "1234567891123");
       
   722 
       
   723     iapId = wlanQtUtils_->createIap(wlanAp.data());
       
   724     QVERIFY(iapId != WlanQtUtils::IapIdNone);
       
   725 }
       
   726 
       
   727 /**
       
   728  * This function tests updating of WLAN IAP in a succesful manner.
       
   729  */
       
   730 void TestWlanQtUtils::testUpdateIapOk()
       
   731 {
       
   732     // Create an IAP that can be updated
       
   733     QScopedPointer<WlanQtUtilsAp> wlanAp(subTestNewAp());
       
   734     wlanAp->setValue(WlanQtUtilsAp::ConfIdSsid, "testUpdateIapOk");
       
   735     int iapId = wlanQtUtils_->createIap(wlanAp.data());
       
   736 
       
   737     // Update the name and verify it changed
       
   738     wlanAp->setValue(WlanQtUtilsAp::ConfIdSsid, "UPDATED_testUpdateIapOk");
       
   739 
       
   740     bool success = wlanQtUtils_->updateIap(iapId, wlanAp.data());
       
   741     QVERIFY(success == true);
       
   742     QString name = wlanQtUtils_->iapName(iapId);
       
   743     QCOMPARE(name, QString("UPDATED_testUpdateIapOk"));
       
   744 }
       
   745 
       
   746 /**
       
   747  * This function tests updating of WLAN IAP in unsuccesful manner.
       
   748  */
       
   749 void TestWlanQtUtils::testUpdateIapErr()
       
   750 {
       
   751     // Try to update a non-existing IAP
       
   752     WlanQtUtilsAp wlanAp;
       
   753     bool success = wlanQtUtils_->updateIap(200, &wlanAp);
       
   754     QVERIFY(success == false);
       
   755 }
       
   756 
       
   757 /**
       
   758  * This function tests deletion of WLAN IAP in a succesful manner.
       
   759  */
       
   760 void TestWlanQtUtils::testDeleteIapOk()
       
   761 {
       
   762     // Create an IAP that can be deleted
       
   763     QScopedPointer<WlanQtUtilsAp> wlanAp(subTestNewAp());
       
   764     wlanAp->setValue(WlanQtUtilsAp::ConfIdSsid, "testDeleteIapOk");
       
   765     int iapId = wlanQtUtils_->createIap(wlanAp.data());
       
   766 
       
   767     // Check that IAP now exists
       
   768     QString name = wlanQtUtils_->iapName(iapId);
       
   769     QCOMPARE(name, QString("testDeleteIapOk"));
       
   770     
       
   771     // Delete it and verify it does not exist anymore
       
   772     wlanQtUtils_->deleteIap(iapId);
       
   773     name = wlanQtUtils_->iapName(iapId);
       
   774     QVERIFY(name.isEmpty());
       
   775 }
       
   776 
       
   777 /**
       
   778  * This function tests deletion of WLAN IAP in unsuccesful manner.
       
   779  */
       
   780 void TestWlanQtUtils::testDeleteIapErr()
       
   781 {
       
   782     // Try to delete a non-existing IAP
       
   783     wlanQtUtils_->deleteIap(200);
       
   784 
       
   785     // No signals or return values to verify
       
   786 }
       
   787 
       
   788 /**
       
   789  * This function tests connecting to IAP in a succesful manner.
       
   790  */
       
   791 void TestWlanQtUtils::testConnectIapOk()
       
   792 {
       
   793     testContext.esock_.startRetValue_ = KErrNone;
       
   794 
       
   795     // Esock stub completes connection creation immediately
       
   796     wlanQtUtils_->connectIap(5);
       
   797 
       
   798     // Connection creation in ConnMon interface
       
   799     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 5);
       
   800     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
   801         EConnMonCreateConnection,
       
   802         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
   803 
       
   804     // Connection status change in ConnMon interface
       
   805     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   806         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   807         0,
       
   808         KConnectionOpen));
       
   809     
       
   810     // Receive signal for connection opening (caused by connectIap, which completed immediately)
       
   811     QList<QVariant> arguments;
       
   812     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); 
       
   813     QCOMPARE(arguments.at(0).toInt(), 5); 
       
   814 
       
   815     // Connection status change to opened in ConnMon interface. Sub test cases between test
       
   816     // cases check that no extra signals are sent
       
   817     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   818         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   819         0,
       
   820         KLinkLayerOpen));
       
   821 }
       
   822 
       
   823 /**
       
   824  * This function tests connecting to IAP in unsuccesful manner.
       
   825  */
       
   826 void TestWlanQtUtils::testConnectIapErr()
       
   827 {
       
   828     testContext.esock_.startRetValue_ = KErrGeneral;
       
   829 
       
   830     wlanQtUtils_->connectIap(7);
       
   831 
       
   832     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 7);
       
   833     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
   834             EConnMonCreateConnection,
       
   835             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
   836     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   837         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   838         0,
       
   839         KConnectionOpen));
       
   840     
       
   841     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
   842             EConnMonDeleteConnection,
       
   843             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
   844     
       
   845     QList<QVariant> arguments;
       
   846     subTestSignalWaitAndTake(signalWlanNetworkClosed_, &arguments); 
       
   847     QCOMPARE(arguments.at(0).toInt(), 7);
       
   848     QCOMPARE(arguments.at(1).toInt(), KErrGeneral);
       
   849 }
       
   850 
       
   851 // TODO: testDisconnectFail cases are needed when fail branches are
       
   852 // implemented into the connmon wrapper
       
   853 /**
       
   854  * This function tests IAP disconnecting functionality.
       
   855  */
       
   856 void TestWlanQtUtils::testDisconnectIapOk()
       
   857 {
       
   858     // Create and connect an IAP we can then disconnect
       
   859     QScopedPointer<WlanQtUtilsAp> wlanAp(subTestNewAp());
       
   860     wlanAp->setValue(WlanQtUtilsAp::ConfIdSsid, "testDisconnectIapOk");
       
   861     wlanAp->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa);
       
   862 
       
   863     int iapId = wlanQtUtils_->createIap(wlanAp.data());
       
   864     testContext.esock_.startRetValue_ = KErrNone;
       
   865     wlanQtUtils_->connectIap(iapId);
       
   866     QList<QVariant> arguments;
       
   867     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); 
       
   868     QCOMPARE(arguments.at(0).toInt(), iapId); 
       
   869     
       
   870     // Make sure there is the newly created connection active and also
       
   871     // another one to gain coverage
       
   872     testContext.connMon_.activeConnections_.createDefaultActiveConnList(2, iapId - 1);
       
   873     // The disconnect function does not have any return values or
       
   874     // signals related to the disconnection, thus plain
       
   875     // function call is done for the test.
       
   876     wlanQtUtils_->disconnectIap(iapId);
       
   877 }
       
   878 
       
   879 /**
       
   880  * This function tests IAP disconnecting functionality when there is no
       
   881  * IAP to disconnect.
       
   882  */
       
   883 void TestWlanQtUtils::testDisconnectIapIgnored()
       
   884 {
       
   885     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 150);
       
   886     wlanQtUtils_->disconnectIap(200);
       
   887     wlanQtUtils_->disconnectIap(WlanQtUtils::IapIdNone);
       
   888 }
       
   889 
       
   890 /**
       
   891  * This function tests connection status getter.
       
   892  */
       
   893 void TestWlanQtUtils::testConnectionStatus()
       
   894 {
       
   895     // Request status when there is no connection
       
   896     WlanQtUtils::ConnStatus status = wlanQtUtils_->connectionStatus();
       
   897     QCOMPARE(status, WlanQtUtils::ConnStatusDisconnected);
       
   898     
       
   899     // Make a connection and request its status
       
   900     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 5);
       
   901     // Send event for connection creation.
       
   902     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
   903             EConnMonCreateConnection,
       
   904             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
   905     // Send events for connection status change -> connecting
       
   906     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   907         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   908         0,
       
   909         KStartingConnection));
       
   910 
       
   911     // Request status when there is connection in connecting state
       
   912     status = wlanQtUtils_->connectionStatus();
       
   913     QCOMPARE(status, WlanQtUtils::ConnStatusConnecting);
       
   914 
       
   915     // Send events for connection status change -> connected
       
   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     // Request status when there is connection in connected state
       
   926     status = wlanQtUtils_->connectionStatus();
       
   927     QCOMPARE(status, WlanQtUtils::ConnStatusConnected);
       
   928 }
       
   929 
       
   930 /**
       
   931  * This function tests IAP name getter with existing IAP ID.
       
   932  */
       
   933 void TestWlanQtUtils::testIapNameFound()
       
   934 {
       
   935     // Create the IAP we want to find with the getter
       
   936     QScopedPointer<WlanQtUtilsAp> wlanAp(subTestNewAp());
       
   937     wlanAp->setValue(WlanQtUtilsAp::ConfIdSsid, "testIapFound");
       
   938     wlanAp->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa2);
       
   939 
       
   940     int iapId = wlanQtUtils_->createIap(wlanAp.data());
       
   941     
       
   942     // Execute the function under test and check that we got the correct name
       
   943     QString name = wlanQtUtils_->iapName(iapId);
       
   944     QCOMPARE(name, QString("testIapFound"));
       
   945 }
       
   946 
       
   947 /**
       
   948  * This function tests IAP name getter with non-existing IAP ID.
       
   949  */
       
   950 void TestWlanQtUtils::testIapNameNotFound()
       
   951 {
       
   952     // Execute the function under test and check that we get no name as result
       
   953     QString name = wlanQtUtils_->iapName(200); // id in valid range, but not found -> KErrNotFound
       
   954     QVERIFY(name.isEmpty());
       
   955 
       
   956     name = wlanQtUtils_->iapName(1000); // id not in valid range -> KErrArgument
       
   957     QVERIFY(name.isEmpty());
       
   958 
       
   959     name = wlanQtUtils_->iapName(3); // id of cellular IAP -> discarded
       
   960     QVERIFY(name.isEmpty());
       
   961 }
       
   962 
       
   963 /**
       
   964  * This function tests active WLAN IAP getter with existing connection.
       
   965  */
       
   966 void TestWlanQtUtils::testActiveIapFound()
       
   967 {
       
   968     // Create the IAP we want to find with the getter
       
   969     QScopedPointer<WlanQtUtilsAp> wlanAp(subTestNewAp());
       
   970     wlanAp->setValue(WlanQtUtilsAp::ConfIdSsid, "testConnectedWlanIdFound");
       
   971     wlanAp->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa);
       
   972 
       
   973     int iapId = wlanQtUtils_->createIap(wlanAp.data());
       
   974     
       
   975     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, iapId);
       
   976 
       
   977     // Send event for connection creation.
       
   978     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
   979         EConnMonCreateConnection,
       
   980         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
   981 
       
   982     // Send events for connection status change -> opened.
       
   983     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   984         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   985         0,
       
   986         KStartingConnection));
       
   987     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
   988         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
   989         0,
       
   990         KLinkLayerOpen));
       
   991 
       
   992     QList<QVariant> arguments;
       
   993     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments);
       
   994     QCOMPARE(arguments.at(0).toInt(), iapId);
       
   995         
       
   996     // Execute the function under test and check that we get valid ID as result
       
   997     int id = wlanQtUtils_->activeIap();
       
   998     QCOMPARE(id, iapId);
       
   999 }
       
  1000 
       
  1001 /**
       
  1002  * This function tests active WLAN IAP getter with connection existing already during dll construction.
       
  1003  */
       
  1004 void TestWlanQtUtils::testActiveIapFoundConstructor()
       
  1005 {
       
  1006     // IAP IDs 4 and 5 exist in default commsdat file, 4 is GPRS, 5 is WLAN
       
  1007     testContext.connMon_.activeConnections_.createDefaultActiveConnList(2, 4);
       
  1008     testContext.connMon_.activeConnections_.activeConnList_[0]->connMonBearerType_ = EBearerGPRS;
       
  1009 
       
  1010     // Create a new instance in order to test functionality triggered in constructor.
       
  1011     WlanQtUtils *utils = new WlanQtUtils();
       
  1012 
       
  1013     // Execute the function under test and check that we get valid ID as result
       
  1014     int id = utils->activeIap();
       
  1015     QCOMPARE(id, 5);
       
  1016 
       
  1017     delete utils;
       
  1018 }
       
  1019 
       
  1020 /**
       
  1021  * This function tests active WLAN IAP getter without existing connection.
       
  1022  */
       
  1023 void TestWlanQtUtils::testActiveIapNotFound()
       
  1024 {
       
  1025     // Execute the function under test and check that we get invalid ID as result
       
  1026     int id = wlanQtUtils_->activeIap();
       
  1027     QCOMPARE(id, WlanQtUtils::IapIdNone);
       
  1028 }
       
  1029 
       
  1030 /**
       
  1031  * Test WLAN scan triggering interface.
       
  1032  */
       
  1033 void TestWlanQtUtils::testScanWlans()
       
  1034 {
       
  1035     // Execute function under test
       
  1036     wlanQtUtils_->scanWlans();
       
  1037 
       
  1038     // No need to verify scan results here, testAvailableWlan* test cases
       
  1039     // are for that. Just make sure the result signal is received.
       
  1040     subTestScanResultSignal(mSignalScanReady, WlanQtUtils::ScanStatusOk);
       
  1041 }
       
  1042 
       
  1043 /**
       
  1044  * Test WLAN scan result ignoring & deletion during an ongoing request.
       
  1045  */
       
  1046 void TestWlanQtUtils::testScanWlansIgnored()
       
  1047 {
       
  1048     // Do not complete scan request immediately
       
  1049     testContext.mScan.mCompleteWlanApScan = false;
       
  1050     
       
  1051     // Execute function under test
       
  1052     wlanQtUtils_->scanWlans();
       
  1053 
       
  1054     // Ongoing scan is cancelled in destructors
       
  1055 }
       
  1056 
       
  1057 /**
       
  1058  * Test WLAN scan stopping interface when scan is active.
       
  1059  */
       
  1060 void TestWlanQtUtils::testStopWlanScanOk()
       
  1061 {
       
  1062     // Do not complete scan request immediately
       
  1063     testContext.mScan.mCompleteWlanApScan = false;
       
  1064     // Start a scan
       
  1065     wlanQtUtils_->scanWlans();
       
  1066     // Execute function under test
       
  1067     wlanQtUtils_->stopWlanScan();
       
  1068 
       
  1069     // Catch & check the scan result signal
       
  1070     subTestScanResultSignal(mSignalScanReady, WlanQtUtils::ScanStatusCancelled);
       
  1071 }
       
  1072 
       
  1073 /**
       
  1074  * Test WLAN scan stopping interface when no scan is ongoing.
       
  1075  */
       
  1076 void TestWlanQtUtils::testStopWlanScanIgnored()
       
  1077 {
       
  1078     // Stop without having an active scan
       
  1079     wlanQtUtils_->stopWlanScan();
       
  1080     
       
  1081     // No return values or signals to verify
       
  1082 }
       
  1083 
       
  1084 /**
       
  1085  * This function tests Wlan network opening signal when network is not opened by the dll.
       
  1086  */
       
  1087 void TestWlanQtUtils::testWlanNetworkOpened()
       
  1088 {
       
  1089     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 5);
       
  1090 
       
  1091     // Send event for connection creation.
       
  1092     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
  1093             EConnMonCreateConnection,
       
  1094             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
  1095 
       
  1096     // Send events for connection status change -> opened.
       
  1097     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1098         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1099         0,
       
  1100         KConnectionOpen));
       
  1101     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1102         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1103         0,
       
  1104         KConfigDaemonFinishedRegistration));
       
  1105     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1106         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1107         0,
       
  1108         KLinkLayerOpen));
       
  1109 
       
  1110     QList<QVariant> arguments;
       
  1111     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments);
       
  1112     QCOMPARE(arguments.at(0).toInt(), 5);
       
  1113 
       
  1114     // Send uninteresting event to gain coverage
       
  1115     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
  1116         EConnMonNetworkStatusChange,
       
  1117         10));
       
  1118 }
       
  1119 
       
  1120 /**
       
  1121  * This function tests Wlan network closing signal when network is not closed by the dll.
       
  1122  */
       
  1123 void TestWlanQtUtils::testWlanNetworkClosed()
       
  1124 {
       
  1125     // First create a connection
       
  1126     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 5);
       
  1127 
       
  1128     // Send event for connection creation.
       
  1129     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
  1130             EConnMonCreateConnection,
       
  1131             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
  1132 
       
  1133     // Send events for connection status change -> opened.
       
  1134     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1135         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1136         0,
       
  1137         KConnectionOpen));
       
  1138     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1139         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1140         0,
       
  1141         KLinkLayerOpen));
       
  1142 
       
  1143     QList<QVariant> arguments;
       
  1144     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments);
       
  1145     QCOMPARE(arguments.at(0).toInt(), 5);
       
  1146 
       
  1147     // Send event for connection status change -> closed.
       
  1148     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1149         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1150         0,
       
  1151         KLinkLayerClosed));
       
  1152 
       
  1153     // Send event for connection deletion.
       
  1154     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
  1155             EConnMonDeleteConnection,
       
  1156             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
  1157 
       
  1158     subTestSignalWaitAndTake(signalWlanNetworkClosed_, &arguments);
       
  1159     QCOMPARE(arguments.at(0).toInt(), 5);
       
  1160     QCOMPARE(arguments.at(1).toInt(), KErrNone);
       
  1161 }
       
  1162 
       
  1163 /**
       
  1164  * This function tests WlanQtUtilsAp copy constructor.
       
  1165  */
       
  1166 void TestWlanQtUtils::testApCopyConstructor()
       
  1167 {
       
  1168     WlanQtUtilsAp firstAp;
       
  1169     firstAp.setValue(WlanQtUtilsAp::ConfIdSsid, "testApCopyConstructor");
       
  1170     firstAp.setValue(WlanQtUtilsAp::ConfIdSignalStrength, 90);
       
  1171     firstAp.setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
       
  1172     firstAp.setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa);
       
  1173     firstAp.setValue(WlanQtUtilsAp::ConfIdWpaPskUse, true);    
       
  1174     firstAp.setValue(WlanQtUtilsAp::ConfIdWpaPsk, "100euronlounas");
       
  1175     
       
  1176     // Create the copy AP
       
  1177     WlanQtUtilsAp secondAp(firstAp);
       
  1178     QCOMPARE(secondAp.value(WlanQtUtilsAp::ConfIdSsid).toString(), QString("testApCopyConstructor"));
       
  1179     QCOMPARE(secondAp.value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(), (int)(CMManagerShim::WlanSecModeWpa));
       
  1180     QCOMPARE(secondAp.value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool(), true);
       
  1181     QCOMPARE(secondAp.value(WlanQtUtilsAp::ConfIdSignalStrength).toInt(), 90);
       
  1182     QCOMPARE(secondAp.value(WlanQtUtilsAp::ConfIdConnectionMode).toInt(), (int)(CMManagerShim::Infra));
       
  1183     QCOMPARE(secondAp.value(WlanQtUtilsAp::ConfIdWpaPsk).toString(), QString("100euronlounas"));
       
  1184 }
       
  1185 
       
  1186 /**
       
  1187  * This function tests ICT when connection test passes.
       
  1188  */
       
  1189 void TestWlanQtUtils::testConnectionTestOk()
       
  1190 {
       
  1191     // Create new IAP to test
       
  1192     QScopedPointer<WlanQtUtilsAp> wlanAp(subTestNewAp());
       
  1193     wlanAp->setValue(WlanQtUtilsAp::ConfIdSsid, "testConnectionTestOk");
       
  1194     int iapId = wlanQtUtils_->createIap(wlanAp.data());
       
  1195     QVERIFY(iapId != WlanQtUtils::IapIdNone);
       
  1196 
       
  1197     testContext.esock_.startRetValue_ = KErrNone;
       
  1198 
       
  1199     // Esock stub completes connection creation immediately
       
  1200     wlanQtUtils_->connectIap(iapId, true);
       
  1201 
       
  1202     // Connection creation in ConnMon interface
       
  1203     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, iapId);
       
  1204     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
  1205             EConnMonCreateConnection,
       
  1206             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
  1207 
       
  1208     // Connection status change in ConnMon interface
       
  1209     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1210         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1211         0,
       
  1212         KConnectionOpen));
       
  1213     
       
  1214     // Receive signal for connection opening (caused by connectIap, which completed immediately)
       
  1215     QList<QVariant> arguments;
       
  1216     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); 
       
  1217     QCOMPARE(arguments.at(0).toInt(), iapId); 
       
  1218 
       
  1219     // Connection status change to opened in ConnMon interface. Sub test cases between test
       
  1220     // cases check that no extra signals are sent
       
  1221     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1222         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1223         0,
       
  1224         KLinkLayerOpen));
       
  1225 
       
  1226     // Connection test automatically started at this point. Call result function explicitly
       
  1227     // No interface exists that we could check that the IAP is moved to Internet SNAP correctly
       
  1228     wlanQtUtils_->d_ptr->updateIctResult(IctsWlanLoginInterface::IctsPassed);
       
  1229 
       
  1230     subTestSignalWaitAndTake(signalIctResult_, &arguments);
       
  1231     QCOMPARE(arguments.at(0).toInt(), iapId); 
       
  1232     QCOMPARE(arguments.at(1).toInt(), (int)WlanQtUtils::IctPassed);
       
  1233 }
       
  1234 
       
  1235 /**
       
  1236  * This function tests ICT when connection test fails.
       
  1237  */
       
  1238 void TestWlanQtUtils::testConnectionTestErr()
       
  1239 {
       
  1240     // Create and connect an IAP and request ICT to be run
       
  1241     QScopedPointer<WlanQtUtilsAp> wlanAp(subTestNewAp());
       
  1242     wlanAp->setValue(WlanQtUtilsAp::ConfIdSsid, "testConnectionTestErr1");
       
  1243     wlanAp->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa);
       
  1244     
       
  1245     int iapId = wlanQtUtils_->createIap(wlanAp.data());
       
  1246     wlanQtUtils_->connectIap(iapId, true);
       
  1247 
       
  1248     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, iapId);
       
  1249     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
  1250             EConnMonCreateConnection,
       
  1251             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
  1252     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1253         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1254         0,
       
  1255         KConnectionOpen));
       
  1256     QList<QVariant> arguments;
       
  1257     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); 
       
  1258     QCOMPARE(arguments.at(0).toInt(), iapId); 
       
  1259 
       
  1260     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1261         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1262         0,
       
  1263         KLinkLayerOpen));
       
  1264 
       
  1265     // Connection test automatically started at this point. Call result function explicitly
       
  1266     // No interface exists that we could check that IAP is not moved to another SNAP
       
  1267     wlanQtUtils_->d_ptr->updateIctResult(IctsWlanLoginInterface::IctsFailed);
       
  1268 
       
  1269     subTestSignalWaitAndTake(signalIctResult_, &arguments);
       
  1270     QCOMPARE(arguments.at(0).toInt(), iapId); 
       
  1271     QCOMPARE(arguments.at(1).toInt(), (int)WlanQtUtils::IctFailed);
       
  1272 
       
  1273     // Repeat with cancel status
       
  1274     // Send event for connection status change -> closed.
       
  1275     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1276         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1277         0,
       
  1278         KLinkLayerClosed));
       
  1279 
       
  1280     // Send event for connection deletion.
       
  1281     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
  1282             EConnMonDeleteConnection,
       
  1283             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
  1284 
       
  1285     subTestSignalWaitAndTake(signalWlanNetworkClosed_, &arguments);
       
  1286     QCOMPARE(arguments.at(0).toInt(), iapId);
       
  1287     QCOMPARE(arguments.at(1).toInt(), KErrNone);
       
  1288 
       
  1289     wlanAp->setValue(WlanQtUtilsAp::ConfIdSsid, "testConnectionTestErr2");
       
  1290     
       
  1291     iapId = wlanQtUtils_->createIap(wlanAp.data());
       
  1292     wlanQtUtils_->connectIap(iapId, true);
       
  1293 
       
  1294     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, iapId);
       
  1295     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
  1296             EConnMonCreateConnection,
       
  1297             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
  1298     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1299         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1300         0,
       
  1301         KConnectionOpen));
       
  1302     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); 
       
  1303     QCOMPARE(arguments.at(0).toInt(), iapId); 
       
  1304 
       
  1305     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1306         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1307         0,
       
  1308         KLinkLayerOpen));
       
  1309 
       
  1310     // Connection test automatically started at this point. Call result function explicitly
       
  1311     // No interface exists that we could check that IAP is not moved to another SNAP
       
  1312     wlanQtUtils_->d_ptr->updateIctResult(IctsWlanLoginInterface::IctsCanceled);
       
  1313 
       
  1314     subTestSignalWaitAndTake(signalIctResult_, &arguments);
       
  1315     QCOMPARE(arguments.at(0).toInt(), iapId); 
       
  1316     QCOMPARE(arguments.at(1).toInt(), (int)WlanQtUtils::IctCancelled);
       
  1317 }
       
  1318 
       
  1319 /**
       
  1320  * This function tests ICT when connection test passes in hotspot case.
       
  1321  */
       
  1322 void TestWlanQtUtils::testConnectionTestHotspot()
       
  1323 {
       
  1324     // Create new IAP to test
       
  1325     QScopedPointer<WlanQtUtilsAp> wlanAp(subTestNewAp());
       
  1326     wlanAp->setValue(WlanQtUtilsAp::ConfIdSsid, "testConnectionTestHotspot");
       
  1327     int iapId = wlanQtUtils_->createIap(wlanAp.data());
       
  1328     QVERIFY(iapId != WlanQtUtils::IapIdNone);
       
  1329 
       
  1330     testContext.esock_.startRetValue_ = KErrNone;
       
  1331 
       
  1332     // Esock stub completes connection creation immediately
       
  1333     wlanQtUtils_->connectIap(iapId, true);
       
  1334 
       
  1335     // Connection creation in ConnMon interface
       
  1336     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, iapId);
       
  1337     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
  1338             EConnMonCreateConnection,
       
  1339             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
  1340 
       
  1341     // Connection status change in ConnMon interface
       
  1342     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1343         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1344         0,
       
  1345         KConnectionOpen));
       
  1346     
       
  1347     // Receive signal for connection opening (caused by connectIap, which completed immediately)
       
  1348     QList<QVariant> arguments;
       
  1349     subTestSignalWaitAndTake(signalWlanNetworkOpened_, &arguments); 
       
  1350     QCOMPARE(arguments.at(0).toInt(), iapId); 
       
  1351 
       
  1352     // Connection status change to opened in ConnMon interface. Sub test cases between test
       
  1353     // cases check that no extra signals are sent
       
  1354     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1355         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1356         0,
       
  1357         KLinkLayerOpen));
       
  1358 
       
  1359     // Connection test automatically started at this point.
       
  1360     // Call hotspot case slot explicitly
       
  1361     wlanQtUtils_->d_ptr->updateIctHotspotCase();
       
  1362     
       
  1363     // Call result function explicitly
       
  1364     // No interface exists that we could check that the IAP is not moved to another SNAP
       
  1365     wlanQtUtils_->d_ptr->updateIctResult(IctsWlanLoginInterface::IctsHotspotPassed);
       
  1366 
       
  1367     subTestSignalWaitAndTake(signalIctResult_, &arguments);
       
  1368     QCOMPARE(arguments.at(0).toInt(), iapId); 
       
  1369     QCOMPARE(arguments.at(1).toInt(), (int)WlanQtUtils::IctHotspotPassed);
       
  1370 }
       
  1371 
       
  1372 /**
       
  1373  * This function tests that Gprs connection events are ignored.
       
  1374  */
       
  1375 void TestWlanQtUtils::testConnMonEventGprs()
       
  1376 {
       
  1377     // First create a connection
       
  1378     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 4);
       
  1379     testContext.connMon_.activeConnections_.activeConnList_[0]->connMonBearerType_ = EBearerGPRS;
       
  1380     
       
  1381     // Send event for connection creation.
       
  1382     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
  1383             EConnMonCreateConnection,
       
  1384             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
  1385 
       
  1386     // Send events for connection status change -> opened.
       
  1387     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1388         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1389         0,
       
  1390         KConnectionOpen));
       
  1391     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1392         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1393         0,
       
  1394         KLinkLayerOpen));
       
  1395 
       
  1396     // Send event for connection status change -> closed.
       
  1397     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1398         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1399         0,
       
  1400         KLinkLayerClosed));
       
  1401 
       
  1402     // Send event for connection deletion.
       
  1403     wlanQtUtils_->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
  1404             EConnMonDeleteConnection,
       
  1405             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
  1406 }
       
  1407 
       
  1408 /**
       
  1409  * This function tests ConnMon event handling with connection existing already during dll construction.
       
  1410  */
       
  1411 void TestWlanQtUtils::testConnMonEventCreatedBeforeConstructor()
       
  1412 {
       
  1413     // IAP ID 5 exists in default commsdat file
       
  1414     testContext.connMon_.activeConnections_.createDefaultActiveConnList(1, 5);
       
  1415 
       
  1416     // Create a new instance in order to test functionality triggered in constructor.
       
  1417     WlanQtUtils *utils = new WlanQtUtils();
       
  1418 
       
  1419     QSignalSpy *signalWlanNetworkOpened = new QSignalSpy(utils, SIGNAL(wlanNetworkOpened(int)));
       
  1420     QVERIFY(signalWlanNetworkOpened->isValid() == true);
       
  1421     QSignalSpy *signalWlanNetworkClosed = new QSignalSpy(utils, SIGNAL(wlanNetworkClosed(int, int)));
       
  1422     QVERIFY(signalWlanNetworkClosed->isValid() == true);
       
  1423     
       
  1424     // Send events for connection status change -> opened.
       
  1425     utils->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1426         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1427         0,
       
  1428         KConnectionOpen));
       
  1429     utils->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1430         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1431         0,
       
  1432         KLinkLayerOpen));
       
  1433 
       
  1434     QList<QVariant> arguments;
       
  1435     subTestSignalWaitAndTake(signalWlanNetworkOpened, &arguments);
       
  1436     QCOMPARE(arguments.at(0).toInt(), 5);
       
  1437 
       
  1438     // Send event for connection status change -> closed.
       
  1439     utils->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonConnectionStatusChange(
       
  1440         testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId(),
       
  1441         0,
       
  1442         KLinkLayerClosed));
       
  1443 
       
  1444     // Send event for connection deletion.
       
  1445     utils->d_ptr->mConMonWrapper->d_ptrInfo->EventL(CConnMonEventBase(
       
  1446             EConnMonDeleteConnection,
       
  1447             testContext.connMon_.activeConnections_.activeConnList_[0]->connectionId()));
       
  1448 
       
  1449     subTestSignalWaitAndTake(signalWlanNetworkClosed, &arguments);
       
  1450     QCOMPARE(arguments.at(0).toInt(), 5);
       
  1451     QCOMPARE(arguments.at(1).toInt(), KErrNone);
       
  1452     
       
  1453     delete signalWlanNetworkOpened;
       
  1454     delete signalWlanNetworkClosed;
       
  1455     delete utils;
       
  1456 }
       
  1457 
       
  1458 // ---------------------------------------------------------
       
  1459 // SUB TEST CASES
       
  1460 // ---------------------------------------------------------
       
  1461 
       
  1462 /**
       
  1463  * This function waits for active objects to get time to run, takes the arguments of the
       
  1464  * first signal and returns them from the given signal spy.
       
  1465  * This function also verifies that the number of signals is 1.
       
  1466  * 
       
  1467  * @param[in] spy Signal spy.
       
  1468  * @param[out] arguments Arguments of the first signal in the given signal spy. NULL if arguments not needed.
       
  1469  */
       
  1470 void TestWlanQtUtils::subTestSignalWaitAndTake(QSignalSpy* spy, QList<QVariant>* arguments)
       
  1471 {
       
  1472     QTest::qWait(1);
       
  1473     QCOMPARE(spy->count(), 1);
       
  1474     QList<QVariant> arguments_tmp = spy->takeFirst();
       
  1475     if (arguments != NULL) {
       
  1476         *arguments = arguments_tmp;
       
  1477     }
       
  1478 }
       
  1479 
       
  1480 /**
       
  1481  * Test case for catching and verifying the scan result signal.
       
  1482  * 
       
  1483  * @param [in] status Scan result status.
       
  1484  */
       
  1485 void TestWlanQtUtils::subTestScanResultSignal(QSignalSpy* spy, int status)
       
  1486 {
       
  1487     QList<QVariant> arguments;
       
  1488     subTestSignalWaitAndTake(spy, &arguments);
       
  1489     QCOMPARE(arguments.length(), 1);
       
  1490     QCOMPARE(arguments.at(0).toInt(), status);
       
  1491 }
       
  1492 
       
  1493 /**
       
  1494  * This function loads given CommsDat file, replacing current one.
       
  1495  * If CommsDat file doesn't exist, it can be re-created by commanding WST script.
       
  1496  * Using help switch is a quick way:
       
  1497  *     run_wst HELP
       
  1498  * 
       
  1499  * @param newCommsdatFilename Filename of the new CommsDat to be loaded. 
       
  1500  */
       
  1501 void TestWlanQtUtils::subTestLoadCommsDatFile(QString newCommsdatFilename)
       
  1502 {
       
  1503     // EPOC's CommsDat filename   
       
  1504     const QString epocCommsdatFilename("cccccc00.cre");
       
  1505     // EPOC's directory for CommsDat file
       
  1506     const QString commsdatDir("c:\\private\\10202be9\\persists\\");
       
  1507     // Created backup directory under EPOC for CommsDat files
       
  1508     const QString storeDir("c:\\private\\10202be9\\persists\\backup\\");
       
  1509     QString nameOld = commsdatDir + epocCommsdatFilename;
       
  1510     QString nameDefault = storeDir + newCommsdatFilename;
       
  1511 
       
  1512     // First remove the old CommsDat file.
       
  1513     Q_ASSERT(QFile::remove(nameOld) == TRUE);
       
  1514     
       
  1515     // Copy the stored default CommsDat file.
       
  1516     Q_ASSERT(QFile::copy(nameDefault, nameOld) == TRUE);
       
  1517 }
       
  1518 
       
  1519 /**
       
  1520  * 
       
  1521  */
       
  1522 void TestWlanQtUtils::subTestNewWlanQtUtils()
       
  1523 {
       
  1524     delete wlanQtUtils_;
       
  1525     wlanQtUtils_ = new WlanQtUtils();
       
  1526 
       
  1527     delete mSignalScanReady;
       
  1528     mSignalScanReady = new QSignalSpy(wlanQtUtils_, SIGNAL(wlanScanReady(int)));
       
  1529     QVERIFY(mSignalScanReady->isValid() == true);
       
  1530 
       
  1531     delete mSignalScanApReady;
       
  1532     mSignalScanApReady = new QSignalSpy(wlanQtUtils_, SIGNAL(wlanScanApReady(int)));
       
  1533     QVERIFY(mSignalScanApReady->isValid() == true);
       
  1534 
       
  1535     delete mSignalScanDirectReady;
       
  1536     mSignalScanDirectReady = new QSignalSpy(wlanQtUtils_, SIGNAL(wlanScanDirectReady(int)));
       
  1537     QVERIFY(mSignalScanDirectReady->isValid() == true);
       
  1538 
       
  1539     delete signalWlanNetworkOpened_;
       
  1540     signalWlanNetworkOpened_ = new QSignalSpy(wlanQtUtils_, SIGNAL(wlanNetworkOpened(int)));
       
  1541     QVERIFY(signalWlanNetworkOpened_->isValid() == true);
       
  1542     
       
  1543     delete signalWlanNetworkClosed_;
       
  1544     signalWlanNetworkClosed_ = new QSignalSpy(wlanQtUtils_, SIGNAL(wlanNetworkClosed(int, int)));
       
  1545     QVERIFY(signalWlanNetworkClosed_->isValid() == true);
       
  1546     
       
  1547     delete signalIctResult_;
       
  1548     signalIctResult_ = new QSignalSpy(wlanQtUtils_, SIGNAL(ictResult(int, int)));
       
  1549     QVERIFY(signalIctResult_->isValid() == true);
       
  1550 }
       
  1551 
       
  1552 /**
       
  1553  * Create a new AP and fill it with default values. 
       
  1554  */
       
  1555 WlanQtUtilsAp *TestWlanQtUtils::subTestNewAp()
       
  1556 {
       
  1557     WlanQtUtilsAp *ap = new WlanQtUtilsAp;
       
  1558 
       
  1559     // Set default values
       
  1560     ap->setValue(WlanQtUtilsAp::ConfIdSsid, QString());
       
  1561     ap->setValue(WlanQtUtilsAp::ConfIdSignalStrength, 90);
       
  1562     ap->setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
       
  1563     ap->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeOpen);
       
  1564     ap->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false);
       
  1565     ap->setValue(WlanQtUtilsAp::ConfIdWpaPsk, QString());
       
  1566     ap->setValue(WlanQtUtilsAp::ConfIdWepKey1, QString());
       
  1567     ap->setValue(WlanQtUtilsAp::ConfIdWepKey2, QString());
       
  1568     ap->setValue(WlanQtUtilsAp::ConfIdWepKey3, QString());
       
  1569     ap->setValue(WlanQtUtilsAp::ConfIdWepKey4, QString());
       
  1570     ap->setValue(WlanQtUtilsAp::ConfIdWepDefaultIndex, CMManagerShim::WepKeyIndex1);
       
  1571     ap->setValue(WlanQtUtilsAp::ConfIdHidden, false);
       
  1572     ap->setValue(WlanQtUtilsAp::ConfIdWlanScanSSID, false);
       
  1573 
       
  1574     return ap;
       
  1575 }