OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "net/base/address_tracker_linux.h" | 6 #include "net/base/address_tracker_linux.h" |
7 | 7 |
8 #include <linux/if.h> | 8 #include <linux/if.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 #ifndef IFA_F_HOMEADDRESS | 15 #ifndef IFA_F_HOMEADDRESS |
16 #define IFA_F_HOMEADDRESS 0x10 | 16 #define IFA_F_HOMEADDRESS 0x10 |
17 #endif | 17 #endif |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 namespace internal { | 20 namespace internal { |
21 namespace { | 21 namespace { |
22 | 22 |
23 const int kTestInterfaceTun = 123; | 23 const int kTestInterfaceTun = 123; |
24 | 24 |
25 const char* TestGetInterfaceName(int interface_index) { | 25 char* TestGetInterfaceName(int interface_index, char* buf) { |
26 if (interface_index == kTestInterfaceTun) | 26 if (interface_index == kTestInterfaceTun) |
27 return "tun0"; | 27 return strncpy(buf, "tun0", IFNAMSIZ); |
28 return "eth0"; | 28 return strncpy(buf, "eth0", IFNAMSIZ); |
29 } | 29 } |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 typedef std::vector<char> Buffer; | 33 typedef std::vector<char> Buffer; |
34 | 34 |
35 class AddressTrackerLinuxTest : public testing::Test { | 35 class AddressTrackerLinuxTest : public testing::Test { |
36 protected: | 36 protected: |
37 AddressTrackerLinuxTest() {} | 37 AddressTrackerLinuxTest() {} |
38 | 38 |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 IFF_UP | IFF_LOWER_UP | IFF_RUNNING | IFF_POINTOPOINT, | 513 IFF_UP | IFF_LOWER_UP | IFF_RUNNING | IFF_POINTOPOINT, |
514 kTestInterfaceTun, &buffer); | 514 kTestInterfaceTun, &buffer); |
515 EXPECT_FALSE(HandleTunnelMessage(buffer)); | 515 EXPECT_FALSE(HandleTunnelMessage(buffer)); |
516 } | 516 } |
517 | 517 |
518 // Check AddressTrackerLinux::get_interface_name_ original implementation | 518 // Check AddressTrackerLinux::get_interface_name_ original implementation |
519 // doesn't crash or return NULL. | 519 // doesn't crash or return NULL. |
520 TEST_F(AddressTrackerLinuxTest, GetInterfaceName) { | 520 TEST_F(AddressTrackerLinuxTest, GetInterfaceName) { |
521 InitializeAddressTracker(true); | 521 InitializeAddressTracker(true); |
522 | 522 |
523 for (int i = 0; i < 10; i++) | 523 for (int i = 0; i < 10; i++) { |
524 EXPECT_NE((const char*)NULL, original_get_interface_name_(i)); | 524 char buf[IFNAMSIZ] = {0}; |
| 525 EXPECT_NE((const char*)NULL, original_get_interface_name_(i, buf)); |
| 526 } |
525 } | 527 } |
526 | 528 |
527 TEST_F(AddressTrackerLinuxTest, NonTrackingMode) { | 529 TEST_F(AddressTrackerLinuxTest, NonTrackingMode) { |
528 InitializeAddressTracker(false); | 530 InitializeAddressTracker(false); |
529 | 531 |
530 const IPAddressNumber kEmpty; | 532 const IPAddressNumber kEmpty; |
531 const IPAddressNumber kAddr0(kAddress0, kAddress0 + arraysize(kAddress0)); | 533 const IPAddressNumber kAddr0(kAddress0, kAddress0 + arraysize(kAddress0)); |
532 | 534 |
533 Buffer buffer; | 535 Buffer buffer; |
534 MakeAddrMessage( | 536 MakeAddrMessage( |
(...skipping 12 matching lines...) Expand all Loading... |
547 | 549 |
548 TEST_F(AddressTrackerLinuxTest, NonTrackingModeInit) { | 550 TEST_F(AddressTrackerLinuxTest, NonTrackingModeInit) { |
549 AddressTrackerLinux tracker; | 551 AddressTrackerLinux tracker; |
550 tracker.Init(); | 552 tracker.Init(); |
551 } | 553 } |
552 | 554 |
553 } // namespace | 555 } // namespace |
554 | 556 |
555 } // namespace internal | 557 } // namespace internal |
556 } // namespace net | 558 } // namespace net |
OLD | NEW |