2 * Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 #include "libds-tests.h"
25 #include "DSWaylandCompositor.h"
26 #include "DSWaylandClient.h"
28 using namespace display_server;
30 class DSWaylandClientTest : public ::testing::Test
33 void SetUp(void) override
35 char *xdir = getenv("DEFAULT_XDG_RUNTIME_DIR");
36 setenv("XDG_RUNTIME_DIR", xdir, 1);
38 void TearDown(void) override
40 unsetenv("XDG_RUNTIME_DIR");
45 TEST_F(DSWaylandClientTest, NewDSWaylandClient)
47 DSWaylandCompositor *comp = DSWaylandCompositor::getInstance();
48 EXPECT_TRUE(comp != nullptr);
52 /* client must be created with a valid wl_client ptr later. */
53 DSWaylandClient *client = new DSWaylandClient(comp, (wl_client *)nullptr);
54 EXPECT_TRUE(client != nullptr);
59 DSWaylandCompositor::releaseInstance();
63 TEST_F(DSWaylandClientTest, GetClientFromWlClient)
65 DSWaylandCompositor *comp = DSWaylandCompositor::getInstance();
66 EXPECT_TRUE(comp != nullptr);
70 /* client must be created with a valid wl_client ptr later. */
71 auto client = new DSWaylandClient(comp, (wl_client *)nullptr);
72 EXPECT_TRUE(client != nullptr);
76 DSWaylandClient *client2 = client->fromWlClient((wl_client *)nullptr);
77 EXPECT_TRUE(client2 == nullptr);
80 DSWaylandCompositor::releaseInstance();
84 TEST_F(DSWaylandClientTest, GetWlClient)
86 DSWaylandCompositor *comp = DSWaylandCompositor::getInstance();
87 EXPECT_TRUE(comp != nullptr);
91 /* client must be created with a valid wl_client ptr later. */
92 auto client = new DSWaylandClient(comp, (wl_client *)nullptr);
93 EXPECT_TRUE(client != nullptr);
97 wl_client *wclient = client->wlClient();
98 EXPECT_TRUE(wclient == nullptr);
101 DSWaylandCompositor::releaseInstance();
105 TEST_F(DSWaylandClientTest, GetCompositor)
107 DSWaylandCompositor *comp = DSWaylandCompositor::getInstance();
108 EXPECT_TRUE(comp != nullptr);
112 /* client must be created with a valid wl_client ptr later. */
113 DSWaylandClient *client = new DSWaylandClient(comp, (wl_client *)nullptr);
114 EXPECT_TRUE(client != nullptr);
118 DSWaylandCompositor *comp2 = client->getCompositor();
119 EXPECT_TRUE(comp2 == comp);
124 DSWaylandCompositor::releaseInstance();
128 TEST_F(DSWaylandClientTest, GetPidUidGid)
130 DSWaylandCompositor *comp = DSWaylandCompositor::getInstance();
131 EXPECT_TRUE(comp != nullptr);
135 /* client must be created with a valid wl_client ptr later. */
136 auto client = new DSWaylandClient(comp, (wl_client *)nullptr);
137 EXPECT_TRUE(client != nullptr);
149 EXPECT_TRUE(pID == 0);
150 EXPECT_TRUE(uID == 0);
151 EXPECT_TRUE(gID == 0);
156 DSWaylandCompositor::releaseInstance();