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 "chromeos/network/network_util.h" | 5 #include "chromeos/network/network_util.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "third_party/cros_system_api/dbus/service_constants.h" | 8 #include "third_party/cros_system_api/dbus/service_constants.h" |
9 | 9 |
10 using chromeos::CellularScanResult; | 10 using chromeos::CellularScanResult; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 EXPECT_EQ("192.0.0.0", PrefixLengthToNetmask(2)); | 97 EXPECT_EQ("192.0.0.0", PrefixLengthToNetmask(2)); |
98 EXPECT_EQ("128.0.0.0", PrefixLengthToNetmask(1)); | 98 EXPECT_EQ("128.0.0.0", PrefixLengthToNetmask(1)); |
99 EXPECT_EQ("0.0.0.0", PrefixLengthToNetmask(0)); | 99 EXPECT_EQ("0.0.0.0", PrefixLengthToNetmask(0)); |
100 // Invalid Prefix Lengths | 100 // Invalid Prefix Lengths |
101 EXPECT_EQ("", PrefixLengthToNetmask(-1)); | 101 EXPECT_EQ("", PrefixLengthToNetmask(-1)); |
102 EXPECT_EQ("", PrefixLengthToNetmask(33)); | 102 EXPECT_EQ("", PrefixLengthToNetmask(33)); |
103 EXPECT_EQ("", PrefixLengthToNetmask(255)); | 103 EXPECT_EQ("", PrefixLengthToNetmask(255)); |
104 } | 104 } |
105 | 105 |
106 TEST_F(NetworkUtilTest, ParseScanResults) { | 106 TEST_F(NetworkUtilTest, ParseScanResults) { |
107 ListValue list; | 107 base::ListValue list; |
108 std::vector<CellularScanResult> scan_results; | 108 std::vector<CellularScanResult> scan_results; |
109 | 109 |
110 // Empty list value. | 110 // Empty list value. |
111 EXPECT_TRUE(ParseCellularScanResults(list, &scan_results)); | 111 EXPECT_TRUE(ParseCellularScanResults(list, &scan_results)); |
112 | 112 |
113 // List contains invalid item. | 113 // List contains invalid item. |
114 list.AppendInteger(0); | 114 list.AppendInteger(0); |
115 EXPECT_FALSE(ParseCellularScanResults(list, &scan_results)); | 115 EXPECT_FALSE(ParseCellularScanResults(list, &scan_results)); |
116 | 116 |
117 // Scan result has no network id. | 117 // Scan result has no network id. |
118 list.Clear(); | 118 list.Clear(); |
119 DictionaryValue* dict_value = new DictionaryValue(); | 119 base::DictionaryValue* dict_value = new base::DictionaryValue(); |
120 dict_value->SetString(shill::kStatusProperty, "available"); | 120 dict_value->SetString(shill::kStatusProperty, "available"); |
121 list.Append(dict_value); | 121 list.Append(dict_value); |
122 EXPECT_TRUE(ParseCellularScanResults(list, &scan_results)); | 122 EXPECT_TRUE(ParseCellularScanResults(list, &scan_results)); |
123 EXPECT_TRUE(scan_results.empty()); | 123 EXPECT_TRUE(scan_results.empty()); |
124 | 124 |
125 // Mixed parse results. | 125 // Mixed parse results. |
126 dict_value = new DictionaryValue(); | 126 dict_value = new base::DictionaryValue(); |
127 dict_value->SetString(shill::kNetworkIdProperty, "000001"); | 127 dict_value->SetString(shill::kNetworkIdProperty, "000001"); |
128 dict_value->SetString(shill::kStatusProperty, "unknown"); | 128 dict_value->SetString(shill::kStatusProperty, "unknown"); |
129 dict_value->SetString(shill::kTechnologyProperty, "GSM"); | 129 dict_value->SetString(shill::kTechnologyProperty, "GSM"); |
130 list.Append(dict_value); | 130 list.Append(dict_value); |
131 | 131 |
132 dict_value = new DictionaryValue(); | 132 dict_value = new base::DictionaryValue(); |
133 dict_value->SetString(shill::kNetworkIdProperty, "000002"); | 133 dict_value->SetString(shill::kNetworkIdProperty, "000002"); |
134 dict_value->SetString(shill::kStatusProperty, "available"); | 134 dict_value->SetString(shill::kStatusProperty, "available"); |
135 dict_value->SetString(shill::kLongNameProperty, "Long Name"); | 135 dict_value->SetString(shill::kLongNameProperty, "Long Name"); |
136 list.Append(dict_value); | 136 list.Append(dict_value); |
137 | 137 |
138 EXPECT_TRUE(ParseCellularScanResults(list, &scan_results)); | 138 EXPECT_TRUE(ParseCellularScanResults(list, &scan_results)); |
139 EXPECT_EQ(static_cast<size_t>(2), scan_results.size()); | 139 EXPECT_EQ(static_cast<size_t>(2), scan_results.size()); |
140 EXPECT_EQ("000001", scan_results[0].network_id); | 140 EXPECT_EQ("000001", scan_results[0].network_id); |
141 EXPECT_EQ("unknown", scan_results[0].status); | 141 EXPECT_EQ("unknown", scan_results[0].status); |
142 EXPECT_EQ("GSM", scan_results[0].technology); | 142 EXPECT_EQ("GSM", scan_results[0].technology); |
143 EXPECT_TRUE(scan_results[0].long_name.empty()); | 143 EXPECT_TRUE(scan_results[0].long_name.empty()); |
144 EXPECT_TRUE(scan_results[0].short_name.empty()); | 144 EXPECT_TRUE(scan_results[0].short_name.empty()); |
145 | 145 |
146 EXPECT_EQ("000002", scan_results[1].network_id); | 146 EXPECT_EQ("000002", scan_results[1].network_id); |
147 EXPECT_EQ("available", scan_results[1].status); | 147 EXPECT_EQ("available", scan_results[1].status); |
148 EXPECT_EQ("Long Name", scan_results[1].long_name); | 148 EXPECT_EQ("Long Name", scan_results[1].long_name); |
149 EXPECT_TRUE(scan_results[1].short_name.empty()); | 149 EXPECT_TRUE(scan_results[1].short_name.empty()); |
150 EXPECT_TRUE(scan_results[1].technology.empty()); | 150 EXPECT_TRUE(scan_results[1].technology.empty()); |
151 } | 151 } |
OLD | NEW |