• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include <gmock/gmock.h>
16 #include <gtest/gtest.h>
17 
18 #include "ui_effect_controller_client.h"
19 #include "ui_effect_controller.h"
20 #include "ui_effect_controller_common.h"
21 
22 namespace OHOS::Rosen {
23 class UIEffectControllerStubTest : public testing::Test {
24 public:
25     static void SetUpTestCase();
26     static void TearDownTestCase();
27     void SetUp() override;
28     void TearDown() override;
29 };
30 
SetUpTestCase()31 void UIEffectControllerStubTest::SetUpTestCase() {}
32 
TearDownTestCase()33 void UIEffectControllerStubTest::TearDownTestCase() {}
34 
SetUp()35 void UIEffectControllerStubTest::SetUp() {}
36 
TearDown()37 void UIEffectControllerStubTest::TearDown() {}
38 
39 namespace {
40 using namespace testing;
41 using namespace testing::ext;
42 HWTEST_F(UIEffectControllerStubTest, UIEffectControllerClientStubSetParam, Function | SmallTest | Level2)
43 {
44     sptr<UIEffectControllerClientStub> stub = sptr<UIEffectControllerClient>::MakeSptr();
45     uint32_t code = static_cast<uint32_t>(
46         IUIEffectControllerClient::UIEffectControllerClientMessage::TRANS_ID_UIEFFECT_SET_PARAM);
47     MessageParcel reply;
48     MessageOption option;
49     MessageParcel dataInvalid;
50     // invalid interface token
51     dataInvalid.WriteInterfaceToken(u"invalid");
52     EXPECT_EQ(stub->OnRemoteRequest(code, dataInvalid, reply, option), ERR_TRANSACTION_FAILED);
53     MessageParcel dataValid;
54     dataValid.WriteInterfaceToken(stub->GetDescriptor());
55     sptr<UIEffectParams> params = sptr<UIEffectParams>::MakeSptr();
56     dataValid.WriteStrongParcelable(params);
57     EXPECT_EQ(stub->OnRemoteRequest(code, dataValid, reply, option), ERR_NONE);
58     MessageParcel dataValid2;
59     dataValid2.WriteInterfaceToken(stub->GetDescriptor());
60     dataValid2.WriteBool(true);
61     EXPECT_EQ(stub->OnRemoteRequest(code, dataValid2, reply, option), ERR_INVALID_DATA);
62     // last invalid case
63     uint32_t codeInvalid = 10000;
64     stub->OnRemoteRequest(codeInvalid, dataValid, reply, option);
65 }
66 
67 HWTEST_F(UIEffectControllerStubTest, UIEffectControllerStubSetParam, TestSize.Level1)
68 {
69     sptr<UIEffectControllerStub> stub = sptr<UIEffectController>::MakeSptr(1, nullptr, nullptr);
70     MessageParcel data1;
71     MessageParcel reply1;
72     data1.WriteStrongParcelable(nullptr);
73     EXPECT_EQ(stub->HandleSetParams(data1, reply1), ERR_INVALID_DATA);
74     MessageParcel data2;
75     MessageParcel reply2;
76     sptr<UIEffectParams> effectPtr = sptr<UIEffectParams>::MakeSptr();
77     data2.WriteStrongParcelable(effectPtr);
78     EXPECT_EQ(stub->HandleSetParams(data2, reply2), ERR_NONE);
79 }
80 
81 HWTEST_F(UIEffectControllerStubTest, UIEffectControllerStubAnimateTo, TestSize.Level1)
82 {
83     sptr<UIEffectControllerStub> stub = sptr<UIEffectController>::MakeSptr(1, nullptr, nullptr);
84     sptr<UIEffectParams> params = sptr<UIEffectParams>::MakeSptr();
85     sptr<WindowAnimationOption> option = sptr<WindowAnimationOption>::MakeSptr();
86     MessageParcel reply;
87     MessageParcel data1;
88     data1.WriteStrongParcelable(nullptr);
89     EXPECT_EQ(stub->HandleAnimateTo(data1, reply), ERR_INVALID_DATA);
90     MessageParcel data2;
91     data2.WriteStrongParcelable(params);
92     data2.WriteStrongParcelable(nullptr);
93     EXPECT_EQ(stub->HandleAnimateTo(data2, reply), ERR_INVALID_DATA);
94     MessageParcel data3;
95     data3.WriteStrongParcelable(params);
96     data3.WriteStrongParcelable(option);
97     data3.WriteBool(true);
98     data3.WriteStrongParcelable(nullptr);
99     EXPECT_EQ(stub->HandleAnimateTo(data3, reply), ERR_INVALID_DATA);
100     MessageParcel data4;
101     data4.WriteStrongParcelable(params);
102     data4.WriteStrongParcelable(option);
103     data4.WriteBool(true);
104     data4.WriteStrongParcelable(option);
105     EXPECT_EQ(stub->HandleAnimateTo(data4, reply), ERR_NONE);
106     MessageParcel data5;
107     data5.WriteStrongParcelable(params);
108     data5.WriteStrongParcelable(option);
109     data5.WriteBool(false);
110     EXPECT_EQ(stub->HandleAnimateTo(data5, reply), ERR_NONE);
111 }
112 
113 HWTEST_F(UIEffectControllerStubTest, UIEffectControllerStubOnRemoteRequest, TestSize.Level1)
114 {
115     sptr<UIEffectControllerStub> stub = sptr<UIEffectController>::MakeSptr(1, nullptr, nullptr);
116     uint32_t code = 0;
117     MessageParcel reply;
118     MessageOption option;
119     MessageParcel dataInvalid;
120     // invalid interface token
121     dataInvalid.WriteInterfaceToken(u"Invalid");
122     EXPECT_EQ(stub->OnRemoteRequest(code, dataInvalid, reply, option), ERR_TRANSACTION_FAILED);
123     MessageParcel dataValid;
124     dataValid.WriteInterfaceToken(stub->GetDescriptor());
125     code = static_cast<uint32_t>(IUIEffectController::UIEffectControllerMessage::TRANS_ID_UIEFFECT_SET_PARAM);
126     stub->OnRemoteRequest(code, dataValid, reply, option);
127     MessageParcel dataValid2;
128     dataValid2.WriteInterfaceToken(stub->GetDescriptor());
129     code = static_cast<uint32_t>(IUIEffectController::UIEffectControllerMessage::TRANS_ID_UIEFFECT_ANIMATE_TO);
130     stub->OnRemoteRequest(code, dataValid2, reply, option);
131     MessageParcel dataValid3;
132     dataValid3.WriteInterfaceToken(stub->GetDescriptor());
133     code = 10000;
134     stub->OnRemoteRequest(code, dataValid3, reply, option);
135 }
136 }
137 } // namespace OHOS::Rosen