1 /*
2  * Copyright (c) 2023 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 #include "memory/rs_memory_graphic.h"
18 
19 namespace OHOS::Rosen {
20 class RSMemoryGraphicTest : public testing::Test {
21 public:
22     static void SetUpTestCase();
23     static void TearDownTestCase();
24     void SetUp() override;
25     void TearDown() override;
26 };
27 
SetUpTestCase()28 void RSMemoryGraphicTest::SetUpTestCase() {}
TearDownTestCase()29 void RSMemoryGraphicTest::TearDownTestCase() {}
SetUp()30 void RSMemoryGraphicTest::SetUp() {}
TearDown()31 void RSMemoryGraphicTest::TearDown() {}
32 
33 
34 /**
35  * @tc.name: UnmarshallingTest
36  * @tc.desc: test
37  * @tc.type: FUNC
38  * @tc.require:
39  */
40 HWTEST_F(RSMemoryGraphicTest, UnmarshallingTest, testing::ext::TestSize.Level1)
41 {
42     Parcel parcel;
43     MemoryGraphic memoryGraphic;
44     auto mem = memoryGraphic.Unmarshalling(parcel);
45     ASSERT_EQ(mem, nullptr);
46 }
47 
48 
49 /**
50  * @tc.name: MarshallingTest
51  * @tc.desc: test
52  * @tc.type: FUNC
53  * @tc.require:
54  */
55 HWTEST_F(RSMemoryGraphicTest, MarshallingTest, testing::ext::TestSize.Level1)
56 {
57     Parcel parcel;
58     MemoryGraphic memoryGraphic;
59     auto mem = memoryGraphic.Marshalling(parcel);
60     ASSERT_EQ(mem, true);
61 }
62 
63 /**
64  * @tc.name: IncreaseCpuMemoryTest
65  * @tc.desc: test
66  * @tc.type: FUNC
67  * @tc.require:
68  */
69 HWTEST_F(RSMemoryGraphicTest, IncreaseCpuMemoryTest, testing::ext::TestSize.Level1)
70 {
71     // for test
72     float glSize = 1.0;
73     // for test
74     float graphicSize = 1.0;
75     MemoryGraphic memoryGraphic;
76     memoryGraphic.IncreaseCpuMemory(glSize);
77     memoryGraphic.IncreaseGpuMemory(graphicSize);
78     int ret = 0;
79     ASSERT_EQ(ret, 0);
80 }
81 
82 /**
83  * @tc.name: GetPidTest
84  * @tc.desc: test
85  * @tc.type: FUNC
86  * @tc.require:
87  */
88 HWTEST_F(RSMemoryGraphicTest, GetPidTest, testing::ext::TestSize.Level1)
89 {
90     MemoryGraphic memoryGraphic;
91     memoryGraphic.SetPid(1.0);
92     auto ret = memoryGraphic.GetPid();
93     ASSERT_EQ(ret, 1.0);
94 }
95 
96 /**
97  * @tc.name: GetGpuMemorySizeTest
98  * @tc.desc: test
99  * @tc.type: FUNC
100  * @tc.require:
101  */
102 HWTEST_F(RSMemoryGraphicTest, GetGpuMemorySizeTest, testing::ext::TestSize.Level1)
103 {
104     MemoryGraphic memoryGraphic;
105     memoryGraphic.SetGpuMemorySize(1.0);
106     memoryGraphic.SetCpuMemorySize(1.0);
107     auto ret = memoryGraphic.GetGpuMemorySize();
108     ASSERT_EQ(ret, 1.0);
109     ret = memoryGraphic.GetCpuMemorySize();
110     ASSERT_EQ(ret, 1.0);
111     ret = memoryGraphic.GetTotalMemorySize();
112     ASSERT_EQ(ret, 2.0);
113 }
114 } // namespace OHOS::Rosen