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, 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#ifndef TEST_WUKONG_SCENE_DELEGATE_H
17#define TEST_WUKONG_SCENE_DELEGATE_H
18
19#include "singleton.h"
20#include "tree_manager.h"
21#include "wukong_define.h"
22
23namespace OHOS {
24namespace WuKong {
25class SceneDelegate : public DelayedSingleton<SceneDelegate> {
26public:
27    SceneDelegate();
28    ~SceneDelegate();
29
30    /**
31     * @brief judge the scene
32     * @param isRandom whether it is a random test
33     * @return ERR_OK is success,other is fail
34     */
35    ErrCode ChooseScene(bool isRandom);
36
37    /**
38     * @brief judge whether to back to the previous page
39     * @return true is back,false is not back
40     */
41    bool IsBackToPrePage()
42    {
43        return isBack_;
44    }
45
46    std::vector<std::string> GetComponentTypeList()
47    {
48        return componentType_;
49    }
50
51    uint64_t GetCurrentPageId()
52    {
53        return pageId_;
54    }
55
56private:
57    /**
58     * @brief compare two component tree
59     * @param componentinfo the information of a component tree
60     * @param othercomponentinfo the information of another component tree
61     * @return ERR_OK is success,other is fail
62     */
63    ErrCode CompareComponentInfos(std::shared_ptr<ComponentTree> &newcomponentinfo,
64                                  std::shared_ptr<ComponentTree> &oldcomponentinfo, bool isRandom);
65
66    /**
67     * @brief get all componentinfo of active page
68     * @param componentinfo the root component node of active page
69     * @return ERR_OK is success,other is fail
70     */
71    ErrCode GetCurrentComponentInfo(std::shared_ptr<ComponentTree> componentinfo,
72                                    std::vector<std::shared_ptr<ComponentTree>> &componentlist);
73
74    /**
75     * @brief set the available component
76     * @param componentinfo the root component node of active page
77     * @return ERR_OK is success,other is fail
78     */
79    ErrCode SetAvailableComponentList(std::shared_ptr<ComponentTree> componentinfo, bool isRandom);
80
81    /**
82     * @brief find the same component in new component list and old component list
83     * @param newcomponentlist new component list
84     * @param oldcomponentlist old component list
85     * @return same count
86     */
87    uint32_t FindSame(const std::vector<std::shared_ptr<ComponentTree>> &newcomponentlist,
88                      const std::vector<std::shared_ptr<ComponentTree>> &oldcomponentlist);
89
90    /**
91     * @brief set the available component
92     * @param isFound whether newcomponentinfos is same with its parent node
93     * @param isRandom whether it is a random test
94     * @return ERR_OK is success,other is fail
95     */
96    ErrCode FindSamePageInChildren(bool &isFound, bool isRandom);
97
98    /**
99     * @brief set the available component
100     * @param isFound whether newcomponentinfos is same with its child node
101     * @param isRandom whether it is a random test
102     * @return ERR_OK is success,other is fail
103     */
104    ErrCode FindSamePageInParent(bool &isFound, bool isRandom);
105
106    /**
107     * @brief check if the component is in screen
108     * @param componentinfo the component
109     * @return true is in screen,false is not in screen
110     */
111    bool IsComponentInScreen(const std::shared_ptr<ComponentTree> componentinfo);
112
113    std::vector<std::shared_ptr<ComponentTree>> componentList_;
114    std::vector<std::string> componentType_;
115    bool isBack_ = false;
116    uint64_t pageId_ = 0;
117};
118}  // namespace WuKong
119}  // namespace OHOS
120#endif  // TEST_WUKONG_SCENE_DELEGATE_H
121