blob: 67857cbb97b7fb989afffe0680e03bdec9064cc8 [file] [log] [blame]
Elliott Hughes9cddb482016-01-04 20:38:05 +00001/*
2 * Copyright (C) 2015 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
17#include <gtest/gtest.h>
18
19#include <ifaddrs.h>
20
21TEST(ifaddrs, freeifaddrs_null) {
22 freeifaddrs(nullptr);
23}
24
25TEST(ifaddrs, getifaddrs_smoke) {
26 ifaddrs* addrs = nullptr;
27
28 ASSERT_EQ(0, getifaddrs(&addrs));
29 ASSERT_TRUE(addrs != nullptr);
30
31 bool saw_loopback = false;
32 for (ifaddrs* addr = addrs; addr != nullptr; addr = addr->ifa_next) {
33 if (addr->ifa_name && strcmp(addr->ifa_name, "lo") == 0) saw_loopback = true;
34 }
35 ASSERT_TRUE(saw_loopback);
36
37 freeifaddrs(addrs);
38}