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
22namespace rtc {
23
24class Win32Test : public testing::Test {
25 public:
26  Win32Test() {
27  }
28};
29
30TEST_F(Win32Test, FileTimeToUInt64Test) {
31  FILETIME ft;
32  ft.dwHighDateTime = 0xBAADF00D;
33  ft.dwLowDateTime = 0xFEED3456;
34
35  uint64 expected = 0xBAADF00DFEED3456;
36  EXPECT_EQ(expected, ToUInt64(ft));
37}
38
39TEST_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}  // namespace rtc
63