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