• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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_UNIT_TEST_H
16 #define SCREEN_CAPTURE_UNIT_TEST_H
17 
18 #include "gtest/gtest.h"
19 #include "screen_capture_mock.h"
20 
21 namespace OHOS {
22 namespace Media {
23 class ScreenCaptureUnitTestCallback : public ScreenCaptureCallBackMock {
24 public:
ScreenCaptureUnitTestCallback(std::shared_ptr<ScreenCaptureMock> ScreenCapture,FILE * aFile,FILE * vFile,int32_t aFlag,int32_t vFlag)25     explicit ScreenCaptureUnitTestCallback(std::shared_ptr<ScreenCaptureMock> ScreenCapture, FILE *aFile, FILE *vFile,
26         int32_t aFlag, int32_t vFlag)
27         : screenCapture_(ScreenCapture), aFile_(aFile), vFile_(vFile), aFlag_(aFlag), vFlag_(vFlag) {}
28     ~ScreenCaptureUnitTestCallback() = default;
29     void OnError(int32_t errorCode) override;
30     void OnAudioBufferAvailable(bool isReady, AudioCaptureSourceType type) override;
31     void OnVideoBufferAvailable(bool isReady) override;
32     void DumpAudioBuffer(std::shared_ptr<AudioBuffer> audioBuffer);
33     void DumpVideoBuffer(sptr<OHOS::SurfaceBuffer> surfacebuffer);
34 private:
35     std::shared_ptr<ScreenCaptureMock> screenCapture_;
36     FILE *aFile_ = nullptr;
37     FILE *vFile_ = nullptr;
38     int32_t aFlag_ = 0;
39     int32_t vFlag_ = 0;
40 };
41 
42 class ScreenCaptureUnitTest : public testing::Test {
43 public:
44     static void SetUpTestCase(void);
45     static void TearDownTestCase(void);
46     void SetUp(void);
47     void TearDown(void);
48     void AudioLoop(void);
49     void AudioLoopWithoutRelease(void);
50     int32_t SetConfig(AVScreenCaptureConfig &config);
51     void OpenFile(std::string filename_);
52     void CloseFile(void);
53     char filename[100] = {0};
54     FILE *aFile = nullptr;
55     FILE *vFile = nullptr;
56     int32_t aFlag = 0;
57     int32_t vFlag = 0;
58 protected:
59     std::shared_ptr<ScreenCaptureMock> screenCapture_ = nullptr;
60     std::shared_ptr<ScreenCaptureUnitTestCallback> screenCaptureCb_ = nullptr;
61     std::unique_ptr<std::thread> audioLoop_ = nullptr;
62 };
63 } // namespace Media
64 } // namespace OHOS
65 #endif