| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/values.h" | 6 #include "base/values.h" |
| 7 #include "chromeos/dbus/flimflam_client_unittest_base.h" | 7 #include "chromeos/dbus/shill_client_unittest_base.h" |
| 8 #include "chromeos/dbus/flimflam_ipconfig_client.h" | 8 #include "chromeos/dbus/shill_ipconfig_client.h" |
| 9 #include "dbus/message.h" | 9 #include "dbus/message.h" |
| 10 #include "dbus/values_util.h" | 10 #include "dbus/values_util.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/cros_system_api/dbus/service_constants.h" | 12 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 13 | 13 |
| 14 namespace chromeos { | 14 namespace chromeos { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const char kExampleIPConfigPath[] = "/foo/bar"; | 18 const char kExampleIPConfigPath[] = "/foo/bar"; |
| 19 | 19 |
| 20 } // namespace | 20 } // namespace |
| 21 | 21 |
| 22 class FlimflamIPConfigClientTest : public FlimflamClientUnittestBase { | 22 class ShillIPConfigClientTest : public ShillClientUnittestBase { |
| 23 public: | 23 public: |
| 24 FlimflamIPConfigClientTest() | 24 ShillIPConfigClientTest() |
| 25 : FlimflamClientUnittestBase( | 25 : ShillClientUnittestBase( |
| 26 flimflam::kFlimflamIPConfigInterface, | 26 flimflam::kFlimflamIPConfigInterface, |
| 27 dbus::ObjectPath(kExampleIPConfigPath)) { | 27 dbus::ObjectPath(kExampleIPConfigPath)) { |
| 28 } | 28 } |
| 29 | 29 |
| 30 virtual void SetUp() { | 30 virtual void SetUp() { |
| 31 FlimflamClientUnittestBase::SetUp(); | 31 ShillClientUnittestBase::SetUp(); |
| 32 // Create a client with the mock bus. | 32 // Create a client with the mock bus. |
| 33 client_.reset(FlimflamIPConfigClient::Create( | 33 client_.reset(ShillIPConfigClient::Create( |
| 34 REAL_DBUS_CLIENT_IMPLEMENTATION, mock_bus_)); | 34 REAL_DBUS_CLIENT_IMPLEMENTATION, mock_bus_)); |
| 35 // Run the message loop to run the signal connection result callback. | 35 // Run the message loop to run the signal connection result callback. |
| 36 message_loop_.RunAllPending(); | 36 message_loop_.RunAllPending(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 virtual void TearDown() { | 39 virtual void TearDown() { |
| 40 FlimflamClientUnittestBase::TearDown(); | 40 ShillClientUnittestBase::TearDown(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 protected: | 43 protected: |
| 44 scoped_ptr<FlimflamIPConfigClient> client_; | 44 scoped_ptr<ShillIPConfigClient> client_; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 TEST_F(FlimflamIPConfigClientTest, PropertyChanged) { | 47 TEST_F(ShillIPConfigClientTest, PropertyChanged) { |
| 48 // Create a signal. | 48 // Create a signal. |
| 49 const base::FundamentalValue kConnected(true); | 49 const base::FundamentalValue kConnected(true); |
| 50 dbus::Signal signal(flimflam::kFlimflamIPConfigInterface, | 50 dbus::Signal signal(flimflam::kFlimflamIPConfigInterface, |
| 51 flimflam::kMonitorPropertyChanged); | 51 flimflam::kMonitorPropertyChanged); |
| 52 dbus::MessageWriter writer(&signal); | 52 dbus::MessageWriter writer(&signal); |
| 53 writer.AppendString(flimflam::kConnectedProperty); | 53 writer.AppendString(flimflam::kConnectedProperty); |
| 54 dbus::AppendBasicTypeValueDataAsVariant(&writer, kConnected); | 54 dbus::AppendBasicTypeValueDataAsVariant(&writer, kConnected); |
| 55 | 55 |
| 56 // Set expectations. | 56 // Set expectations. |
| 57 client_->SetPropertyChangedHandler(dbus::ObjectPath(kExampleIPConfigPath), | 57 client_->SetPropertyChangedHandler(dbus::ObjectPath(kExampleIPConfigPath), |
| 58 base::Bind(&ExpectPropertyChanged, | 58 base::Bind(&ExpectPropertyChanged, |
| 59 flimflam::kConnectedProperty, | 59 flimflam::kConnectedProperty, |
| 60 &kConnected)); | 60 &kConnected)); |
| 61 // Run the signal callback. | 61 // Run the signal callback. |
| 62 SendPropertyChangedSignal(&signal); | 62 SendPropertyChangedSignal(&signal); |
| 63 | 63 |
| 64 // Reset the handler. | 64 // Reset the handler. |
| 65 client_->ResetPropertyChangedHandler(dbus::ObjectPath(kExampleIPConfigPath)); | 65 client_->ResetPropertyChangedHandler(dbus::ObjectPath(kExampleIPConfigPath)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 TEST_F(FlimflamIPConfigClientTest, GetProperties) { | 68 TEST_F(ShillIPConfigClientTest, GetProperties) { |
| 69 const char kAddress[] = "address"; | 69 const char kAddress[] = "address"; |
| 70 const int32 kMtu = 68; | 70 const int32 kMtu = 68; |
| 71 | 71 |
| 72 // Create response. | 72 // Create response. |
| 73 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 73 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 74 dbus::MessageWriter writer(response.get()); | 74 dbus::MessageWriter writer(response.get()); |
| 75 dbus::MessageWriter array_writer(NULL); | 75 dbus::MessageWriter array_writer(NULL); |
| 76 writer.OpenArray("{sv}", &array_writer); | 76 writer.OpenArray("{sv}", &array_writer); |
| 77 dbus::MessageWriter entry_writer(NULL); | 77 dbus::MessageWriter entry_writer(NULL); |
| 78 // Append address. | 78 // Append address. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 98 PrepareForMethodCall(flimflam::kGetPropertiesFunction, | 98 PrepareForMethodCall(flimflam::kGetPropertiesFunction, |
| 99 base::Bind(&ExpectNoArgument), | 99 base::Bind(&ExpectNoArgument), |
| 100 response.get()); | 100 response.get()); |
| 101 // Call method. | 101 // Call method. |
| 102 client_->GetProperties(dbus::ObjectPath(kExampleIPConfigPath), | 102 client_->GetProperties(dbus::ObjectPath(kExampleIPConfigPath), |
| 103 base::Bind(&ExpectDictionaryValueResult, &value)); | 103 base::Bind(&ExpectDictionaryValueResult, &value)); |
| 104 // Run the message loop. | 104 // Run the message loop. |
| 105 message_loop_.RunAllPending(); | 105 message_loop_.RunAllPending(); |
| 106 } | 106 } |
| 107 | 107 |
| 108 TEST_F(FlimflamIPConfigClientTest, CallGetPropertiesAndBlock) { | 108 TEST_F(ShillIPConfigClientTest, CallGetPropertiesAndBlock) { |
| 109 const char kAddress[] = "address"; | 109 const char kAddress[] = "address"; |
| 110 const int32 kMtu = 68; | 110 const int32 kMtu = 68; |
| 111 | 111 |
| 112 // Create response. | 112 // Create response. |
| 113 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 113 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 114 dbus::MessageWriter writer(response.get()); | 114 dbus::MessageWriter writer(response.get()); |
| 115 dbus::MessageWriter array_writer(NULL); | 115 dbus::MessageWriter array_writer(NULL); |
| 116 writer.OpenArray("{sv}", &array_writer); | 116 writer.OpenArray("{sv}", &array_writer); |
| 117 dbus::MessageWriter entry_writer(NULL); | 117 dbus::MessageWriter entry_writer(NULL); |
| 118 // Append address. | 118 // Append address. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 139 response.get()); | 139 response.get()); |
| 140 // Call method. | 140 // Call method. |
| 141 scoped_ptr<base::DictionaryValue> result( | 141 scoped_ptr<base::DictionaryValue> result( |
| 142 client_->CallGetPropertiesAndBlock( | 142 client_->CallGetPropertiesAndBlock( |
| 143 dbus::ObjectPath(kExampleIPConfigPath))); | 143 dbus::ObjectPath(kExampleIPConfigPath))); |
| 144 | 144 |
| 145 ASSERT_TRUE(result.get()); | 145 ASSERT_TRUE(result.get()); |
| 146 EXPECT_TRUE(result->Equals(&value)); | 146 EXPECT_TRUE(result->Equals(&value)); |
| 147 } | 147 } |
| 148 | 148 |
| 149 TEST_F(FlimflamIPConfigClientTest, SetProperty) { | 149 TEST_F(ShillIPConfigClientTest, SetProperty) { |
| 150 const char kAddress[] = "address"; | 150 const char kAddress[] = "address"; |
| 151 | 151 |
| 152 // Create response. | 152 // Create response. |
| 153 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 153 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 154 | 154 |
| 155 // Set expectations. | 155 // Set expectations. |
| 156 base::StringValue value(kAddress); | 156 base::StringValue value(kAddress); |
| 157 PrepareForMethodCall(flimflam::kSetPropertyFunction, | 157 PrepareForMethodCall(flimflam::kSetPropertyFunction, |
| 158 base::Bind(&ExpectStringAndValueArguments, | 158 base::Bind(&ExpectStringAndValueArguments, |
| 159 flimflam::kAddressProperty, | 159 flimflam::kAddressProperty, |
| 160 &value), | 160 &value), |
| 161 response.get()); | 161 response.get()); |
| 162 // Call method. | 162 // Call method. |
| 163 client_->SetProperty(dbus::ObjectPath(kExampleIPConfigPath), | 163 client_->SetProperty(dbus::ObjectPath(kExampleIPConfigPath), |
| 164 flimflam::kAddressProperty, | 164 flimflam::kAddressProperty, |
| 165 value, | 165 value, |
| 166 base::Bind(&ExpectNoResultValue)); | 166 base::Bind(&ExpectNoResultValue)); |
| 167 // Run the message loop. | 167 // Run the message loop. |
| 168 message_loop_.RunAllPending(); | 168 message_loop_.RunAllPending(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 TEST_F(FlimflamIPConfigClientTest, ClearProperty) { | 171 TEST_F(ShillIPConfigClientTest, ClearProperty) { |
| 172 // Create response. | 172 // Create response. |
| 173 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 173 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 174 | 174 |
| 175 // Set expectations. | 175 // Set expectations. |
| 176 PrepareForMethodCall(flimflam::kClearPropertyFunction, | 176 PrepareForMethodCall(flimflam::kClearPropertyFunction, |
| 177 base::Bind(&ExpectStringArgument, | 177 base::Bind(&ExpectStringArgument, |
| 178 flimflam::kAddressProperty), | 178 flimflam::kAddressProperty), |
| 179 response.get()); | 179 response.get()); |
| 180 // Call method. | 180 // Call method. |
| 181 client_->ClearProperty(dbus::ObjectPath(kExampleIPConfigPath), | 181 client_->ClearProperty(dbus::ObjectPath(kExampleIPConfigPath), |
| 182 flimflam::kAddressProperty, | 182 flimflam::kAddressProperty, |
| 183 base::Bind(&ExpectNoResultValue)); | 183 base::Bind(&ExpectNoResultValue)); |
| 184 // Run the message loop. | 184 // Run the message loop. |
| 185 message_loop_.RunAllPending(); | 185 message_loop_.RunAllPending(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 TEST_F(FlimflamIPConfigClientTest, Remove) { | 188 TEST_F(ShillIPConfigClientTest, Remove) { |
| 189 // Create response. | 189 // Create response. |
| 190 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 190 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 191 | 191 |
| 192 // Set expectations. | 192 // Set expectations. |
| 193 PrepareForMethodCall(flimflam::kRemoveConfigFunction, | 193 PrepareForMethodCall(flimflam::kRemoveConfigFunction, |
| 194 base::Bind(&ExpectNoArgument), | 194 base::Bind(&ExpectNoArgument), |
| 195 response.get()); | 195 response.get()); |
| 196 // Call method. | 196 // Call method. |
| 197 client_->Remove(dbus::ObjectPath(kExampleIPConfigPath), | 197 client_->Remove(dbus::ObjectPath(kExampleIPConfigPath), |
| 198 base::Bind(&ExpectNoResultValue)); | 198 base::Bind(&ExpectNoResultValue)); |
| 199 | 199 |
| 200 // Run the message loop. | 200 // Run the message loop. |
| 201 message_loop_.RunAllPending(); | 201 message_loop_.RunAllPending(); |
| 202 } | 202 } |
| 203 | 203 |
| 204 TEST_F(FlimflamIPConfigClientTest, CallRemoveAndBlock) { | 204 TEST_F(ShillIPConfigClientTest, CallRemoveAndBlock) { |
| 205 // Create response. | 205 // Create response. |
| 206 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); | 206 scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty()); |
| 207 | 207 |
| 208 // Set expectations. | 208 // Set expectations. |
| 209 PrepareForMethodCall(flimflam::kRemoveConfigFunction, | 209 PrepareForMethodCall(flimflam::kRemoveConfigFunction, |
| 210 base::Bind(&ExpectNoArgument), | 210 base::Bind(&ExpectNoArgument), |
| 211 response.get()); | 211 response.get()); |
| 212 // Call method. | 212 // Call method. |
| 213 EXPECT_TRUE(client_->CallRemoveAndBlock( | 213 EXPECT_TRUE(client_->CallRemoveAndBlock( |
| 214 dbus::ObjectPath(kExampleIPConfigPath))); | 214 dbus::ObjectPath(kExampleIPConfigPath))); |
| 215 } | 215 } |
| 216 | 216 |
| 217 } // namespace chromeos | 217 } // namespace chromeos |
| OLD | NEW |