• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 MOCK_PLUGIN_BUFFER_MEMORY_H
17 #define MOCK_PLUGIN_BUFFER_MEMORY_H
18 
19 #include <gmock/gmock.h>
20 #include <gtest/gtest.h>
21 #include <memory>
22 #include <string>
23 #include "plugin_memory.h"
24 #include "plugin_buffer.h"
25 
26 namespace OHOS {
27 namespace Media {
28 namespace Plugins {
29 class MockMemory;
30 class MockBuffer : public Buffer {
31 public:
32     MockBuffer() = default;
33     ~MockBuffer() override = default;
34     MOCK_METHOD(std::shared_ptr<Memory>, WrapMemory, (uint8_t* data, size_t capacity, size_t size), (override));
35     MOCK_METHOD(std::shared_ptr<Memory>, WrapMemoryPtr,
36         (std::shared_ptr<uint8_t> data, size_t capacity, size_t size), (override));
37     MOCK_METHOD(std::shared_ptr<Memory>, AllocMemory,
38         (std::shared_ptr<Allocator> allocator, size_t capacity, size_t align), (override));
39     MOCK_METHOD(uint32_t, GetMemoryCount, (), (override));
40     MOCK_METHOD(std::shared_ptr<Memory>, GetMemory, (), (override));
41     MOCK_METHOD(void, Reset, (), (override));
42     MOCK_METHOD(bool, IsEmpty, (), (override));
43 #if !defined(OHOS_LITE) && defined(VIDEO_SUPPORT)
44     MOCK_METHOD(std::shared_ptr<Memory>, WrapSurfaceMemory, (sptr<SurfaceBuffer> surfaceBuffer), (override));
45 #endif
46 };
47 class MockMemory : public Memory {
48 public:
49     explicit MockMemory(size_t capacity, std::shared_ptr<Allocator> allocator = nullptr,
50                size_t align = 1, MemoryType type = MemoryType::VIRTUAL_MEMORY,  bool allocMem = true)
Memory(capacity,allocator,align,type,allocMem)51         : Memory(capacity, allocator, align, type, allocMem) {}
52 
53     MOCK_METHOD(size_t, GetCapacity, (), (override));
54     MOCK_METHOD(size_t, GetSize, (), (override));
55     MOCK_METHOD(const uint8_t*, GetReadOnlyData, (size_t position), (override));
56     MOCK_METHOD(uint8_t*, GetWritableAddr, (size_t estimatedWriteSize, size_t position), (override));
57     MOCK_METHOD(void, UpdateDataSize, (size_t realWriteSize, size_t position), (override));
58     MOCK_METHOD(size_t, Write, (const uint8_t* in, size_t writeSize, size_t position), (override));
59     MOCK_METHOD(size_t, Read, (uint8_t* out, size_t readSize, size_t position), (override));
60     MOCK_METHOD(void, Reset, (), (override));
61     MOCK_METHOD(MemoryType, GetMemoryType, (), (override));
62     MOCK_METHOD(uint8_t*, GetRealAddr, (), (const, override));
63 };
64 } // namespace Plugin
65 } // namespace Media
66 } // namespace OHOS
67 #endif // MOCK_PLUGIN_BUFFER_MEMORY_H