1 /* 2 * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_RENDER_MOCK_CANVAS_IMAGE__H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_RENDER_MOCK_CANVAS_IMAGE__H 18 19 #include "gmock/gmock.h" 20 21 #include "core/components_ng/render/canvas_image.h" 22 23 namespace OHOS::Ace::NG { 24 class MockCanvasImage : public CanvasImage { 25 DECLARE_ACE_TYPE(MockCanvasImage, CanvasImage); 26 public: 27 MockCanvasImage() = default; 28 ~MockCanvasImage() override = default; 29 MOCK_METHOD4(DrawToRSCanvas, void(RSCanvas&, const RSRect&, const RSRect&, const BorderRadiusArray&)); 30 MOCK_METHOD3(DrawRect, void(RSCanvas&, const RSRect&, const RSRect&)); 31 MOCK_CONST_METHOD0(GetWidth, int32_t()); 32 MOCK_CONST_METHOD0(GetHeight, int32_t()); 33 MOCK_METHOD0(IsStatic, bool()); 34 IsHdrPixelMap()35 bool IsHdrPixelMap() override 36 { 37 return true; 38 } 39 SetRedrawCallback(std::function<void ()> && callback)40 void SetRedrawCallback(std::function<void()>&& callback) override 41 { 42 redrawCallback_ = callback; 43 } 44 SetOnFinishCallback(std::function<void ()> && callback)45 void SetOnFinishCallback(std::function<void ()> &&callback) override 46 { 47 onFinishCallback_ = callback; 48 } 49 GetPixelMap()50 RefPtr<PixelMap> GetPixelMap() const override 51 { 52 void* voidPtr = static_cast<void*>(new char[0]); 53 RefPtr<PixelMap> pixelMap = PixelMap::CreatePixelMap(voidPtr); 54 if (!needPixelMap) { 55 return nullptr; 56 } 57 return pixelMap; 58 } 59 60 std::function<void()> redrawCallback_ = nullptr; 61 std::function<void()> onFinishCallback_ = nullptr; 62 63 bool needPixelMap = false; 64 }; 65 } // namespace OHOS::Ace::NG 66 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_RENDER_MOCK_CANVAS_IMAGE__H 67