1/*
2 * Copyright (c) 2021-2021 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#include "gtest/gtest.h"
17#include "plugin/common/plugin_buffer.h"
18#include "plugin/common/surface_allocator.h"
19#include "plugin/common/surface_memory.h"
20#include "plugin/common/share_memory.h"
21#include "surface.h"
22namespace OHOS {
23namespace Media {
24namespace Test {
25using namespace Plugin;
26using namespace testing::ext;
27HWTEST(PluginBufferTest, test_PluginBuffer, TestSize.Level1) {
28    std::shared_ptr<Buffer> audioBuffer = Buffer::CreateDefaultBuffer(BufferMetaType::AUDIO, 16,
29                                                                      std::shared_ptr<Allocator>(), 1);
30    audioBuffer->AllocMemory(nullptr, 16);
31    ASSERT_TRUE(nullptr == audioBuffer->GetMemory(10));
32    std::shared_ptr<Memory> memory = audioBuffer->GetMemory(0);
33    uint8_t in;
34    memory->Write(&in, 10, -1);
35    memory->Write(&in, 10, 0);
36    memory->Read(&in, 10, 0);
37    ASSERT_TRUE(nullptr == memory->GetReadOnlyData(17));
38    ASSERT_TRUE(nullptr == memory->GetWritableAddr(8, 9));
39    memory->UpdateDataSize(8, 9);
40    audioBuffer->Reset();
41    audioBuffer->ChangeBufferMetaType(BufferMetaType::AUDIO);
42    audioBuffer->ChangeBufferMetaType(BufferMetaType::VIDEO);
43    std::shared_ptr<Buffer> videoBuffer = Buffer::CreateDefaultBuffer(BufferMetaType::VIDEO, 16,
44                                                                      std::shared_ptr<Allocator>(), 1);
45    videoBuffer->Reset();
46}
47} //namespace Test
48} //namespace Media
49} //namespace OHOS