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 | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 27 | : profile_(new DefaultProfile(&control_interface_, |
| 28 | &glib_, |
| 29 | &manager_, |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame^] | 30 | FilePath(kTestStoragePath), |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 31 | properties_)) { |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 32 | } |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 33 | |
| 34 | virtual ~DefaultProfileTest() {} |
| 35 | |
| 36 | protected: |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame^] | 37 | static const char kTestStoragePath[]; |
| 38 | |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 39 | ProfileRefPtr profile_; |
Darin Petkov | a476682 | 2011-07-07 10:42:22 -0700 | [diff] [blame] | 40 | GLib glib_; |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 41 | Manager::Properties properties_; |
| 42 | }; |
| 43 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame^] | 44 | const char DefaultProfileTest::kTestStoragePath[] = "/no/where"; |
| 45 | |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 46 | TEST_F(DefaultProfileTest, GetProperties) { |
| 47 | Error error(Error::kInvalidProperty, ""); |
| 48 | { |
| 49 | map<string, ::DBus::Variant> props; |
| 50 | ::DBus::Error dbus_error; |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 51 | DBusAdaptor::GetProperties(profile_->store(), &props, &dbus_error); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 52 | ASSERT_FALSE(props.find(flimflam::kOfflineModeProperty) == props.end()); |
| 53 | EXPECT_FALSE(props[flimflam::kOfflineModeProperty].reader().get_bool()); |
| 54 | } |
| 55 | properties_.offline_mode = true; |
| 56 | { |
| 57 | map<string, ::DBus::Variant> props; |
| 58 | ::DBus::Error dbus_error; |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 59 | DBusAdaptor::GetProperties(profile_->store(), &props, &dbus_error); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 60 | ASSERT_FALSE(props.find(flimflam::kOfflineModeProperty) == props.end()); |
| 61 | EXPECT_TRUE(props[flimflam::kOfflineModeProperty].reader().get_bool()); |
| 62 | } |
| 63 | { |
| 64 | Error error(Error::kInvalidProperty, ""); |
| 65 | EXPECT_FALSE( |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 66 | profile_->store()->SetBoolProperty(flimflam::kOfflineModeProperty, |
| 67 | true, |
| 68 | &error)); |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
Chris Masone | 2ae797d | 2011-08-23 20:41:00 -0700 | [diff] [blame^] | 72 | TEST_F(DefaultProfileTest, GetStoragePath) { |
| 73 | FilePath path; |
| 74 | EXPECT_TRUE(profile_->GetStoragePath(&path)); |
| 75 | EXPECT_EQ(string(kTestStoragePath) + "/default.profile", path.value()); |
| 76 | } |
| 77 | |
Chris Masone | 88cbd5f | 2011-07-03 14:30:04 -0700 | [diff] [blame] | 78 | } // namespace shill |