1 /*
2  * Copyright (C) 2021 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 "recorder_lite_test.h"
16 
17 #include "media_info.h"
18 #include "media_errors.h"
19 #include "recorder.h"
20 
21 #include <iostream>
22 
23 using namespace std;
24 using namespace OHOS;
25 using namespace OHOS::Media;
26 using namespace testing::ext;
27 
28 namespace OHOS {
29 const int32_t RET_OK = 0;
30 const int32_t RET_NOK = -1;
31 static int32_t g_recorderSourceMaxCount = 4; // max recorder source setting
32 
SetUpTestCase(void)33 void RecorderLiteTest::SetUpTestCase(void) {}
34 
TearDownTestCase(void)35 void RecorderLiteTest::TearDownTestCase(void) {}
36 
SetUp()37 void RecorderLiteTest::SetUp() {}
38 
TearDown()39 void RecorderLiteTest::TearDown() {}
40 
OnError(const int32_t errorType,const int32_t errorCode)41 void RecorderLiteTest::OnError(const int32_t errorType, const int32_t errorCode)
42 {
43     cout << "RecorderLiteTest::OnError ..." << endl;
44 }
45 
OnInfo(const int32_t type,const int32_t extra)46 void RecorderLiteTest::OnInfo(const int32_t type, const int32_t extra)
47 {
48     cout << "RecorderLiteTest::OnInfo ..." << endl;
49 }
50 
51 namespace Media {
OnError(int32_t errorType,int32_t errorCode)52 void TestVideoRecorderCallback::OnError(int32_t errorType, int32_t errorCode)
53 {
54     cout << "TestVideoRecorderCallback::OnError ..." << endl;
55 }
56 
OnInfo(int32_t type,int32_t extra)57 void TestVideoRecorderCallback::OnInfo(int32_t type, int32_t extra)
58 {
59     cout << "TestVideoRecorderCallback::OnInfo ..." << endl;
60 }
61 }
62 
63 /*
64  * Feature: Recorder
65  * Function: Start Recording
66  * SubFunction: NA
67  * FunctionPoints: NA
68  * EnvConditions: NA
69  * CaseDescription: Start recorder without recorder sink prepare
70  */
HWTEST_F(RecorderLiteTest,medialite_recorder_Start_test_002,Level1)71 HWTEST_F(RecorderLiteTest, medialite_recorder_Start_test_002, Level1)
72 {
73     int32_t retStatus = 0;
74     int32_t sourceId = 0;
75     int32_t audioSourceId = 0;
76     Recorder *recInstance = new Recorder();
77     shared_ptr<TestVideoRecorderCallback> cb = std::make_shared<TestVideoRecorderCallback> ();
78 
79     retStatus = recInstance->SetVideoSource(VIDEO_SOURCE_SURFACE_ES, sourceId);
80     EXPECT_EQ(RET_OK, retStatus);
81     retStatus = recInstance->SetAudioSource(AUDIO_MIC, audioSourceId);
82     EXPECT_EQ(RET_OK, retStatus);
83     retStatus = recInstance->SetRecorderCallback(cb);
84     EXPECT_EQ(RET_OK, retStatus);
85     retStatus = recInstance->Start();
86     EXPECT_NE(RET_OK, retStatus);
87     retStatus = recInstance->Release();
88     delete recInstance;
89     recInstance = nullptr;
90 }
91 
92 /*
93  * Feature: Recorder
94  * Function: Pause Recording
95  * SubFunction: NA
96  * FunctionPoints: NA
97  * EnvConditions: NA
98  * CaseDescription: Pause recorder
99  */
HWTEST_F(RecorderLiteTest,medialite_recorder_Pause_test_001,Level1)100 HWTEST_F(RecorderLiteTest, medialite_recorder_Pause_test_001, Level1)
101 {
102     int32_t retStatus = 0;
103     int32_t sourceId = 0;
104     int32_t audioSourceId = 0;
105     Recorder *recInstance = new Recorder();
106     shared_ptr<TestVideoRecorderCallback> cb = std::make_shared<TestVideoRecorderCallback> ();
107 
108     retStatus = recInstance->SetVideoSource(VIDEO_SOURCE_SURFACE_ES, sourceId);
109     EXPECT_EQ(RET_OK, retStatus);
110     retStatus = recInstance->SetAudioSource(AUDIO_MIC, audioSourceId);
111     EXPECT_EQ(RET_OK, retStatus);
112     retStatus = recInstance->Prepare();
113     EXPECT_EQ(RET_OK, retStatus);
114     retStatus = recInstance->SetRecorderCallback(cb);
115     EXPECT_EQ(RET_OK, retStatus);
116     retStatus = recInstance->Start();
117     EXPECT_EQ(RET_OK, retStatus);
118     retStatus = recInstance->Pause();
119     EXPECT_EQ(RET_OK, retStatus);
120     retStatus = recInstance->Release();
121     delete recInstance;
122     recInstance = nullptr;
123 }
124 } // namespace OHOS
125