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
11 using ::testing::_;
12 using ::testing::Return;
13 using ::testing::SetArgumentPointee;
14 using ::testing::StrEq;
15
16 namespace base {
17 namespace nix {
18
19 namespace {
20
21 class 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
28 const char* kGnome = "gnome";
29 const char* kKDE4 = "kde4";
30 const char* kKDE = "kde";
31 const char* kXFCE = "xfce";
32
33 } // namespace
34
TEST(XDGUtilTest,GetDesktopEnvironmentGnome)35 TEST(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
TEST(XDGUtilTest,GetDesktopEnvironmentKDE4)45 TEST(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
TEST(XDGUtilTest,GetDesktopEnvironmentKDE3)55 TEST(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
TEST(XDGUtilTest,GetDesktopEnvironmentXFCE)65 TEST(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