William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [diff] [blame^] | 1 | #include "ncsi_sockio.h" |
| 2 | #include "net_iface_mock.h" |
| 3 | |
| 4 | #include <gmock/gmock.h> |
| 5 | |
| 6 | TEST(TestSockIO, TestBind) |
| 7 | { |
| 8 | mock::IFace iface_mock; |
| 9 | constexpr int test_index = 5; |
| 10 | iface_mock.index = test_index; |
| 11 | |
| 12 | // This needs to be negative so that ncsi::SockIO |
| 13 | // won't try to close the socket upon desctrution. |
| 14 | constexpr int sock_fake_fd = -10; |
| 15 | ncsi::SockIO ncsi_sock(sock_fake_fd); |
| 16 | |
| 17 | ncsi_sock.bind_to_iface(iface_mock); |
| 18 | EXPECT_THAT(iface_mock.bound_socks.size(), testing::Ge(0)); |
| 19 | EXPECT_THAT(iface_mock.bound_socks, testing::Contains(sock_fake_fd)); |
| 20 | EXPECT_EQ(iface_mock.flags & IFF_PROMISC, IFF_PROMISC); |
| 21 | } |