• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 RS_GRAPHIC_TEST_EXT_H
17 #define RS_GRAPHIC_TEST_EXT_H
18 
19 #include "gtest/gtest.h"
20 #include "rs_graphic_log.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 enum RSGraphicTestType {
25     FRAMEWORK_TEST,
26     ANIMATION_TEST,
27     CONTENT_DISPLAY_TEST,
28     SCREEN_MANAGER_TEST,
29     HARDWARE_PRESENT_TEST,
30     DRAWING_TEST,
31     LTPO_TEST,
32     TEXT_TEST,
33     PIXMAP_TEST,
34     SYMBOL_TEST,
35     EFFECT_TEST,
36     HYBRID_RENDER_TEST,
37 };
38 
39 enum class RSGraphicTestMode : uint8_t {
40     AUTOMATIC = 0x01,
41     MANUAL = 0x02,
42     DYNAMIC = 0x04,
43     ALL = 0x01 | 0x02 | 0x04,
44 };
45 
46 struct TestDefInfo {
47     std::string testCaseName;
48     std::string testName;
49     RSGraphicTestType testType;
50     RSGraphicTestMode testMode;
51     std::string filePath;
52     bool isMultiple;
53     uint8_t testId;
54 };
55 
56 class TestDefManager {
57 private:
TestDefManager()58     TestDefManager() {};
59     std::map<std::string, TestDefInfo> testInfos_;
60     std::map<std::string, int> testCaseInfos_;
61 
62 public:
63     static TestDefManager& Instance();
64     bool Regist(const char* testCaseName, const char* testName, RSGraphicTestType type, RSGraphicTestMode mode,
65         const char* filePath, const bool isMultiple);
66     const TestDefInfo* GetTestInfo(const char* testCaseName, const char* testName) const;
67     std::vector<const TestDefInfo*> GetTestInfosByType(RSGraphicTestType type) const;
68     std::vector<const TestDefInfo*> GetAllTestInfos() const;
69     int GetTestCaseCnt(std::string testCaseName) const;
70 };
71 } // namespace Rosen
72 } // namespace OHOS
73 
74 #define GRAPHIC_TEST_PARAMS(test_case_name, test_name, test_type, test_mode, multiple_test) \
75     bool GTEST_TEST_UNIQUE_ID_(test_case_name, test_name, __LINE__) = \
76         OHOS::Rosen::TestDefManager::Instance().Regist( \
77         #test_case_name, #test_name, test_type, test_mode, __FILE__, multiple_test); \
78     TEST_F(test_case_name, test_name)
79 
80 #define GRAPHIC_TEST_2(test_type, test_name) \
81     GRAPHIC_TEST_PARAMS(RSGraphicTest, test_name, test_type, RSGraphicTestMode::AUTOMATIC, false)
82 
83 #define GRAPHIC_TEST_3(test_case_name, test_type, test_name) \
84     GRAPHIC_TEST_PARAMS(test_case_name, test_name, test_type, RSGraphicTestMode::AUTOMATIC, false)
85 
86 #define GRAPHIC_TESTS_2(test_type, test_name) \
87     GRAPHIC_TEST_PARAMS(RSGraphicTest, test_name, test_type, RSGraphicTestMode::AUTOMATIC, true)
88 
89 #define GRAPHIC_TESTS_3(test_case_name, test_type, test_name) \
90     GRAPHIC_TEST_PARAMS(test_case_name, test_name, test_type, RSGraphicTestMode::AUTOMATIC, true)
91 
92 #define GRAPHIC_N_TEST_2(test_type, test_name) \
93     GRAPHIC_TEST_PARAMS(RSGraphicTest, test_name, test_type, RSGraphicTestMode::MANUAL, false)
94 
95 #define GRAPHIC_N_TEST_3(test_case_name, test_type, test_name) \
96     GRAPHIC_TEST_PARAMS(test_case_name, test_name, test_type, RSGraphicTestMode::MANUAL, false)
97 
98 #define GRAPHIC_D_TEST_2(test_type, test_name) \
99     GRAPHIC_TEST_PARAMS(RSGraphicTest, test_name, test_type, RSGraphicTestMode::DYNAMIC, false)
100 
101 #define GRAPHIC_D_TEST_3(test_case_name, test_type, test_name) \
102     GRAPHIC_TEST_PARAMS(test_case_name, test_name, test_type, RSGraphicTestMode::DYNAMIC, false)
103 
104 #define GET_MACRO(_1, _2, _3, NAME, ...) NAME
105 #define GRAPHIC_TEST(...) GET_MACRO(__VA_ARGS__, GRAPHIC_TEST_3, GRAPHIC_TEST_2)(__VA_ARGS__)
106 #define GRAPHIC_N_TEST(...) GET_MACRO(__VA_ARGS__, GRAPHIC_N_TEST_3, GRAPHIC_N_TEST_2)(__VA_ARGS__)
107 #define GRAPHIC_TESTS(...) GET_MACRO(__VA_ARGS__, GRAPHIC_TESTS_3, GRAPHIC_TESTS_2)(__VA_ARGS__)
108 #define GRAPHIC_D_TEST(...) GET_MACRO(__VA_ARGS__, GRAPHIC_D_TEST_3, GRAPHIC_D_TEST_2)(__VA_ARGS__)
109 
110 #endif // RS_GRAPHIC_TEST_EXT_H
111