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 "avmedia_description.h"
19 #include "avsession_log.h"
20 #include "avsession_manager.h"
21 #include "av_session.h"
22 #include "avsession_errors.h"
23
24 using namespace testing::ext;
25 using namespace OHOS::AVSession;
26
27 namespace OHOS {
28 namespace AVSession {
29 static AVMediaDescription g_mediaDescriptionCloneTest;
30 static AVMediaDescription g_mediaDescription;
31 static OHOS::Parcel g_parcel;
32
33 class AVMediaDescriptionTest : public testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp() override;
38 void TearDown() override;
39 };
40
SetUpTestCase()41 void AVMediaDescriptionTest::SetUpTestCase()
42 {
43 }
44
TearDownTestCase()45 void AVMediaDescriptionTest::TearDownTestCase()
46 {
47 }
48
SetUp()49 void AVMediaDescriptionTest::SetUp()
50 {
51 g_mediaDescription.Reset();
52 g_mediaDescription.SetMediaId("123");
53 g_mediaDescription.SetTitle("Title");
54 g_mediaDescription.SetSubtitle("Subtitle");
55 g_mediaDescription.SetDescription("This is music description");
56 g_mediaDescription.SetIcon(nullptr);
57 g_mediaDescription.SetIconUri("xxxxx");
58 g_mediaDescription.SetExtras(nullptr);
59 g_mediaDescription.SetMediaUri("Media url");
60 }
61
TearDown()62 void AVMediaDescriptionTest::TearDown()
63 {
64 }
65
66 /**
67 * @tc.name: SetAVMediaDescription001
68 * @tc.desc: Set av media description
69 * @tc.type: FUNC
70 * @tc.require: I6RJST
71 */
72 HWTEST_F(AVMediaDescriptionTest, SetAVmediaDescription001, TestSize.Level1)
73 {
74 SLOGI("SetAVMediaDescription001 Begin");
75 AVMediaDescription mediaDescription;
76 mediaDescription.Reset();
77 mediaDescription.SetMediaId("123");
78 mediaDescription.SetTitle("Title");
79 mediaDescription.SetSubtitle("Subtitle");
80 mediaDescription.SetDescription("This is music description");
81 mediaDescription.SetIcon(nullptr);
82 mediaDescription.SetIconUri("xxxxx");
83 mediaDescription.SetExtras(nullptr);
84 mediaDescription.SetMediaUri("Media url");
85
86 EXPECT_EQ("123", mediaDescription.GetMediaId());
87 EXPECT_EQ("Title", mediaDescription.GetTitle());
88 EXPECT_EQ("Subtitle", mediaDescription.GetSubtitle());
89 EXPECT_EQ("This is music description", mediaDescription.GetDescription());
90 EXPECT_EQ(nullptr, mediaDescription.GetIcon());
91 EXPECT_EQ("xxxxx", mediaDescription.GetIconUri());
92 EXPECT_EQ(nullptr, mediaDescription.GetExtras());
93 EXPECT_EQ("Media url", mediaDescription.GetMediaUri());
94
95 SLOGI("SetAVMediaDescription001 End");
96 }
97
98 /**
99 * @tc.name: IsAVmediaDescriptionValid001
100 * @tc.desc: Check is av media description valid
101 * @tc.type: FUNC
102 * @tc.require: I6RJST
103 */
104 HWTEST_F(AVMediaDescriptionTest, IsAVmediaDescriptionValid001, TestSize.Level1)
105 {
106 SLOGI("IsAVmediaDescriptionValid001 Begin");
107 AVMediaDescription mediaDescription;
108 mediaDescription.Reset();
109 mediaDescription.SetMediaId("123");
110 bool ret = mediaDescription.IsValid();
111 EXPECT_EQ(ret, true);
112 SLOGI("IsAVmediaDescriptionValid001 End");
113 }
114
115 /**
116 * @tc.name: IsAVmediaDescriptionValid002
117 * @tc.desc: Check is av media description valid
118 * @tc.type: FUNC
119 * @tc.require: I6RJST
120 */
121 HWTEST_F(AVMediaDescriptionTest, IsAVmediaDescriptionValid002, TestSize.Level1)
122 {
123 SLOGI("IsAVmediaDescriptionValid002 Begin");
124 AVMediaDescription mediaDescription;
125 mediaDescription.Reset();
126 bool ret = mediaDescription.IsValid();
127 EXPECT_EQ(ret, false);
128 SLOGI("IsAVmediaDescriptionValid002 End");
129 }
130
131 /**
132 * @tc.name: AVmediaDescriptionMarshalling001
133 * @tc.desc: mediaDescription marshalling test
134 * @tc.type: FUNC
135 * @tc.require:I6RJST
136 */
137 HWTEST_F(AVMediaDescriptionTest, AVmediaDescriptionMarshalling001, TestSize.Level1)
138 {
139 SLOGI("AVmediaDescriptionMarshalling001 Begin");
140 OHOS::Parcel& parcel = g_parcel;
141 auto ret = g_mediaDescription.Marshalling(parcel);
142 EXPECT_EQ(ret, true);
143 SLOGI("AVmediaDescriptionMarshalling001 End");
144 }
145
146 /**
147 * @tc.name: AVmediaDescriptionUnmarshalling001
148 * @tc.desc: mediaDescription unmarshalling test
149 * @tc.type: FUNC
150 * @tc.require:I6RJST
151 */
152 HWTEST_F(AVMediaDescriptionTest, AVmediaDescriptionUnmarshalling001, TestSize.Level1)
153 {
154 SLOGI("AVmediaDescriptionUnmarshalling001 Begin");
155 OHOS::Parcel& parcel = g_parcel;
156 auto unmarshallingPtr = g_mediaDescription.Unmarshalling(parcel);
157 EXPECT_NE(unmarshallingPtr, nullptr);
158 SLOGI("AVmediaDescriptionUnmarshalling001 End");
159 }
160 } // namespace AVSession
161 } // namespace OHOS
162