blob: 5828875a8fc77e6ce6d39d0545c8550775a71b62 [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_,
28 &glib_,
29 &manager_,
Chris Masone2ae797d2011-08-23 20:41:00 -070030 FilePath(kTestStoragePath),
Chris Masone6791a432011-07-12 13:23:19 -070031 properties_)) {
Chris Masone7aa5f902011-07-11 11:13:35 -070032 }
Chris Masone88cbd5f2011-07-03 14:30:04 -070033
34 virtual ~DefaultProfileTest() {}
35
36 protected:
Chris Masone2ae797d2011-08-23 20:41:00 -070037 static const char kTestStoragePath[];
38
Chris Masone7aa5f902011-07-11 11:13:35 -070039 ProfileRefPtr profile_;
Darin Petkova4766822011-07-07 10:42:22 -070040 GLib glib_;
Chris Masone88cbd5f2011-07-03 14:30:04 -070041 Manager::Properties properties_;
42};
43
Chris Masone2ae797d2011-08-23 20:41:00 -070044const char DefaultProfileTest::kTestStoragePath[] = "/no/where";
45
Chris Masone88cbd5f2011-07-03 14:30:04 -070046TEST_F(DefaultProfileTest, GetProperties) {
47 Error error(Error::kInvalidProperty, "");
48 {
49 map<string, ::DBus::Variant> props;
50 ::DBus::Error dbus_error;
Chris Masone7aa5f902011-07-11 11:13:35 -070051 DBusAdaptor::GetProperties(profile_->store(), &props, &dbus_error);
Chris Masone88cbd5f2011-07-03 14:30:04 -070052 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 Masone7aa5f902011-07-11 11:13:35 -070059 DBusAdaptor::GetProperties(profile_->store(), &props, &dbus_error);
Chris Masone88cbd5f2011-07-03 14:30:04 -070060 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 Masone7aa5f902011-07-11 11:13:35 -070066 profile_->store()->SetBoolProperty(flimflam::kOfflineModeProperty,
67 true,
68 &error));
Chris Masone88cbd5f2011-07-03 14:30:04 -070069 }
70}
71
Chris Masone2ae797d2011-08-23 20:41:00 -070072TEST_F(DefaultProfileTest, GetStoragePath) {
73 FilePath path;
74 EXPECT_TRUE(profile_->GetStoragePath(&path));
75 EXPECT_EQ(string(kTestStoragePath) + "/default.profile", path.value());
76}
77
Chris Masone88cbd5f2011-07-03 14:30:04 -070078} // namespace shill