1 /*
2  * Copyright (c) 2021 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 OHOS_ACELITE_BASIC_TDD_TEST_CONSTANTS_H
17 #define OHOS_ACELITE_BASIC_TDD_TEST_CONSTANTS_H
18 
19 #ifdef TDD_ASSERTIONS
20 #include <climits>
21 #include <gtest/gtest.h>
22 #else
23 #include <typeinfo.h>
24 #endif
25 #include "component.h"
26 #include "dock/screen_device_proxy.h"
27 #include "test_common.h"
28 #include "window/window.h"
29 #include "wrapper/js.h"
30 
31 namespace OHOS {
32 namespace ACELite {
33 #ifdef TDD_ASSERTIONS
34 using namespace std;
35 using namespace testing::ext;
36 class BasicTddTest : public testing::Test {
37 #else
38 class BasicTddTest {
39 #endif
40 public:
41     BasicTddTest();
42     virtual ~BasicTddTest();
43     static void SetUpTestCase(void);
44     static void TearDownTestCase(void);
45     void SetUp();
46     void TearDown();
47 
48 protected:
49     JSValue RunJS(const char *bundle, const uint32_t size) const;
50     JSValue CreatePage(const char *bundle, const uint32_t size);
51     void DestroyPage(JSValue page);
52     UIView *GetViewByRef(JSValue page, const char *ref) const;
53     void ClickByRef(JSValue page, const char *ref, uint8_t sleepTicks = 50) const;
54     void LongPressByRef(JSValue page, const char *ref, uint8_t sleepTicks = 200) const;
55     void Click(const UIView *view, uint8_t sleepTicks = 50) const;
56     void LongPress(const UIView *view, uint8_t sleepTicks = 200) const;
57     void Click(int16_t x, int16_t y, uint8_t sleepTicks = 50) const;
58     void LongPress(int16_t x, int16_t y, uint8_t sleepTicks = 200) const;
59     void Swipe(int16_t startX, int16_t startY, int16_t endX, int16_t endY, uint8_t sleepTicks = 150) const;
60     uint8_t GetChildrenSize(const UIViewGroup &grop) const;
61 
62 private:
63     static void *TickHandler(void *args);
64     static ScreenDevice *display_;
65     static Window *window_;
66     static pthread_t tickThread_;
67     static bool isTickTaskRunning_;
68     void CallLifecycle(JSValue page, const char *lifecycle) const;
69 
70     Component *rootComponent_;
71 };
72 } // namespace ACELite
73 } // namespace OHOS
74 #endif // OHOS_ACELITE_BASIC_TDD_TEST_CONSTANTS_H
75