xref: /openbmc/google-misc/nemora-postd/subprojects/ncsid/test/sock_test.cpp (revision adb8ffe4759e879cf1a0d7b569271ab64b66f38d)
11285115cSWilliam A. Kennington III // Copyright 2021 Google LLC
21285115cSWilliam A. Kennington III //
31285115cSWilliam A. Kennington III // Licensed under the Apache License, Version 2.0 (the "License");
41285115cSWilliam A. Kennington III // you may not use this file except in compliance with the License.
51285115cSWilliam A. Kennington III // You may obtain a copy of the License at
61285115cSWilliam A. Kennington III //
71285115cSWilliam A. Kennington III //      http://www.apache.org/licenses/LICENSE-2.0
81285115cSWilliam A. Kennington III //
91285115cSWilliam A. Kennington III // Unless required by applicable law or agreed to in writing, software
101285115cSWilliam A. Kennington III // distributed under the License is distributed on an "AS IS" BASIS,
111285115cSWilliam A. Kennington III // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
121285115cSWilliam A. Kennington III // See the License for the specific language governing permissions and
131285115cSWilliam A. Kennington III // limitations under the License.
141285115cSWilliam A. Kennington III 
151285115cSWilliam A. Kennington III #include "ncsi_sockio.h"
161285115cSWilliam A. Kennington III #include "net_iface_mock.h"
171285115cSWilliam A. Kennington III 
18*adb8ffe4SWilly Tu #include <linux/if.h>
19*adb8ffe4SWilly Tu 
20*adb8ffe4SWilly Tu #include <vector>
21*adb8ffe4SWilly Tu 
22*adb8ffe4SWilly Tu #include "gmock/gmock.h"
23*adb8ffe4SWilly Tu #include "gtest/gtest.h"
24*adb8ffe4SWilly Tu #include <gtest/gtest.h>
251285115cSWilliam A. Kennington III 
261285115cSWilliam A. Kennington III TEST(TestSockIO, TestBind)
271285115cSWilliam A. Kennington III {
281285115cSWilliam A. Kennington III     mock::IFace iface_mock;
291285115cSWilliam A. Kennington III     constexpr int test_index = 5;
301285115cSWilliam A. Kennington III     iface_mock.index = test_index;
311285115cSWilliam A. Kennington III 
321285115cSWilliam A. Kennington III     // This needs to be negative so that ncsi::SockIO
331285115cSWilliam A. Kennington III     // won't try to close the socket upon desctrution.
341285115cSWilliam A. Kennington III     constexpr int sock_fake_fd = -10;
351285115cSWilliam A. Kennington III     ncsi::SockIO ncsi_sock(sock_fake_fd);
361285115cSWilliam A. Kennington III 
371285115cSWilliam A. Kennington III     ncsi_sock.bind_to_iface(iface_mock);
381285115cSWilliam A. Kennington III     EXPECT_THAT(iface_mock.bound_socks.size(), testing::Ge(0));
391285115cSWilliam A. Kennington III     EXPECT_THAT(iface_mock.bound_socks, testing::Contains(sock_fake_fd));
401285115cSWilliam A. Kennington III     EXPECT_EQ(iface_mock.flags & IFF_PROMISC, IFF_PROMISC);
411285115cSWilliam A. Kennington III }
42