From: Tomek Mrugalski Date: Thu, 18 Aug 2011 16:17:47 +0000 (+0200) Subject: [878] Fix in ifacemgr_unittest: separate instances are now used X-Git-Tag: perftcpdns_before_epoll~37^2~21^2~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ee826c177bef06f22cdbbf82044085972bfd8737;p=thirdparty%2Fkea.git [878] Fix in ifacemgr_unittest: separate instances are now used 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. --- diff --git a/src/bin/dhcp6/tests/iface_mgr_unittest.cc b/src/bin/dhcp6/tests/iface_mgr_unittest.cc index 6c2dd0a1e6..0f7f431224 100644 --- a/src/bin/dhcp6/tests/iface_mgr_unittest.cc +++ b/src/bin/dhcp6/tests/iface_mgr_unittest.cc @@ -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();