1 /*
2 * Copyright (c) 2022 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, Hardware
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 #include <securec.h>
18
19 #include "screen_manager/rs_screen_capability.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26 class RSScreenCapabilityTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp() override;
31 void TearDown() override;
32 };
33
SetUpTestCase()34 void RSScreenCapabilityTest::SetUpTestCase() {}
TearDownTestCase()35 void RSScreenCapabilityTest::TearDownTestCase() {}
SetUp()36 void RSScreenCapabilityTest::SetUp() {}
TearDown()37 void RSScreenCapabilityTest::TearDown() {}
38
39 /**
40 * @tc.name: Marshalling001
41 * @tc.desc: test
42 * @tc.type:FUNC
43 * @tc.require:
44 */
45 HWTEST_F(RSScreenCapabilityTest, Marshalling001, TestSize.Level1)
46 {
47 RSScreenCapability capability;
48 Parcel parcel;
49 ASSERT_TRUE(capability.Marshalling(parcel));
50 }
51
52 /**
53 * @tc.name: Unmarshalling001
54 * @tc.desc: test
55 * @tc.type:FUNC
56 * @tc.require:
57 */
58 HWTEST_F(RSScreenCapabilityTest, Unmarshalling001, TestSize.Level1)
59 {
60 RSScreenCapability capability;
61 Parcel parcel;
62 std::shared_ptr<RSScreenCapability>(capability.Unmarshalling(parcel));
63 ASSERT_EQ(std::shared_ptr<RSScreenCapability>(capability.Unmarshalling(parcel)), nullptr);
64 }
65
66 /**
67 * @tc.name: marshallingAndUnmarshallling001
68 * @tc.desc: test
69 * @tc.type:FUNC
70 * @tc.require:
71 */
72 HWTEST_F(RSScreenCapabilityTest, marshallingAndUnmarshallling001, TestSize.Level1)
73 {
74 RSScreenProps rp1;
75 RSScreenProps rp2;
76 std::vector<RSScreenProps> props = { rp1, rp2 };
77 RSScreenCapability capability("1", ScreenInterfaceType::DISP_INTF_LCD, 2, 4, 3, 3, true, props);
78 Parcel parcel;
79 auto bufferSize = parcel.GetMaxCapacity();
80 char* buffer = static_cast<char*>(malloc(parcel.GetMaxCapacity()));
81 memset_s(buffer, parcel.GetMaxCapacity(), 0, parcel.GetMaxCapacity());
82 ASSERT_TRUE(parcel.WriteUnpadBuffer(buffer, parcel.GetMaxCapacity()));
83 bool ret = false;
84 parcel.SkipBytes(bufferSize);
85 while (!ret) {
86 size_t position = parcel.GetWritePosition();
87 ret = capability.Marshalling(parcel) &&
88 (std::shared_ptr<RSScreenCapability>(RSScreenCapability::Unmarshalling(parcel)) != nullptr);
89 parcel.SetMaxCapacity(parcel.GetMaxCapacity() + 1);
90 if (!ret) {
91 parcel.RewindWrite(position);
92 parcel.RewindRead(bufferSize);
93 }
94 }
95 free(buffer);
96 ASSERT_TRUE(ret);
97 }
98 } // namespace Rosen
99 } // namespace OHOS
100