Patrick Rohr | 27846ff | 2022-01-17 12:22:51 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
| 16 | * TcUtilsTest.cpp - unit tests for TcUtils.cpp |
| 17 | */ |
| 18 | |
| 19 | #include <gtest/gtest.h> |
| 20 | |
| 21 | #include <tcutils/tcutils.h> |
| 22 | |
| 23 | #include <errno.h> |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | TEST(LibTcUtilsTest, IsEthernetOfNonExistingIf) { |
| 28 | bool result = false; |
| 29 | int error = isEthernet("not_existing_if", result); |
| 30 | ASSERT_FALSE(result); |
| 31 | ASSERT_EQ(-ENODEV, error); |
| 32 | } |
| 33 | |
| 34 | TEST(LibTcUtilsTest, IsEthernetOfLoopback) { |
| 35 | bool result = false; |
| 36 | int error = isEthernet("lo", result); |
| 37 | ASSERT_FALSE(result); |
| 38 | ASSERT_EQ(-EAFNOSUPPORT, error); |
| 39 | } |
| 40 | |
| 41 | // If wireless 'wlan0' interface exists it should be Ethernet. |
| 42 | // See also HardwareAddressTypeOfWireless. |
| 43 | TEST(LibTcUtilsTest, IsEthernetOfWireless) { |
| 44 | bool result = false; |
| 45 | int error = isEthernet("wlan0", result); |
| 46 | if (!result && error == -ENODEV) |
| 47 | return; |
| 48 | |
| 49 | ASSERT_EQ(0, error); |
| 50 | ASSERT_TRUE(result); |
| 51 | } |
| 52 | |
| 53 | // If cellular 'rmnet_data0' interface exists it should |
| 54 | // *probably* not be Ethernet and instead be RawIp. |
| 55 | // See also HardwareAddressTypeOfCellular. |
| 56 | TEST(LibTcUtilsTest, IsEthernetOfCellular) { |
| 57 | bool result = false; |
| 58 | int error = isEthernet("rmnet_data0", result); |
| 59 | if (!result && error == -ENODEV) |
| 60 | return; |
| 61 | |
| 62 | ASSERT_EQ(0, error); |
| 63 | ASSERT_FALSE(result); |
| 64 | } |
| 65 | |
| 66 | } // namespace android |