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 }; 36 37 enum class RSGraphicTestMode : uint8_t { 38 AUTOMATIC = 0x01, 39 MANUAL = 0x02, 40 ALL = 0x01 | 0x02, 41 }; 42 43 struct TestDefInfo { 44 std::string testCaseName; 45 std::string testName; 46 RSGraphicTestType testType; 47 RSGraphicTestMode testMode; 48 std::string filePath; 49 bool isMultiple; 50 uint8_t testId; 51 }; 52 53 class TestDefManager { 54 private: TestDefManager()55 TestDefManager() {}; 56 std::map<std::string, TestDefInfo> testInfos_; 57 std::map<std::string, int> testCaseInfos_; 58 59 public: 60 static TestDefManager& Instance(); 61 bool Regist(const char* testCaseName, const char* testName, RSGraphicTestType type, RSGraphicTestMode mode, 62 const char* filePath, const bool isMultiple); 63 const TestDefInfo* GetTestInfo(const char* testCaseName, const char* testName) const; 64 std::vector<const TestDefInfo*> GetTestInfosByType(RSGraphicTestType type) const; 65 std::vector<const TestDefInfo*> GetAllTestInfos() const; 66 int GetTestCaseCnt(std::string testCaseName) const; 67 }; 68 } // namespace Rosen 69 } // namespace OHOS 70 71 #define GRAPHIC_TEST_PARAMS(test_case_name, test_name, test_type, test_mode, multiple_test) \ 72 bool GTEST_TEST_UNIQUE_ID_(test_case_name, test_name, __LINE__) = \ 73 OHOS::Rosen::TestDefManager::Instance().Regist( \ 74 #test_case_name, #test_name, test_type, test_mode, __FILE__, multiple_test); \ 75 TEST_F(test_case_name, test_name) 76 77 #define GRAPHIC_TEST_2(test_type, test_name) \ 78 GRAPHIC_TEST_PARAMS(RSGraphicTest, test_name, test_type, RSGraphicTestMode::AUTOMATIC, false) 79 80 #define GRAPHIC_TEST_3(test_case_name, test_type, test_name) \ 81 GRAPHIC_TEST_PARAMS(test_case_name, test_name, test_type, RSGraphicTestMode::AUTOMATIC, false) 82 83 #define GRAPHIC_TESTS_2(test_type, test_name) \ 84 GRAPHIC_TEST_PARAMS(RSGraphicTest, test_name, test_type, RSGraphicTestMode::AUTOMATIC, true) 85 86 #define GRAPHIC_TESTS_3(test_case_name, test_type, test_name) \ 87 GRAPHIC_TEST_PARAMS(test_case_name, test_name, test_type, RSGraphicTestMode::AUTOMATIC, true) 88 89 #define GRAPHIC_N_TEST_2(test_type, test_name) \ 90 GRAPHIC_TEST_PARAMS(RSGraphicTest, test_name, test_type, RSGraphicTestMode::MANUAL, false) 91 92 #define GRAPHIC_N_TEST_3(test_case_name, test_type, test_name) \ 93 GRAPHIC_TEST_PARAMS(test_case_name, test_name, test_type, RSGraphicTestMode::MANUAL, false) 94 95 #define GET_MACRO(_1, _2, _3, NAME, ...) NAME 96 #define GRAPHIC_TEST(...) GET_MACRO(__VA_ARGS__, GRAPHIC_TEST_3, GRAPHIC_TEST_2)(__VA_ARGS__) 97 #define GRAPHIC_N_TEST(...) GET_MACRO(__VA_ARGS__, GRAPHIC_N_TEST_3, GRAPHIC_N_TEST_2)(__VA_ARGS__) 98 #define GRAPHIC_TESTS(...) GET_MACRO(__VA_ARGS__, GRAPHIC_TESTS_3, GRAPHIC_TESTS_2)(__VA_ARGS__) 99 100 #endif // RS_GRAPHIC_TEST_EXT_H 101