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
16 #include <gtest/gtest.h>
17
18 #include "avcall_state.h"
19
20 using namespace testing::ext;
21
22 namespace OHOS {
23 namespace AVSession {
24 class AVCallStateTest : 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 AVCallStateTest::SetUpTestCase()
33 {}
34
TearDownTestCase()35 void AVCallStateTest::TearDownTestCase()
36 {}
37
SetUp()38 void AVCallStateTest::SetUp()
39 {}
40
TearDown()41 void AVCallStateTest::TearDown()
42 {}
43
44 /**
45 * @tc.name: SetAVCallState001
46 * @tc.desc: Setting AVCallState with empty constructor
47 * @tc.type: FUNC
48 */
49 HWTEST_F(AVCallStateTest, SetAVCallState001, TestSize.Level1)
50 {
51 auto *avp = new (std::nothrow) AVCallState();
52 EXPECT_NE(avp, nullptr);
53 avp->SetAVCallState(1);
54 avp->SetAVCallMuted(true);
55 auto *parcel = new (std::nothrow) OHOS::Parcel();
56 EXPECT_NE(parcel, nullptr);
57 bool boo = avp->Marshalling(*parcel);
58 EXPECT_EQ(boo, true);
59 }
60
61 /**
62 * @tc.name: IsValid001
63 * @tc.desc: Return is avcallstate IsValid success
64 * @tc.type: FUNC
65 */
66 HWTEST_F(AVCallStateTest, IsValid001, TestSize.Level1)
67 {
68 AVCallState avCallState;
69 avCallState.SetAVCallState(2);
70 avCallState.SetAVCallMuted(false);
71
72 EXPECT_EQ(avCallState.IsValid(), true);
73 }
74
75 /**
76 * @tc.name: IsValid002
77 * @tc.desc: Return is avcallstate IsValid failed
78 * @tc.type: FUNC
79 */
80 HWTEST_F(AVCallStateTest, IsValid002, TestSize.Level1)
81 {
82 AVCallState avCallState;
83 avCallState.SetAVCallState(-1);
84 avCallState.SetAVCallMuted(false);
85
86 EXPECT_EQ(avCallState.IsValid(), false);
87 }
88
89 /**
90 * @tc.name: GetAVCallState001
91 * @tc.desc: Getting avcall state after using marshalling to set
92 * @tc.type: FUNC
93 */
94 HWTEST_F(AVCallStateTest, GetAVCallState001, TestSize.Level1)
95 {
96 auto *avp = new (std::nothrow) AVCallState();
97 EXPECT_NE(avp, nullptr);
98 avp->SetAVCallState(3);
99 auto *parcel = new (std::nothrow) OHOS::Parcel();
100 EXPECT_NE(parcel, nullptr);
101 bool boo = avp->Marshalling(*parcel);
102 ASSERT_EQ(boo, true);
103 AVCallState *result = AVCallState::Unmarshalling(*parcel);
104 ASSERT_NE(result, nullptr);
105 EXPECT_EQ(result->GetAVCallState(), 3);
106 }
107
108 /**
109 * @tc.name: CopyToByMask001
110 * @tc.desc: Return is avcallstate CopyToByMask success
111 * @tc.type: FUNC
112 */
113 HWTEST_F(AVCallStateTest, CopyToByMask001, TestSize.Level1)
114 {
115 AVCallState stateOut;
116 stateOut.SetAVCallState(2);
117 AVCallState::AVCallStateMaskType mask = stateOut.GetMask();
118
119 AVCallState stateTest;
120 stateTest.SetAVCallState(2);
121 auto ret = stateTest.CopyToByMask(mask, stateOut);
122 EXPECT_EQ(ret, true);
123 }
124
125 /**
126 * @tc.name: CopyToByMask002
127 * @tc.desc: Return is avcallstate CopyToByMask failed
128 * @tc.type: FUNC
129 */
130 HWTEST_F(AVCallStateTest, CopyToByMask002, TestSize.Level1)
131 {
132 AVCallState stateOut;
133 AVCallState::AVCallStateMaskType mask = stateOut.GetMask();
134
135 AVCallState stateTest;
136 auto ret = stateTest.CopyToByMask(mask, stateOut);
137 EXPECT_EQ(ret, false);
138 }
139
140 /**
141 * @tc.name: CopyFrom001
142 * @tc.desc: Return is avcallstate CopyFrom success
143 * @tc.type: FUNC
144 */
145 HWTEST_F(AVCallStateTest, CopyFrom001, TestSize.Level1)
146 {
147 AVCallState stateOut;
148 stateOut.SetAVCallState(1);
149
150 AVCallState stateTest;
151 auto ret = stateTest.CopyFrom(stateOut);
152 EXPECT_EQ(stateTest.GetAVCallState(), 1);
153 EXPECT_EQ(ret, true);
154 }
155
156 /**
157 * @tc.name: CopyFrom002
158 * @tc.desc: Return is avcallstate CopyFrom failed
159 * @tc.type: FUNC
160 */
161 HWTEST_F(AVCallStateTest, CopyFrom002, TestSize.Level1)
162 {
163 AVCallState stateOut;
164
165 AVCallState stateTest;
166 auto ret = stateTest.CopyFrom(stateOut);
167 EXPECT_EQ(ret, false);
168 }
169 } // namespace AVSession
170 } // namespace OHOS