1 /* 2 * Copyright (c) 2025 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 EFFECT_TEST_UTILS_H 17 #define EFFECT_TEST_UTILS_H 18 19 #include <functional> 20 #include <memory> 21 #include "gtest/gtest.h" 22 23 #ifdef ROSEN_OHOS 24 #include <parcel.h> 25 #endif 26 27 namespace OHOS { 28 namespace Rosen { 29 namespace Drawing { 30 31 class ImageFilter; 32 class ShaderEffect; 33 class Data; 34 35 class EffectTestUtils { 36 public: 37 // Compare serialization data between two ImageFilters 38 static bool CompareImageFilter(const std::shared_ptr<ImageFilter>& filter1, 39 const std::shared_ptr<ImageFilter>& filter2); 40 41 // Compare serialization data between two ShaderEffects 42 static bool CompareShaderEffect(const std::shared_ptr<ShaderEffect>& shader1, 43 const std::shared_ptr<ShaderEffect>& shader2); 44 45 #ifdef ROSEN_OHOS 46 // Setup marshalling/unmarshalling callbacks for effect tests 47 static void SetupMarshallingCallbacks(); 48 49 // Restore original marshalling/unmarshalling callbacks 50 static void RestoreMarshallingCallbacks(); 51 52 // Temporarily clear marshalling callback and return saved callback for restoration 53 static std::function<bool(Parcel&, std::shared_ptr<Data>)> ClearMarshallingCallback(); 54 55 // Restore specific marshalling callback 56 static void RestoreMarshallingCallback(const std::function<bool(Parcel&, std::shared_ptr<Data>)>& callback); 57 58 private: 59 static std::function<bool(Parcel&, std::shared_ptr<Data>)> originalMarshallingCallback_; 60 static std::function<std::shared_ptr<Data>(Parcel&)> originalUnmarshallingCallback_; 61 #endif 62 }; 63 64 } // namespace Drawing 65 } // namespace Rosen 66 } // namespace OHOS 67 68 #endif // EFFECT_TEST_UTILS_H