• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "interfaces/inner_api/xcomponent_controller/xcomponent_controller.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 namespace OHOS::Ace {
23 namespace {
24     const std::string SURFACE_ID = "2430951489577";
25 } // namespace
26 class XComponentControllerTest : public testing::Test {
27 public:
SetUpTestCase()28     static void SetUpTestCase() {};
TearDownTestCase()29     static void TearDownTestCase() {};
30 };
31 
32 /**
33  * @tc.name: XComponentControllerTest001
34  * @tc.desc: Test XComponentController::GetXComponentControllerFromNapiValue function.
35  * @tc.type: FUNC
36  */
37 HWTEST_F(XComponentControllerTest, XComponentControllerTest001, TestSize.Level1)
38 {
39     napi_env__* env = nullptr;
40     napi_value__* value = nullptr;
41     auto controller = XComponentController::GetXComponentControllerFromNapiValue(env, value);
42     EXPECT_EQ(controller, nullptr);
43 }
44 
45 /**
46  * @tc.name: XComponentControllerTest002
47  * @tc.desc: Test XComponentController::SetSurfaceCallbackMode function.
48  * @tc.type: FUNC
49  */
50 HWTEST_F(XComponentControllerTest, XComponentControllerTest002, TestSize.Level1)
51 {
52     napi_env__* env = nullptr;
53     napi_value__* value = nullptr;
54     SurfaceCallbackMode mode = SurfaceCallbackMode::DEFAULT;
55     uint32_t code = XComponentController::SetSurfaceCallbackMode(env, value, mode);
56     EXPECT_EQ(code, 1);
57 }
58 
59 /**
60  * @tc.name: SetRenderFitBySurfaceIdErrorCodeTest
61  * @tc.desc: Test XComponentController::SetRenderFitBySurfaceId function with invalid input.
62  * @tc.type: FUNC
63  */
64 HWTEST_F(XComponentControllerTest, SetRenderFitBySurfaceIdErrorCodeTest, TestSize.Level1)
65 {
66     /**
67      * @tc.step1: Test SetRenderFitBySurfaceId when renderFitNumber is less than zero.
68      * @tc.expected: the error code indicates parameter invalid or load ace lib failed.
69      */
70     std::string surfaceId = SURFACE_ID;
71     int32_t renderFitNumberInvalid = -1;
72     auto code = XComponentController::SetRenderFitBySurfaceId(surfaceId, renderFitNumberInvalid, true);
73     EXPECT_NE(code, 0);
74     /**
75      * @tc.step2: Test SetRenderFitBySurfaceId when renderFitNumber is larger than fifteen.
76      * @tc.expected: the error code indicates parameter invalid or load ace lib failed.
77      */
78     renderFitNumberInvalid = 16;
79     code = XComponentController::SetRenderFitBySurfaceId(surfaceId, renderFitNumberInvalid, true);
80     EXPECT_NE(code, 0);
81 }
82 
83 /**
84  * @tc.name: GetRenderFitBySurfaceIdErrorCodeTest
85  * @tc.desc: Test XComponentController::GetRenderFitBySurfaceId function with invalid input.
86  * @tc.type: FUNC
87  */
88 HWTEST_F(XComponentControllerTest, GetRenderFitBySurfaceIdErrorCodeTest, TestSize.Level1)
89 {
90     /**
91      * @tc.step1: Test GetRenderFitBySurfaceId when surfaceId is invalid.
92      * @tc.expected: the error code indicates parameter invalid or load ace lib failed.
93      */
94     std::string surfaceId = "";
95     int32_t renderFitNumber = -1;
96     bool isEnable = false;
97     auto code = XComponentController::GetRenderFitBySurfaceId(surfaceId, renderFitNumber, isEnable);
98     EXPECT_NE(code, 0);
99 }
100 
101 /**
102  * @tc.name: GetSurfaceRotationBySurfaceIdErrorCodeTest
103  * @tc.desc: Test XComponentController::GetSurfaceRotationBySurfaceId function with invalid input.
104  * @tc.type: FUNC
105  */
106 HWTEST_F(XComponentControllerTest, GetSurfaceRotationBySurfaceIdErrorCodeTest, TestSize.Level1)
107 {
108     /**
109      * @tc.step1: Test GetSurfaceRotationBySurfaceId when surfaceId is invalid.
110      * @tc.expected: the error code indicates parameter invalid or load ace lib failed.
111      */
112     std::string surfaceId = "";
113     bool isSurfaceLock = false;
114     auto code = XComponentController::GetSurfaceRotationBySurfaceId(surfaceId, isSurfaceLock);
115     EXPECT_NE(code, 0);
116 }
117 } // namespace OHOS::Ace
118