]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[878] Fix in ifacemgr_unittest: separate instances are now used
authorTomek Mrugalski <tomasz@isc.org>
Thu, 18 Aug 2011 16:17:47 +0000 (18:17 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Thu, 18 Aug 2011 16:17:47 +0000 (18:17 +0200)
Tests used single instance of IfaceMgr (it is singleton after all).
Therefore first fake interface data was reused in later tests,
causing them to fail.

src/bin/dhcp6/tests/iface_mgr_unittest.cc

index 6c2dd0a1e6d2415d27340a7f7e6c634fbf502f23..0f7f43122490fd492a3707e2f500f8276f8b9dd9 100644 (file)
@@ -112,7 +112,7 @@ TEST_F(IfaceMgrTest, detectIfaces) {
     // test detects that interfaces can be detected
     // there is no code for that now, but interfaces are
     // read from file
-    fstream fakeifaces("interfaces.txt", ios::out);
+    fstream fakeifaces("interfaces.txt", ios::out|ios::trunc);
     fakeifaces << "eth0 fe80::1234";
     fakeifaces.close();
 
@@ -120,11 +120,11 @@ TEST_F(IfaceMgrTest, detectIfaces) {
     // interfaces. Nevertheless, this fake interface should
     // be on list, but if_nametoindex() will fail.
 
-    IfaceMgr & ifacemgr = IfaceMgr::instance();
+    NakedIfaceMgr * ifacemgr = new NakedIfaceMgr();
 
-    ASSERT_TRUE( ifacemgr.getIface("eth0") != NULL );
+    ASSERT_TRUE( ifacemgr->getIface("eth0") != NULL );
 
-    IfaceMgr::Iface * eth0 = ifacemgr.getIface("eth0");
+    IfaceMgr::Iface * eth0 = ifacemgr->getIface("eth0");
 
     // there should be one address
     EXPECT_EQ(1, eth0->addrs_.size());
@@ -133,6 +133,8 @@ TEST_F(IfaceMgrTest, detectIfaces) {
     ASSERT_TRUE( addr != NULL );
 
     EXPECT_STREQ( "fe80::1234", addr->toText().c_str() );
+
+    delete ifacemgr;
 }
 
 TEST_F(IfaceMgrTest, sockets) {
@@ -163,7 +165,7 @@ TEST_F(IfaceMgrTest, sendReceive) {
     // testing socket operation in a portable way is tricky
     // without interface detection implemented
 
-    fstream fakeifaces("interfaces.txt", ios::out);
+    fstream fakeifaces("interfaces.txt", ios::out|ios::trunc);
     fakeifaces << "lo ::1";
     fakeifaces.close();