• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "transcoder_callback_unit_test.h"
17 #include <utility>
18 #include "common/log.h"
19 #include "osal/task/autolock.h"
20 #include "osal/utils/steady_clock.h"
21 #include "hitranscoder_callback_looper.h"
22 
23 using namespace OHOS;
24 using namespace OHOS::Media;
25 using namespace std;
26 using namespace testing;
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace Media {
31 namespace {
32     constexpr int32_t WHAT_NONE = 0;
33     constexpr int32_t WHAT_INFO = 2;
34 }
SetUpTestCase(void)35 void TranscoderCallbackUnitTest::SetUpTestCase(void) {}
36 
TearDownTestCase(void)37 void TranscoderCallbackUnitTest::TearDownTestCase(void) {}
38 
SetUp(void)39 void TranscoderCallbackUnitTest::SetUp(void)
40 {
41     callback_ = std::make_shared<HiTransCoderCallbackLooper>();
42     mockTranscoderEngine_ = new MockITransCoderEngine();
43     callback_->transCoderEngine_ = mockTranscoderEngine_;
44     testObs_ = std::make_shared<MockITransCoderEngineObs>();
45     callback_->task_ = std::make_unique<Task>("callbackTestThread");
46     callback_->StartWithTransCoderEngineObs(testObs_);
47 }
48 
TearDown(void)49 void TranscoderCallbackUnitTest::TearDown(void)
50 {
51     if (mockTranscoderEngine_) {
52         delete mockTranscoderEngine_;
53         mockTranscoderEngine_ = nullptr;
54     }
55     if (testObs_) {
56         testObs_ = nullptr;
57     }
58     callback_ = nullptr;
59 }
60 
61 /**
62  * @tc.name: DoReportMediaProgress_01
63  * @tc.desc: DoReportMediaProgress_01
64  * @tc.type: FUNC
65  * @tc.require:
66  */
67 HWTEST_F(TranscoderCallbackUnitTest, DoReportMediaProgress_01, TestSize.Level0)
68 {
69     callback_->reportMediaProgress_ = true;
70     testObs_ = nullptr;
71     callback_->DoReportMediaProgress();
72     EXPECT_FALSE(callback_->isDropMediaProgress_);
73     callback_->reportMediaProgress_ = false;
74 }
75 
76 /**
77  * @tc.name: DoReportMediaProgress_02
78  * @tc.desc: DoReportMediaProgress_02
79  * @tc.type: FUNC
80  * @tc.require:
81  */
82 HWTEST_F(TranscoderCallbackUnitTest, DoReportMediaProgress_02, TestSize.Level0)
83 {
84     callback_->reportMediaProgress_ = true;
85     callback_->isDropMediaProgress_ = true;
86     callback_->DoReportMediaProgress();
87     EXPECT_FALSE(testObs_->onInfoFlag);
88     callback_->reportMediaProgress_ = false;
89 }
90 
91 /**
92  * @tc.name: Enqueue
93  * @tc.desc: Enqueue
94  * @tc.type: FUNC
95  * @tc.require:
96  */
97 HWTEST_F(TranscoderCallbackUnitTest, Enqueue, TestSize.Level0)
98 {
99     std::shared_ptr<HiTransCoderCallbackLooper::Event> event =
100         std::make_shared<HiTransCoderCallbackLooper::Event>(WHAT_NONE,
101         SteadyClock::GetCurrentTimeMs(), Any());
102     callback_->Enqueue(event);
103     EXPECT_FALSE(testObs_->onInfoFlag);
104     callback_->reportMediaProgress_ = false;
105 }
106 
107 /**
108  * @tc.name: LoopOnce
109  * @tc.desc: LoopOnce
110  * @tc.type: FUNC
111  * @tc.require:
112  */
113 HWTEST_F(TranscoderCallbackUnitTest, LoopOnce, TestSize.Level0)
114 {
115     std::shared_ptr<HiTransCoderCallbackLooper::Event> event =
116         std::make_shared<HiTransCoderCallbackLooper::Event>(WHAT_INFO,
117         SteadyClock::GetCurrentTimeMs() + 100, Any());
118     callback_->LoopOnce(event);
119     EXPECT_FALSE(testObs_->onInfoFlag);
120 }
121 } // namespace Media
122 } // namespace OHOS