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 #include <fcntl.h>
17 #include "avmetadata_extractor.h"
18 #include "avmetadata_extractor_base.h"
19 #include "avmetadataextractor_unit_test.h"
20 #include "native_player_magic.h"
21 #include "native_mfmagic.h"
22 #include "gtest/gtest.h"
23 #include "media_errors.h"
24
25 #include "pixel_map.h"
26 #include "pixelmap_native_impl.h"
27
28 using namespace std;
29 using namespace OHOS;
30 using namespace OHOS::Media;
31 using namespace testing::ext;
32
33 #define ALC "/data/test/MP3_SURFACE.mp3"
34 #define MD "/data/test/ChineseColor_H264_AAC_480p_15fps.mp4"
35 #define LOC "/data/test/camera_info_parser.mp4"
36
SetUpTestCase(void)37 void NativeMetadataExtractorUnitTest::SetUpTestCase(void) {}
38
TearDownTestCase(void)39 void NativeMetadataExtractorUnitTest::TearDownTestCase(void) {}
40
SetUp(void)41 void NativeMetadataExtractorUnitTest::SetUp(void) {}
42
TearDown(void)43 void NativeMetadataExtractorUnitTest::TearDown(void) {}
44
45 /**
46 * @tc.name: AVMetadataExtractor_Create_0100
47 * @tc.desc: Test create a metadata extractor object
48 * @tc.type: FUNC
49 */
HWTEST_F(NativeMetadataExtractorUnitTest,AVMetadataExtractor_Create_0100,Level2)50 HWTEST_F(NativeMetadataExtractorUnitTest, AVMetadataExtractor_Create_0100, Level2)
51 {
52 OH_AVMetadataExtractor* metadataextractor = nullptr;
53 metadataextractor = OH_AVMetadataExtractor_Create();
54
55 ASSERT_NE(nullptr, metadataextractor);
56 OH_AVMetadataExtractor_Release(metadataextractor);
57 }
58
59 /**
60 * @tc.name: AVMetadataExtractor_SetFDSource_0100
61 * @tc.desc: Test set up a data source
62 * @tc.type: FUNC
63 */
HWTEST_F(NativeMetadataExtractorUnitTest,AVMetadataExtractor_SetFDSource_0100,Level2)64 HWTEST_F(NativeMetadataExtractorUnitTest, AVMetadataExtractor_SetFDSource_0100, Level2)
65 {
66 OH_AVMetadataExtractor* metadataextractor = OH_AVMetadataExtractor_Create();
67 ASSERT_NE(nullptr, metadataextractor);
68
69 int32_t fd = open(MD, O_RDONLY);
70 ASSERT_GT(fd, 0);
71 int64_t offset = 0;
72 int64_t size = -1;
73
74 int32_t ret = OH_AVMetadataExtractor_SetFDSource(metadataextractor, fd, offset, size);
75 close(fd);
76 EXPECT_EQ(AV_ERR_OK, ret);
77 OH_AVMetadataExtractor_Release(metadataextractor);
78 }
79
80 /**
81 * @tc.name: AVMetadataExtractor_FetchMetadata_0100
82 * @tc.desc: Test get metadata
83 * @tc.type: FUNC
84 */
85 HWTEST_F(NativeMetadataExtractorUnitTest, AVMetadataExtractor_FetchMetadata_0100, TestSize.Level2)
86 {
87 OH_AVMetadataExtractor* metadataextractor = OH_AVMetadataExtractor_Create();
88 ASSERT_NE(nullptr, metadataextractor);
89
90 OH_AVFormat* avMetadata = OH_AVFormat_Create();
91
92 int32_t fd = open(MD, O_RDONLY);
93 ASSERT_GT(fd, 0);
94 int64_t offset = 0;
95 int64_t size = -1;
96
97 int32_t ret = OH_AVMetadataExtractor_SetFDSource(metadataextractor, fd, offset, size);
98 close(fd);
99 EXPECT_EQ(AV_ERR_OK, ret);
100
101
102 ret = OH_AVMetadataExtractor_FetchMetadata(metadataextractor, avMetadata);
103 EXPECT_EQ(AV_ERR_OK, ret);
104
105 OH_AVMetadataExtractor_Release(metadataextractor);
106 OH_AVFormat_Destroy(avMetadata);
107 }
108
109 /**
110 * @tc.name: AVMetadataExtractor_FetchMetadata_0200
111 * @tc.desc: Test get metadata
112 * @tc.type: FUNC
113 */
114 HWTEST_F(NativeMetadataExtractorUnitTest, AVMetadataExtractor_FetchMetadata_0200, TestSize.Level2)
115 {
116 OH_AVMetadataExtractor* metadataextractor = OH_AVMetadataExtractor_Create();
117 ASSERT_NE(nullptr, metadataextractor);
118
119 OH_AVFormat* avMetadata = OH_AVFormat_Create();
120
121 int32_t fd = open(LOC, O_RDONLY);
122 ASSERT_GT(fd, 0);
123 int64_t offset = 0;
124 int64_t size = -1;
125
126 int32_t ret = OH_AVMetadataExtractor_SetFDSource(metadataextractor, fd, offset, size);
127 close(fd);
128 EXPECT_EQ(AV_ERR_OK, ret);
129
130
131 ret = OH_AVMetadataExtractor_FetchMetadata(metadataextractor, avMetadata);
132 EXPECT_EQ(AV_ERR_OK, ret);
133
134 OH_AVMetadataExtractor_Release(metadataextractor);
135 OH_AVFormat_Destroy(avMetadata);
136 }
137
138 /**
139 * @tc.name: AVMetadataExtractor_FetchAlbumCover_0100
140 * @tc.desc: Test get the albumCover
141 * @tc.type: FUNC
142 */
143 HWTEST_F(NativeMetadataExtractorUnitTest, AVMetadataExtractor_FetchAlbumCover_0100, TestSize.Level2)
144 {
145 OH_AVMetadataExtractor* metadataextractor = OH_AVMetadataExtractor_Create();
146 ASSERT_NE(nullptr, metadataextractor);
147
148 int32_t fd = open(ALC, O_RDONLY);
149 ASSERT_GT(fd, 0);
150 int64_t offset = 0;
151 int64_t size = -1;
152 int32_t ret = OH_AVMetadataExtractor_SetFDSource(metadataextractor, fd, offset, size);
153 close(fd);
154 EXPECT_EQ(AV_ERR_OK, ret);
155
156 OH_PixelmapNative* pixelmapNative = nullptr;
157
158 ret = OH_AVMetadataExtractor_FetchAlbumCover(metadataextractor, &pixelmapNative);
159 EXPECT_EQ(AV_ERR_OK, ret);
160 OH_AVMetadataExtractor_Release(metadataextractor);
161 OH_PixelmapNative_Release(pixelmapNative);
162 }
163
164 /**
165 * @tc.name: AVMetadataExtractor_Release_0100
166 * @tc.desc: Test release the metadata extractor object
167 * @tc.type: FUNC
168 */
169 HWTEST_F(NativeMetadataExtractorUnitTest, AVMetadataExtractor_Release_0100, TestSize.Level2)
170 {
171 OH_AVMetadataExtractor* metadataextractor = OH_AVMetadataExtractor_Create();
172 ASSERT_NE(nullptr, metadataextractor);
173
174 OH_AVErrCode ret = OH_AVMetadataExtractor_Release(metadataextractor);
175 EXPECT_EQ(AV_ERR_OK, ret);
176 }