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 }; 50 51 class TestDefManager { 52 private: TestDefManager()53 TestDefManager() {}; 54 std::map<std::string, TestDefInfo> testInfos_; 55 56 public: 57 static TestDefManager& Instance(); 58 bool Regist(const char* testCaseName, const char* testName, RSGraphicTestType type, RSGraphicTestMode mode, 59 const char* filePath); 60 const TestDefInfo* GetTestInfo(const char* testCaseName, const char* testName) const; 61 std::vector<const TestDefInfo*> GetTestInfosByType(RSGraphicTestType type) const; 62 std::vector<const TestDefInfo*> GetAllTestInfos() const; 63 }; 64 } // namespace Rosen 65 } // namespace OHOS 66 67 #define GRAPHIC_TEST_PARAMS(test_case_name, test_name, test_type, test_mode) \ 68 bool GTEST_TEST_UNIQUE_ID_(test_case_name, test_name, __LINE__) = \ 69 OHOS::Rosen::TestDefManager::Instance().Regist(#test_case_name, #test_name, test_type, test_mode, __FILE__); \ 70 TEST_F(test_case_name, test_name) 71 72 #define GRAPHIC_TEST_2(test_type, test_name) \ 73 GRAPHIC_TEST_PARAMS(RSGraphicTest, test_name, test_type, RSGraphicTestMode::AUTOMATIC) 74 75 #define GRAPHIC_TEST_3(test_case_name, test_type, test_name) \ 76 GRAPHIC_TEST_PARAMS(test_case_name, test_name, test_type, RSGraphicTestMode::AUTOMATIC) 77 78 #define GRAPHIC_N_TEST_2(test_type, test_name) \ 79 GRAPHIC_TEST_PARAMS(RSGraphicTest, test_name, test_type, RSGraphicTestMode::MANUAL) 80 81 #define GRAPHIC_N_TEST_3(test_case_name, test_type, test_name) \ 82 GRAPHIC_TEST_PARAMS(test_case_name, test_name, test_type, RSGraphicTestMode::MANUAL) 83 84 #define GET_MACRO(_1, _2, _3, NAME, ...) NAME 85 #define GRAPHIC_TEST(...) GET_MACRO(__VA_ARGS__, GRAPHIC_TEST_3, GRAPHIC_TEST_2)(__VA_ARGS__) 86 #define GRAPHIC_N_TEST(...) GET_MACRO(__VA_ARGS__, GRAPHIC_N_TEST_3, GRAPHIC_N_TEST_2)(__VA_ARGS__) 87 88 #endif // RS_GRAPHIC_TEST_EXT_H 89