1 /*
2 * Copyright (c) 2022 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 <gtest/gtest.h>
17
18 #include "avplayback_state.h"
19
20 using namespace testing::ext;
21 using namespace OHOS::AVSession;
22 class AVPlaybackStateTest : public testing::Test {
23 public:
24 static void SetUpTestCase();
25 static void TearDownTestCase();
26 void SetUp() override;
27 void TearDown() override;
28 };
29
SetUpTestCase()30 void AVPlaybackStateTest::SetUpTestCase()
31 {}
32
TearDownTestCase()33 void AVPlaybackStateTest::TearDownTestCase()
34 {}
35
SetUp()36 void AVPlaybackStateTest::SetUp()
37 {}
38
TearDown()39 void AVPlaybackStateTest::TearDown()
40 {}
41
42 /**
43 * @tc.name: SetState001
44 * @tc.desc: Setting State with empty constructor
45 * @tc.type: FUNC
46 * @tc.require: AR000H31JM
47 */
48 HWTEST_F(AVPlaybackStateTest, SetState001, TestSize.Level1)
49 {
50 auto *avp = new (std::nothrow) AVPlaybackState();
51 EXPECT_NE(avp, nullptr);
52 avp->SetState(0);
53 avp->SetSpeed(3.0);
54 avp->SetLoopMode(1);
55 avp->SetBufferedTime(40);
56 avp->SetPosition({10, 10});
57 avp->SetFavorite(true);
58 auto *parcel = new (std::nothrow) OHOS::Parcel();
59 EXPECT_NE(parcel, nullptr);
60 bool boo = avp->Marshalling(*parcel);
61 EXPECT_EQ(boo, true);
62 }
63
64 /**
65 * @tc.name: IsValid001
66 * @tc.desc: Return is avplaybackstate IsValid success
67 * @tc.type: FUNC
68 * @tc.require: I5YMXD
69 */
70 HWTEST_F(AVPlaybackStateTest, IsValid001, TestSize.Level1)
71 {
72 AVPlaybackState avPlaybackState;
73 avPlaybackState.SetState(1);
74 avPlaybackState.SetSpeed(3.0);
75 avPlaybackState.SetLoopMode(1);
76 avPlaybackState.SetBufferedTime(40);
77 avPlaybackState.SetPosition({10, 10});
78 avPlaybackState.SetFavorite(true);
79
80 EXPECT_EQ(avPlaybackState.IsValid(), true);
81 }
82
83 /**
84 * @tc.name: IsValid002
85 * @tc.desc: Return is avplaybackstate IsValid failed
86 * @tc.type: FUNC
87 * @tc.require: I5YMXD
88 */
89 HWTEST_F(AVPlaybackStateTest, IsValid002, TestSize.Level1)
90 {
91 AVPlaybackState avPlaybackState;
92 avPlaybackState.SetState(-1);
93 avPlaybackState.SetSpeed(3.0);
94 avPlaybackState.SetLoopMode(1);
95 avPlaybackState.SetBufferedTime(40);
96 avPlaybackState.SetPosition({10, 10});
97 avPlaybackState.SetFavorite(true);
98
99 EXPECT_EQ(avPlaybackState.IsValid(), false);
100 }
101
102 /**
103 * @tc.name: GetState001
104 * @tc.desc: Getting state after using parcel to set
105 * @tc.type: FUNC
106 * @tc.require: AR000H31JM
107 */
108 HWTEST_F(AVPlaybackStateTest, GetState001, TestSize.Level1)
109 {
110 auto *parcel = new (std::nothrow) OHOS::Parcel();
111 EXPECT_NE(parcel, nullptr);
112 AVPlaybackState::PlaybackStateMaskType mask;
113 mask.set();
114 parcel->WriteString(mask.to_string());
115 parcel->WriteInt32(0);
116 parcel->WriteDouble(3.0);
117 parcel->WriteInt64(30);
118 parcel->WriteInt64(3);
119 parcel->WriteInt64(3);
120 parcel->WriteInt32(3);
121 parcel->WriteBool(true);
122 AVPlaybackState *result = AVPlaybackState::Unmarshalling(*parcel);
123 ASSERT_NE(result, nullptr);
124 EXPECT_EQ(result->GetFavorite(), true);
125 }
126
127 /**
128 * @tc.name: GetState002
129 * @tc.desc: Getting state after using marshalling to set
130 * @tc.type: FUNC
131 * @tc.require: AR000H31JM
132 */
133 HWTEST_F(AVPlaybackStateTest, GetState002, TestSize.Level1)
134 {
135 auto *avp = new (std::nothrow) AVPlaybackState();
136 EXPECT_NE(avp, nullptr);
137 avp->SetSpeed(3.0);
138 auto *parcel = new (std::nothrow) OHOS::Parcel();
139 EXPECT_NE(parcel, nullptr);
140 bool boo = avp->Marshalling(*parcel);
141 ASSERT_EQ(boo, true);
142 AVPlaybackState *result = AVPlaybackState::Unmarshalling(*parcel);
143 ASSERT_NE(result, nullptr);
144 EXPECT_EQ(result->GetSpeed(), 3.0);
145 }
146
147 /**
148 * @tc.name: GetMask001
149 * @tc.desc: Return is avplaybackstate GetMask success
150 * @tc.type: FUNC
151 * @tc.require: I5YMXD
152 */
153 HWTEST_F(AVPlaybackStateTest, GetMask001, TestSize.Level1)
154 {
155 AVPlaybackState avPlaybackState;
156 avPlaybackState.SetState(0);
157 avPlaybackState.SetSpeed(3.0);
158 avPlaybackState.SetLoopMode(1);
159 avPlaybackState.SetBufferedTime(40);
160 avPlaybackState.SetPosition({10, 10});
161 avPlaybackState.SetFavorite(true);
162
163 EXPECT_EQ(avPlaybackState.GetMask(), 0b111111);
164 }
165
166 /**
167 * @tc.name: CopyToByMask001
168 * @tc.desc: Return is avplaybackstate CopyToByMask success
169 * @tc.type: FUNC
170 * @tc.require: I5YMXD
171 */
172 HWTEST_F(AVPlaybackStateTest, CopyToByMask001, TestSize.Level1)
173 {
174 AVPlaybackState stateOut;
175 stateOut.SetSpeed(3.0);
176 AVPlaybackState::PlaybackStateMaskType mask = stateOut.GetMask();
177
178 AVPlaybackState stateTest;
179 stateTest.SetSpeed(3.0);
180 auto ret = stateTest.CopyToByMask(mask, stateOut);
181 EXPECT_EQ(ret, true);
182 }
183
184 /**
185 * @tc.name: CopyToByMask002
186 * @tc.desc: Return is avplaybackstate CopyToByMask failed
187 * @tc.type: FUNC
188 * @tc.require: I5YMXD
189 */
190 HWTEST_F(AVPlaybackStateTest, CopyToByMask002, TestSize.Level1)
191 {
192 AVPlaybackState stateOut;
193 AVPlaybackState::PlaybackStateMaskType mask = stateOut.GetMask();
194
195 AVPlaybackState stateTest;
196 auto ret = stateTest.CopyToByMask(mask, stateOut);
197 EXPECT_EQ(ret, false);
198 }
199
200 /**
201 * @tc.name: CopyFrom001
202 * @tc.desc: Return is avplaybackstate CopyFrom success
203 * @tc.type: FUNC
204 * @tc.require: I5YMXD
205 */
206 HWTEST_F(AVPlaybackStateTest, CopyFrom001, TestSize.Level1)
207 {
208 AVPlaybackState stateOut;
209 stateOut.SetSpeed(3.0);
210
211 AVPlaybackState stateTest;
212 auto ret = stateTest.CopyFrom(stateOut);
213 EXPECT_EQ(stateTest.GetSpeed(), 3.0);
214 EXPECT_EQ(ret, true);
215 }
216
217 /**
218 * @tc.name: CopyFrom002
219 * @tc.desc: Return is avplaybackstate CopyFrom failed
220 * @tc.type: FUNC
221 * @tc.require: I5YMXD
222 */
223 HWTEST_F(AVPlaybackStateTest, CopyFrom002, TestSize.Level1)
224 {
225 AVPlaybackState stateOut;
226
227 AVPlaybackState stateTest;
228 auto ret = stateTest.CopyFrom(stateOut);
229 EXPECT_EQ(ret, false);
230 }