• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <test_header.h>
18 
19 #include "frame_collector.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 class FrameCollectorTest : 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 FrameCollectorTest::SetUpTestCase() {}
TearDownTestCase()35 void FrameCollectorTest::TearDownTestCase() {}
SetUp()36 void FrameCollectorTest::SetUp() {}
TearDown()37 void FrameCollectorTest::TearDown() {}
38 
39 /*
40  * Function: Singleton is single
41  * Type: Function
42  * EnvConditions: N/A
43  * CaseDescription: 1. call GetInstance twice
44  *                  2. check instance should be same
45  */
46 HWTEST_F(FrameCollectorTest, Singleton, Function | SmallTest | Level4)
47 {
48     PART("CaseDescription") {
49         STEP("1. call GetInstance twice") {
50             auto &instance1 = FrameCollector::GetInstance();
51             auto &instance2 = FrameCollector::GetInstance();
52             STEP("2. check instance should be same") {
53                 STEP_ASSERT_EQ(&instance1, &instance2);
54             }
55         }
56     }
57 }
58 
59 /*
60  * Function: IsEnabled/SetEnabled
61  * Type: Function
62  * EnvConditions: N/A
63  * CaseDescription: 1. save IsEnabled as e
64  *                  2. SetEnabled !e
65  *                  3. check IsEnabled is !e
66  */
67 HWTEST_F(FrameCollectorTest, Enable, Function | SmallTest | Level2)
68 {
69     PART("CaseDescription") {
70         bool e = false;
71         STEP("1. save IsEnabled as e") {
72             e = FrameCollector::GetInstance().IsEnabled();
73         }
74 
75         STEP("2. SetEnabled !e") {
76             FrameCollector::GetInstance().SetEnabled(!e);
77         }
78 
79         STEP("3. save IsEnabled as e") {
80             STEP_ASSERT_EQ(FrameCollector::GetInstance().IsEnabled(), !e);
81         }
82     }
83 }
84 
85 /*
86  * Function: MarkFrameEvent
87  * Type: Function
88  * EnvConditions: Enable and ClearEvents FrameCollector
89  * CaseDescription: 1. check queue size 0
90  *                  2. mark UIMarks
91  *                  3. check queue size 0
92  *                  4. mark WaitVsyncStart
93  *                  5. check queue size 1
94  *                  6. mark WaitVsyncStart
95  *                  7. check queue size 2
96  *                  8. clear events
97  *                  9. check queue size 0
98  */
99 HWTEST_F(FrameCollectorTest, MarkFrameEvent, Function | MediumTest | Level2)
100 {
101     auto &collector = FrameCollector::GetInstance();
102     PART("EnvConditions") {
103         STEP("Enable and ClearEvents FrameCollector") {
104             collector.SetEnabled(true);
105             collector.ClearEvents();
106         }
107     }
108 
109     PART("CaseDescription") {
110         STEP("1. check queue size 0") {
111             STEP_ASSERT_EQ(collector.LockGetFrameQueue().GetSize(), 0);
112             collector.UnlockFrameQueue();
113         }
114 
115         STEP("2. mark UIMarks") {
116             collector.MarkFrameEvent(FrameEventType::UploadStart);
117             collector.MarkFrameEvent(FrameEventType::UploadEnd);
118             collector.MarkFrameEvent(FrameEventType::AnimateStart);
119             collector.MarkFrameEvent(FrameEventType::AnimateEnd);
120             collector.MarkFrameEvent(FrameEventType::LayoutStart);
121             collector.MarkFrameEvent(FrameEventType::LayoutEnd);
122             collector.MarkFrameEvent(FrameEventType::DrawStart);
123             collector.MarkFrameEvent(FrameEventType::DrawEnd);
124         }
125 
126         STEP("3. check queue size 0") {
127             STEP_ASSERT_EQ(collector.LockGetFrameQueue().GetSize(), 0);
128             collector.UnlockFrameQueue();
129         }
130 
131         STEP("4. mark WaitVsyncStart") {
132             collector.MarkFrameEvent(FrameEventType::WaitVsyncStart);
133         }
134 
135         STEP("5. check queue size 1") {
136             STEP_ASSERT_EQ(collector.LockGetFrameQueue().GetSize(), 1);
137             collector.UnlockFrameQueue();
138         }
139 
140         STEP("6. mark WaitVsyncStart") {
141             collector.MarkFrameEvent(FrameEventType::WaitVsyncStart);
142         }
143 
144         STEP("7. check queue size 2") {
145             STEP_ASSERT_EQ(collector.LockGetFrameQueue().GetSize(), 2);
146             collector.UnlockFrameQueue();
147         }
148 
149         STEP("8. clear events") {
150             collector.ClearEvents();
151         }
152 
153         STEP("9. check queue size 0") {
154             STEP_ASSERT_EQ(collector.LockGetFrameQueue().GetSize(), 0);
155             collector.UnlockFrameQueue();
156         }
157     }
158 }
159 } // namespace Rosen
160 } // namespace OHOS
161