1a69a01cdSopenharmony_ci/*
2a69a01cdSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3a69a01cdSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4a69a01cdSopenharmony_ci * you may not use this file except in compliance with the License.
5a69a01cdSopenharmony_ci * You may obtain a copy of the License at
6a69a01cdSopenharmony_ci *
7a69a01cdSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8a69a01cdSopenharmony_ci *
9a69a01cdSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10a69a01cdSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11a69a01cdSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12a69a01cdSopenharmony_ci * See the License for the specific language governing permissions and
13a69a01cdSopenharmony_ci * limitations under the License.
14a69a01cdSopenharmony_ci */
15a69a01cdSopenharmony_ci
16a69a01cdSopenharmony_ci#ifndef TEST_WUKONG_SCENE_DELEGATE_H
17a69a01cdSopenharmony_ci#define TEST_WUKONG_SCENE_DELEGATE_H
18a69a01cdSopenharmony_ci
19a69a01cdSopenharmony_ci#include "singleton.h"
20a69a01cdSopenharmony_ci#include "tree_manager.h"
21a69a01cdSopenharmony_ci#include "wukong_define.h"
22a69a01cdSopenharmony_ci
23a69a01cdSopenharmony_cinamespace OHOS {
24a69a01cdSopenharmony_cinamespace WuKong {
25a69a01cdSopenharmony_ciclass SceneDelegate : public DelayedSingleton<SceneDelegate> {
26a69a01cdSopenharmony_cipublic:
27a69a01cdSopenharmony_ci    SceneDelegate();
28a69a01cdSopenharmony_ci    ~SceneDelegate();
29a69a01cdSopenharmony_ci
30a69a01cdSopenharmony_ci    /**
31a69a01cdSopenharmony_ci     * @brief judge the scene
32a69a01cdSopenharmony_ci     * @param isRandom whether it is a random test
33a69a01cdSopenharmony_ci     * @return ERR_OK is success,other is fail
34a69a01cdSopenharmony_ci     */
35a69a01cdSopenharmony_ci    ErrCode ChooseScene(bool isRandom);
36a69a01cdSopenharmony_ci
37a69a01cdSopenharmony_ci    /**
38a69a01cdSopenharmony_ci     * @brief judge whether to back to the previous page
39a69a01cdSopenharmony_ci     * @return true is back,false is not back
40a69a01cdSopenharmony_ci     */
41a69a01cdSopenharmony_ci    bool IsBackToPrePage()
42a69a01cdSopenharmony_ci    {
43a69a01cdSopenharmony_ci        return isBack_;
44a69a01cdSopenharmony_ci    }
45a69a01cdSopenharmony_ci
46a69a01cdSopenharmony_ci    std::vector<std::string> GetComponentTypeList()
47a69a01cdSopenharmony_ci    {
48a69a01cdSopenharmony_ci        return componentType_;
49a69a01cdSopenharmony_ci    }
50a69a01cdSopenharmony_ci
51a69a01cdSopenharmony_ci    uint64_t GetCurrentPageId()
52a69a01cdSopenharmony_ci    {
53a69a01cdSopenharmony_ci        return pageId_;
54a69a01cdSopenharmony_ci    }
55a69a01cdSopenharmony_ci
56a69a01cdSopenharmony_ciprivate:
57a69a01cdSopenharmony_ci    /**
58a69a01cdSopenharmony_ci     * @brief compare two component tree
59a69a01cdSopenharmony_ci     * @param componentinfo the information of a component tree
60a69a01cdSopenharmony_ci     * @param othercomponentinfo the information of another component tree
61a69a01cdSopenharmony_ci     * @return ERR_OK is success,other is fail
62a69a01cdSopenharmony_ci     */
63a69a01cdSopenharmony_ci    ErrCode CompareComponentInfos(std::shared_ptr<ComponentTree> &newcomponentinfo,
64a69a01cdSopenharmony_ci                                  std::shared_ptr<ComponentTree> &oldcomponentinfo, bool isRandom);
65a69a01cdSopenharmony_ci
66a69a01cdSopenharmony_ci    /**
67a69a01cdSopenharmony_ci     * @brief get all componentinfo of active page
68a69a01cdSopenharmony_ci     * @param componentinfo the root component node of active page
69a69a01cdSopenharmony_ci     * @return ERR_OK is success,other is fail
70a69a01cdSopenharmony_ci     */
71a69a01cdSopenharmony_ci    ErrCode GetCurrentComponentInfo(std::shared_ptr<ComponentTree> componentinfo,
72a69a01cdSopenharmony_ci                                    std::vector<std::shared_ptr<ComponentTree>> &componentlist);
73a69a01cdSopenharmony_ci
74a69a01cdSopenharmony_ci    /**
75a69a01cdSopenharmony_ci     * @brief set the available component
76a69a01cdSopenharmony_ci     * @param componentinfo the root component node of active page
77a69a01cdSopenharmony_ci     * @return ERR_OK is success,other is fail
78a69a01cdSopenharmony_ci     */
79a69a01cdSopenharmony_ci    ErrCode SetAvailableComponentList(std::shared_ptr<ComponentTree> componentinfo, bool isRandom);
80a69a01cdSopenharmony_ci
81a69a01cdSopenharmony_ci    /**
82a69a01cdSopenharmony_ci     * @brief find the same component in new component list and old component list
83a69a01cdSopenharmony_ci     * @param newcomponentlist new component list
84a69a01cdSopenharmony_ci     * @param oldcomponentlist old component list
85a69a01cdSopenharmony_ci     * @return same count
86a69a01cdSopenharmony_ci     */
87a69a01cdSopenharmony_ci    uint32_t FindSame(const std::vector<std::shared_ptr<ComponentTree>> &newcomponentlist,
88a69a01cdSopenharmony_ci                      const std::vector<std::shared_ptr<ComponentTree>> &oldcomponentlist);
89a69a01cdSopenharmony_ci
90a69a01cdSopenharmony_ci    /**
91a69a01cdSopenharmony_ci     * @brief set the available component
92a69a01cdSopenharmony_ci     * @param isFound whether newcomponentinfos is same with its parent node
93a69a01cdSopenharmony_ci     * @param isRandom whether it is a random test
94a69a01cdSopenharmony_ci     * @return ERR_OK is success,other is fail
95a69a01cdSopenharmony_ci     */
96a69a01cdSopenharmony_ci    ErrCode FindSamePageInChildren(bool &isFound, bool isRandom);
97a69a01cdSopenharmony_ci
98a69a01cdSopenharmony_ci    /**
99a69a01cdSopenharmony_ci     * @brief set the available component
100a69a01cdSopenharmony_ci     * @param isFound whether newcomponentinfos is same with its child node
101a69a01cdSopenharmony_ci     * @param isRandom whether it is a random test
102a69a01cdSopenharmony_ci     * @return ERR_OK is success,other is fail
103a69a01cdSopenharmony_ci     */
104a69a01cdSopenharmony_ci    ErrCode FindSamePageInParent(bool &isFound, bool isRandom);
105a69a01cdSopenharmony_ci
106a69a01cdSopenharmony_ci    /**
107a69a01cdSopenharmony_ci     * @brief check if the component is in screen
108a69a01cdSopenharmony_ci     * @param componentinfo the component
109a69a01cdSopenharmony_ci     * @return true is in screen,false is not in screen
110a69a01cdSopenharmony_ci     */
111a69a01cdSopenharmony_ci    bool IsComponentInScreen(const std::shared_ptr<ComponentTree> componentinfo);
112a69a01cdSopenharmony_ci
113a69a01cdSopenharmony_ci    std::vector<std::shared_ptr<ComponentTree>> componentList_;
114a69a01cdSopenharmony_ci    std::vector<std::string> componentType_;
115a69a01cdSopenharmony_ci    bool isBack_ = false;
116a69a01cdSopenharmony_ci    uint64_t pageId_ = 0;
117a69a01cdSopenharmony_ci};
118a69a01cdSopenharmony_ci}  // namespace WuKong
119a69a01cdSopenharmony_ci}  // namespace OHOS
120a69a01cdSopenharmony_ci#endif  // TEST_WUKONG_SCENE_DELEGATE_H
121