• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 
18 #include "dcamera_pipeline_source.h"
19 #include "distributed_camera_constants.h"
20 #include "distributed_camera_errno.h"
21 #include "mock_dcamera_data_process_listener.h"
22 
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace DistributedHardware {
27 class DCameraPipelineSourceTest : public testing::Test {
28 public:
29     static void SetUpTestCase(void);
30     static void TearDownTestCase(void);
31     void SetUp();
32     void TearDown();
33 
34     std::shared_ptr<IDataProcessPipeline> testSourcePipeline_;
35 };
36 
37 namespace {
38 const int32_t TEST_WIDTH = 1920;
39 const int32_t TEST_HEIGTH = 1080;
40 const int32_t TEST_WIDTH2 = 640;
41 const int32_t TEST_HEIGTH2 = 480;
42 }
43 
SetUpTestCase(void)44 void DCameraPipelineSourceTest::SetUpTestCase(void)
45 {
46 }
47 
TearDownTestCase(void)48 void DCameraPipelineSourceTest::TearDownTestCase(void)
49 {
50 }
51 
SetUp(void)52 void DCameraPipelineSourceTest::SetUp(void)
53 {
54     testSourcePipeline_ = std::make_shared<DCameraPipelineSource>();
55 }
56 
TearDown(void)57 void DCameraPipelineSourceTest::TearDown(void)
58 {
59     testSourcePipeline_ = nullptr;
60 }
61 
62 /**
63  * @tc.name: dcamera_pipeline_source_test_001
64  * @tc.desc: Verify pipeline source CreateDataProcessPipeline normal.
65  * @tc.type: FUNC
66  * @tc.require: Issue Number
67  */
68 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_001, TestSize.Level1)
69 {
70     EXPECT_EQ(false, testSourcePipeline_ == nullptr);
71 
72     std::shared_ptr<DataProcessListener> listener = std::make_shared<MockDCameraDataProcessListener>();
73     VideoConfigParams srcParams(VideoCodecType::CODEC_H264,
74                                 Videoformat::NV12,
75                                 DCAMERA_PRODUCER_FPS_DEFAULT,
76                                 TEST_WIDTH,
77                                 TEST_HEIGTH);
78     VideoConfigParams destParams(VideoCodecType::CODEC_H264,
79                                  Videoformat::NV21,
80                                  DCAMERA_PRODUCER_FPS_DEFAULT,
81                                  TEST_WIDTH2,
82                                  TEST_HEIGTH2);
83     int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener);
84     EXPECT_EQ(rc, DCAMERA_OK);
85 }
86 
87 /**
88  * @tc.name: dcamera_pipeline_source_test_002
89  * @tc.desc: Verify pipeline source ProcessData normal.
90  * @tc.type: FUNC
91  * @tc.require: Issue Number
92  */
93 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_002, TestSize.Level1)
94 {
95     EXPECT_EQ(false, testSourcePipeline_ == nullptr);
96 
97     std::shared_ptr<DataProcessListener> listener = std::make_shared<MockDCameraDataProcessListener>();
98     VideoConfigParams srcParams(VideoCodecType::CODEC_H264,
99                                 Videoformat::NV21,
100                                 DCAMERA_PRODUCER_FPS_DEFAULT,
101                                 TEST_WIDTH,
102                                 TEST_HEIGTH);
103     VideoConfigParams destParams(VideoCodecType::CODEC_H264,
104                                  Videoformat::NV21,
105                                  DCAMERA_PRODUCER_FPS_DEFAULT,
106                                  TEST_WIDTH,
107                                  TEST_HEIGTH);
108     int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener);
109     EXPECT_EQ(rc, DCAMERA_OK);
110 }
111 
112 /**
113  * @tc.name: dcamera_pipeline_source_test_003
114  * @tc.desc: Verify pipeline source CreateDataProcessPipeline abnormal.
115  * @tc.type: FUNC
116  * @tc.require: Issue Number
117  */
118 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_003, TestSize.Level1)
119 {
120     EXPECT_EQ(false, testSourcePipeline_ == nullptr);
121 
122     std::shared_ptr<DataProcessListener> listener = std::make_shared<MockDCameraDataProcessListener>();
123     VideoConfigParams srcParams(VideoCodecType::NO_CODEC,
124                                 Videoformat::NV21,
125                                 DCAMERA_PRODUCER_FPS_DEFAULT,
126                                 TEST_WIDTH,
127                                 TEST_HEIGTH);
128     VideoConfigParams destParams(VideoCodecType::CODEC_H264,
129                                  Videoformat::NV21,
130                                  DCAMERA_PRODUCER_FPS_DEFAULT,
131                                  TEST_WIDTH,
132                                  TEST_HEIGTH);
133     int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(
134         PipelineType::PHOTO_JPEG, srcParams, destParams, listener);
135     EXPECT_EQ(rc, DCAMERA_NOT_FOUND);
136 }
137 
138 /**
139  * @tc.name: dcamera_pipeline_source_test_004
140  * @tc.desc: Verify pipeline source ProcessData abnormal.
141  * @tc.type: FUNC
142  * @tc.require: Issue Number
143  */
144 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_004, TestSize.Level1)
145 {
146     EXPECT_EQ(false, testSourcePipeline_ == nullptr);
147 
148     std::shared_ptr<DataProcessListener> listener = std::make_shared<MockDCameraDataProcessListener>();
149     VideoConfigParams srcParams(VideoCodecType::NO_CODEC,
150                                 Videoformat::NV21,
151                                 DCAMERA_PRODUCER_FPS_DEFAULT,
152                                 TEST_WIDTH,
153                                 TEST_HEIGTH);
154     VideoConfigParams destParams(VideoCodecType::NO_CODEC,
155                                  Videoformat::NV21,
156                                  DCAMERA_PRODUCER_FPS_DEFAULT,
157                                  TEST_WIDTH,
158                                  TEST_HEIGTH);
159     int32_t rc = testSourcePipeline_->CreateDataProcessPipeline(PipelineType::VIDEO, srcParams, destParams, listener);
160     EXPECT_EQ(rc, DCAMERA_OK);
161 
162     std::vector<std::shared_ptr<DataBuffer>> buffers;
163     rc = testSourcePipeline_->ProcessData(buffers);
164     EXPECT_EQ(rc, DCAMERA_BAD_VALUE);
165 }
166 
167 /**
168  * @tc.name: dcamera_pipeline_source_test_005
169  * @tc.desc: Verify pipeline source ProcessData abnormal.
170  * @tc.type: FUNC
171  * @tc.require: Issue Number
172  */
173 HWTEST_F(DCameraPipelineSourceTest, dcamera_pipeline_source_test_005, TestSize.Level1)
174 {
175     EXPECT_EQ(false, testSourcePipeline_ == nullptr);
176 
177     size_t capacity = 100;
178     std::vector<std::shared_ptr<DataBuffer>> buffers;
179     std::shared_ptr<DataBuffer> db = std::make_shared<DataBuffer>(capacity);
180     buffers.push_back(db);
181     int32_t rc = testSourcePipeline_->ProcessData(buffers);
182     EXPECT_EQ(rc, DCAMERA_INIT_ERR);
183 }
184 } // namespace DistributedHardware
185 } // namespace OHOS
186