Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/static_ip_parameters.h" |
| 6 | |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 7 | #include <base/strings/string_number_conversions.h> |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 8 | #include <chromeos/dbus/service_constants.h> |
| 9 | #include <gtest/gtest.h> |
| 10 | |
| 11 | #include "shill/ipconfig.h" |
| 12 | #include "shill/mock_store.h" |
| 13 | #include "shill/property_store.h" |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 14 | |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 15 | using base::IntToString; |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 16 | using std::string; |
| 17 | using std::vector; |
| 18 | using testing::_; |
| 19 | using testing::DoAll; |
| 20 | using testing::Return; |
| 21 | using testing::SetArgumentPointee; |
| 22 | using testing::StrictMock; |
| 23 | using testing::Test; |
| 24 | |
| 25 | namespace shill { |
| 26 | |
| 27 | namespace { |
Ben Chan | be0849f | 2014-08-15 23:02:32 -0700 | [diff] [blame] | 28 | |
| 29 | const char kAddress[] = "10.0.0.1"; |
| 30 | const char kGateway[] = "10.0.0.254"; |
| 31 | const int32_t kMtu = 512; |
| 32 | const char kNameServer0[] = "10.0.1.253"; |
| 33 | const char kNameServer1[] = "10.0.1.252"; |
| 34 | const char kNameServers[] = "10.0.1.253,10.0.1.252"; |
| 35 | const char kPeerAddress[] = "10.0.0.2"; |
| 36 | const int32_t kPrefixLen = 24; |
| 37 | |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 38 | } // namespace |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 39 | |
| 40 | class StaticIpParametersTest : public Test { |
| 41 | public: |
| 42 | StaticIpParametersTest() {} |
| 43 | |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 44 | void ExpectEmptyIPConfig() { |
| 45 | EXPECT_TRUE(ipconfig_props_.address.empty()); |
| 46 | EXPECT_TRUE(ipconfig_props_.gateway.empty()); |
Paul Stewart | 024a6c8 | 2015-01-23 14:59:40 -0800 | [diff] [blame^] | 47 | EXPECT_EQ(IPConfig::kUndefinedMTU, ipconfig_props_.mtu); |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 48 | EXPECT_TRUE(ipconfig_props_.dns_servers.empty()); |
| 49 | EXPECT_TRUE(ipconfig_props_.peer_address.empty()); |
| 50 | EXPECT_FALSE(ipconfig_props_.subnet_prefix); |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 51 | } |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 52 | // Modify an IP address string in some predictable way. There's no need |
| 53 | // for the output string to be valid from a networking perspective. |
| 54 | string VersionedAddress(const string &address, int version) { |
| 55 | string returned_address = address; |
| 56 | CHECK(returned_address.length()); |
| 57 | returned_address[returned_address.length() - 1] += version; |
| 58 | return returned_address; |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 59 | } |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 60 | void ExpectPopulatedIPConfigWithVersion(int version) { |
| 61 | EXPECT_EQ(VersionedAddress(kAddress, version), ipconfig_props_.address); |
| 62 | EXPECT_EQ(VersionedAddress(kGateway, version), ipconfig_props_.gateway); |
| 63 | EXPECT_EQ(kMtu + version, ipconfig_props_.mtu); |
| 64 | EXPECT_EQ(2, ipconfig_props_.dns_servers.size()); |
| 65 | EXPECT_EQ(VersionedAddress(kNameServer0, version), |
| 66 | ipconfig_props_.dns_servers[0]); |
| 67 | EXPECT_EQ(VersionedAddress(kNameServer1, version), |
| 68 | ipconfig_props_.dns_servers[1]); |
| 69 | EXPECT_EQ(VersionedAddress(kPeerAddress, version), |
| 70 | ipconfig_props_.peer_address); |
| 71 | EXPECT_EQ(kPrefixLen + version, ipconfig_props_.subnet_prefix); |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 72 | } |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 73 | void ExpectPopulatedIPConfig() { ExpectPopulatedIPConfigWithVersion(0); } |
| 74 | void ExpectPropertiesWithVersion(PropertyStore *store, |
| 75 | const string &property_prefix, |
| 76 | int version) { |
| 77 | string string_value; |
| 78 | Error unused_error; |
| 79 | EXPECT_TRUE(store->GetStringProperty(property_prefix + ".Address", |
| 80 | &string_value, |
| 81 | &unused_error)); |
| 82 | EXPECT_EQ(VersionedAddress(kAddress, version), string_value); |
| 83 | EXPECT_TRUE(store->GetStringProperty(property_prefix + ".Gateway", |
| 84 | &string_value, |
| 85 | &unused_error)); |
| 86 | EXPECT_EQ(VersionedAddress(kGateway, version), string_value); |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 87 | int32_t int_value; |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 88 | EXPECT_TRUE(store->GetInt32Property(property_prefix + ".Mtu", &int_value, |
| 89 | &unused_error)); |
| 90 | EXPECT_EQ(kMtu + version, int_value); |
| 91 | EXPECT_TRUE(store->GetStringProperty(property_prefix + ".NameServers", |
| 92 | &string_value, |
| 93 | &unused_error)); |
| 94 | EXPECT_EQ(VersionedAddress(kNameServer0, version) + "," + |
| 95 | VersionedAddress(kNameServer1, version), |
| 96 | string_value); |
| 97 | EXPECT_TRUE(store->GetStringProperty(property_prefix + ".PeerAddress", |
| 98 | &string_value, |
| 99 | &unused_error)); |
| 100 | EXPECT_EQ(VersionedAddress(kPeerAddress, version), string_value); |
| 101 | EXPECT_TRUE(store->GetInt32Property(property_prefix + ".Prefixlen", |
| 102 | &int_value, |
| 103 | &unused_error)); |
| 104 | EXPECT_EQ(kPrefixLen + version, int_value); |
| 105 | } |
| 106 | void ExpectProperties(PropertyStore *store, const string &property_prefix) { |
| 107 | ExpectPropertiesWithVersion(store, property_prefix, 0); |
| 108 | } |
| 109 | void PopulateIPConfig() { |
| 110 | ipconfig_props_.address = kAddress; |
| 111 | ipconfig_props_.gateway = kGateway; |
| 112 | ipconfig_props_.mtu = kMtu; |
| 113 | ipconfig_props_.dns_servers.push_back(kNameServer0); |
| 114 | ipconfig_props_.dns_servers.push_back(kNameServer1); |
| 115 | ipconfig_props_.peer_address = kPeerAddress; |
| 116 | ipconfig_props_.subnet_prefix = kPrefixLen; |
| 117 | } |
| 118 | void SetStaticPropertiesWithVersion(PropertyStore *store, int version) { |
| 119 | Error error; |
| 120 | store->SetStringProperty( |
| 121 | "StaticIP.Address", VersionedAddress(kAddress, version), &error); |
| 122 | store->SetStringProperty( |
| 123 | "StaticIP.Gateway", VersionedAddress(kGateway, version), &error); |
| 124 | store->SetInt32Property( |
| 125 | "StaticIP.Mtu", kMtu + version, &error); |
| 126 | store->SetStringProperty( |
| 127 | "StaticIP.NameServers", |
| 128 | VersionedAddress(kNameServer0, version) + "," + |
| 129 | VersionedAddress(kNameServer1, version), |
| 130 | &error); |
| 131 | store->SetStringProperty( |
| 132 | "StaticIP.PeerAddress", |
| 133 | VersionedAddress(kPeerAddress, version), |
| 134 | &error); |
| 135 | store->SetInt32Property("StaticIP.Prefixlen", kPrefixLen + version, &error); |
| 136 | } |
| 137 | void SetStaticProperties(PropertyStore *store) { |
| 138 | SetStaticPropertiesWithVersion(store, 0); |
| 139 | } |
Peter Qiu | 08bf508 | 2014-09-08 15:57:12 -0700 | [diff] [blame] | 140 | void SetStaticDictPropertiesWithVersion(PropertyStore *store, int version) { |
| 141 | KeyValueStore args; |
| 142 | args.SetString(kAddressProperty, VersionedAddress(kAddress, version)); |
| 143 | args.SetString(kGatewayProperty, VersionedAddress(kGateway, version)); |
| 144 | args.SetInt(kMtuProperty, kMtu + version); |
| 145 | vector<string> name_servers; |
| 146 | name_servers.push_back(VersionedAddress(kNameServer0, version)); |
| 147 | name_servers.push_back(VersionedAddress(kNameServer1, version)); |
| 148 | args.SetStrings(kNameServersProperty, name_servers); |
| 149 | args.SetString(kPeerAddressProperty, |
| 150 | VersionedAddress(kPeerAddress, version)); |
| 151 | args.SetInt(kPrefixlenProperty, kPrefixLen + version); |
| 152 | Error error; |
| 153 | store->SetKeyValueStoreProperty(kStaticIPConfigProperty, args, &error); |
| 154 | } |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 155 | |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 156 | protected: |
| 157 | StaticIPParameters static_params_; |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 158 | IPConfig::Properties ipconfig_props_; |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | TEST_F(StaticIpParametersTest, InitState) { |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 162 | ExpectEmptyIPConfig(); |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 163 | |
| 164 | // Applying an empty set of parameters on an empty set of properties should |
| 165 | // be a no-op. |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 166 | static_params_.ApplyTo(&ipconfig_props_); |
| 167 | ExpectEmptyIPConfig(); |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | TEST_F(StaticIpParametersTest, ApplyEmptyParameters) { |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 171 | PopulateIPConfig(); |
| 172 | static_params_.ApplyTo(&ipconfig_props_); |
| 173 | ExpectPopulatedIPConfig(); |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | TEST_F(StaticIpParametersTest, ControlInterface) { |
| 177 | PropertyStore store; |
| 178 | static_params_.PlumbPropertyStore(&store); |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 179 | SetStaticProperties(&store); |
| 180 | static_params_.ApplyTo(&ipconfig_props_); |
| 181 | ExpectPopulatedIPConfig(); |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 182 | |
| 183 | EXPECT_TRUE(static_params_.ContainsAddress()); |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 184 | Error unused_error; |
| 185 | store.ClearProperty("StaticIP.Address", &unused_error); |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 186 | EXPECT_FALSE(static_params_.ContainsAddress()); |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 187 | store.ClearProperty("StaticIP.Mtu", &unused_error); |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 188 | IPConfig::Properties props; |
| 189 | const string kTestAddress("test_address"); |
| 190 | props.address = kTestAddress; |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 191 | const int32_t kTestMtu = 256; |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 192 | props.mtu = kTestMtu; |
| 193 | static_params_.ApplyTo(&props); |
| 194 | EXPECT_EQ(kTestAddress, props.address); |
| 195 | EXPECT_EQ(kTestMtu, props.mtu); |
| 196 | |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 197 | { |
| 198 | Error error; |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 199 | EXPECT_FALSE(store.GetStringProperty("StaticIP.Address", nullptr, &error)); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 200 | EXPECT_EQ(Error::kNotFound, error.type()); |
| 201 | } |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 202 | string string_value; |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 203 | EXPECT_TRUE(store.GetStringProperty("StaticIP.Gateway", &string_value, |
| 204 | &unused_error)); |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 205 | EXPECT_EQ(kGateway, string_value); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 206 | { |
| 207 | Error error; |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 208 | EXPECT_FALSE(store.GetInt32Property("StaticIP.Mtu", nullptr, &error)); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 209 | EXPECT_EQ(Error::kNotFound, error.type()); |
| 210 | } |
| 211 | EXPECT_TRUE(store.GetStringProperty("StaticIP.NameServers", &string_value, |
| 212 | &unused_error)); |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 213 | EXPECT_EQ(kNameServers, string_value); |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 214 | EXPECT_TRUE(store.GetStringProperty("StaticIP.PeerAddress", &string_value, |
| 215 | &unused_error)); |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 216 | EXPECT_EQ(kPeerAddress, string_value); |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 217 | int32_t int_value; |
Paul Stewart | e6e8e49 | 2013-01-17 11:00:50 -0800 | [diff] [blame] | 218 | EXPECT_TRUE(store.GetInt32Property("StaticIP.Prefixlen", &int_value, |
| 219 | &unused_error)); |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 220 | EXPECT_EQ(kPrefixLen, int_value); |
| 221 | } |
| 222 | |
| 223 | TEST_F(StaticIpParametersTest, Profile) { |
| 224 | StrictMock<MockStore> store; |
| 225 | const string kID = "storage_id"; |
| 226 | EXPECT_CALL(store, GetString(kID, "StaticIP.Address", _)) |
| 227 | .WillOnce(DoAll(SetArgumentPointee<2>(string(kAddress)), Return(true))); |
| 228 | EXPECT_CALL(store, GetString(kID, "StaticIP.Gateway", _)) |
| 229 | .WillOnce(DoAll(SetArgumentPointee<2>(string(kGateway)), Return(true))); |
| 230 | EXPECT_CALL(store, GetInt(kID, "StaticIP.Mtu", _)) |
| 231 | .WillOnce(DoAll(SetArgumentPointee<2>(kMtu), Return(true))); |
| 232 | EXPECT_CALL(store, GetString(kID, "StaticIP.NameServers", _)) |
| 233 | .WillOnce(DoAll(SetArgumentPointee<2>(string(kNameServers)), |
| 234 | Return(true))); |
| 235 | EXPECT_CALL(store, GetString(kID, "StaticIP.PeerAddress", _)) |
| 236 | .WillOnce(DoAll(SetArgumentPointee<2>(string(kPeerAddress)), |
| 237 | Return(true))); |
| 238 | EXPECT_CALL(store, GetInt(kID, "StaticIP.Prefixlen", _)) |
| 239 | .WillOnce(DoAll(SetArgumentPointee<2>(kPrefixLen), Return(true))); |
| 240 | static_params_.Load(&store, kID); |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 241 | static_params_.ApplyTo(&ipconfig_props_); |
| 242 | ExpectPopulatedIPConfig(); |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 243 | |
| 244 | EXPECT_CALL(store, SetString(kID, "StaticIP.Address", kAddress)) |
| 245 | .WillOnce(Return(true)); |
| 246 | EXPECT_CALL(store, SetString(kID, "StaticIP.Gateway", kGateway)) |
| 247 | .WillOnce(Return(true)); |
| 248 | EXPECT_CALL(store, SetInt(kID, "StaticIP.Mtu", kMtu)) |
| 249 | .WillOnce(Return(true)); |
| 250 | EXPECT_CALL(store, SetString(kID, "StaticIP.NameServers", kNameServers)) |
| 251 | .WillOnce(Return(true)); |
| 252 | EXPECT_CALL(store, SetString(kID, "StaticIP.PeerAddress", kPeerAddress)) |
| 253 | .WillOnce(Return(true)); |
| 254 | EXPECT_CALL(store, SetInt(kID, "StaticIP.Prefixlen", kPrefixLen)) |
| 255 | .WillOnce(Return(true)); |
| 256 | static_params_.Save(&store, kID); |
| 257 | } |
| 258 | |
Paul Stewart | def189e | 2012-08-02 20:12:09 -0700 | [diff] [blame] | 259 | TEST_F(StaticIpParametersTest, SavedParameters) { |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 260 | // Calling RestoreTo() when no parameters are set should not crash or |
| 261 | // add any entries. |
| 262 | static_params_.RestoreTo(&ipconfig_props_); |
| 263 | ExpectEmptyIPConfig(); |
Paul Stewart | def189e | 2012-08-02 20:12:09 -0700 | [diff] [blame] | 264 | |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 265 | PopulateIPConfig(); |
| 266 | PropertyStore static_params_props; |
| 267 | static_params_.PlumbPropertyStore(&static_params_props); |
| 268 | SetStaticPropertiesWithVersion(&static_params_props, 1); |
| 269 | static_params_.ApplyTo(&ipconfig_props_); |
Paul Stewart | def189e | 2012-08-02 20:12:09 -0700 | [diff] [blame] | 270 | |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 271 | // The version 0 properties in |ipconfig_props_| are now in SavedIP.* |
| 272 | // properties, while the version 1 StaticIP parameters are now in |
| 273 | // |ipconfig_props_|. |
| 274 | ExpectPropertiesWithVersion(&static_params_props, "SavedIP", 0); |
| 275 | ExpectPopulatedIPConfigWithVersion(1); |
Paul Stewart | def189e | 2012-08-02 20:12:09 -0700 | [diff] [blame] | 276 | |
Paul Stewart | 8223653 | 2013-12-10 15:33:11 -0800 | [diff] [blame] | 277 | // Clear all "StaticIP" parameters. |
| 278 | static_params_.args_.Clear(); |
| 279 | |
| 280 | // Another ApplyTo() call rotates the version 1 properties in |
| 281 | // |ipconfig_props_| over to SavedIP.*. Since there are no StaticIP |
| 282 | // parameters, |ipconfig_props_| should remain populated with version 1 |
| 283 | // parameters. |
| 284 | static_params_.ApplyTo(&ipconfig_props_); |
| 285 | ExpectPropertiesWithVersion(&static_params_props, "SavedIP", 1); |
| 286 | ExpectPopulatedIPConfigWithVersion(1); |
| 287 | |
| 288 | // Reset |ipconfig_props_| to version 0. |
| 289 | PopulateIPConfig(); |
| 290 | |
| 291 | // A RestoreTo() call moves the version 1 "SavedIP" parameters into |
| 292 | // |ipconfig_props_|. |
| 293 | SetStaticPropertiesWithVersion(&static_params_props, 2); |
| 294 | static_params_.RestoreTo(&ipconfig_props_); |
| 295 | ExpectPopulatedIPConfigWithVersion(1); |
| 296 | |
| 297 | // All "SavedIP" parameters should be cleared. |
| 298 | EXPECT_TRUE(static_params_.saved_args_.IsEmpty()); |
| 299 | |
| 300 | // Static IP parameters should be unchanged. |
| 301 | ExpectPropertiesWithVersion(&static_params_props, "StaticIP", 2); |
Paul Stewart | def189e | 2012-08-02 20:12:09 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Peter Qiu | 08bf508 | 2014-09-08 15:57:12 -0700 | [diff] [blame] | 304 | TEST_F(StaticIpParametersTest, SavedParametersDict) { |
| 305 | // Calling RestoreTo() when no parameters are set should not crash or |
| 306 | // add any entries. |
| 307 | static_params_.RestoreTo(&ipconfig_props_); |
| 308 | ExpectEmptyIPConfig(); |
| 309 | |
| 310 | PopulateIPConfig(); |
| 311 | PropertyStore static_params_props; |
| 312 | static_params_.PlumbPropertyStore(&static_params_props); |
| 313 | SetStaticDictPropertiesWithVersion(&static_params_props, 1); |
| 314 | static_params_.ApplyTo(&ipconfig_props_); |
| 315 | |
| 316 | // The version 0 properties in |ipconfig_props_| are now in SavedIP.* |
| 317 | // properties, while the version 1 StaticIP parameters are now in |
| 318 | // |ipconfig_props_|. |
| 319 | ExpectPropertiesWithVersion(&static_params_props, "SavedIP", 0); |
| 320 | ExpectPopulatedIPConfigWithVersion(1); |
| 321 | |
| 322 | // Clear all "StaticIP" parameters. |
| 323 | static_params_.args_.Clear(); |
| 324 | |
| 325 | // Another ApplyTo() call rotates the version 1 properties in |
| 326 | // |ipconfig_props_| over to SavedIP.*. Since there are no StaticIP |
| 327 | // parameters, |ipconfig_props_| should remain populated with version 1 |
| 328 | // parameters. |
| 329 | static_params_.ApplyTo(&ipconfig_props_); |
| 330 | ExpectPropertiesWithVersion(&static_params_props, "SavedIP", 1); |
| 331 | ExpectPopulatedIPConfigWithVersion(1); |
| 332 | |
| 333 | // Reset |ipconfig_props_| to version 0. |
| 334 | PopulateIPConfig(); |
| 335 | |
| 336 | // A RestoreTo() call moves the version 1 "SavedIP" parameters into |
| 337 | // |ipconfig_props_|. |
| 338 | SetStaticDictPropertiesWithVersion(&static_params_props, 2); |
| 339 | static_params_.RestoreTo(&ipconfig_props_); |
| 340 | ExpectPopulatedIPConfigWithVersion(1); |
| 341 | |
| 342 | // All "SavedIP" parameters should be cleared. |
| 343 | EXPECT_TRUE(static_params_.saved_args_.IsEmpty()); |
| 344 | |
| 345 | // Static IP parameters should be unchanged. |
| 346 | ExpectPropertiesWithVersion(&static_params_props, "StaticIP", 2); |
| 347 | } |
| 348 | |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 349 | } // namespace shill |