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