1 // Copyright 2021 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "ncsi_sockio.h" 16 #include "net_iface_mock.h" 17 18 #include <gmock/gmock.h> 19 20 TEST(TestSockIO, TestBind) 21 { 22 mock::IFace iface_mock; 23 constexpr int test_index = 5; 24 iface_mock.index = test_index; 25 26 // This needs to be negative so that ncsi::SockIO 27 // won't try to close the socket upon desctrution. 28 constexpr int sock_fake_fd = -10; 29 ncsi::SockIO ncsi_sock(sock_fake_fd); 30 31 ncsi_sock.bind_to_iface(iface_mock); 32 EXPECT_THAT(iface_mock.bound_socks.size(), testing::Ge(0)); 33 EXPECT_THAT(iface_mock.bound_socks, testing::Contains(sock_fake_fd)); 34 EXPECT_EQ(iface_mock.flags & IFF_PROMISC, IFF_PROMISC); 35 } 36