Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: chromeos/network/cros_network_functions_unittest.cc

Issue 11756002: Move cros_network_functions.cc to src/chromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clang fixes Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chromeos/network/cros_network_functions.cc ('k') | chromeos/network/network_ip_config.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/chromeos/cros/cros_network_functions.h"
9 #include "chrome/browser/chromeos/cros/sms_watcher.h"
10 #include "chromeos/dbus/mock_dbus_thread_manager.h" 8 #include "chromeos/dbus/mock_dbus_thread_manager.h"
9 #include "chromeos/dbus/mock_gsm_sms_client.h"
11 #include "chromeos/dbus/mock_shill_device_client.h" 10 #include "chromeos/dbus/mock_shill_device_client.h"
12 #include "chromeos/dbus/mock_shill_ipconfig_client.h" 11 #include "chromeos/dbus/mock_shill_ipconfig_client.h"
13 #include "chromeos/dbus/mock_shill_manager_client.h" 12 #include "chromeos/dbus/mock_shill_manager_client.h"
14 #include "chromeos/dbus/mock_shill_network_client.h" 13 #include "chromeos/dbus/mock_shill_network_client.h"
15 #include "chromeos/dbus/mock_shill_profile_client.h" 14 #include "chromeos/dbus/mock_shill_profile_client.h"
16 #include "chromeos/dbus/mock_shill_service_client.h" 15 #include "chromeos/dbus/mock_shill_service_client.h"
17 #include "chromeos/dbus/mock_gsm_sms_client.h" 16 #include "chromeos/network/cros_network_functions.h"
17 #include "chromeos/network/sms_watcher.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/cros_system_api/dbus/service_constants.h" 19 #include "third_party/cros_system_api/dbus/service_constants.h"
20 20
21 using ::testing::_; 21 using ::testing::_;
22 using ::testing::Invoke; 22 using ::testing::Invoke;
23 using ::testing::Pointee; 23 using ::testing::Pointee;
24 using ::testing::Return; 24 using ::testing::Return;
25 using ::testing::SaveArg; 25 using ::testing::SaveArg;
26 using ::testing::StrEq; 26 using ::testing::StrEq;
27 27
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 const std::string key2 = "key2"; 935 const std::string key2 = "key2";
936 const std::string string2 = "string2"; 936 const std::string string2 = "string2";
937 base::DictionaryValue value; 937 base::DictionaryValue value;
938 value.SetString(key1, string1); 938 value.SetString(key1, string1);
939 value.SetString(key2, string2); 939 value.SetString(key2, string2);
940 EXPECT_CALL(*mock_manager_client_, ConfigureService(IsEqualTo(&value), _, _)) 940 EXPECT_CALL(*mock_manager_client_, ConfigureService(IsEqualTo(&value), _, _))
941 .Times(1); 941 .Times(1);
942 CrosConfigureService(value); 942 CrosConfigureService(value);
943 } 943 }
944 944
945 TEST_F(CrosNetworkFunctionsTest, NetmaskToPrefixLength) {
946 // Valid netmasks
947 EXPECT_EQ(32, CrosNetmaskToPrefixLength("255.255.255.255"));
948 EXPECT_EQ(31, CrosNetmaskToPrefixLength("255.255.255.254"));
949 EXPECT_EQ(30, CrosNetmaskToPrefixLength("255.255.255.252"));
950 EXPECT_EQ(29, CrosNetmaskToPrefixLength("255.255.255.248"));
951 EXPECT_EQ(28, CrosNetmaskToPrefixLength("255.255.255.240"));
952 EXPECT_EQ(27, CrosNetmaskToPrefixLength("255.255.255.224"));
953 EXPECT_EQ(26, CrosNetmaskToPrefixLength("255.255.255.192"));
954 EXPECT_EQ(25, CrosNetmaskToPrefixLength("255.255.255.128"));
955 EXPECT_EQ(24, CrosNetmaskToPrefixLength("255.255.255.0"));
956 EXPECT_EQ(23, CrosNetmaskToPrefixLength("255.255.254.0"));
957 EXPECT_EQ(22, CrosNetmaskToPrefixLength("255.255.252.0"));
958 EXPECT_EQ(21, CrosNetmaskToPrefixLength("255.255.248.0"));
959 EXPECT_EQ(20, CrosNetmaskToPrefixLength("255.255.240.0"));
960 EXPECT_EQ(19, CrosNetmaskToPrefixLength("255.255.224.0"));
961 EXPECT_EQ(18, CrosNetmaskToPrefixLength("255.255.192.0"));
962 EXPECT_EQ(17, CrosNetmaskToPrefixLength("255.255.128.0"));
963 EXPECT_EQ(16, CrosNetmaskToPrefixLength("255.255.0.0"));
964 EXPECT_EQ(15, CrosNetmaskToPrefixLength("255.254.0.0"));
965 EXPECT_EQ(14, CrosNetmaskToPrefixLength("255.252.0.0"));
966 EXPECT_EQ(13, CrosNetmaskToPrefixLength("255.248.0.0"));
967 EXPECT_EQ(12, CrosNetmaskToPrefixLength("255.240.0.0"));
968 EXPECT_EQ(11, CrosNetmaskToPrefixLength("255.224.0.0"));
969 EXPECT_EQ(10, CrosNetmaskToPrefixLength("255.192.0.0"));
970 EXPECT_EQ(9, CrosNetmaskToPrefixLength("255.128.0.0"));
971 EXPECT_EQ(8, CrosNetmaskToPrefixLength("255.0.0.0"));
972 EXPECT_EQ(7, CrosNetmaskToPrefixLength("254.0.0.0"));
973 EXPECT_EQ(6, CrosNetmaskToPrefixLength("252.0.0.0"));
974 EXPECT_EQ(5, CrosNetmaskToPrefixLength("248.0.0.0"));
975 EXPECT_EQ(4, CrosNetmaskToPrefixLength("240.0.0.0"));
976 EXPECT_EQ(3, CrosNetmaskToPrefixLength("224.0.0.0"));
977 EXPECT_EQ(2, CrosNetmaskToPrefixLength("192.0.0.0"));
978 EXPECT_EQ(1, CrosNetmaskToPrefixLength("128.0.0.0"));
979 EXPECT_EQ(0, CrosNetmaskToPrefixLength("0.0.0.0"));
980 // Invalid netmasks
981 EXPECT_EQ(-1, CrosNetmaskToPrefixLength("255.255.255"));
982 EXPECT_EQ(-1, CrosNetmaskToPrefixLength("255.255.255.255.255"));
983 EXPECT_EQ(-1, CrosNetmaskToPrefixLength("255.255.255.255.0"));
984 EXPECT_EQ(-1, CrosNetmaskToPrefixLength("255.255.255.256"));
985 EXPECT_EQ(-1, CrosNetmaskToPrefixLength("255.255.255.1"));
986 EXPECT_EQ(-1, CrosNetmaskToPrefixLength("255.255.240.255"));
987 EXPECT_EQ(-1, CrosNetmaskToPrefixLength("255.0.0.255"));
988 EXPECT_EQ(-1, CrosNetmaskToPrefixLength("255.255.255.FF"));
989 EXPECT_EQ(-1, CrosNetmaskToPrefixLength("255,255,255,255"));
990 EXPECT_EQ(-1, CrosNetmaskToPrefixLength("255 255 255 255"));
991 }
992
993 TEST_F(CrosNetworkFunctionsTest, PrefixLengthToNetmask) {
994 // Valid Prefix Lengths
995 EXPECT_EQ("255.255.255.255", CrosPrefixLengthToNetmask(32));
996 EXPECT_EQ("255.255.255.254", CrosPrefixLengthToNetmask(31));
997 EXPECT_EQ("255.255.255.252", CrosPrefixLengthToNetmask(30));
998 EXPECT_EQ("255.255.255.248", CrosPrefixLengthToNetmask(29));
999 EXPECT_EQ("255.255.255.240", CrosPrefixLengthToNetmask(28));
1000 EXPECT_EQ("255.255.255.224", CrosPrefixLengthToNetmask(27));
1001 EXPECT_EQ("255.255.255.192", CrosPrefixLengthToNetmask(26));
1002 EXPECT_EQ("255.255.255.128", CrosPrefixLengthToNetmask(25));
1003 EXPECT_EQ("255.255.255.0", CrosPrefixLengthToNetmask(24));
1004 EXPECT_EQ("255.255.254.0", CrosPrefixLengthToNetmask(23));
1005 EXPECT_EQ("255.255.252.0", CrosPrefixLengthToNetmask(22));
1006 EXPECT_EQ("255.255.248.0", CrosPrefixLengthToNetmask(21));
1007 EXPECT_EQ("255.255.240.0", CrosPrefixLengthToNetmask(20));
1008 EXPECT_EQ("255.255.224.0", CrosPrefixLengthToNetmask(19));
1009 EXPECT_EQ("255.255.192.0", CrosPrefixLengthToNetmask(18));
1010 EXPECT_EQ("255.255.128.0", CrosPrefixLengthToNetmask(17));
1011 EXPECT_EQ("255.255.0.0", CrosPrefixLengthToNetmask(16));
1012 EXPECT_EQ("255.254.0.0", CrosPrefixLengthToNetmask(15));
1013 EXPECT_EQ("255.252.0.0", CrosPrefixLengthToNetmask(14));
1014 EXPECT_EQ("255.248.0.0", CrosPrefixLengthToNetmask(13));
1015 EXPECT_EQ("255.240.0.0", CrosPrefixLengthToNetmask(12));
1016 EXPECT_EQ("255.224.0.0", CrosPrefixLengthToNetmask(11));
1017 EXPECT_EQ("255.192.0.0", CrosPrefixLengthToNetmask(10));
1018 EXPECT_EQ("255.128.0.0", CrosPrefixLengthToNetmask(9));
1019 EXPECT_EQ("255.0.0.0", CrosPrefixLengthToNetmask(8));
1020 EXPECT_EQ("254.0.0.0", CrosPrefixLengthToNetmask(7));
1021 EXPECT_EQ("252.0.0.0", CrosPrefixLengthToNetmask(6));
1022 EXPECT_EQ("248.0.0.0", CrosPrefixLengthToNetmask(5));
1023 EXPECT_EQ("240.0.0.0", CrosPrefixLengthToNetmask(4));
1024 EXPECT_EQ("224.0.0.0", CrosPrefixLengthToNetmask(3));
1025 EXPECT_EQ("192.0.0.0", CrosPrefixLengthToNetmask(2));
1026 EXPECT_EQ("128.0.0.0", CrosPrefixLengthToNetmask(1));
1027 EXPECT_EQ("0.0.0.0", CrosPrefixLengthToNetmask(0));
1028 // Invalid Prefix Lengths
1029 EXPECT_EQ("", CrosPrefixLengthToNetmask(-1));
1030 EXPECT_EQ("", CrosPrefixLengthToNetmask(33));
1031 EXPECT_EQ("", CrosPrefixLengthToNetmask(255));
1032 }
1033
1034 } // namespace chromeos 945 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/cros_network_functions.cc ('k') | chromeos/network/network_ip_config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698