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 <fstream>
17
18 #include <dlfcn.h>
19 #include <gtest/gtest.h>
20
21 #include "infrared_emitter_controller.h"
22 #include "mmi_log.h"
23 #include "uds_server.h"
24
25 namespace OHOS {
26 namespace MMI {
27 namespace {
28 using namespace testing::ext;
29 const std::string IR_WRAPPER_PATH = "libconsumer_ir_service_1.0.z.so";
30 } // namespace
31
32 class InfraredEmitterControllerTest : public testing::Test {
33 public:
SetUpTestCase(void)34 static void SetUpTestCase(void) {}
TearDownTestCase(void)35 static void TearDownTestCase(void) {}
36 };
37
38 /**
39 * @tc.name: InfraredEmitterControllerTest_GetInstance_001
40 * @tc.desc: Test the funcation GetInstance
41 * @tc.type: FUNC
42 * @tc.require:
43 */
HWTEST_F(InfraredEmitterControllerTest, InfraredEmitterControllerTest_GetInstance_001, TestSize.Level1)44 HWTEST_F(InfraredEmitterControllerTest, InfraredEmitterControllerTest_GetInstance_001, TestSize.Level1)
45 {
46 CALL_TEST_DEBUG;
47 InfraredEmitterController controller;
48 InfraredEmitterController* instance1 = controller.GetInstance();
49 ASSERT_NE(instance1, nullptr);
50 InfraredEmitterController* instance2 = controller.GetInstance();
51 ASSERT_EQ(instance1, instance2);
52 }
53
54 /**
55 * @tc.name: InfraredEmitterControllerTest_InitInfraredEmitter_001
56 * @tc.desc: Test the funcation InitInfraredEmitter
57 * @tc.type: FUNC
58 * @tc.require:
59 */
HWTEST_F(InfraredEmitterControllerTest, InfraredEmitterControllerTest_InitInfraredEmitter_001, TestSize.Level1)60 HWTEST_F(InfraredEmitterControllerTest, InfraredEmitterControllerTest_InitInfraredEmitter_001, TestSize.Level1)
61 {
62 CALL_TEST_DEBUG;
63 InfraredEmitterController controller;
64 controller.irInterface_ = nullptr;
65 controller.soIrHandle_ = nullptr;
66 ASSERT_NO_FATAL_FAILURE(controller.InitInfraredEmitter());
67 controller.soIrHandle_ = dlopen(IR_WRAPPER_PATH.c_str(), RTLD_NOW);
68 ASSERT_NO_FATAL_FAILURE(controller.InitInfraredEmitter());
69 }
70
71 /**
72 * @tc.name: InfraredEmitterControllerTest_Transmit_001
73 * @tc.desc: Test the funcation Transmit
74 * @tc.type: FUNC
75 * @tc.require:
76 */
HWTEST_F(InfraredEmitterControllerTest, InfraredEmitterControllerTest_Transmit_001, TestSize.Level1)77 HWTEST_F(InfraredEmitterControllerTest, InfraredEmitterControllerTest_Transmit_001, TestSize.Level1)
78 {
79 CALL_TEST_DEBUG;
80 InfraredEmitterController controller;
81 int64_t carrierFreq = 12;
82 std::vector<int64_t> pattern = {10, 20, 30};
83 bool ret = controller.Transmit(carrierFreq, pattern);
84 ASSERT_TRUE(ret);
85 }
86
87 /**
88 * @tc.name: InfraredEmitterControllerTest_GetFrequencies_001
89 * @tc.desc: Test the funcation GetFrequencies
90 * @tc.type: FUNC
91 * @tc.require:
92 */
HWTEST_F(InfraredEmitterControllerTest, InfraredEmitterControllerTest_GetFrequencies_001, TestSize.Level1)93 HWTEST_F(InfraredEmitterControllerTest, InfraredEmitterControllerTest_GetFrequencies_001, TestSize.Level1)
94 {
95 CALL_TEST_DEBUG;
96 InfraredEmitterController controller;
97 controller.irInterface_ = nullptr;
98 std::vector<InfraredFrequencyInfo> frequencyInfo;
99 frequencyInfo.push_back(InfraredFrequencyInfo({1, 1000}));
100 bool ret = controller.GetFrequencies(frequencyInfo);
101 ASSERT_TRUE(ret);
102 }
103 } // namespace MMI
104 } // namespace OHOS