1 /* This file is part of the KDE project
2 Copyright (C) 2005 Kevin Ottens <ervin@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
20 #include "solidnettest.h"
22 #include <qtest_kde.h>
24 #include <solid/control/networkmanager.h>
25 #include <solid/control/networkinterface.h>
26 #include <solid/control/managerbase_p.h>
29 #include <fakenetworkmanager.h>
31 #ifndef FAKE_NETWORKING_XML
32 #error "FAKE_NETWORKING_XML not set. An XML file describing a networking context is required for this test"
35 QTEST_KDEMAIN_CORE(SolidNetTest
)
37 void SolidNetTest::initTestCase()
39 fakeManager
= new FakeNetworkManager(0, QStringList(), FAKE_NETWORKING_XML
);
40 Solid::Control::ManagerBasePrivate::_k_forcePreloadedBackend("Solid::Control::Ifaces::NetworkManager", fakeManager
);
43 void SolidNetTest::testNetworkInterfaces()
45 Solid::Control::NetworkInterfaceList interfaces
= Solid::Control::NetworkManager::networkInterfaces();
47 // Verify that the framework reported correctly the interfaces available
49 QSet
<QString
> expected_unis
, received_unis
;
51 expected_unis
= QSet
<QString
>::fromList(fakeManager
->networkInterfaces());
53 foreach (Solid::Control::NetworkInterface iface
, interfaces
)
55 received_unis
<< iface
.uni();
58 QCOMPARE(expected_unis
, received_unis
);
61 void SolidNetTest::testFindNetworkInterface()
63 QCOMPARE(Solid::Control::NetworkManager::findNetworkInterface("/org/kde/solid/fakenet/eth0").isValid(), true);
64 QCOMPARE(Solid::Control::NetworkManager::findNetworkInterface("/org/kde/solid/fakenet/eth1").isValid(), true);
66 // Note the extra space
67 QCOMPARE(Solid::Control::NetworkManager::findNetworkInterface("/org/kde/solid/fakenet/eth0 ").isValid(), false);
68 QCOMPARE(Solid::Control::NetworkManager::findNetworkInterface("#'({(�").isValid(), false);
69 QCOMPARE(Solid::Control::NetworkManager::findNetworkInterface(QString()).isValid(), false);
72 void SolidNetTest::testManagerBasicFeatures()
74 QCOMPARE(Solid::Control::NetworkManager::isNetworkingEnabled(), true);
75 QCOMPARE(Solid::Control::NetworkManager::isWirelessEnabled(), true);
77 Solid::Control::NetworkManager::setNetworkingEnabled(false);
79 QCOMPARE(Solid::Control::NetworkManager::isNetworkingEnabled(), false);
80 QCOMPARE(Solid::Control::NetworkManager::isWirelessEnabled(), false);
82 Solid::Control::NetworkManager::setNetworkingEnabled(true);
84 QCOMPARE(Solid::Control::NetworkManager::isNetworkingEnabled(), true);
85 QCOMPARE(Solid::Control::NetworkManager::isWirelessEnabled(), true);
87 Solid::Control::NetworkManager::setWirelessEnabled(false);
89 QCOMPARE(Solid::Control::NetworkManager::isNetworkingEnabled(), true);
90 QCOMPARE(Solid::Control::NetworkManager::isWirelessEnabled(), false);
92 Solid::Control::NetworkManager::setNetworkingEnabled(false);
94 QCOMPARE(Solid::Control::NetworkManager::isNetworkingEnabled(), false);
95 QCOMPARE(Solid::Control::NetworkManager::isWirelessEnabled(), false);
97 Solid::Control::NetworkManager::setNetworkingEnabled(true);
99 QCOMPARE(Solid::Control::NetworkManager::isNetworkingEnabled(), true);
100 QCOMPARE(Solid::Control::NetworkManager::isWirelessEnabled(), false);
102 Solid::Control::NetworkManager::setWirelessEnabled(true);
104 QCOMPARE(Solid::Control::NetworkManager::isNetworkingEnabled(), true);
105 QCOMPARE(Solid::Control::NetworkManager::isWirelessEnabled(), true);
108 void SolidNetTest::testInterfaceBasicFeatures()
110 // Retrieve a valid NetworkInterface object
111 Solid::Control::NetworkInterface
valid_iface("/org/kde/solid/fakenet/eth0");
113 QCOMPARE(valid_iface
.isValid(), true);
116 // A few attempts at creating invalid Device objects
117 Solid::Control::NetworkInterface
invalid_iface("uhoh? doesn't exist, I guess");
118 QCOMPARE(invalid_iface
.isValid(), false);
119 invalid_iface
= Solid::Control::NetworkManager::findNetworkInterface(QString());
120 QCOMPARE(invalid_iface
.isValid(), false);
121 invalid_iface
= Solid::Control::NetworkInterface();
122 QCOMPARE(invalid_iface
.isValid(), false);
126 QCOMPARE(valid_iface
.uni(), QString("/org/kde/solid/fakenet/eth0"));
127 QCOMPARE(invalid_iface
.uni(), QString());
130 QCOMPARE(valid_iface
.isActive(), true);
131 QCOMPARE(valid_iface
.type(), Solid::Control::NetworkInterface::Ieee80211
);
132 QCOMPARE(valid_iface
.connectionState(), Solid::Control::NetworkInterface::NeedUserKey
);
133 QCOMPARE(valid_iface
.signalStrength(), 90);
134 QCOMPARE(valid_iface
.designSpeed(), 83886080);
135 QCOMPARE(valid_iface
.isLinkUp(), true);
136 QCOMPARE(valid_iface
.capabilities(), Solid::Control::NetworkInterface::IsManageable
137 |Solid::Control::NetworkInterface::SupportsCarrierDetect
138 |Solid::Control::NetworkInterface::SupportsWirelessScan
);
140 QVERIFY(valid_iface
.findNetwork("/org/kde/solid/fakenet/eth0/net1")!=0);
141 QCOMPARE(valid_iface
.findNetwork("/org/kde/solid/fakenet/eth0/net1")->isValid(), true);
143 QVERIFY(valid_iface
.findNetwork("emldzn")!=0);
144 QCOMPARE(valid_iface
.findNetwork("emldzn")->isValid(), false);
146 QVERIFY(valid_iface
.findNetwork("/org/kde/solid/fakenet/eth1/net0")!=0);
147 QCOMPARE(valid_iface
.findNetwork("/org/kde/solid/fakenet/eth1/net0")->isValid(), false);
149 QVERIFY(valid_iface
.findNetwork("/org/kde/solid/fakenet/eth0/net0 ")!=0);
150 QCOMPARE(valid_iface
.findNetwork("/org/kde/solid/fakenet/eth0/net0")->isValid(), true);
152 QCOMPARE(valid_iface
.findNetwork("/org/kde/solid/fakenet/eth0/net0")->addressEntries().size(), 1);
153 QCOMPARE(valid_iface
.networks().size(), 4);
156 #include "solidnettest.moc"