1 //
2 // Copyright (C) 2023 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 #include <gtest/gtest.h>
17 
18 #include "common/libs/utils/network.h"
19 
20 namespace cuttlefish {
21 namespace {
22 
TEST(CommonUtilNetwork,MacAddressToString)23 TEST(CommonUtilNetwork, MacAddressToString) {
24   ASSERT_EQ(
25       MacAddressToString((uint8_t[6]){0xab, 0xcd, 0xef, 0x12, 0x34, 0x56}),
26       "ab:cd:ef:12:34:56");
27   ASSERT_EQ(
28       MacAddressToString((uint8_t[6]){0x01, 0x02, 0x03, 0x04, 0x05, 0x06}),
29       "01:02:03:04:05:06");
30 }
31 
TEST(CommonUtilNetwork,Ipv6ToString)32 TEST(CommonUtilNetwork, Ipv6ToString) {
33   uint8_t address[] = {0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
34                        0x00, 0x00, 0xff, 0x00, 0x00, 0x42, 0x83, 0x29};
35   ASSERT_EQ(Ipv6ToString(address), "2001:db8::ff00:42:8329");
36 }
37 
38 }  // namespace
39 }  // namespace cuttlefish
40