1// Copyright (c) 2010 The Chromium 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 "base/nix/xdg_util.h"
6
7#include "base/environment.h"
8#include "testing/gmock/include/gmock/gmock.h"
9#include "testing/gtest/include/gtest/gtest.h"
10
11using ::testing::_;
12using ::testing::Return;
13using ::testing::SetArgumentPointee;
14using ::testing::StrEq;
15
16namespace base {
17namespace nix {
18
19namespace {
20
21class MockEnvironment : public Environment {
22 public:
23  MOCK_METHOD2(GetVar, bool(const char*, std::string* result));
24  MOCK_METHOD2(SetVar, bool(const char*, const std::string& new_value));
25  MOCK_METHOD1(UnSetVar, bool(const char*));
26};
27
28const char* kGnome = "gnome";
29const char* kKDE4 = "kde4";
30const char* kKDE = "kde";
31const char* kXFCE = "xfce";
32
33}  // namespace
34
35TEST(XDGUtilTest, GetDesktopEnvironmentGnome) {
36  MockEnvironment getter;
37  EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
38  EXPECT_CALL(getter, GetVar(StrEq("DESKTOP_SESSION"), _))
39      .WillOnce(DoAll(SetArgumentPointee<1>(kGnome), Return(true)));
40
41  EXPECT_EQ(DESKTOP_ENVIRONMENT_GNOME,
42            GetDesktopEnvironment(&getter));
43}
44
45TEST(XDGUtilTest, GetDesktopEnvironmentKDE4) {
46  MockEnvironment getter;
47  EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
48  EXPECT_CALL(getter, GetVar(StrEq("DESKTOP_SESSION"), _))
49      .WillOnce(DoAll(SetArgumentPointee<1>(kKDE4), Return(true)));
50
51  EXPECT_EQ(DESKTOP_ENVIRONMENT_KDE4,
52            GetDesktopEnvironment(&getter));
53}
54
55TEST(XDGUtilTest, GetDesktopEnvironmentKDE3) {
56  MockEnvironment getter;
57  EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
58  EXPECT_CALL(getter, GetVar(StrEq("DESKTOP_SESSION"), _))
59      .WillOnce(DoAll(SetArgumentPointee<1>(kKDE), Return(true)));
60
61  EXPECT_EQ(DESKTOP_ENVIRONMENT_KDE3,
62            GetDesktopEnvironment(&getter));
63}
64
65TEST(XDGUtilTest, GetDesktopEnvironmentXFCE) {
66  MockEnvironment getter;
67  EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
68  EXPECT_CALL(getter, GetVar(StrEq("DESKTOP_SESSION"), _))
69      .WillOnce(DoAll(SetArgumentPointee<1>(kXFCE), Return(true)));
70
71  EXPECT_EQ(DESKTOP_ENVIRONMENT_XFCE,
72            GetDesktopEnvironment(&getter));
73}
74
75}  // namespace nix
76}  // namespace base
77