wlanutilities/wlanqtutilities/tsrc/context/wlanqtutilstestcontext.cpp
author hgs
Thu, 24 Jun 2010 10:49:51 +0300
changeset 39 7b3e49e4608a
parent 31 e8f4211554fb
child 53 bdc64aa9b954
permissions -rw-r--r--
201025
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:
hgs
parents:
diff changeset
    15
* This is the source file for Connection Utilities test context.
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include <QObject>
hgs
parents:
diff changeset
    19
#include <QSharedPointer>
hgs
parents:
diff changeset
    20
#include <QTest>
hgs
parents:
diff changeset
    21
#include <rconnmon.h>
hgs
parents:
diff changeset
    22
#include <nifvar.h>
hgs
parents:
diff changeset
    23
#include <cmmanager_shim.h>
hgs
parents:
diff changeset
    24
hgs
parents:
diff changeset
    25
#include "wlanqtutils.h"
hgs
parents:
diff changeset
    26
#include "wlanqtutilstestcontext.h"
hgs
parents:
diff changeset
    27
#include "wlanqtutilsap.h"
hgs
parents:
diff changeset
    28
#include "wlanqtutilsconnection.h"
hgs
parents:
diff changeset
    29
hgs
parents:
diff changeset
    30
// ---------------------------------------------------------
hgs
parents:
diff changeset
    31
// class WlanQtUtilsCtxEsock
hgs
parents:
diff changeset
    32
// ---------------------------------------------------------
hgs
parents:
diff changeset
    33
hgs
parents:
diff changeset
    34
WlanQtUtilsCtxEsock::WlanQtUtilsCtxEsock() :
hgs
parents:
diff changeset
    35
    startRetValue_(KErrNone)
hgs
parents:
diff changeset
    36
{
hgs
parents:
diff changeset
    37
}
hgs
parents:
diff changeset
    38
hgs
parents:
diff changeset
    39
WlanQtUtilsCtxEsock::~WlanQtUtilsCtxEsock()
hgs
parents:
diff changeset
    40
{
hgs
parents:
diff changeset
    41
}
hgs
parents:
diff changeset
    42
hgs
parents:
diff changeset
    43
void WlanQtUtilsCtxEsock::initialize()
hgs
parents:
diff changeset
    44
{
hgs
parents:
diff changeset
    45
    startRetValue_ = KErrNone;
hgs
parents:
diff changeset
    46
}
hgs
parents:
diff changeset
    47
hgs
parents:
diff changeset
    48
// ---------------------------------------------------------
hgs
parents:
diff changeset
    49
// class WlanQtUtilsCtxActiveConn
hgs
parents:
diff changeset
    50
// ---------------------------------------------------------
hgs
parents:
diff changeset
    51
hgs
parents:
diff changeset
    52
WlanQtUtilsCtxActiveConn::WlanQtUtilsCtxActiveConn() :
hgs
parents:
diff changeset
    53
    WlanQtUtilsConnection(), connMonBearerType_(EBearerUnknown), connMonConnectionStatus_(
hgs
parents:
diff changeset
    54
        KConnectionUninitialised), connMonWlanConnectionMode_(-1), connMonWlanSecurityMode_(-1),
hgs
parents:
diff changeset
    55
        applicationUids_()
hgs
parents:
diff changeset
    56
{
hgs
parents:
diff changeset
    57
}
hgs
parents:
diff changeset
    58
hgs
parents:
diff changeset
    59
WlanQtUtilsCtxActiveConn::~WlanQtUtilsCtxActiveConn()
hgs
parents:
diff changeset
    60
{
hgs
parents:
diff changeset
    61
}
hgs
parents:
diff changeset
    62
hgs
parents:
diff changeset
    63
// ---------------------------------------------------------
hgs
parents:
diff changeset
    64
// class WlanQtUtilsCtxActiveConnections
hgs
parents:
diff changeset
    65
// ---------------------------------------------------------
hgs
parents:
diff changeset
    66
hgs
parents:
diff changeset
    67
WlanQtUtilsCtxActiveConnections::WlanQtUtilsCtxActiveConnections() :
hgs
parents:
diff changeset
    68
    activeConnList_()
hgs
parents:
diff changeset
    69
{
hgs
parents:
diff changeset
    70
}
hgs
parents:
diff changeset
    71
hgs
parents:
diff changeset
    72
WlanQtUtilsCtxActiveConnections::~WlanQtUtilsCtxActiveConnections()
hgs
parents:
diff changeset
    73
{
hgs
parents:
diff changeset
    74
    clearActiveConnList();
hgs
parents:
diff changeset
    75
}
hgs
parents:
diff changeset
    76
hgs
parents:
diff changeset
    77
void WlanQtUtilsCtxActiveConnections::initialize()
hgs
parents:
diff changeset
    78
{
hgs
parents:
diff changeset
    79
    clearActiveConnList();
hgs
parents:
diff changeset
    80
}
hgs
parents:
diff changeset
    81
hgs
parents:
diff changeset
    82
void WlanQtUtilsCtxActiveConnections::createDefaultActiveConnList(int numberOfActiveConns,
hgs
parents:
diff changeset
    83
    int firstIapId)
hgs
parents:
diff changeset
    84
{
hgs
parents:
diff changeset
    85
    clearActiveConnList();
hgs
parents:
diff changeset
    86
    for (int i = 0; i < numberOfActiveConns; i++) {
hgs
parents:
diff changeset
    87
        WlanQtUtilsCtxActiveConn *activeConn = new WlanQtUtilsCtxActiveConn();
hgs
parents:
diff changeset
    88
hgs
parents:
diff changeset
    89
        activeConn->setConnectionId((i + 1) * 100);
hgs
parents:
diff changeset
    90
        activeConn->setIapId(firstIapId + i);
hgs
parents:
diff changeset
    91
        activeConn->connMonConnectionStatus_ = KLinkLayerOpen;
hgs
parents:
diff changeset
    92
        activeConn->setConnectionStatus(WlanQtUtils::ConnStatusConnected);
hgs
parents:
diff changeset
    93
hgs
parents:
diff changeset
    94
        // WLAN connection.
hgs
parents:
diff changeset
    95
        activeConn->connMonBearerType_ = EBearerWLAN;
hgs
parents:
diff changeset
    96
        activeConn->connMonWlanSecurityMode_ = EConnMonSecurityOpen;
hgs
parents:
diff changeset
    97
        activeConn->connMonWlanConnectionMode_ = EConnMonInfraStructure;
hgs
parents:
diff changeset
    98
        activeConnList_.append(activeConn);
hgs
parents:
diff changeset
    99
    }
hgs
parents:
diff changeset
   100
}
hgs
parents:
diff changeset
   101
hgs
parents:
diff changeset
   102
void WlanQtUtilsCtxActiveConnections::clearActiveConnList()
hgs
parents:
diff changeset
   103
{
hgs
parents:
diff changeset
   104
    Q_FOREACH(WlanQtUtilsCtxActiveConn* activeConn, activeConnList_)
hgs
parents:
diff changeset
   105
        {
hgs
parents:
diff changeset
   106
            delete activeConn;
hgs
parents:
diff changeset
   107
        }
hgs
parents:
diff changeset
   108
    activeConnList_.clear();
hgs
parents:
diff changeset
   109
}
hgs
parents:
diff changeset
   110
hgs
parents:
diff changeset
   111
void WlanQtUtilsCtxActiveConnections::verifyActiveConnList(
hgs
parents:
diff changeset
   112
    QList<WlanQtUtilsConnection*> activeConnList)
hgs
parents:
diff changeset
   113
{
hgs
parents:
diff changeset
   114
    QCOMPARE(activeConnList.count(), activeConnList_.count());
hgs
parents:
diff changeset
   115
hgs
parents:
diff changeset
   116
    for (int i = 0; i < activeConnList_.count(); i++) {
hgs
parents:
diff changeset
   117
        QCOMPARE(activeConnList[i]->connectionId(), activeConnList_[i]->connectionId());
hgs
parents:
diff changeset
   118
        QCOMPARE(activeConnList[i]->iapId(), activeConnList_[i]->iapId());
hgs
parents:
diff changeset
   119
        QCOMPARE(activeConnList[i]->connectionStatus(), activeConnList_[i]->connectionStatus());
hgs
parents:
diff changeset
   120
    }
hgs
parents:
diff changeset
   121
}
hgs
parents:
diff changeset
   122
hgs
parents:
diff changeset
   123
WlanQtUtilsCtxActiveConn *WlanQtUtilsCtxActiveConnections::findActiveConn(uint connectionId) const
hgs
parents:
diff changeset
   124
{
hgs
parents:
diff changeset
   125
    WlanQtUtilsCtxActiveConn *activeConn = NULL;
hgs
parents:
diff changeset
   126
    for (int i = 0; i < activeConnList_.count(); i++) {
hgs
parents:
diff changeset
   127
        if (activeConnList_[i]->connectionId() == connectionId) {
hgs
parents:
diff changeset
   128
            activeConn = activeConnList_[i];
hgs
parents:
diff changeset
   129
        }
hgs
parents:
diff changeset
   130
    }
hgs
parents:
diff changeset
   131
    Q_ASSERT(activeConn != NULL);
hgs
parents:
diff changeset
   132
    return activeConn;
hgs
parents:
diff changeset
   133
}
hgs
parents:
diff changeset
   134
hgs
parents:
diff changeset
   135
// ---------------------------------------------------------
hgs
parents:
diff changeset
   136
// class WlanQtUtilsWlanScanResult
hgs
parents:
diff changeset
   137
// ---------------------------------------------------------
hgs
parents:
diff changeset
   138
39
hgs
parents: 31
diff changeset
   139
WlanQtUtilsWlanScan::WlanQtUtilsWlanScan() :
hgs
parents: 31
diff changeset
   140
    mScanResultIterator(0),
hgs
parents: 31
diff changeset
   141
    mWlanScanResultList(),
hgs
parents: 31
diff changeset
   142
    mCompleteWlanScan(true),
hgs
parents: 31
diff changeset
   143
    mScanRetValue(KErrNone)
31
hgs
parents:
diff changeset
   144
{
hgs
parents:
diff changeset
   145
}
hgs
parents:
diff changeset
   146
39
hgs
parents: 31
diff changeset
   147
WlanQtUtilsWlanScan::~WlanQtUtilsWlanScan()
31
hgs
parents:
diff changeset
   148
{
hgs
parents:
diff changeset
   149
    clearWlanScanResultList();
hgs
parents:
diff changeset
   150
}
hgs
parents:
diff changeset
   151
39
hgs
parents: 31
diff changeset
   152
void WlanQtUtilsWlanScan::initialize()
31
hgs
parents:
diff changeset
   153
{
hgs
parents:
diff changeset
   154
    clearWlanScanResultList();
39
hgs
parents: 31
diff changeset
   155
    mCompleteWlanScan = true;
hgs
parents: 31
diff changeset
   156
    mScanRetValue = KErrNone;
31
hgs
parents:
diff changeset
   157
}
hgs
parents:
diff changeset
   158
39
hgs
parents: 31
diff changeset
   159
void WlanQtUtilsWlanScan::createDefaultWlanScanResultList(int numberOfWlanAps)
31
hgs
parents:
diff changeset
   160
{
hgs
parents:
diff changeset
   161
    clearWlanScanResultList();
hgs
parents:
diff changeset
   162
    for (int i = 0; i < numberOfWlanAps; i++) {
39
hgs
parents: 31
diff changeset
   163
        QSharedPointer<WlanQtUtilsAp> ap(new WlanQtUtilsAp());
31
hgs
parents:
diff changeset
   164
        ap->setValue(WlanQtUtilsAp::ConfIdSsid, "TestWlanAp" + QString::number(i + 1));
39
hgs
parents: 31
diff changeset
   165
        ap->setValue(WlanQtUtilsAp::ConfIdBssid, QByteArray("123456"));
31
hgs
parents:
diff changeset
   166
        ap->setValue(WlanQtUtilsAp::ConfIdSignalStrength, 20);
hgs
parents:
diff changeset
   167
        ap->setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
hgs
parents:
diff changeset
   168
        ap->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   169
        ap->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false);
39
hgs
parents: 31
diff changeset
   170
        ap->setValue(WlanQtUtilsAp::ConfIdWpsSupported, false);
hgs
parents: 31
diff changeset
   171
        mWlanScanResultList.append(ap);
31
hgs
parents:
diff changeset
   172
    }
hgs
parents:
diff changeset
   173
}
hgs
parents:
diff changeset
   174
39
hgs
parents: 31
diff changeset
   175
void WlanQtUtilsWlanScan::clearWlanScanResultList()
31
hgs
parents:
diff changeset
   176
{
39
hgs
parents: 31
diff changeset
   177
    mWlanScanResultList.clear();
31
hgs
parents:
diff changeset
   178
}
hgs
parents:
diff changeset
   179
39
hgs
parents: 31
diff changeset
   180
void WlanQtUtilsWlanScan::verifyWlanScanResultList(
hgs
parents: 31
diff changeset
   181
    QList< QSharedPointer<WlanQtUtilsAp> > wlanApList)
31
hgs
parents:
diff changeset
   182
{
39
hgs
parents: 31
diff changeset
   183
    QCOMPARE(wlanApList.count(), mWlanScanResultList.count());
31
hgs
parents:
diff changeset
   184
39
hgs
parents: 31
diff changeset
   185
    for (int i = 0; i < mWlanScanResultList.count(); i++) {
hgs
parents: 31
diff changeset
   186
        QCOMPARE(
hgs
parents: 31
diff changeset
   187
            wlanApList[i]->value(WlanQtUtilsAp::ConfIdSsid),
hgs
parents: 31
diff changeset
   188
            mWlanScanResultList[i]->value(WlanQtUtilsAp::ConfIdSsid));
hgs
parents: 31
diff changeset
   189
        QCOMPARE(
hgs
parents: 31
diff changeset
   190
            wlanApList[i]->value(WlanQtUtilsAp::ConfIdBssid),
hgs
parents: 31
diff changeset
   191
            mWlanScanResultList[i]->value(WlanQtUtilsAp::ConfIdBssid));
hgs
parents: 31
diff changeset
   192
        QCOMPARE(
hgs
parents: 31
diff changeset
   193
            wlanApList[i]->value(WlanQtUtilsAp::ConfIdSignalStrength),
hgs
parents: 31
diff changeset
   194
            mWlanScanResultList[i]->value(WlanQtUtilsAp::ConfIdSignalStrength));
hgs
parents: 31
diff changeset
   195
        QCOMPARE(
hgs
parents: 31
diff changeset
   196
            wlanApList[i]->value(WlanQtUtilsAp::ConfIdConnectionMode),
hgs
parents: 31
diff changeset
   197
            mWlanScanResultList[i]->value(WlanQtUtilsAp::ConfIdConnectionMode));
hgs
parents: 31
diff changeset
   198
        QCOMPARE(
hgs
parents: 31
diff changeset
   199
            wlanApList[i]->value(WlanQtUtilsAp::ConfIdSecurityMode),
hgs
parents: 31
diff changeset
   200
            mWlanScanResultList[i]->value(WlanQtUtilsAp::ConfIdSecurityMode));
hgs
parents: 31
diff changeset
   201
        QCOMPARE(
hgs
parents: 31
diff changeset
   202
            wlanApList[i]->value(WlanQtUtilsAp::ConfIdWpaPskUse),
hgs
parents: 31
diff changeset
   203
            mWlanScanResultList[i]->value(WlanQtUtilsAp::ConfIdWpaPskUse));
hgs
parents: 31
diff changeset
   204
        QCOMPARE(
hgs
parents: 31
diff changeset
   205
            wlanApList[i]->value(WlanQtUtilsAp::ConfIdWpsSupported),
hgs
parents: 31
diff changeset
   206
            mWlanScanResultList[i]->value(WlanQtUtilsAp::ConfIdWpsSupported));
31
hgs
parents:
diff changeset
   207
    }
hgs
parents:
diff changeset
   208
}
hgs
parents:
diff changeset
   209
hgs
parents:
diff changeset
   210
// ---------------------------------------------------------
hgs
parents:
diff changeset
   211
// class WlanQtUtilsCtxConnMon
hgs
parents:
diff changeset
   212
// ---------------------------------------------------------
hgs
parents:
diff changeset
   213
hgs
parents:
diff changeset
   214
WlanQtUtilsCtxConnMon::WlanQtUtilsCtxConnMon() :
39
hgs
parents: 31
diff changeset
   215
    activeConnections_()
31
hgs
parents:
diff changeset
   216
{
hgs
parents:
diff changeset
   217
}
hgs
parents:
diff changeset
   218
hgs
parents:
diff changeset
   219
WlanQtUtilsCtxConnMon::~WlanQtUtilsCtxConnMon()
hgs
parents:
diff changeset
   220
{
hgs
parents:
diff changeset
   221
}
hgs
parents:
diff changeset
   222
hgs
parents:
diff changeset
   223
void WlanQtUtilsCtxConnMon::initialize()
hgs
parents:
diff changeset
   224
{
hgs
parents:
diff changeset
   225
    activeConnections_.initialize();
hgs
parents:
diff changeset
   226
}
hgs
parents:
diff changeset
   227
hgs
parents:
diff changeset
   228
// ---------------------------------------------------------
hgs
parents:
diff changeset
   229
// class WlanQtUtilsCtxIct
hgs
parents:
diff changeset
   230
// ---------------------------------------------------------
hgs
parents:
diff changeset
   231
hgs
parents:
diff changeset
   232
WlanQtUtilsCtxIct::WlanQtUtilsCtxIct()
hgs
parents:
diff changeset
   233
{
hgs
parents:
diff changeset
   234
}
hgs
parents:
diff changeset
   235
hgs
parents:
diff changeset
   236
WlanQtUtilsCtxIct::~WlanQtUtilsCtxIct()
hgs
parents:
diff changeset
   237
{
hgs
parents:
diff changeset
   238
}
hgs
parents:
diff changeset
   239
hgs
parents:
diff changeset
   240
void WlanQtUtilsCtxIct::initialize()
hgs
parents:
diff changeset
   241
{
hgs
parents:
diff changeset
   242
}
hgs
parents:
diff changeset
   243
hgs
parents:
diff changeset
   244
// ---------------------------------------------------------
hgs
parents:
diff changeset
   245
// class WlanQtUtilsTestContext
hgs
parents:
diff changeset
   246
// ---------------------------------------------------------
hgs
parents:
diff changeset
   247
hgs
parents:
diff changeset
   248
WlanQtUtilsTestContext::WlanQtUtilsTestContext() :
hgs
parents:
diff changeset
   249
    esock_(), connMon_(), ict_()
hgs
parents:
diff changeset
   250
{
hgs
parents:
diff changeset
   251
}
hgs
parents:
diff changeset
   252
hgs
parents:
diff changeset
   253
WlanQtUtilsTestContext::~WlanQtUtilsTestContext()
hgs
parents:
diff changeset
   254
{
hgs
parents:
diff changeset
   255
}
hgs
parents:
diff changeset
   256
hgs
parents:
diff changeset
   257
void WlanQtUtilsTestContext::initialize()
hgs
parents:
diff changeset
   258
{
hgs
parents:
diff changeset
   259
    esock_.initialize();
hgs
parents:
diff changeset
   260
    connMon_.initialize();
hgs
parents:
diff changeset
   261
    ict_.initialize();
39
hgs
parents: 31
diff changeset
   262
    mScan.initialize();
31
hgs
parents:
diff changeset
   263
}