1 /* 2 * Copyright 2010 The WebRTC Project Authors. All rights reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include <string> 12 13 #include "webrtc/base/gunit.h" 14 #include "webrtc/base/nethelpers.h" 15 #include "webrtc/base/win32.h" 16 #include "webrtc/base/winping.h" 17 18 #if !defined(WEBRTC_WIN) 19 #error Only for Windows 20 #endif 21 22 namespace rtc { 23 24 class Win32Test : public testing::Test { 25 public: 26 Win32Test() { 27 } 28 }; 29 30 TEST_F(Win32Test, FileTimeToUInt64Test) { 31 FILETIME ft; 32 ft.dwHighDateTime = 0xBAADF00D; 33 ft.dwLowDateTime = 0xFEED3456; 34 35 uint64_t expected = 0xBAADF00DFEED3456; 36 EXPECT_EQ(expected, ToUInt64(ft)); 37 } 38 39 TEST_F(Win32Test, WinPingTest) { 40 WinPing ping; 41 ASSERT_TRUE(ping.IsValid()); 42 43 // Test valid ping cases. 44 WinPing::PingResult result = ping.Ping(IPAddress(INADDR_LOOPBACK), 20, 50, 1, 45 false); 46 ASSERT_EQ(WinPing::PING_SUCCESS, result); 47 if (HasIPv6Enabled()) { 48 WinPing::PingResult v6result = ping.Ping(IPAddress(in6addr_loopback), 20, 49 50, 1, false); 50 ASSERT_EQ(WinPing::PING_SUCCESS, v6result); 51 } 52 53 // Test invalid parameter cases. 54 ASSERT_EQ(WinPing::PING_INVALID_PARAMS, ping.Ping( 55 IPAddress(INADDR_LOOPBACK), 0, 50, 1, false)); 56 ASSERT_EQ(WinPing::PING_INVALID_PARAMS, ping.Ping( 57 IPAddress(INADDR_LOOPBACK), 20, 0, 1, false)); 58 ASSERT_EQ(WinPing::PING_INVALID_PARAMS, ping.Ping( 59 IPAddress(INADDR_LOOPBACK), 20, 50, 0, false)); 60 } 61 62 TEST_F(Win32Test, IPv6AddressCompression) { 63 IPAddress ipv6; 64 65 // Zero compression should be done on the leftmost 0s when there are 66 // multiple longest series. 67 ASSERT_TRUE(IPFromString("2a00:8a00:a000:1190:0000:0001:000:252", &ipv6)); 68 EXPECT_EQ("2a00:8a00:a000:1190::1:0:252", ipv6.ToString()); 69 70 // Ensure the zero compression could handle multiple octects. 71 ASSERT_TRUE(IPFromString("0:0:0:0:0:0:0:1", &ipv6)); 72 EXPECT_EQ("::1", ipv6.ToString()); 73 74 // Make sure multiple 0 octects compressed. 75 ASSERT_TRUE(IPFromString("fe80:0:0:0:2aa:ff:fe9a:4ca2", &ipv6)); 76 EXPECT_EQ("fe80::2aa:ff:fe9a:4ca2", ipv6.ToString()); 77 78 // Test zero compression at the end of string. 79 ASSERT_TRUE(IPFromString("2a00:8a00:a000:1190:0000:0001:000:00", &ipv6)); 80 EXPECT_EQ("2a00:8a00:a000:1190:0:1::", ipv6.ToString()); 81 82 // Test zero compression at the beginning of string. 83 ASSERT_TRUE(IPFromString("0:0:000:1190:0000:0001:000:00", &ipv6)); 84 EXPECT_EQ("::1190:0:1:0:0", ipv6.ToString()); 85 86 // Test zero compression only done once. 87 ASSERT_TRUE(IPFromString("0:1:000:1190:0000:0001:000:01", &ipv6)); 88 EXPECT_EQ("::1:0:1190:0:1:0:1", ipv6.ToString()); 89 90 // Make sure noncompressable IPv6 is the same. 91 ASSERT_TRUE(IPFromString("1234:5678:abcd:1234:5678:abcd:1234:5678", &ipv6)); 92 EXPECT_EQ("1234:5678:abcd:1234:5678:abcd:1234:5678", ipv6.ToString()); 93 } 94 95 } // namespace rtc 96