e20da033a35889d7084a26688ba6d1c2d1a907d3
[platform/core/uifw/libds.git] / tests / DSSeat-test.cpp
1 /*
2 * Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved.
3 *
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:
10 *
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
13 * Software.
14 *
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.
22 */
23
24 #include "libds-tests.h"
25 #include "DSSeat.h"
26 #include "DSCompositor.h"
27
28 using namespace display_server;
29
30 class DSSeatTest : public ::testing::Test
31 {
32 public:
33         void SetUp(void) override
34         {
35                 char *xdir = getenv("DEFAULT_XDG_RUNTIME_DIR");
36                 setenv("XDG_RUNTIME_DIR", xdir, 1);
37         }
38         void TearDown(void) override
39         {
40                 unsetenv("XDG_RUNTIME_DIR");
41         }
42 };
43
44 class MockCompositor : public DSCompositor
45 {
46 public:
47         MockCompositor() {}
48         ~MockCompositor() {}
49
50         std::shared_ptr<DSCanvas> _onInitialized() override
51         {
52                 auto canvas = std::make_shared<DSCanvas>();
53                 return canvas;
54         }
55
56         void _onOutputAdded(std::shared_ptr<IDSOutput> output) override
57         {}
58
59         void _onOutputRemoved(std::shared_ptr<IDSOutput> output) override
60         {}
61
62         void _onInputAdded(std::shared_ptr<DSInput> input) override
63         {}
64
65         void _onInputRemoved(std::shared_ptr<DSInput> input) override
66         {}
67 };
68
69 TEST_F(DSSeatTest, NewDSSeat)
70 {
71         DSSeat *seat = new DSSeat();
72
73         EXPECT_TRUE(seat != nullptr);
74
75         if (seat)
76                 delete seat;
77 }
78
79 TEST_F(DSSeatTest, BasicMethods)
80 {
81         std::string seatName{"default"};
82         std::shared_ptr<DSCompositor> compositor = std::make_shared<MockCompositor>();
83         EXPECT_TRUE(compositor != nullptr);
84
85         if (compositor)
86         {
87                 std::shared_ptr<DSSeat> seat = std::make_shared<DSSeat>(compositor.get(), seatName);
88                 EXPECT_TRUE(seat != nullptr);
89         }
90 }