| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> |
| 10 #include <utility> |
| 11 |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/cros_system_api/dbus/service_constants.h" | 13 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 11 | 14 |
| 12 using chromeos::CellularScanResult; | 15 using chromeos::CellularScanResult; |
| 13 using chromeos::network_util::NetmaskToPrefixLength; | 16 using chromeos::network_util::NetmaskToPrefixLength; |
| 14 using chromeos::network_util::PrefixLengthToNetmask; | 17 using chromeos::network_util::PrefixLengthToNetmask; |
| 15 using chromeos::network_util::ParseCellularScanResults; | 18 using chromeos::network_util::ParseCellularScanResults; |
| 16 | 19 |
| 17 typedef testing::Test NetworkUtilTest; | 20 typedef testing::Test NetworkUtilTest; |
| 18 | 21 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 114 |
| 112 // Empty list value. | 115 // Empty list value. |
| 113 EXPECT_TRUE(ParseCellularScanResults(list, &scan_results)); | 116 EXPECT_TRUE(ParseCellularScanResults(list, &scan_results)); |
| 114 | 117 |
| 115 // List contains invalid item. | 118 // List contains invalid item. |
| 116 list.AppendInteger(0); | 119 list.AppendInteger(0); |
| 117 EXPECT_FALSE(ParseCellularScanResults(list, &scan_results)); | 120 EXPECT_FALSE(ParseCellularScanResults(list, &scan_results)); |
| 118 | 121 |
| 119 // Scan result has no network id. | 122 // Scan result has no network id. |
| 120 list.Clear(); | 123 list.Clear(); |
| 121 base::DictionaryValue* dict_value = new base::DictionaryValue(); | 124 std::unique_ptr<base::DictionaryValue> dict_value( |
| 125 new base::DictionaryValue()); |
| 122 dict_value->SetString(shill::kStatusProperty, "available"); | 126 dict_value->SetString(shill::kStatusProperty, "available"); |
| 123 list.Append(dict_value); | 127 list.Append(std::move(dict_value)); |
| 124 EXPECT_TRUE(ParseCellularScanResults(list, &scan_results)); | 128 EXPECT_TRUE(ParseCellularScanResults(list, &scan_results)); |
| 125 EXPECT_TRUE(scan_results.empty()); | 129 EXPECT_TRUE(scan_results.empty()); |
| 126 | 130 |
| 127 // Mixed parse results. | 131 // Mixed parse results. |
| 128 dict_value = new base::DictionaryValue(); | 132 dict_value.reset(new base::DictionaryValue()); |
| 129 dict_value->SetString(shill::kNetworkIdProperty, "000001"); | 133 dict_value->SetString(shill::kNetworkIdProperty, "000001"); |
| 130 dict_value->SetString(shill::kStatusProperty, "unknown"); | 134 dict_value->SetString(shill::kStatusProperty, "unknown"); |
| 131 dict_value->SetString(shill::kTechnologyProperty, "GSM"); | 135 dict_value->SetString(shill::kTechnologyProperty, "GSM"); |
| 132 list.Append(dict_value); | 136 list.Append(std::move(dict_value)); |
| 133 | 137 |
| 134 dict_value = new base::DictionaryValue(); | 138 dict_value.reset(new base::DictionaryValue()); |
| 135 dict_value->SetString(shill::kNetworkIdProperty, "000002"); | 139 dict_value->SetString(shill::kNetworkIdProperty, "000002"); |
| 136 dict_value->SetString(shill::kStatusProperty, "available"); | 140 dict_value->SetString(shill::kStatusProperty, "available"); |
| 137 dict_value->SetString(shill::kLongNameProperty, "Long Name"); | 141 dict_value->SetString(shill::kLongNameProperty, "Long Name"); |
| 138 list.Append(dict_value); | 142 list.Append(std::move(dict_value)); |
| 139 | 143 |
| 140 EXPECT_TRUE(ParseCellularScanResults(list, &scan_results)); | 144 EXPECT_TRUE(ParseCellularScanResults(list, &scan_results)); |
| 141 EXPECT_EQ(static_cast<size_t>(2), scan_results.size()); | 145 EXPECT_EQ(static_cast<size_t>(2), scan_results.size()); |
| 142 EXPECT_EQ("000001", scan_results[0].network_id); | 146 EXPECT_EQ("000001", scan_results[0].network_id); |
| 143 EXPECT_EQ("unknown", scan_results[0].status); | 147 EXPECT_EQ("unknown", scan_results[0].status); |
| 144 EXPECT_EQ("GSM", scan_results[0].technology); | 148 EXPECT_EQ("GSM", scan_results[0].technology); |
| 145 EXPECT_TRUE(scan_results[0].long_name.empty()); | 149 EXPECT_TRUE(scan_results[0].long_name.empty()); |
| 146 EXPECT_TRUE(scan_results[0].short_name.empty()); | 150 EXPECT_TRUE(scan_results[0].short_name.empty()); |
| 147 | 151 |
| 148 EXPECT_EQ("000002", scan_results[1].network_id); | 152 EXPECT_EQ("000002", scan_results[1].network_id); |
| 149 EXPECT_EQ("available", scan_results[1].status); | 153 EXPECT_EQ("available", scan_results[1].status); |
| 150 EXPECT_EQ("Long Name", scan_results[1].long_name); | 154 EXPECT_EQ("Long Name", scan_results[1].long_name); |
| 151 EXPECT_TRUE(scan_results[1].short_name.empty()); | 155 EXPECT_TRUE(scan_results[1].short_name.empty()); |
| 152 EXPECT_TRUE(scan_results[1].technology.empty()); | 156 EXPECT_TRUE(scan_results[1].technology.empty()); |
| 153 } | 157 } |
| OLD | NEW |