wlanutilities/wlansniffer/wlansnifferapplication/tsrc/t_wlansniffer.cpp
author hgs
Mon, 23 Aug 2010 13:30:09 +0300
changeset 53 bdc64aa9b954
parent 39 7b3e49e4608a
child 58 301aeb18ae47
permissions -rw-r--r--
201033
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 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 testing Wlan Sniffer application.
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
// System includes
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
#include <QTest>
hgs
parents:
diff changeset
    21
#include <QSharedPointer>
hgs
parents:
diff changeset
    22
#include <HbApplication>
hgs
parents:
diff changeset
    23
#include <HbListWidget>
hgs
parents:
diff changeset
    24
#include <HbListWidgetItem>
hgs
parents:
diff changeset
    25
#include <cmmanagerdefines_shim.h>
hgs
parents:
diff changeset
    26
hgs
parents:
diff changeset
    27
// User includes
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
#include "wlanqtutilsiap.h"
hgs
parents:
diff changeset
    30
#include "wlanqtutilsap.h"
hgs
parents:
diff changeset
    31
hgs
parents:
diff changeset
    32
#include "wlansnifferlistwidget.h"
hgs
parents:
diff changeset
    33
#include "t_wlansniffer.h"
hgs
parents:
diff changeset
    34
hgs
parents:
diff changeset
    35
// External function prototypes
hgs
parents:
diff changeset
    36
hgs
parents:
diff changeset
    37
// Local constants
hgs
parents:
diff changeset
    38
hgs
parents:
diff changeset
    39
// ======== LOCAL FUNCTIONS ========
hgs
parents:
diff changeset
    40
hgs
parents:
diff changeset
    41
/*!
hgs
parents:
diff changeset
    42
    Test main function. Runs all test cases.
hgs
parents:
diff changeset
    43
 */
hgs
parents:
diff changeset
    44
hgs
parents:
diff changeset
    45
int main(int argc, char *argv[])
hgs
parents:
diff changeset
    46
{
hgs
parents:
diff changeset
    47
    HbApplication app(argc, argv);
hgs
parents:
diff changeset
    48
    
hgs
parents:
diff changeset
    49
    char *pass[3];  
hgs
parents:
diff changeset
    50
    pass[0] = argv[0];
hgs
parents:
diff changeset
    51
    pass[1] = "-o"; 
hgs
parents:
diff changeset
    52
    pass[2] = "c:\\data\\TestWlanSniffer.txt";
hgs
parents:
diff changeset
    53
 
hgs
parents:
diff changeset
    54
    TestWlanSniffer tc;
hgs
parents:
diff changeset
    55
    int res = QTest::qExec(&tc, 3, pass);
hgs
parents:
diff changeset
    56
 
hgs
parents:
diff changeset
    57
    return res;
hgs
parents:
diff changeset
    58
}
hgs
parents:
diff changeset
    59
hgs
parents:
diff changeset
    60
// ======== MEMBER FUNCTIONS ========
hgs
parents:
diff changeset
    61
hgs
parents:
diff changeset
    62
/*!
hgs
parents:
diff changeset
    63
    This function will be called before the first test function is executed.
hgs
parents:
diff changeset
    64
*/
hgs
parents:
diff changeset
    65
hgs
parents:
diff changeset
    66
void TestWlanSniffer::initTestCase()
hgs
parents:
diff changeset
    67
{
hgs
parents:
diff changeset
    68
    mWidget = NULL;
hgs
parents:
diff changeset
    69
}
hgs
parents:
diff changeset
    70
hgs
parents:
diff changeset
    71
/*!
hgs
parents:
diff changeset
    72
    This function will be called after the last test function was executed.
hgs
parents:
diff changeset
    73
 */
hgs
parents:
diff changeset
    74
hgs
parents:
diff changeset
    75
void TestWlanSniffer::cleanupTestCase()
hgs
parents:
diff changeset
    76
{
hgs
parents:
diff changeset
    77
}
hgs
parents:
diff changeset
    78
hgs
parents:
diff changeset
    79
/*!
hgs
parents:
diff changeset
    80
    This function will be called before each test function is executed.
hgs
parents:
diff changeset
    81
 */
hgs
parents:
diff changeset
    82
hgs
parents:
diff changeset
    83
void TestWlanSniffer::init()
hgs
parents:
diff changeset
    84
{
hgs
parents:
diff changeset
    85
    mListWidget = new HbListWidget();
hgs
parents:
diff changeset
    86
    mWidget = new WlanSnifferListWidget(mListWidget);
hgs
parents:
diff changeset
    87
    
hgs
parents:
diff changeset
    88
    mIaps.clear();
hgs
parents:
diff changeset
    89
    mAps.clear();
hgs
parents:
diff changeset
    90
}
hgs
parents:
diff changeset
    91
hgs
parents:
diff changeset
    92
/*!
hgs
parents:
diff changeset
    93
    This function will be called after each test function is executed.
hgs
parents:
diff changeset
    94
 */
hgs
parents:
diff changeset
    95
hgs
parents:
diff changeset
    96
void TestWlanSniffer::cleanup()
hgs
parents:
diff changeset
    97
{
hgs
parents:
diff changeset
    98
    delete mWidget;
hgs
parents:
diff changeset
    99
    mWidget = NULL;
hgs
parents:
diff changeset
   100
hgs
parents:
diff changeset
   101
    mListWidget->clear();
hgs
parents:
diff changeset
   102
    delete mListWidget;
hgs
parents:
diff changeset
   103
    mListWidget = NULL;
hgs
parents:
diff changeset
   104
}
hgs
parents:
diff changeset
   105
hgs
parents:
diff changeset
   106
/*!
hgs
parents:
diff changeset
   107
    This function tests Wlan list widget content updating.
hgs
parents:
diff changeset
   108
 */
hgs
parents:
diff changeset
   109
hgs
parents:
diff changeset
   110
void TestWlanSniffer::testUpdateContentIapAdded()
hgs
parents:
diff changeset
   111
{
hgs
parents:
diff changeset
   112
    appendWlanAp("SSID 1", 20, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   113
    appendWlanAp("SSID 2", 90, 0, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   114
hgs
parents:
diff changeset
   115
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   116
    
hgs
parents:
diff changeset
   117
    QCOMPARE(mListWidget->count(), 2);
hgs
parents:
diff changeset
   118
    verifyAp(0, QString("SSID 1"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   119
    verifyAp(1, QString("SSID 2"), CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   120
hgs
parents:
diff changeset
   121
    appendWlanIap(1, 0, "SSID 3", "SSID 3", 20, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   122
hgs
parents:
diff changeset
   123
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   124
    
hgs
parents:
diff changeset
   125
    QCOMPARE(mListWidget->count(), 3);
hgs
parents:
diff changeset
   126
    verifyIap(0, 1);
hgs
parents:
diff changeset
   127
    verifyAp(1, QString("SSID 1"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   128
    verifyAp(2, QString("SSID 2"), CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   129
}
hgs
parents:
diff changeset
   130
hgs
parents:
diff changeset
   131
/*!
hgs
parents:
diff changeset
   132
    This function tests Wlan list widget content updating.
hgs
parents:
diff changeset
   133
 */
hgs
parents:
diff changeset
   134
hgs
parents:
diff changeset
   135
void TestWlanSniffer::testUpdateContentApAdded()
hgs
parents:
diff changeset
   136
{
hgs
parents:
diff changeset
   137
    appendWlanAp("SSID 1", 20, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   138
hgs
parents:
diff changeset
   139
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   140
    
hgs
parents:
diff changeset
   141
    QCOMPARE(mListWidget->count(), 1);
hgs
parents:
diff changeset
   142
    verifyAp(0, QString("SSID 1"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   143
hgs
parents:
diff changeset
   144
    appendWlanAp("SSID 2", 90, 0, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   145
hgs
parents:
diff changeset
   146
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   147
    
hgs
parents:
diff changeset
   148
    QCOMPARE(mListWidget->count(), 2);
hgs
parents:
diff changeset
   149
    verifyAp(0, QString("SSID 1"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   150
    verifyAp(1, QString("SSID 2"), CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   151
}
hgs
parents:
diff changeset
   152
hgs
parents:
diff changeset
   153
/*!
hgs
parents:
diff changeset
   154
    This function tests Wlan list widget content updating.
hgs
parents:
diff changeset
   155
 */
hgs
parents:
diff changeset
   156
hgs
parents:
diff changeset
   157
void TestWlanSniffer::testUpdateContentIapRemoved()
hgs
parents:
diff changeset
   158
{
hgs
parents:
diff changeset
   159
    appendWlanIap(1, 0, "SSID 1", "SSID 1", 20, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   160
    appendWlanIap(2, 0, "SSID 2", "SSID 2", 90, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   161
    appendWlanAp("SSID 3", 90, 0, CMManagerShim::WlanSecModeWep);
hgs
parents:
diff changeset
   162
hgs
parents:
diff changeset
   163
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   164
    
hgs
parents:
diff changeset
   165
    QCOMPARE(mListWidget->count(), 3);
hgs
parents:
diff changeset
   166
    verifyIap(0, 1);
hgs
parents:
diff changeset
   167
    verifyIap(1, 2);
hgs
parents:
diff changeset
   168
    verifyAp(2, QString("SSID 3"), CMManagerShim::WlanSecModeWep);
hgs
parents:
diff changeset
   169
hgs
parents:
diff changeset
   170
    mIaps.takeAt(0);
hgs
parents:
diff changeset
   171
hgs
parents:
diff changeset
   172
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   173
    
hgs
parents:
diff changeset
   174
    QCOMPARE(mListWidget->count(), 2);
hgs
parents:
diff changeset
   175
    verifyIap(0, 2);
hgs
parents:
diff changeset
   176
    verifyAp(1, QString("SSID 3"), CMManagerShim::WlanSecModeWep);
hgs
parents:
diff changeset
   177
}
hgs
parents:
diff changeset
   178
hgs
parents:
diff changeset
   179
/*!
hgs
parents:
diff changeset
   180
    This function tests Wlan list widget content updating.
hgs
parents:
diff changeset
   181
 */
hgs
parents:
diff changeset
   182
hgs
parents:
diff changeset
   183
void TestWlanSniffer::testUpdateContentApRemoved()
hgs
parents:
diff changeset
   184
{
hgs
parents:
diff changeset
   185
    appendWlanAp("SSID 1", 20, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   186
hgs
parents:
diff changeset
   187
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   188
    
hgs
parents:
diff changeset
   189
    QCOMPARE(mListWidget->count(), 1);
hgs
parents:
diff changeset
   190
    verifyAp(0, QString("SSID 1"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   191
hgs
parents:
diff changeset
   192
    mAps.takeAt(0);
hgs
parents:
diff changeset
   193
hgs
parents:
diff changeset
   194
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   195
    
hgs
parents:
diff changeset
   196
    QCOMPARE(mListWidget->count(), 0);
hgs
parents:
diff changeset
   197
}
hgs
parents:
diff changeset
   198
hgs
parents:
diff changeset
   199
/*!
hgs
parents:
diff changeset
   200
    This function tests Wlan list widget content updating.
hgs
parents:
diff changeset
   201
 */
hgs
parents:
diff changeset
   202
hgs
parents:
diff changeset
   203
void TestWlanSniffer::testUpdateContentIapConnected()
hgs
parents:
diff changeset
   204
{
hgs
parents:
diff changeset
   205
    appendWlanIap(1, 0, "SSID 1", "SSID 1", 95, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   206
    appendWlanIap(2, 0, "SSID 2", "SSID 2", 15, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   207
    appendWlanAp("SSID 3", 20, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   208
hgs
parents:
diff changeset
   209
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   210
    
hgs
parents:
diff changeset
   211
    QCOMPARE(mListWidget->count(), 3);
hgs
parents:
diff changeset
   212
    verifyIap(0, 1);
hgs
parents:
diff changeset
   213
    verifyIap(1, 2);
hgs
parents:
diff changeset
   214
    verifyAp(2, QString("SSID 3"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   215
hgs
parents:
diff changeset
   216
    // IAP order changed because one is connected
hgs
parents:
diff changeset
   217
    mIaps.clear();
hgs
parents:
diff changeset
   218
    appendWlanIap(2, 0, "SSID 2", "SSID 2", 20, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   219
    appendWlanIap(1, 0, "SSID 1", "SSID 1", 20, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   220
hgs
parents:
diff changeset
   221
    mWidget->updateContent(mIaps, mAps, 2);
hgs
parents:
diff changeset
   222
    
hgs
parents:
diff changeset
   223
    QCOMPARE(mListWidget->count(), 3);
hgs
parents:
diff changeset
   224
    verifyIap(0, 2);
hgs
parents:
diff changeset
   225
    verifyIap(1, 1);
hgs
parents:
diff changeset
   226
    verifyAp(2, QString("SSID 3"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   227
}
hgs
parents:
diff changeset
   228
hgs
parents:
diff changeset
   229
/*!
hgs
parents:
diff changeset
   230
    This function tests Wlan list widget content updating.
hgs
parents:
diff changeset
   231
 */
hgs
parents:
diff changeset
   232
hgs
parents:
diff changeset
   233
void TestWlanSniffer::testUpdateContentIapDisconnected()
hgs
parents:
diff changeset
   234
{
hgs
parents:
diff changeset
   235
    appendWlanIap(2, 0, "SSID 2", "SSID 2", 20, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   236
    appendWlanIap(1, 0, "SSID 1", "SSID 1", 20, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   237
    appendWlanAp("SSID 3", 20, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   238
hgs
parents:
diff changeset
   239
    mWidget->updateContent(mIaps, mAps, 2);
hgs
parents:
diff changeset
   240
    
hgs
parents:
diff changeset
   241
    QCOMPARE(mListWidget->count(), 3);
hgs
parents:
diff changeset
   242
    verifyIap(0, 2);
hgs
parents:
diff changeset
   243
    verifyIap(1, 1);
hgs
parents:
diff changeset
   244
    verifyAp(2, QString("SSID 3"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   245
hgs
parents:
diff changeset
   246
    // IAP order changed because not connected anymore
hgs
parents:
diff changeset
   247
    mIaps.clear();
hgs
parents:
diff changeset
   248
    appendWlanIap(1, 0, "SSID 1", "SSID 1", 20, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   249
    appendWlanIap(2, 0, "SSID 2", "SSID 2", 60, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   250
hgs
parents:
diff changeset
   251
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   252
    
hgs
parents:
diff changeset
   253
    QCOMPARE(mListWidget->count(), 3);
hgs
parents:
diff changeset
   254
    verifyIap(0, 1);
hgs
parents:
diff changeset
   255
    verifyIap(1, 2);
hgs
parents:
diff changeset
   256
    verifyAp(2, QString("SSID 3"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   257
}
hgs
parents:
diff changeset
   258
hgs
parents:
diff changeset
   259
/*!
hgs
parents:
diff changeset
   260
    This function tests Wlan list widget content updating.
hgs
parents:
diff changeset
   261
 */
hgs
parents:
diff changeset
   262
hgs
parents:
diff changeset
   263
void TestWlanSniffer::testUpdateContentRobustness1()
hgs
parents:
diff changeset
   264
{
hgs
parents:
diff changeset
   265
    appendWlanIap(1, 0, "SSID 1", "SSID 1", 15, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   266
    appendWlanIap(2, 0, "SSID 2", "SSID 2", 95, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   267
    appendWlanAp("SSID 3", 20, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   268
    appendWlanAp("SSID 4", 30, 0, CMManagerShim::WlanSecModeWep);
hgs
parents:
diff changeset
   269
    appendWlanAp("SSID 5", 40, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   270
hgs
parents:
diff changeset
   271
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   272
    
hgs
parents:
diff changeset
   273
    QCOMPARE(mListWidget->count(), 5);
hgs
parents:
diff changeset
   274
    verifyIap(0, 1);
hgs
parents:
diff changeset
   275
    verifyIap(1, 2);
hgs
parents:
diff changeset
   276
    verifyAp(2, QString("SSID 3"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   277
    verifyAp(3, QString("SSID 4"), CMManagerShim::WlanSecModeWep);
hgs
parents:
diff changeset
   278
    verifyAp(4, QString("SSID 5"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   279
hgs
parents:
diff changeset
   280
    mIaps.clear();
hgs
parents:
diff changeset
   281
    appendWlanIap(3, 0, "SSID 3", "SSID 3", 10, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   282
    appendWlanIap(1, 0, "SSID 1", "SSID 1", 20, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   283
    appendWlanIap(2, 0, "SSID 2", "SSID 2", 30, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   284
    mAps.clear();
hgs
parents:
diff changeset
   285
    appendWlanAp("SSID 4", 30, 0, CMManagerShim::WlanSecModeWep);
hgs
parents:
diff changeset
   286
    appendWlanAp("SSID 5", 40, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   287
    appendWlanAp("SSID 6", 30, 0, CMManagerShim::WlanSecModeWep);
hgs
parents:
diff changeset
   288
    appendWlanAp("SSID 7", 40, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   289
hgs
parents:
diff changeset
   290
    mWidget->updateContent(mIaps, mAps, 3);
hgs
parents:
diff changeset
   291
    
hgs
parents:
diff changeset
   292
    QCOMPARE(mListWidget->count(), 7);
hgs
parents:
diff changeset
   293
    verifyIap(0, 3);
hgs
parents:
diff changeset
   294
    verifyIap(1, 1);
hgs
parents:
diff changeset
   295
    verifyIap(2, 2);
hgs
parents:
diff changeset
   296
    verifyAp(3, QString("SSID 4"), CMManagerShim::WlanSecModeWep);
hgs
parents:
diff changeset
   297
    verifyAp(4, QString("SSID 5"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   298
    verifyAp(5, QString("SSID 6"), CMManagerShim::WlanSecModeWep);
hgs
parents:
diff changeset
   299
    verifyAp(6, QString("SSID 7"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   300
hgs
parents:
diff changeset
   301
    mIaps.clear();
hgs
parents:
diff changeset
   302
    appendWlanIap(4, 0, "SSID X", "SSID X", 10, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   303
    appendWlanIap(2, 0, "SSID 2", "SSID 2", 20, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   304
    appendWlanIap(3, 0, "SSID 3", "SSID 3", 10, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   305
    appendWlanIap(5, 0, "SSID 3", "SSID 3", 50, CMManagerShim::WlanSecModeWapi);
hgs
parents:
diff changeset
   306
    mAps.clear();
hgs
parents:
diff changeset
   307
    appendWlanAp("SSID 4", 30, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   308
    appendWlanAp("SSID 4a", 40, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   309
    appendWlanAp("SSID 7", 76, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   310
    appendWlanAp("SSID 7", 90, 0, CMManagerShim::WlanSecModeWep);
hgs
parents:
diff changeset
   311
    appendWlanAp("SSID 8", 30, 0, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   312
    appendWlanAp("SSID 9", 30, 0, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   313
hgs
parents:
diff changeset
   314
    mWidget->updateContent(mIaps, mAps, 4);
hgs
parents:
diff changeset
   315
hgs
parents:
diff changeset
   316
    QCOMPARE(mListWidget->count(), 10);
hgs
parents:
diff changeset
   317
    verifyIap(0, 4);
hgs
parents:
diff changeset
   318
    verifyIap(1, 2);
hgs
parents:
diff changeset
   319
    verifyIap(2, 3);
hgs
parents:
diff changeset
   320
    verifyIap(3, 5);
hgs
parents:
diff changeset
   321
    verifyAp(4, QString("SSID 4"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   322
    verifyAp(5, QString("SSID 4a"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   323
    verifyAp(6, QString("SSID 7"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   324
    verifyAp(7, QString("SSID 7"), CMManagerShim::WlanSecModeWep);
hgs
parents:
diff changeset
   325
    verifyAp(8, QString("SSID 8"), CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   326
    verifyAp(9, QString("SSID 9"), CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   327
hgs
parents:
diff changeset
   328
    mIaps.clear();
hgs
parents:
diff changeset
   329
    appendWlanIap(3, 0, "SSID 3", "SSID 3", 50, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   330
    mAps.clear();
hgs
parents:
diff changeset
   331
hgs
parents:
diff changeset
   332
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   333
hgs
parents:
diff changeset
   334
    QCOMPARE(mListWidget->count(), 1);
hgs
parents:
diff changeset
   335
    verifyIap(0, 3);
hgs
parents:
diff changeset
   336
hgs
parents:
diff changeset
   337
    mIaps.clear();
hgs
parents:
diff changeset
   338
    mAps.clear();
hgs
parents:
diff changeset
   339
hgs
parents:
diff changeset
   340
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   341
hgs
parents:
diff changeset
   342
    QCOMPARE(mListWidget->count(), 0);
hgs
parents:
diff changeset
   343
}
hgs
parents:
diff changeset
   344
hgs
parents:
diff changeset
   345
/*!
hgs
parents:
diff changeset
   346
    This function tests Wlan list widget content updating.
hgs
parents:
diff changeset
   347
 */
hgs
parents:
diff changeset
   348
hgs
parents:
diff changeset
   349
void TestWlanSniffer::testUpdateContentRobustness2()
hgs
parents:
diff changeset
   350
{
hgs
parents:
diff changeset
   351
    QSharedPointer<WlanQtUtilsIap> iap2(new WlanQtUtilsIap());
hgs
parents:
diff changeset
   352
    iap2->setValue(WlanQtUtilsIap::ConfIdIapId, 2);
hgs
parents:
diff changeset
   353
    iap2->setValue(WlanQtUtilsIap::ConfIdNetworkId, 0);
hgs
parents:
diff changeset
   354
    iap2->setValue(WlanQtUtilsIap::ConfIdName, "SSID 2");
hgs
parents:
diff changeset
   355
    iap2->setValue(WlanQtUtilsAp::ConfIdSsid, "SSID 2");
hgs
parents:
diff changeset
   356
    iap2->setValue(WlanQtUtilsAp::ConfIdSignalStrength, 10);
39
hgs
parents: 31
diff changeset
   357
    iap2->setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
31
hgs
parents:
diff changeset
   358
    iap2->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   359
    QSharedPointer<WlanQtUtilsIap> iap4(new WlanQtUtilsIap());
hgs
parents:
diff changeset
   360
    iap4->setValue(WlanQtUtilsIap::ConfIdIapId, 4);
hgs
parents:
diff changeset
   361
    iap4->setValue(WlanQtUtilsIap::ConfIdNetworkId, 0);
hgs
parents:
diff changeset
   362
    iap4->setValue(WlanQtUtilsIap::ConfIdName, "SSID 4");
hgs
parents:
diff changeset
   363
    iap4->setValue(WlanQtUtilsAp::ConfIdSsid, "SSID 4");
hgs
parents:
diff changeset
   364
    iap4->setValue(WlanQtUtilsAp::ConfIdSignalStrength, 20);
39
hgs
parents: 31
diff changeset
   365
    iap4->setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
31
hgs
parents:
diff changeset
   366
    iap4->setValue(WlanQtUtilsAp::ConfIdSecurityMode, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   367
    
hgs
parents:
diff changeset
   368
    appendWlanAp("SSID 1", 20, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   369
    appendWlanAp("SSID 3", 20, 0, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   370
    appendWlanAp("SSID 5", 20, 0, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   371
    appendWlanAp("SSID 6", 20, 0, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   372
hgs
parents:
diff changeset
   373
    mIaps.append(iap2);
hgs
parents:
diff changeset
   374
    mIaps.append(iap4);
hgs
parents:
diff changeset
   375
hgs
parents:
diff changeset
   376
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   377
    
hgs
parents:
diff changeset
   378
    QCOMPARE(mListWidget->count(), 6);
hgs
parents:
diff changeset
   379
    verifyIap(0, 2);
hgs
parents:
diff changeset
   380
    verifyIap(1, 4);
hgs
parents:
diff changeset
   381
    verifyAp(2, QString("SSID 1"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   382
    verifyAp(3, QString("SSID 3"), CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   383
    verifyAp(4, QString("SSID 5"), CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   384
    verifyAp(5, QString("SSID 6"), CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   385
hgs
parents:
diff changeset
   386
    mIaps.clear();
hgs
parents:
diff changeset
   387
    mAps.clear();
hgs
parents:
diff changeset
   388
    mIaps.append(iap2);
hgs
parents:
diff changeset
   389
    appendWlanAp("SSID 1", 20, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   390
hgs
parents:
diff changeset
   391
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   392
    
hgs
parents:
diff changeset
   393
    QCOMPARE(mListWidget->count(), 2);
hgs
parents:
diff changeset
   394
    verifyIap(0, 2);
hgs
parents:
diff changeset
   395
    verifyAp(1, QString("SSID 1"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   396
hgs
parents:
diff changeset
   397
    mIaps.clear();
hgs
parents:
diff changeset
   398
    mAps.clear();
hgs
parents:
diff changeset
   399
    mIaps.append(iap2);
hgs
parents:
diff changeset
   400
    mIaps.append(iap4);
hgs
parents:
diff changeset
   401
    appendWlanAp("SSID 1", 20, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   402
    appendWlanAp("SSID 3", 20, 0, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   403
    appendWlanAp("SSID 5", 20, 0, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   404
    appendWlanAp("SSID 6", 20, 0, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   405
hgs
parents:
diff changeset
   406
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   407
    
hgs
parents:
diff changeset
   408
    QCOMPARE(mListWidget->count(), 6);
hgs
parents:
diff changeset
   409
    verifyIap(0, 2);
hgs
parents:
diff changeset
   410
    verifyIap(1, 4);
hgs
parents:
diff changeset
   411
    verifyAp(2, QString("SSID 1"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   412
    verifyAp(3, QString("SSID 3"), CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   413
    verifyAp(4, QString("SSID 5"), CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   414
    verifyAp(5, QString("SSID 6"), CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   415
}
hgs
parents:
diff changeset
   416
hgs
parents:
diff changeset
   417
/*!
hgs
parents:
diff changeset
   418
    This function tests list sorting. The list content comes in "random" order,
hgs
parents:
diff changeset
   419
    and the list widget should sort the list alphabetically. 
hgs
parents:
diff changeset
   420
 */
hgs
parents:
diff changeset
   421
hgs
parents:
diff changeset
   422
void TestWlanSniffer::testUpdateContentSort()
hgs
parents:
diff changeset
   423
{
hgs
parents:
diff changeset
   424
    appendWlanIap(1, 0, "Dada", "dada", 20, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   425
    appendWlanIap(2, 0, "salakka", "salakka", 30, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   426
    appendWlanIap(3, 0, "lahna", "lahna", 40, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   427
    appendWlanIap(4, 0, "Labiili", "labiili", 50, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   428
    appendWlanIap(5, 0, "ABCD", "ABCD", 60, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   429
    appendWlanIap(6, 0, "connected", "connected", 60, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   430
    appendWlanIap(7, 0, "IAP 1", "IAP 1", 10, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   431
    appendWlanIap(8, 0, "IAP 10", "IAP 10", 10, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   432
    appendWlanIap(9, 0, "IAP 2", "IAP 2", 10, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   433
    appendWlanIap(10, 0, "IAP 11", "IAP 11", 10, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   434
hgs
parents:
diff changeset
   435
    appendWlanAp("jokuap", 20, 0, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   436
    appendWlanAp("Jippii", 30, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   437
    appendWlanAp("jalava", 40, 0, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   438
    appendWlanAp("abba", 50, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   439
    appendWlanAp("hippokampus", 60, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   440
hgs
parents:
diff changeset
   441
    mWidget->updateContent(mIaps, mAps, 6);
hgs
parents:
diff changeset
   442
    
hgs
parents:
diff changeset
   443
    QCOMPARE(mListWidget->count(), 15);
hgs
parents:
diff changeset
   444
    verifyIap(0, 6);
hgs
parents:
diff changeset
   445
    verifyIap(1, 5);
hgs
parents:
diff changeset
   446
    verifyIap(2, 1);
hgs
parents:
diff changeset
   447
    verifyIap(3, 7);
hgs
parents:
diff changeset
   448
    verifyIap(4, 8);
hgs
parents:
diff changeset
   449
    verifyIap(5, 10);
hgs
parents:
diff changeset
   450
    verifyIap(6, 9);
hgs
parents:
diff changeset
   451
    verifyIap(7, 4);
hgs
parents:
diff changeset
   452
    verifyIap(8, 3);
hgs
parents:
diff changeset
   453
    verifyIap(9, 2);
hgs
parents:
diff changeset
   454
    verifyAp(10, QString("abba"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   455
    verifyAp(11, QString("hippokampus"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   456
    verifyAp(12, QString("jalava"), CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   457
    verifyAp(13, QString("Jippii"), CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   458
    verifyAp(14, QString("jokuap"), CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   459
}
hgs
parents:
diff changeset
   460
hgs
parents:
diff changeset
   461
/*!
hgs
parents:
diff changeset
   462
    This function tests list scrolling. There's no way to verify in this test
hgs
parents:
diff changeset
   463
    that the scrolling actually works, but let's execute the code at least. 
hgs
parents:
diff changeset
   464
 */
hgs
parents:
diff changeset
   465
hgs
parents:
diff changeset
   466
void TestWlanSniffer::testScrollTo()
hgs
parents:
diff changeset
   467
{
hgs
parents:
diff changeset
   468
    appendWlanIap(1, 0, "SSID 1", "SSID 1", 15, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   469
    appendWlanIap(2, 0, "SSID 2", "SSID 2", 95, CMManagerShim::WlanSecModeWpa);
hgs
parents:
diff changeset
   470
    appendWlanAp("SSID 3", 20, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   471
    appendWlanAp("SSID 4", 30, 0, CMManagerShim::WlanSecModeWep);
hgs
parents:
diff changeset
   472
    appendWlanAp("SSID 5", 40, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   473
    appendWlanAp("SSID 6", 20, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   474
    appendWlanAp("SSID 7", 30, 0, CMManagerShim::WlanSecModeWep);
hgs
parents:
diff changeset
   475
    appendWlanAp("SSID 8", 40, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   476
    appendWlanAp("SSID 9", 20, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   477
    appendWlanAp("SSID 10", 30, 0, CMManagerShim::WlanSecModeWep);
hgs
parents:
diff changeset
   478
    appendWlanAp("SSID 11", 40, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   479
    appendWlanAp("SSID 12", 20, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   480
    appendWlanAp("SSID 13", 30, 0, CMManagerShim::WlanSecModeWep);
hgs
parents:
diff changeset
   481
    appendWlanAp("SSID 14", 40, 0, CMManagerShim::WlanSecModeOpen);
hgs
parents:
diff changeset
   482
hgs
parents:
diff changeset
   483
    mWidget->updateContent(mIaps, mAps, 0);
hgs
parents:
diff changeset
   484
    
hgs
parents:
diff changeset
   485
    QCOMPARE(mListWidget->count(), 14);
hgs
parents:
diff changeset
   486
hgs
parents:
diff changeset
   487
    // Scroll to last row
hgs
parents:
diff changeset
   488
    mWidget->scrollTo(13);
hgs
parents:
diff changeset
   489
    // Scroll to non-existing row -> ignored
hgs
parents:
diff changeset
   490
    mWidget->scrollTo(20);
hgs
parents:
diff changeset
   491
    // Scroll to first row
hgs
parents:
diff changeset
   492
    mWidget->scrollTo(0);
hgs
parents:
diff changeset
   493
hgs
parents:
diff changeset
   494
    QCOMPARE(mListWidget->count(), 14);
hgs
parents:
diff changeset
   495
}
hgs
parents:
diff changeset
   496
hgs
parents:
diff changeset
   497
/*!
hgs
parents:
diff changeset
   498
    This function verifies that the item on "row" is an IAP matching the given parameters.
hgs
parents:
diff changeset
   499
 */
hgs
parents:
diff changeset
   500
hgs
parents:
diff changeset
   501
void TestWlanSniffer::verifyIap(int row, int iapId)
hgs
parents:
diff changeset
   502
{
hgs
parents:
diff changeset
   503
    QVERIFY(mListWidget->item(row)->data().canConvert<int>());
hgs
parents:
diff changeset
   504
    int id = mListWidget->item(row)->data().value<int>();
hgs
parents:
diff changeset
   505
    QCOMPARE(id, iapId);
hgs
parents:
diff changeset
   506
}
hgs
parents:
diff changeset
   507
hgs
parents:
diff changeset
   508
/*!
hgs
parents:
diff changeset
   509
    This function verifies that the item on "row" is an AP matching the given parameters.
hgs
parents:
diff changeset
   510
 */
hgs
parents:
diff changeset
   511
hgs
parents:
diff changeset
   512
void TestWlanSniffer::verifyAp(int row, QString ssid, int securityMode)
hgs
parents:
diff changeset
   513
{
hgs
parents:
diff changeset
   514
    QVERIFY(mListWidget->item(row)->data().canConvert<WlanQtUtilsAp>());
hgs
parents:
diff changeset
   515
    WlanQtUtilsAp ap = mListWidget->item(row)->data().value<WlanQtUtilsAp>();
hgs
parents:
diff changeset
   516
    QCOMPARE(ap.value(WlanQtUtilsAp::ConfIdSsid).toString(), ssid);
hgs
parents:
diff changeset
   517
    QCOMPARE(ap.value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(), securityMode);
hgs
parents:
diff changeset
   518
}
hgs
parents:
diff changeset
   519
hgs
parents:
diff changeset
   520
/*!
hgs
parents:
diff changeset
   521
    Sub test case for appending an AP to AP list.
hgs
parents:
diff changeset
   522
*/
hgs
parents:
diff changeset
   523
hgs
parents:
diff changeset
   524
void TestWlanSniffer::appendWlanAp(
hgs
parents:
diff changeset
   525
    QString ssId, 
hgs
parents:
diff changeset
   526
    int signalStrength, 
hgs
parents:
diff changeset
   527
    int networkMode, 
hgs
parents:
diff changeset
   528
    int securityMode)
hgs
parents:
diff changeset
   529
{
hgs
parents:
diff changeset
   530
    QSharedPointer<WlanQtUtilsAp> ap(new WlanQtUtilsAp());
hgs
parents:
diff changeset
   531
    ap->setValue(WlanQtUtilsAp::ConfIdSsid, ssId);
hgs
parents:
diff changeset
   532
    ap->setValue(WlanQtUtilsAp::ConfIdSignalStrength, signalStrength);
hgs
parents:
diff changeset
   533
    ap->setValue(WlanQtUtilsAp::ConfIdConnectionMode, networkMode);
hgs
parents:
diff changeset
   534
    ap->setValue(WlanQtUtilsAp::ConfIdSecurityMode, securityMode);
hgs
parents:
diff changeset
   535
    ap->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false);
39
hgs
parents: 31
diff changeset
   536
    ap->setValue(WlanQtUtilsAp::ConfIdWpsSupported, false);
31
hgs
parents:
diff changeset
   537
    mAps.append(ap);
hgs
parents:
diff changeset
   538
}
hgs
parents:
diff changeset
   539
hgs
parents:
diff changeset
   540
/*!
hgs
parents:
diff changeset
   541
    Sub test case for appending an IAP to IAP list.
hgs
parents:
diff changeset
   542
*/
hgs
parents:
diff changeset
   543
hgs
parents:
diff changeset
   544
void TestWlanSniffer::appendWlanIap(
hgs
parents:
diff changeset
   545
    int iapId,
hgs
parents:
diff changeset
   546
    int netId,
hgs
parents:
diff changeset
   547
    QString name,
hgs
parents:
diff changeset
   548
    QString ssId, 
hgs
parents:
diff changeset
   549
    int signalStrength,
hgs
parents:
diff changeset
   550
    int securityMode)
hgs
parents:
diff changeset
   551
{
hgs
parents:
diff changeset
   552
    WlanQtUtilsIap *iap = new WlanQtUtilsIap();
hgs
parents:
diff changeset
   553
    iap->setValue(WlanQtUtilsIap::ConfIdIapId, iapId);
hgs
parents:
diff changeset
   554
    iap->setValue(WlanQtUtilsIap::ConfIdNetworkId, netId);
hgs
parents:
diff changeset
   555
    iap->setValue(WlanQtUtilsIap::ConfIdName, name);
hgs
parents:
diff changeset
   556
    iap->setValue(WlanQtUtilsAp::ConfIdSsid, ssId);
hgs
parents:
diff changeset
   557
    iap->setValue(WlanQtUtilsAp::ConfIdSignalStrength, signalStrength);
39
hgs
parents: 31
diff changeset
   558
    iap->setValue(WlanQtUtilsAp::ConfIdConnectionMode, CMManagerShim::Infra);
31
hgs
parents:
diff changeset
   559
    iap->setValue(WlanQtUtilsAp::ConfIdSecurityMode, securityMode);
39
hgs
parents: 31
diff changeset
   560
    iap->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false);
hgs
parents: 31
diff changeset
   561
    iap->setValue(WlanQtUtilsAp::ConfIdWpsSupported, false);
31
hgs
parents:
diff changeset
   562
    mIaps.append(QSharedPointer<WlanQtUtilsIap>(iap));
hgs
parents:
diff changeset
   563
}