src/3rdparty/libconninet/tests/ut_iapmonitor.cpp
changeset 37 758a864f9613
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
       
     1 /*
       
     2   libconninet - Internet Connectivity support library
       
     3 
       
     4   Copyright (C) 2009-2010 Nokia Corporation. All rights reserved.
       
     5 
       
     6   Contact: Jukka Rissanen <jukka.rissanen@nokia.com>
       
     7 
       
     8   This library is free software; you can redistribute it and/or
       
     9   modify it under the terms of the GNU Lesser General Public License
       
    10   version 2.1 as published by the Free Software Foundation.
       
    11 
       
    12   This library is distributed in the hope that it will be useful, but
       
    13   WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
       
    15   Lesser General Public License for more details.
       
    16 
       
    17   You should have received a copy of the GNU Lesser General Public
       
    18   License along with this library; if not, write to the Free Software
       
    19   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
       
    20   02110-1301 USA
       
    21 */
       
    22 
       
    23 
       
    24 #include <QtTest/QtTest>
       
    25 #include <QDebug>
       
    26 
       
    27 #include <iapmonitor.h>
       
    28 #include <iapconf.h>
       
    29 
       
    30 static const char *iap_id = "test_monitor_1";
       
    31 
       
    32 class TestIAPMonitor : public Maemo::IAPMonitor
       
    33 {
       
    34 public:
       
    35     QString addedIap;
       
    36     QString removedIap;
       
    37     
       
    38 protected:
       
    39     virtual void iapAdded(const QString &id)
       
    40     {
       
    41         addedIap = id;
       
    42     }
       
    43 
       
    44     virtual void iapRemoved(const QString &id)
       
    45     {
       
    46         removedIap = id;
       
    47     }
       
    48 };
       
    49 
       
    50 class Ut_IAPMonitor : public QObject
       
    51 {
       
    52     Q_OBJECT
       
    53 
       
    54 private Q_SLOTS:
       
    55     void init();
       
    56     void cleanup();
       
    57     void initTestCase();
       
    58     void cleanupTestCase();
       
    59 
       
    60     void check();
       
    61 
       
    62 private:
       
    63     TestIAPMonitor *mon;
       
    64     Maemo::IAPConf *iap;
       
    65 };
       
    66 
       
    67 void Ut_IAPMonitor::init()
       
    68 {
       
    69     mon = new TestIAPMonitor;
       
    70 }
       
    71 
       
    72 void Ut_IAPMonitor::cleanup()
       
    73 {
       
    74     delete mon;
       
    75     mon = 0;
       
    76 }
       
    77 
       
    78 void Ut_IAPMonitor::initTestCase()
       
    79 {
       
    80 } 
       
    81 
       
    82 void Ut_IAPMonitor::cleanupTestCase()
       
    83 {
       
    84 }
       
    85 
       
    86 void Ut_IAPMonitor::check()
       
    87 {
       
    88     QVERIFY(mon->addedIap.isEmpty());
       
    89 
       
    90     iap = new Maemo::IAPConf(iap_id);
       
    91     iap->set("ipv4_type", "AUTO",
       
    92 	    "wlan_wepkey1", "connt",
       
    93 	    "wlan_wepdefkey", 1,
       
    94 	    "wlan_ssid", QByteArray(iap_id));
       
    95     
       
    96     QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
       
    97     QVERIFY(mon->addedIap == iap_id);
       
    98     mon->addedIap.clear();
       
    99 
       
   100     QVERIFY(mon->removedIap.isEmpty());
       
   101 
       
   102     // Unset only one value and verify that IAP is not removed
       
   103     iap->set("ipv4_type", QVariant());
       
   104     QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
       
   105     QVERIFY(mon->removedIap.isEmpty());
       
   106 
       
   107     // Clear the whole IAP and check that it is removed
       
   108     iap->clear();
       
   109     delete iap;
       
   110 
       
   111     QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
       
   112 
       
   113     QVERIFY(mon->removedIap == iap_id);
       
   114 }
       
   115 
       
   116 QTEST_MAIN(Ut_IAPMonitor)
       
   117 
       
   118 #include "ut_iapmonitor.moc"