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 <linux/if.h> 19 20 #include <vector> 21 22 #include "gmock/gmock.h" 23 #include "gtest/gtest.h" 24 #include <gtest/gtest.h> 25 TEST(TestSockIO,TestBind)26TEST(TestSockIO, TestBind) 27 { 28 mock::IFace iface_mock; 29 constexpr int test_index = 5; 30 iface_mock.index = test_index; 31 32 // This needs to be negative so that ncsi::SockIO 33 // won't try to close the socket upon desctrution. 34 constexpr int sock_fake_fd = -10; 35 ncsi::SockIO ncsi_sock(sock_fake_fd); 36 37 ncsi_sock.bind_to_iface(iface_mock); 38 EXPECT_THAT(iface_mock.bound_socks.size(), testing::Ge(0)); 39 EXPECT_THAT(iface_mock.bound_socks, testing::Contains(sock_fake_fd)); 40 EXPECT_EQ(iface_mock.flags & IFF_PROMISC, IFF_PROMISC); 41 } 42