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 "rs_window_animation_target.h"
19 #include "ui/rs_surface_node.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26 class RSWindowAnimationTargetMock : public RSWindowAnimationTarget {
27 public:
28 RSWindowAnimationTargetMock() = default;
29 virtual ~RSWindowAnimationTargetMock() = default;
30 };
31
32 class RSWindowAnimationTargetTest : public testing::Test {
33 public:
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp() override;
37 void TearDown() override;
38 };
39
SetUpTestCase()40 void RSWindowAnimationTargetTest::SetUpTestCase() {}
TearDownTestCase()41 void RSWindowAnimationTargetTest::TearDownTestCase() {}
SetUp()42 void RSWindowAnimationTargetTest::SetUp() {}
TearDown()43 void RSWindowAnimationTargetTest::TearDown() {}
44
45 /**
46 * @tc.name: Unmarshalling001
47 * @tc.desc: Verify the Unmarshalling
48 * @tc.type:FUNC
49 */
50 HWTEST_F(RSWindowAnimationTargetTest, Unmarshalling001, TestSize.Level1)
51 {
52 GTEST_LOG_(INFO) << "RSWindowAnimationTargetTest Unmarshalling001 start";
53 RSSurfaceNodeConfig config;
54 std::shared_ptr<RSSurfaceNode> animationSurfaceNode = RSSurfaceNode::Create(config, true);
55 std::shared_ptr<RSWindowAnimationTarget> windowAnimationTarget = std::make_shared<RSWindowAnimationTarget>();
56 windowAnimationTarget->bundleName_ = "";
57 windowAnimationTarget->abilityName_ = "";
58 windowAnimationTarget->windowBounds_ = RRect();
59 windowAnimationTarget->surfaceNode_ = animationSurfaceNode;
60 windowAnimationTarget->windowId_ = 0;
61 windowAnimationTarget->displayId_ = 0;
62 windowAnimationTarget->missionId_ = 0;
63
64 Parcel parcel;
65 auto res = windowAnimationTarget->Unmarshalling(parcel);
66 ASSERT_EQ(res, nullptr);
67 windowAnimationTarget->Marshalling(parcel);
68 res = windowAnimationTarget->Unmarshalling(parcel);
69 ASSERT_NE(res, nullptr);
70 GTEST_LOG_(INFO) << "RSWindowAnimationTargetTest Unmarshalling001 end";
71 }
72
73 /**
74 * @tc.name: Marshalling001
75 * @tc.desc: Verify the Marshalling
76 * @tc.type:FUNC
77 */
78 HWTEST_F(RSWindowAnimationTargetTest, Marshalling001, TestSize.Level1)
79 {
80 GTEST_LOG_(INFO) << "RSWindowAnimationTargetTest Marshalling001 start";
81 RSSurfaceNodeConfig config;
82 std::shared_ptr<RSSurfaceNode> animationSurfaceNode = RSSurfaceNode::Create(config, true);
83 std::shared_ptr<RSWindowAnimationTarget> windowAnimationTarget = std::make_shared<RSWindowAnimationTarget>();
84 windowAnimationTarget->bundleName_ = "";
85 windowAnimationTarget->abilityName_ = "";
86 windowAnimationTarget->windowBounds_ = RRect();
87 windowAnimationTarget->surfaceNode_ = animationSurfaceNode;
88 windowAnimationTarget->windowId_ = 0;
89 windowAnimationTarget->displayId_ = 0;
90 windowAnimationTarget->missionId_ = 0;
91
92 Parcel parcel;
93 bool res = windowAnimationTarget->Marshalling(parcel);
94 ASSERT_EQ(res, true);
95 windowAnimationTarget->surfaceNode_ = nullptr;
96 res = windowAnimationTarget->Marshalling(parcel);
97 ASSERT_EQ(res, true);
98 GTEST_LOG_(INFO) << "RSWindowAnimationTargetTest Marshalling001 end";
99 }
100
101 /**
102 * @tc.name: ReadFromParcel001
103 * @tc.desc: Verify the ReadFromParcel
104 * @tc.type:FUNC
105 */
106 HWTEST_F(RSWindowAnimationTargetTest, ReadFromParcel001, TestSize.Level1)
107 {
108 GTEST_LOG_(INFO) << "RSWindowAnimationTargetTest ReadFromParcel001 start";
109 RSSurfaceNodeConfig config;
110 std::shared_ptr<RSSurfaceNode> animationSurfaceNode = RSSurfaceNode::Create(config, true);
111 std::shared_ptr<RSWindowAnimationTarget> windowAnimationTarget = std::make_shared<RSWindowAnimationTarget>();
112 windowAnimationTarget->bundleName_ = "";
113 windowAnimationTarget->abilityName_ = "";
114 windowAnimationTarget->windowBounds_ = RRect();
115 windowAnimationTarget->surfaceNode_ = animationSurfaceNode;
116 windowAnimationTarget->windowId_ = 0;
117 windowAnimationTarget->displayId_ = 0;
118 windowAnimationTarget->missionId_ = 0;
119
120 Parcel parcel;
121 bool res = windowAnimationTarget->ReadFromParcel(parcel);
122 ASSERT_EQ(res, false);
123 windowAnimationTarget->Marshalling(parcel);
124 res = windowAnimationTarget->ReadFromParcel(parcel);
125 ASSERT_EQ(res, true);
126
127 Parcel parcelNull;
128 windowAnimationTarget->surfaceNode_ = nullptr;
129 windowAnimationTarget->Marshalling(parcelNull);
130 res = windowAnimationTarget->ReadFromParcel(parcelNull);
131 ASSERT_EQ(res, true);
132 GTEST_LOG_(INFO) << "RSWindowAnimationTargetTest ReadFromParcel001 end";
133 }
134 } // namespace Rosen
135 } // namespace OHOS