1 /*
2 * Copyright (c) 2025 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 "avsession_callback_client.h"
19 #include "avsession_descriptor.h"
20
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace AVSession {
25
26 namespace {
27 std::string g_errLog;
MyLogCallback(const LogType type,const LogLevel level,const unsigned int domain,const char * tag,const char * msg)28 void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char *tag,
29 const char *msg)
30 {
31 g_errLog = msg;
32 }
33 } // namespace
34
35 class AVSessionDescriptorTest : public testing::Test {
36 public:
37 static void SetUpTestCase();
38 static void TearDownTestCase();
39 void SetUp() override;
40 void TearDown() override;
41 };
42
SetUpTestCase()43 void AVSessionDescriptorTest::SetUpTestCase()
44 {}
45
TearDownTestCase()46 void AVSessionDescriptorTest::TearDownTestCase()
47 {}
48
SetUp()49 void AVSessionDescriptorTest::SetUp()
50 {}
51
TearDown()52 void AVSessionDescriptorTest::TearDown()
53 {}
54
55 /**
56 * @tc.name: Marshalling001
57 * @tc.desc: test Marshalling
58 * @tc.type: FUNC
59 * @tc.require:
60 */
61 HWTEST_F(AVSessionDescriptorTest, Marshalling001, TestSize.Level1)
62 {
63 LOG_SetCallback(MyLogCallback);
64 std::shared_ptr<AVHistoryDescriptor> avHistoryDescriptor = std::make_shared<AVHistoryDescriptor>();
65 EXPECT_NE(avHistoryDescriptor, nullptr);
66 Parcel out;
67 bool ret = avHistoryDescriptor->Marshalling(out);
68 EXPECT_EQ(ret, true);
69 }
70
71 /**
72 * @tc.name: Unmarshalling001
73 * @tc.desc: test Unmarshalling
74 * @tc.type: FUNC
75 * @tc.require:
76 */
77 HWTEST_F(AVSessionDescriptorTest, Unmarshalling001, TestSize.Level1)
78 {
79 LOG_SetCallback(MyLogCallback);
80 std::shared_ptr<AVHistoryDescriptor> avHistoryDescriptor = std::make_shared<AVHistoryDescriptor>();
81 Parcel in;
82 EXPECT_NE(avHistoryDescriptor, nullptr);
83 avHistoryDescriptor->Unmarshalling(in);
84 }
85
86 /**
87 * @tc.name: Marshalling002
88 * @tc.desc: test Marshalling
89 * @tc.type: FUNC
90 * @tc.require:
91 */
92 HWTEST_F(AVSessionDescriptorTest, Marshalling002, TestSize.Level1)
93 {
94 LOG_SetCallback(MyLogCallback);
95 std::shared_ptr<DeviceInfo> deviceInfo = std::make_shared<DeviceInfo>();
96 EXPECT_NE(deviceInfo, nullptr);
97 Parcel out;
98 bool ret = deviceInfo->Marshalling(out);
99 EXPECT_EQ(ret, true);
100 }
101
102 /**
103 * @tc.name: Unmarshalling002
104 * @tc.desc: test Unmarshalling
105 * @tc.type: FUNC
106 * @tc.require:
107 */
108 HWTEST_F(AVSessionDescriptorTest, Unmarshalling002, TestSize.Level1)
109 {
110 LOG_SetCallback(MyLogCallback);
111 std::shared_ptr<DeviceInfo> deviceInfo = std::make_shared<DeviceInfo>();
112 EXPECT_NE(deviceInfo, nullptr);
113 Parcel in;
114 deviceInfo->Unmarshalling(in);
115 }
116
117 /**
118 * @tc.name: Marshalling003
119 * @tc.desc: test Marshalling
120 * @tc.type: FUNC
121 * @tc.require:
122 */
123 HWTEST_F(AVSessionDescriptorTest, Marshalling003, TestSize.Level1)
124 {
125 LOG_SetCallback(MyLogCallback);
126 std::shared_ptr<CastDisplayInfo> castDisplayInfo = std::make_shared<CastDisplayInfo>();
127 EXPECT_NE(castDisplayInfo, nullptr);
128 Parcel out;
129 bool ret = castDisplayInfo->Marshalling(out);
130 EXPECT_EQ(ret, true);
131 }
132
133 /**
134 * @tc.name: Unmarshalling003
135 * @tc.desc: test Unmarshalling
136 * @tc.type: FUNC
137 * @tc.require:
138 */
139 HWTEST_F(AVSessionDescriptorTest, Unmarshalling003, TestSize.Level1)
140 {
141 LOG_SetCallback(MyLogCallback);
142 std::shared_ptr<CastDisplayInfo> castDisplayInfo = std::make_shared<CastDisplayInfo>();
143 EXPECT_NE(castDisplayInfo, nullptr);
144 Parcel in;
145 castDisplayInfo->Unmarshalling(in);
146 }
147
148 /**
149 * @tc.name: ReadFromParcel003
150 * @tc.desc: test ReadFromParcel
151 * @tc.type: FUNC
152 * @tc.require:
153 */
154 HWTEST_F(AVSessionDescriptorTest, ReadFromParcel003, TestSize.Level1)
155 {
156 LOG_SetCallback(MyLogCallback);
157 std::shared_ptr<CastDisplayInfo> castDisplayInfo = std::make_shared<CastDisplayInfo>();
158 EXPECT_NE(castDisplayInfo, nullptr);
159 Parcel in;
160 bool ret = castDisplayInfo->ReadFromParcel(in);
161 EXPECT_EQ(ret, false);
162 }
163
164 /**
165 * @tc.name: Marshalling004
166 * @tc.desc: test Marshalling
167 * @tc.type: FUNC
168 * @tc.require:
169 */
170 HWTEST_F(AVSessionDescriptorTest, Marshalling004, TestSize.Level1)
171 {
172 LOG_SetCallback(MyLogCallback);
173 DeviceState deviceState;
174 Parcel out;
175 bool ret = deviceState.Marshalling(out);
176 EXPECT_EQ(ret, true);
177 }
178
179 /**
180 * @tc.name: Unmarshalling004
181 * @tc.desc: test Unmarshalling
182 * @tc.type: FUNC
183 * @tc.require:
184 */
185 HWTEST_F(AVSessionDescriptorTest, Unmarshalling004, TestSize.Level1)
186 {
187 LOG_SetCallback(MyLogCallback);
188 DeviceState deviceState;
189 Parcel in;
190 auto ret = deviceState.Unmarshalling(in);
191 EXPECT_EQ(ret, nullptr);
192 }
193
194 /**
195 * @tc.name: ReadFromParcel004
196 * @tc.desc: test ReadFromParcel
197 * @tc.type: FUNC
198 * @tc.require:
199 */
200 HWTEST_F(AVSessionDescriptorTest, ReadFromParcel004, TestSize.Level1)
201 {
202 LOG_SetCallback(MyLogCallback);
203 DeviceState deviceState;
204 Parcel in;
205 bool ret = deviceState.ReadFromParcel(in);
206 EXPECT_EQ(ret, false);
207 }
208 } // namespace AVSESSION
209 } // namespace OHOS