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(unsigned int interface_index, char* buf) { |
26 if (interface_index == kTestInterfaceTun) | 26 if (interface_index == kTestInterfaceTun) |
27 return "tun0"; | 27 strncpy(buf, "tun0", IFNAMSIZ); |
pauljensen
2015/01/15 15:05:10
I think this needs curly braces, but instead of do
derekjchow1
2015/01/15 20:32:51
Done.
| |
28 return "eth0"; | 28 else |
29 strncpy(buf, "eth0", IFNAMSIZ); | |
30 return buf; | |
29 } | 31 } |
30 | 32 |
31 } // namespace | 33 } // namespace |
32 | 34 |
33 typedef std::vector<char> Buffer; | 35 typedef std::vector<char> Buffer; |
34 | 36 |
35 class AddressTrackerLinuxTest : public testing::Test { | 37 class AddressTrackerLinuxTest : public testing::Test { |
36 protected: | 38 protected: |
37 AddressTrackerLinuxTest() {} | 39 AddressTrackerLinuxTest() {} |
38 | 40 |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
513 IFF_UP | IFF_LOWER_UP | IFF_RUNNING | IFF_POINTOPOINT, | 515 IFF_UP | IFF_LOWER_UP | IFF_RUNNING | IFF_POINTOPOINT, |
514 kTestInterfaceTun, &buffer); | 516 kTestInterfaceTun, &buffer); |
515 EXPECT_FALSE(HandleTunnelMessage(buffer)); | 517 EXPECT_FALSE(HandleTunnelMessage(buffer)); |
516 } | 518 } |
517 | 519 |
518 // Check AddressTrackerLinux::get_interface_name_ original implementation | 520 // Check AddressTrackerLinux::get_interface_name_ original implementation |
519 // doesn't crash or return NULL. | 521 // doesn't crash or return NULL. |
520 TEST_F(AddressTrackerLinuxTest, GetInterfaceName) { | 522 TEST_F(AddressTrackerLinuxTest, GetInterfaceName) { |
521 InitializeAddressTracker(true); | 523 InitializeAddressTracker(true); |
522 | 524 |
523 for (int i = 0; i < 10; i++) | 525 for (int i = 0; i < 10; i++) { |
524 EXPECT_NE((const char*)NULL, original_get_interface_name_(i)); | 526 char buf[IFNAMSIZ] = {0}; |
527 EXPECT_NE((const char*)NULL, original_get_interface_name_(i, buf)); | |
528 } | |
525 } | 529 } |
526 | 530 |
527 TEST_F(AddressTrackerLinuxTest, NonTrackingMode) { | 531 TEST_F(AddressTrackerLinuxTest, NonTrackingMode) { |
528 InitializeAddressTracker(false); | 532 InitializeAddressTracker(false); |
529 | 533 |
530 const IPAddressNumber kEmpty; | 534 const IPAddressNumber kEmpty; |
531 const IPAddressNumber kAddr0(kAddress0, kAddress0 + arraysize(kAddress0)); | 535 const IPAddressNumber kAddr0(kAddress0, kAddress0 + arraysize(kAddress0)); |
532 | 536 |
533 Buffer buffer; | 537 Buffer buffer; |
534 MakeAddrMessage( | 538 MakeAddrMessage( |
(...skipping 12 matching lines...) Expand all Loading... | |
547 | 551 |
548 TEST_F(AddressTrackerLinuxTest, NonTrackingModeInit) { | 552 TEST_F(AddressTrackerLinuxTest, NonTrackingModeInit) { |
549 AddressTrackerLinux tracker; | 553 AddressTrackerLinux tracker; |
550 tracker.Init(); | 554 tracker.Init(); |
551 } | 555 } |
552 | 556 |
553 } // namespace | 557 } // namespace |
554 | 558 |
555 } // namespace internal | 559 } // namespace internal |
556 } // namespace net | 560 } // namespace net |
OLD | NEW |