• 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 "gtest/gtest.h"
16 #define protected public
17 #define private public
18 #include "core/common/layout_inspector.h"
19 #include <memory>
20 #include "pixel_map.h"
21 using namespace testing;
22 using namespace OHOS::Ace;
23 using namespace std;
24 using namespace testing::ext;
25 
26 namespace Global::Resource {
27 class ResConfig;
28 }
29 
30 namespace OHOS::Ace {
31 class LayoutInspectorTest : public testing::Test {
32 public:
33 };
34 
35 /**
36  * @tc.name: Filter3DSnapshot001
37  * @tc.desc: Test cast to Filter3DSnapshot
38  * @tc.type: FUNC
39  */
40 HWTEST_F(LayoutInspectorTest, Filter3DSnapshot001, TestSize.Level1)
41 {
42     std::vector<PixelMapPair> snapinfos;
43     auto infos = LayoutInspector::Filter3DSnapshot(snapinfos);
44     EXPECT_EQ(snapinfos.size(), 0);
45     EXPECT_EQ(infos.size(), 0);
46 
47     snapinfos.emplace_back(1, nullptr);
48     snapinfos.emplace_back(2, nullptr);
49     snapinfos.emplace_back(3, std::make_shared<Media::PixelMap>());
50     snapinfos.emplace_back(4, std::make_shared<Media::PixelMap>());
51     snapinfos.emplace_back(5, nullptr);
52     infos = LayoutInspector::Filter3DSnapshot(snapinfos);
53     EXPECT_EQ(snapinfos.size(), 5);
54     EXPECT_EQ(infos.size(), 2);
55 }
56 
57 /**
58  * @tc.name: ProcessMessagesTest
59  * @tc.desc: Test cast to ProcessMessages
60  * @tc.type: FUNC
61  */
62 HWTEST_F(LayoutInspectorTest, ProcessMessagesTest, TestSize.Level1)
63 {
64     // test1: empty msg
65     std::string inspectorMsg = "";
66     auto result = LayoutInspector::ProcessMessages(inspectorMsg);
67     uint32_t windowId = result.first;
68     int32_t methodNum = result.second;
69     EXPECT_EQ(windowId, 0);
70     EXPECT_EQ(methodNum, -1);
71 
72     // test2: invalid msg1, window id is corret, method is wrong
73     inspectorMsg = "{\"method\":\"ArkUI.xxx\", \"params\":{\"windowId\":\"10\"}}";
74     result = LayoutInspector::ProcessMessages(inspectorMsg);
75     windowId = result.first;
76     methodNum = result.second;
77     EXPECT_EQ(windowId, 0);
78     EXPECT_EQ(methodNum, -1);
79 
80     // test3: invalid msg2, window id is wrong, method is corret
81     inspectorMsg = "{\"method\":\"ArkUI.tree\", \"params\":{\"windowId\":\"xxx\"}}";
82     result = LayoutInspector::ProcessMessages(inspectorMsg);
83     windowId = result.first;
84     methodNum = result.second;
85     EXPECT_EQ(windowId, 0);
86     EXPECT_EQ(methodNum, 0);
87 
88     // test4: valid msg, window id is corret, method is ArkUI.tree
89     inspectorMsg = "{\"method\":\"ArkUI.tree\", \"params\":{\"windowId\":\"11\"}}";
90     result = LayoutInspector::ProcessMessages(inspectorMsg);
91     windowId = result.first;
92     methodNum = result.second;
93     EXPECT_EQ(windowId, 11);
94     EXPECT_EQ(methodNum, 0);
95 
96     // test5: valid msg, window id is corret, method is ArkUI.tree.3D
97     inspectorMsg = "{\"method\":\"ArkUI.tree.3D\", \"params\":{\"windowId\":\"11\"}}";
98     result = LayoutInspector::ProcessMessages(inspectorMsg);
99     windowId = result.first;
100     methodNum = result.second;
101     EXPECT_EQ(windowId, 11);
102     EXPECT_EQ(methodNum, 1);
103 
104     // test6: valid msg, window id is corret, method is ArkUI.queryAbilities
105     inspectorMsg = "{\"method\":\"ArkUI.queryAbilities\", \"params\":{\"windowId\":\"11\"}}";
106     result = LayoutInspector::ProcessMessages(inspectorMsg);
107     windowId = result.first;
108     methodNum = result.second;
109     EXPECT_EQ(windowId, 11);
110     EXPECT_EQ(methodNum, 2);
111 }
112 } // namespace OHOS::Ace::NG