blob: 463bc6f747b505d1692f2ec86f78424a5fcd7b1f [file] [log] [blame]
Brandon Kimdab96f12021-02-18 11:21:37 -08001// 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
William A. Kennington III7d6fa422021-02-08 17:04:02 -080015#include "ncsi_sockio.h"
16#include "net_iface_mock.h"
17
Willy Tuadb8ffe2023-07-17 13:44:22 -070018#include <linux/if.h>
19
20#include <vector>
21
22#include "gmock/gmock.h"
23#include "gtest/gtest.h"
24#include <gtest/gtest.h>
William A. Kennington III7d6fa422021-02-08 17:04:02 -080025
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}