• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <string>
16 #include <sys/stat.h>
17 #include <fcntl.h>
18 #include <cinttypes>
19 #include "gtest/gtest.h"
20 #include "avcodec_errors.h"
21 #include "avcodec_info.h"
22 #include "media_description.h"
23 #include "file_source_plugin_unit_test.h"
24 
25 using namespace OHOS;
26 using namespace OHOS::Media;
27 using namespace std;
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace Media {
32 namespace Plugins {
33 namespace FileSource {
SetUpTestCase(void)34 void OHOS::Media::Plugins::FileSource::FileSourceUnitTest::SetUpTestCase(void)
35 {
36 }
37 
TearDownTestCase(void)38 void FileSourceUnitTest::TearDownTestCase(void)
39 {
40 }
41 
SetUp(void)42 void FileSourceUnitTest::SetUp(void)
43 {
44     fileSourcePlugin_ = std::make_shared<FileSourcePlugin>("SourceTest");
45 }
46 
TearDown(void)47 void FileSourceUnitTest::TearDown(void)
48 {
49     fileSourcePlugin_ = nullptr;
50 }
51 
52 /**
53  * @tc.name  : Alloc_001
54  * @tc.number: Alloc_001
55  * @tc.desc  : Test when size is zero, Alloc should return nullptr
56  */
57 HWTEST_F(FileSourceUnitTest, Alloc_001, TestSize.Level1)
58 {
59     FileSourceAllocator allocator;
60     void* result = allocator.Alloc(0);
61     EXPECT_EQ(result, nullptr);
62 }
63 
64 /**
65  * @tc.name  : Alloc_002
66  * @tc.number: AllocTest_002
67  * @tc.desc  : Test when size is non-zero, Alloc should return valid memory
68  */
69 HWTEST_F(FileSourceUnitTest, Alloc_002, TestSize.Level1)
70 {
71     FileSourceAllocator allocator;
72     void* result = allocator.Alloc(10);
73     EXPECT_NE(result, nullptr);
74     delete[] static_cast<uint8_t*>(result);
75 }
76 
77 /**
78  * @tc.name: FileSource_Prepare_0100
79  * @tc.desc: FileSource_Prepare_0100
80  * @tc.type: FUNC
81  */
82 HWTEST_F(FileSourceUnitTest, FileSource_Prepare_0100, TestSize.Level1)
83 {
84     EXPECT_EQ(Status::OK, fileSourcePlugin_->Prepare());
85 }
86 /**
87  * @tc.name: FileSource_Reset_0100
88  * @tc.desc: FileSource_Reset_0100
89  * @tc.type: FUNC
90  */
91 HWTEST_F(FileSourceUnitTest, FileSource_Reset_0100, TestSize.Level1)
92 {
93     EXPECT_EQ(Status::OK, fileSourcePlugin_->Reset());
94 }
95 /**
96  * @tc.name: FileSource_GetParameter_0100
97  * @tc.desc: FileSource_GetParameter_0100
98  * @tc.type: FUNC
99  */
100 HWTEST_F(FileSourceUnitTest, FileSource_GetParameter_0100, TestSize.Level1)
101 {
102     std::shared_ptr<Meta> meta = std::make_shared<Meta>();
103     fileSourcePlugin_->GetParameter(meta);
104     EXPECT_EQ(Status::OK, fileSourcePlugin_->Deinit());
105 }
106 /**
107  * @tc.name: FileSource_GetAllocator_0100
108  * @tc.desc: FileSource_GetAllocator_0100
109  * @tc.type: FUNC
110  */
111 HWTEST_F(FileSourceUnitTest, FileSource_GetAllocator_0100, TestSize.Level1)
112 {
113     fileSourcePlugin_->GetAllocator();
114     EXPECT_EQ(Status::OK, fileSourcePlugin_->Deinit());
115 }
116 /**
117  * @tc.name: FileSource_SetSource_0100
118  * @tc.desc: FileSource_SetSource_0100
119  * @tc.type: FUNC
120  */
121 HWTEST_F(FileSourceUnitTest, FileSource_SetSource_0100, TestSize.Level1)
122 {
123     std::shared_ptr<MediaSource> source = std::make_shared<MediaSource>("file:////");
124     EXPECT_NE(Status::OK, fileSourcePlugin_->SetSource(source));
125     EXPECT_EQ(Status::OK, fileSourcePlugin_->Deinit());
126 }
127 /**
128  * @tc.name: FileSource_ParseFileName_0100
129  * @tc.desc: FileSource_ParseFileName_0100
130  * @tc.type: FUNC
131  */
132 HWTEST_F(FileSourceUnitTest, FileSource_ParseFileName_0100, TestSize.Level1)
133 {
134     std::string uri = "";
135     std::shared_ptr<MediaSource> source = std::make_shared<MediaSource>(uri);
136     fileSourcePlugin_->SetSource(source);
137     uri = "file://#test";
138     source = std::make_shared<MediaSource>(uri);
139     fileSourcePlugin_->SetSource(source);
140     uri = "file://#";
141     source = std::make_shared<MediaSource>(uri);
142     fileSourcePlugin_->SetSource(source);
143     uri = "file://#";
144     source = std::make_shared<MediaSource>(uri);
145     fileSourcePlugin_->SetSource(source);
146     uri = "file:///////////#";
147     source = std::make_shared<MediaSource>(uri);
148     fileSourcePlugin_->SetSource(source);
149     EXPECT_EQ(Status::OK, fileSourcePlugin_->Deinit());
150 }
151 
152 /**
153  * @tc.name: FileSource_IsLocalFd_0100
154  * @tc.desc: FileSource_IsLocalFd_0100
155  * @tc.type: FUNC
156  */
157 HWTEST_F(FileSourceUnitTest, FileSource_IsLocalFd_0100, TestSize.Level1)
158 {
159     ASSERT_TRUE(fileSourcePlugin_->IsLocalFd());
160 }
161 } // namespace FileSource
162 } // namespace Plugins
163 } // namespace Media
164 } // namespace OHOS