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 #include <memory>
17 #include <iostream>
18 #include "av_hardware_memory.h"
19 #include "gtest/gtest.h"
20 #include "osal/utils/dump_buffer.h"
21 #include "common/media_core.h"
22 #include "meta/meta.h"
23 #include "buffer/avbuffer.h"
24
25 using namespace testing::ext;
26 using namespace OHOS::Media;
27
28 namespace {
29 std::string DUMP_PARAM = "w";
30 std::string DUMP_FILE_NAME = "DumpBufferTest.es";
31 const int DUMP_SIZE = 1024;
32 }
33
34 namespace OHOS {
35 namespace Media {
36 class DumpBufferTest : public testing::Test {
37 public:
SetUpTestCase(void)38 static void SetUpTestCase(void) {};
TearDownTestCase(void)39 static void TearDownTestCase(void) {};
SetUp(void)40 void SetUp(void) {};
TearDown(void)41 void TearDown(void) {};
42 };
43
44 /**
45 * @tc.name: DumpAVBufferToFile
46 * @tc.desc: DumpAVBufferToFile
47 * @tc.type: FUNC
48 */
HWTEST_F(DumpBufferTest, DumpAVBufferToFile, TestSize.Level1)49 HWTEST_F(DumpBufferTest, DumpAVBufferToFile, TestSize.Level1)
50 {
51 std::shared_ptr<Media::AVBuffer> outputBuffer = nullptr;
52 outputBuffer = std::make_shared<AVBuffer>();
53 DumpAVBufferToFile(DUMP_PARAM, DUMP_FILE_NAME, outputBuffer);
54 }
55
HWTEST_F(DumpBufferTest, DumpAVBufferToFile_002, TestSize.Level1)56 HWTEST_F(DumpBufferTest, DumpAVBufferToFile_002, TestSize.Level1)
57 {
58 std::shared_ptr<Media::AVBuffer> outputBuffer = std::make_shared<AVBuffer>();
59 outputBuffer->memory_ = nullptr;
60 DumpAVBufferToFile(DUMP_PARAM, DUMP_FILE_NAME, outputBuffer);
61 }
62
HWTEST_F(DumpBufferTest, DumpAVBufferToFile_003, TestSize.Level1)63 HWTEST_F(DumpBufferTest, DumpAVBufferToFile_003, TestSize.Level1)
64 {
65 DUMP_PARAM = "invalid";
66 std::shared_ptr<Media::AVBuffer> outputBuffer = std::make_shared<AVBuffer>();
67 outputBuffer->memory_ = std::make_shared<AVHardwareMemory>();
68 DumpAVBufferToFile(DUMP_PARAM, DUMP_FILE_NAME, outputBuffer);
69 DUMP_PARAM = "w";
70 }
71
HWTEST_F(DumpBufferTest, DumpAVBufferToFile_004, TestSize.Level1)72 HWTEST_F(DumpBufferTest, DumpAVBufferToFile_004, TestSize.Level1)
73 {
74 DUMP_FILE_NAME = "";
75 std::shared_ptr<Media::AVBuffer> outputBuffer = std::make_shared<AVBuffer>();
76 outputBuffer->memory_ = std::make_shared<AVHardwareMemory>();
77 DumpAVBufferToFile(DUMP_PARAM, DUMP_FILE_NAME, outputBuffer);
78 DUMP_FILE_NAME = "DumpBufferTest.es";
79 }
80
HWTEST_F(DumpBufferTest, DumpAVBufferToFile_005, TestSize.Level1)81 HWTEST_F(DumpBufferTest, DumpAVBufferToFile_005, TestSize.Level1)
82 {
83 std::shared_ptr<Media::AVBuffer> outputBuffer = std::make_shared<AVBuffer>();
84 outputBuffer->memory_ = std::make_shared<AVHardwareMemory>();
85 outputBuffer->memory_->SetSize(0);
86 DumpAVBufferToFile(DUMP_PARAM, DUMP_FILE_NAME, outputBuffer);
87 }
88
HWTEST_F(DumpBufferTest, DumpAVBufferToFile_006, TestSize.Level1)89 HWTEST_F(DumpBufferTest, DumpAVBufferToFile_006, TestSize.Level1)
90 {
91 std::shared_ptr<Media::AVBuffer> outputBuffer = std::make_shared<AVBuffer>();
92 outputBuffer->memory_ = std::make_shared<AVHardwareMemory>();
93 outputBuffer->memory_->SetSize(DUMP_SIZE);
94 DumpAVBufferToFile(DUMP_PARAM, DUMP_FILE_NAME, outputBuffer);
95 }
96
HWTEST_F(DumpBufferTest, DumpAVBufferToFile_007, TestSize.Level1)97 HWTEST_F(DumpBufferTest, DumpAVBufferToFile_007, TestSize.Level1)
98 {
99 std::shared_ptr<Media::AVBuffer> outputBuffer = std::make_shared<AVBuffer>();
100 outputBuffer->memory_ = std::make_shared<AVHardwareMemory>();
101 outputBuffer->memory_->SetSize(DUMP_SIZE);
102 outputBuffer->memory_->base_ = new uint8_t[DUMP_SIZE];
103 DumpAVBufferToFile(DUMP_PARAM, DUMP_FILE_NAME, outputBuffer);
104 }
105
106 }
107 }