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 #ifndef SCREEN_CAPTURE_SERVER_FUNCTION_UNITTEST_H
16 #define SCREEN_CAPTURE_SERVER_FUNCTION_UNITTEST_H
17 
18 #include <fcntl.h>
19 #include <iostream>
20 #include <string>
21 #include <nativetoken_kit.h>
22 #include "media_errors.h"
23 #include "accesstoken_kit.h"
24 #include "token_setproc.h"
25 #include "screen_capture_server.h"
26 #include "gtest/gtest.h"
27 
28 namespace OHOS {
29 namespace Media {
30 namespace ScreenCaptureTestParam {
31 constexpr uint32_t RECORDER_TIME = 2;
32 }
33 class ScreenCaptureServerFunctionTest : public testing::Test {
34 public:
35     virtual void SetUp();
36     virtual void TearDown();
37     int32_t SetInvalidConfig();
38     int32_t SetValidConfig();
39     int32_t SetInvalidConfigFile(RecorderInfo &recorderInfo);
40     int32_t SetValidConfigFile(RecorderInfo &recorderInfo);
41     int32_t SetRecorderInfo(std::string name, RecorderInfo &recorderInfo);
42     void OpenFileFd(std::string name);
43     int32_t InitFileScreenCaptureServer();
44     int32_t InitStreamScreenCaptureServer();
45     void SetHapPermission();
46     int32_t SetScreenCaptureObserver();
47     int32_t StartFileAudioCapture();
48     int32_t StartStreamAudioCapture();
49 
50 protected:
51     std::shared_ptr<ScreenCaptureServer> screenCaptureServer_;
52     AVScreenCaptureConfig config_;
53     int32_t outputFd_ = -1;
54 private:
55     const std::string ScreenRecorderBundleName = "com.ohos.screenrecorder";
56 };
57 
58 class ScreenCaptureServerUnittestCallback : public ScreenCaptureCallBack {
59 public:
60     virtual ~ScreenCaptureServerUnittestCallback() = default;
OnError(ScreenCaptureErrorType errorType,int32_t errorCode)61     void OnError(ScreenCaptureErrorType errorType, int32_t errorCode) {};
OnAudioBufferAvailable(bool isReady,AudioCaptureSourceType type)62     void OnAudioBufferAvailable(bool isReady, AudioCaptureSourceType type) {};
OnVideoBufferAvailable(bool isReady)63     void OnVideoBufferAvailable(bool isReady) {};
OnStateChange(AVScreenCaptureStateCode stateCode)64     void OnStateChange(AVScreenCaptureStateCode stateCode) {};
65 };
66 } // Media
67 } // OHOS
68 #endif