Chris Masone | 7156c92 | 2011-08-23 20:36:21 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 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 | 2176a88 | 2011-09-14 22:29:15 -0700 | [diff] [blame^] | 27 | : profile_(new DefaultProfile(control_interface(), |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 28 | manager(), |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 29 | FilePath(kTestStoragePath), |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 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 | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 36 | static const char kTestStoragePath[]; |
| 37 | |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 38 | ProfileRefPtr profile_; |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 39 | Manager::Properties properties_; |
| 40 | }; |
| 41 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 42 | const char DefaultProfileTest::kTestStoragePath[] = "/no/where"; |
| 43 | |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 44 | TEST_F(DefaultProfileTest, GetProperties) { |
| 45 | Error error(Error::kInvalidProperty, ""); |
| 46 | { |
| 47 | map<string, ::DBus::Variant> props; |
| 48 | ::DBus::Error dbus_error; |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 49 | DBusAdaptor::GetProperties(profile_->store(), &props, &dbus_error); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 50 | ASSERT_FALSE(props.find(flimflam::kOfflineModeProperty) == props.end()); |
| 51 | EXPECT_FALSE(props[flimflam::kOfflineModeProperty].reader().get_bool()); |
| 52 | } |
| 53 | properties_.offline_mode = true; |
| 54 | { |
| 55 | map<string, ::DBus::Variant> props; |
| 56 | ::DBus::Error dbus_error; |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 57 | DBusAdaptor::GetProperties(profile_->store(), &props, &dbus_error); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 58 | ASSERT_FALSE(props.find(flimflam::kOfflineModeProperty) == props.end()); |
| 59 | EXPECT_TRUE(props[flimflam::kOfflineModeProperty].reader().get_bool()); |
| 60 | } |
| 61 | { |
| 62 | Error error(Error::kInvalidProperty, ""); |
| 63 | EXPECT_FALSE( |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 64 | profile_->store()->SetBoolProperty(flimflam::kOfflineModeProperty, |
| 65 | true, |
| 66 | &error)); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame] | 70 | TEST_F(DefaultProfileTest, GetStoragePath) { |
| 71 | FilePath path; |
| 72 | EXPECT_TRUE(profile_->GetStoragePath(&path)); |
| 73 | EXPECT_EQ(string(kTestStoragePath) + "/default.profile", path.value()); |
| 74 | } |
| 75 | |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 76 | } // namespace shill |