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 "dragging_player_agent_unittest.h"
17
18 using namespace OHOS;
19 using namespace OHOS::Media;
20 using namespace testing;
21 using namespace testing::ext;
22
23 const static int64_t TEST_SEEK_MS = 1000;
24 const static int32_t TEST_TIMES_ONE = 1;
25
26 namespace OHOS {
27 namespace Media {
SetUpTestCase(void)28 void DraggingPlayerAgentUnitTest::SetUpTestCase(void) {}
29
TearDownTestCase(void)30 void DraggingPlayerAgentUnitTest::TearDownTestCase(void) {}
31
SetUp(void)32 void DraggingPlayerAgentUnitTest::SetUp(void)
33 {
34 mockDraggingPlayer_ = new MockDraggingPlayer();
35 }
36
TearDown(void)37 void DraggingPlayerAgentUnitTest::TearDown(void)
38 {
39 if (mockDraggingPlayer_) {
40 delete mockDraggingPlayer_;
41 mockDraggingPlayer_ = nullptr;
42 }
43 seekClosestDelegator_ = nullptr;
44 seekContinuousDelegator_ = nullptr;
45 }
46
47 /**
48 * @tc.name : Test Create
49 * @tc.number: Create_001
50 * @tc.desc : Test SeekContinuousDelegator delegator->Init() != Status::OK
51 * Test SeekContinuousDelegator DraggingPlayerAgent::createFunc_ = nullptr
52 */
53 HWTEST_F(DraggingPlayerAgentUnitTest, Create_001, TestSize.Level1)
54 {
55 seekContinuousDelegator_ = SeekContinuousDelegator::Create(nullptr, nullptr, nullptr, "");
56 EXPECT_EQ(seekContinuousDelegator_, nullptr);
57
58 seekContinuousDelegator_ = std::make_shared<SeekContinuousDelegator>(nullptr, nullptr, nullptr, "");
59 EXPECT_EQ(seekContinuousDelegator_->draggingPlayer_, nullptr);
60 }
61
62 /**
63 * @tc.name : Test Create
64 * @tc.number: Create_002
65 * @tc.desc : Test SeekClosestDelegator delegator->Init() == Status::OK
66 */
67 HWTEST_F(DraggingPlayerAgentUnitTest, Create_002, TestSize.Level1)
68 {
69 seekClosestDelegator_ = SeekClosestDelegator::Create(nullptr, nullptr, nullptr, "");
70 EXPECT_TRUE(seekClosestDelegator_);
71 }
72
73 /**
74 * @tc.name : Test Release
75 * @tc.number: Release_001
76 * @tc.desc : Test SeekContinuousDelegator monitorTask_ == nullptr
77 * Test SeekContinuousDelegator draggingPlayer_ == nullptr
78 * Test SeekContinuousDelegator demuxer_ == nullptr
79 * Test SeekContinuousDelegator decoder_ == nullptr
80 * Test ~SeekContinuousDelegator isReleased_ == false
81 * Test ~SeekContinuousDelegator draggingPlayer_ == nullptr
82 */
83 HWTEST_F(DraggingPlayerAgentUnitTest, Release_001, TestSize.Level1)
84 {
85 seekContinuousDelegator_ = std::make_shared<SeekContinuousDelegator>(nullptr, nullptr, nullptr, "");
86 seekContinuousDelegator_->Release();
87 EXPECT_TRUE(seekContinuousDelegator_->isReleased_);
88
89 seekContinuousDelegator_->isReleased_ = false;
90 seekContinuousDelegator_->draggingPlayer_ = nullptr;
91 }
92
93 /**
94 * @tc.name : Test Release
95 * @tc.number: Release_002
96 * @tc.desc : Test SeekClosestDelegator seekTask_ == nullptr
97 * Test ~SeekClosestDelegator isReleased_ == false
98 * Test ~DraggingPlayerAgent isReleased_ == true
99 * Test ~DraggingPlayerAgent delegator_ == nullptr
100 */
101 HWTEST_F(DraggingPlayerAgentUnitTest, Release_002, TestSize.Level1)
102 {
103 seekClosestDelegator_ = std::make_shared<SeekClosestDelegator>(nullptr, nullptr, nullptr, "");
104 seekClosestDelegator_->Release();
105 EXPECT_TRUE(seekClosestDelegator_->isReleased_);
106
107 seekClosestDelegator_->isReleased_ = false;
108
109 auto draggingPlayerAgent = std::make_shared<DraggingPlayerAgent>();
110 draggingPlayerAgent->isReleased_ = true;
111 draggingPlayerAgent->delegator_ = nullptr;
112 }
113
114 /**
115 * @tc.name : Test UpdateSeekPos
116 * @tc.number: UpdateSeekPos_001
117 * @tc.desc : Test SeekContinuousDelegator monitorTask_ == nullptr
118 */
119 HWTEST_F(DraggingPlayerAgentUnitTest, UpdateSeekPos_001, TestSize.Level1)
120 {
121 seekContinuousDelegator_ = std::make_shared<SeekContinuousDelegator>(nullptr, nullptr, nullptr, "");
122 seekContinuousDelegator_->draggingPlayer_ = mockDraggingPlayer_;
123 EXPECT_CALL(*mockDraggingPlayer_, UpdateSeekPos(_)).Times(TEST_TIMES_ONE);
124 seekContinuousDelegator_->UpdateSeekPos(TEST_SEEK_MS);
125 EXPECT_TRUE(!seekContinuousDelegator_->monitorTask_);
126 seekContinuousDelegator_->draggingPlayer_ = nullptr;
127 }
128 } // namespace Media
129 } // namespace OHOS