OSDN Git Service

Merge "Add basic tests for <net/if.h>."
[android-x86/bionic.git] / tests / net_if_test.cpp
1 /*
2  * Copyright (C) 2016 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 <net/if.h>
18
19 #include <errno.h>
20
21 #include <gtest/gtest.h>
22
23 TEST(net_if, if_nametoindex_if_indextoname) {
24   unsigned index;
25   index = if_nametoindex("lo");
26   ASSERT_NE(index, 0U);
27
28   char buf[IF_NAMESIZE] = {};
29   char* name = if_indextoname(index, buf);
30   ASSERT_STREQ("lo", name);
31 }
32
33 TEST(net_if, if_nametoindex_fail) {
34   unsigned index = if_nametoindex("this-interface-does-not-exist");
35   ASSERT_EQ(0U, index);
36 }