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 "pipline_func_unit_test.h"
16
17 using namespace std;
18 using namespace testing::ext;
19 using namespace OHOS::Media;
20
21 namespace OHOS {
22 namespace Media {
23 namespace PiplineFuncUT {
24
SetUpTestCase(void)25 void PiplineUnitTest::SetUpTestCase(void)
26 {
27 std::cout << "[SetUpTestCase]: SetUp!!!" << std::endl;
28 }
29
TearDownTestCase(void)30 void PiplineUnitTest::TearDownTestCase(void)
31 {
32 std::cout << "[TearDownTestCase]: over!!!" << std::endl;
33 }
34
SetUp(void)35 void PiplineUnitTest::SetUp(void)
36 {
37 std::cout << "[SetUp]: SetUp!!!" << std::endl;
38 pipeline_ = std::make_shared<Pipeline::Pipeline>();
39 ASSERT_NE(pipeline_, nullptr);
40 testId = std::string("Test_") + std::to_string(Pipeline::Pipeline::GetNextPipelineId());
41 pipeline_->Init(nullptr, nullptr, testId);
42 filterOne_ = std::make_shared<TestFilter>("filterOne", Pipeline::FilterType::AUDIO_CAPTURE);
43 filterTwo_ = std::make_shared<TestFilter>("filterTwo", Pipeline::FilterType::FILTERTYPE_AENC);
44 }
45
TearDown(void)46 void PiplineUnitTest::TearDown(void)
47 {
48 std::cout << "[TearDown]: over!!!" << std::endl;
49 }
50
51 /**
52 * @tc.name: Pipeline_Test_AddHeadFilters_0100
53 * @tc.desc: Pipeline_Test_AddHeadFilters_0100
54 * @tc.type: FUNC
55 */
56 HWTEST_F(PiplineUnitTest, Pipeline_Test_AddHeadFilters_0100, TestSize.Level1)
57 {
58 EXPECT_EQ(pipeline_->AddHeadFilters({filterOne_, filterTwo_}), Status::OK);
59 }
60
61 /**
62 * @tc.name: Pipeline_Test_LinkFilters_0100
63 * @tc.desc: Pipeline_Test_LinkFilters_0100
64 * @tc.type: FUNC
65 */
66 HWTEST_F(PiplineUnitTest, Pipeline_Test_LinkFilters_0100, TestSize.Level1)
67 {
68 EXPECT_EQ(pipeline_->AddHeadFilters({filterOne_}), Status::OK);
69 EXPECT_EQ(pipeline_->LinkFilters(filterOne_, {filterTwo_},
70 Pipeline::StreamType::STREAMTYPE_ENCODED_AUDIO), Status::OK);
71 EXPECT_EQ(pipeline_->UpdateFilters(filterOne_, {filterTwo_},
72 Pipeline::StreamType::STREAMTYPE_ENCODED_AUDIO), Status::OK);
73 EXPECT_EQ(pipeline_->UnLinkFilters(filterOne_, {filterTwo_},
74 Pipeline::StreamType::STREAMTYPE_ENCODED_AUDIO), Status::OK);
75 }
76
77 /**
78 * @tc.name: Pipeline_Test_pipline_0100
79 * @tc.desc: Pipeline_Test_pipline_0100
80 * @tc.type: FUNC
81 */
82 HWTEST_F(PiplineUnitTest, Pipeline_Test_pipline_0100, TestSize.Level1)
83 {
84 EXPECT_EQ(pipeline_->AddHeadFilters({filterOne_}), Status::OK);
85 EXPECT_EQ(pipeline_->LinkFilters(filterOne_, {filterTwo_},
86 Pipeline::StreamType::STREAMTYPE_ENCODED_AUDIO), Status::OK);
87 EXPECT_EQ(pipeline_->UpdateFilters(filterOne_, {filterTwo_},
88 Pipeline::StreamType::STREAMTYPE_ENCODED_AUDIO), Status::OK);
89 EXPECT_EQ(pipeline_->UnLinkFilters(filterOne_, {filterTwo_},
90 Pipeline::StreamType::STREAMTYPE_ENCODED_AUDIO), Status::OK);
91 EXPECT_EQ(pipeline_->Prepare(), Status::OK);
92 EXPECT_EQ(pipeline_->Start(), Status::OK);
93 EXPECT_EQ(pipeline_->Pause(), Status::OK);
94 EXPECT_EQ(pipeline_->Resume(), Status::OK);
95 EXPECT_EQ(pipeline_->Stop(), Status::OK);
96 EXPECT_EQ(pipeline_->Flush(), Status::OK);
97 EXPECT_EQ(pipeline_->RemoveHeadFilter(filterOne_), Status::OK);
98 EXPECT_EQ(pipeline_->Release(), Status::OK);
99 }
100
101 } // namespace PiplineFuncUT
102 } // namespace Media
103 } // namespace OHOS
104