Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 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/default_profile.h" |
| 6 | |
| 7 | #include <map> |
| 8 | #include <string> |
| 9 | |
| 10 | #include <chromeos/dbus/service_constants.h> |
| 11 | #include <gtest/gtest.h> |
| 12 | #include <gmock/gmock.h> |
| 13 | |
| 14 | #include "shill/manager.h" |
| 15 | #include "shill/mock_control.h" |
| 16 | #include "shill/property_store_unittest.h" |
| 17 | |
| 18 | using std::map; |
| 19 | using std::string; |
| 20 | using ::testing::_; |
| 21 | |
| 22 | namespace shill { |
| 23 | |
| 24 | class DefaultProfileTest : public PropertyStoreTest { |
| 25 | public: |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 26 | DefaultProfileTest() |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 27 | : profile_(new DefaultProfile(&control_interface_, |
| 28 | &glib_, |
| 29 | &manager_, |
| 30 | properties_)) { |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 31 | } |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 32 | |
| 33 | virtual ~DefaultProfileTest() {} |
| 34 | |
| 35 | protected: |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 36 | ProfileRefPtr profile_; |
Darin Petkov | a476682 | 2011-07-07 10:42:22 -0700 | [diff] [blame] | 37 | GLib glib_; |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 38 | Manager::Properties properties_; |
| 39 | }; |
| 40 | |
| 41 | TEST_F(DefaultProfileTest, GetProperties) { |
| 42 | Error error(Error::kInvalidProperty, ""); |
| 43 | { |
| 44 | map<string, ::DBus::Variant> props; |
| 45 | ::DBus::Error dbus_error; |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 46 | DBusAdaptor::GetProperties(profile_->store(), &props, &dbus_error); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 47 | ASSERT_FALSE(props.find(flimflam::kOfflineModeProperty) == props.end()); |
| 48 | EXPECT_FALSE(props[flimflam::kOfflineModeProperty].reader().get_bool()); |
| 49 | } |
| 50 | properties_.offline_mode = true; |
| 51 | { |
| 52 | map<string, ::DBus::Variant> props; |
| 53 | ::DBus::Error dbus_error; |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 54 | DBusAdaptor::GetProperties(profile_->store(), &props, &dbus_error); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 55 | ASSERT_FALSE(props.find(flimflam::kOfflineModeProperty) == props.end()); |
| 56 | EXPECT_TRUE(props[flimflam::kOfflineModeProperty].reader().get_bool()); |
| 57 | } |
| 58 | { |
| 59 | Error error(Error::kInvalidProperty, ""); |
| 60 | EXPECT_FALSE( |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 61 | profile_->store()->SetBoolProperty(flimflam::kOfflineModeProperty, |
| 62 | true, |
| 63 | &error)); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 64 | } |
| 65 | } |
| 66 | |
| 67 | } // namespace shill |