blob: 79e75e7eb58afc6e4a45c67ea240bbfeb3e0f3df [file] [log] [blame]
Chris Masone7156c922011-08-23 20:36:21 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
Chris Masone88cbd5f2011-07-03 14:30:04 -07002// 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
18using std::map;
19using std::string;
20using ::testing::_;
21
22namespace shill {
23
24class DefaultProfileTest : public PropertyStoreTest {
25 public:
Chris Masone7aa5f902011-07-11 11:13:35 -070026 DefaultProfileTest()
Chris Masone6791a432011-07-12 13:23:19 -070027 : profile_(new DefaultProfile(&control_interface_,
Chris Masone9d779932011-08-25 16:33:41 -070028 manager(),
Chris Masone2ae797d2011-08-23 20:41:00 -070029 FilePath(kTestStoragePath),
Chris Masone6791a432011-07-12 13:23:19 -070030 properties_)) {
Chris Masone7aa5f902011-07-11 11:13:35 -070031 }
Chris Masone88cbd5f2011-07-03 14:30:04 -070032
33 virtual ~DefaultProfileTest() {}
34
35 protected:
Chris Masone2ae797d2011-08-23 20:41:00 -070036 static const char kTestStoragePath[];
37
Chris Masone7aa5f902011-07-11 11:13:35 -070038 ProfileRefPtr profile_;
Chris Masone88cbd5f2011-07-03 14:30:04 -070039 Manager::Properties properties_;
40};
41
Chris Masone2ae797d2011-08-23 20:41:00 -070042const char DefaultProfileTest::kTestStoragePath[] = "/no/where";
43
Chris Masone88cbd5f2011-07-03 14:30:04 -070044TEST_F(DefaultProfileTest, GetProperties) {
45 Error error(Error::kInvalidProperty, "");
46 {
47 map<string, ::DBus::Variant> props;
48 ::DBus::Error dbus_error;
Chris Masone7aa5f902011-07-11 11:13:35 -070049 DBusAdaptor::GetProperties(profile_->store(), &props, &dbus_error);
Chris Masone88cbd5f2011-07-03 14:30:04 -070050 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 Masone7aa5f902011-07-11 11:13:35 -070057 DBusAdaptor::GetProperties(profile_->store(), &props, &dbus_error);
Chris Masone88cbd5f2011-07-03 14:30:04 -070058 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 Masone7aa5f902011-07-11 11:13:35 -070064 profile_->store()->SetBoolProperty(flimflam::kOfflineModeProperty,
65 true,
66 &error));
Chris Masone88cbd5f2011-07-03 14:30:04 -070067 }
68}
69
Chris Masone2ae797d2011-08-23 20:41:00 -070070TEST_F(DefaultProfileTest, GetStoragePath) {
71 FilePath path;
72 EXPECT_TRUE(profile_->GetStoragePath(&path));
73 EXPECT_EQ(string(kTestStoragePath) + "/default.profile", path.value());
74}
75
Chris Masone88cbd5f2011-07-03 14:30:04 -070076} // namespace shill