1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17
18 #include "proto.h"
19 #include "input_event_handler.h"
20 #include "input_screen_capture_agent.h"
21 #include "mmi_log.h"
22 #include "mmi_service.h"
23
24 #undef MMI_LOG_TAG
25 #define MMI_LOG_TAG "InputScreenCaptureAgentTest"
26 namespace OHOS {
27 namespace MMI {
28 namespace {
29 using namespace testing::ext;
30
31 #ifdef __aarch64__
32 const std::string REFERENCE_LIB_PATH = "/system/lib64/platformsdk";
33 #else
34 const std::string REFERENCE_LIB_PATH = "/system/lib/platformsdk";
35 #endif
36 const std::string FILESEPARATOR = "/";
37 const std::string REFERENCE_LIB_NAME = "libmmi-screen_capture.z.so";
38 std::string REFENCE_LIB_ABSOLUTE_PATH = REFERENCE_LIB_PATH + FILESEPARATOR + REFERENCE_LIB_NAME;
39 } // namespace
40
41 class InputScreenCaptureAgentTest : public testing::Test {
42 public:
43 static void SetUpTestCase(void);
44 static void TearDownTestCase(void);
45 void SetUp();
46 void TearDown();
47 InputScreenCaptureAgent inputScreenCaptureAgent;
48 };
SetUpTestCase(void)49 void InputScreenCaptureAgentTest::SetUpTestCase(void)
50 {}
51
TearDownTestCase(void)52 void InputScreenCaptureAgentTest::TearDownTestCase(void)
53 {}
54
SetUp()55 void InputScreenCaptureAgentTest::SetUp()
56 {
57 inputScreenCaptureAgent.handle_.handle = nullptr;
58 inputScreenCaptureAgent.handle_.isWorking = nullptr;
59 inputScreenCaptureAgent.handle_.registerListener = nullptr;
60 inputScreenCaptureAgent.handle_.isMusicActivate = nullptr;
61 }
62
TearDown()63 void InputScreenCaptureAgentTest::TearDown()
64 {
65 if (inputScreenCaptureAgent.handle_.handle != nullptr) {
66 inputScreenCaptureAgent.handle_.Free();
67 }
68 }
69
70 /**
71 * @tc.name: IsScreenCaptureWorking_001
72 * @tc.desc: Test IsScreenCaptureWorking
73 * @tc.type: FUNC
74 * @tc.require:
75 */
76 HWTEST_F(InputScreenCaptureAgentTest, IsScreenCaptureWorking_001, TestSize.Level1)
77 {
78 CALL_TEST_DEBUG;
79 int32_t capturePid = 1;
80 EXPECT_FALSE(inputScreenCaptureAgent.IsScreenCaptureWorking(capturePid));
81 }
82
83 /**
84 * @tc.name: LoadLibrary_001
85 * @tc.desc: Test LoadLibrary
86 * @tc.type: FUNC
87 * @tc.require:
88 */
89 HWTEST_F(InputScreenCaptureAgentTest, LoadLibrary_001, TestSize.Level1)
90 {
91 CALL_TEST_DEBUG;
92 EXPECT_EQ(inputScreenCaptureAgent.handle_.handle, nullptr);
93 EXPECT_EQ(inputScreenCaptureAgent.handle_.isWorking, nullptr);
94 EXPECT_EQ(inputScreenCaptureAgent.handle_.registerListener, nullptr);
95 char libRealPath[PATH_MAX] = {};
96 realpath(REFENCE_LIB_ABSOLUTE_PATH.c_str(), libRealPath);
97 inputScreenCaptureAgent.handle_.handle = dlopen(libRealPath, RTLD_LAZY);
98 EXPECT_NE(inputScreenCaptureAgent.handle_.handle, nullptr);
99 int32_t ret = inputScreenCaptureAgent.LoadLibrary();
100 EXPECT_EQ(ret, RET_OK);
101 }
102
103 /**
104 * @tc.name: LoadAudioLibrary_001
105 * @tc.desc: Test LoadAudioLibrary
106 * @tc.type: FUNC
107 * @tc.require:
108 */
109 HWTEST_F(InputScreenCaptureAgentTest, LoadAudioLibrary_001, TestSize.Level1)
110 {
111 CALL_TEST_DEBUG;
112 EXPECT_EQ(inputScreenCaptureAgent.handle_.handle, nullptr);
113 EXPECT_EQ(inputScreenCaptureAgent.handle_.isWorking, nullptr);
114 EXPECT_EQ(inputScreenCaptureAgent.handle_.registerListener, nullptr);
115 char libRealPath[PATH_MAX] = {};
116 realpath(REFENCE_LIB_ABSOLUTE_PATH.c_str(), libRealPath);
117 inputScreenCaptureAgent.handle_.handle = dlopen(libRealPath, RTLD_LAZY);
118 EXPECT_NE(inputScreenCaptureAgent.handle_.handle, nullptr);
119 int32_t ret = inputScreenCaptureAgent.LoadAudioLibrary();
120 EXPECT_EQ(ret, RET_OK);
121 }
122
123 } // namespace MMI
124 } // namespace OHOS
125