1 /*
2 * Copyright (c) 2024 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_log.h"
19 #include "media_info_holder.h"
20
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace AVSession {
25
26 static constexpr int32_t TEST_NUM = 2000;
27 class MediaInfoHolderTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp() override;
32 void TearDown() override;
33 };
34
SetUpTestCase()35 void MediaInfoHolderTest::SetUpTestCase()
36 {}
37
TearDownTestCase()38 void MediaInfoHolderTest::TearDownTestCase()
39 {}
40
SetUp()41 void MediaInfoHolderTest::SetUp()
42 {}
43
TearDown()44 void MediaInfoHolderTest::TearDown()
45 {}
46
47 /**
48 * @tc.name: SetAVCallState001
49 * @tc.desc: test SetAVCallState
50 * @tc.type: FUNC
51 * @tc.require:
52 */
53 HWTEST_F(MediaInfoHolderTest, SetAVCallState001, TestSize.Level1)
54 {
55 MediaInfoHolder mediaInfoHolder;
56 Parcel parcel;
57 parcel.SetDataSize(0);
58 parcel.GetDataCapacity();
59 mediaInfoHolder.SetCurrentIndex(1);
60 AVQueueItem avQueueItem;
61 std::shared_ptr<AVMediaDescription> description = std::make_shared<AVMediaDescription>();
62 description->SetMediaId("123");
63 description->SetTitle("Title");
64 description->SetSubtitle("Subtitle");
65 description->SetDescription("This is music description");
66 description->SetIcon(nullptr);
67 description->SetIconUri("xxxxx");
68 description->SetExtras(nullptr);
69 description->SetMediaUri("Media url");
70 avQueueItem.SetDescription(description);
71 std::vector<AVQueueItem> playInfos = {avQueueItem};
72 mediaInfoHolder.SetPlayInfos(playInfos);
73 ASSERT_TRUE(mediaInfoHolder.Marshalling(parcel));
74 MediaInfoHolder *result = mediaInfoHolder.Unmarshalling(parcel);
75 EXPECT_NE(result, nullptr);
76 }
77
78 /**
79 * @tc.name: SetAVCallState002
80 * @tc.desc: test SetAVCallState
81 * @tc.type: FUNC
82 * @tc.require:
83 */
84 HWTEST_F(MediaInfoHolderTest, SetAVCallState002, TestSize.Level1)
85 {
86 MediaInfoHolder mediaInfoHolder;
87 Parcel parcel;
88 mediaInfoHolder.SetCurrentIndex(1);
89 std::vector<AVQueueItem> playInfos;
90
91 for (int32_t i = 0; i < TEST_NUM; ++i) {
92 AVQueueItem avQueueItem;
93 std::shared_ptr<AVMediaDescription> description = std::make_shared<AVMediaDescription>();
94 description->SetMediaId("123");
95 description->SetTitle("Title");
96 description->SetSubtitle("Subtitle");
97 description->SetDescription("This is music description");
98 description->SetIcon(nullptr);
99 description->SetIconUri("xxxxx");
100 description->SetExtras(nullptr);
101 description->SetMediaUri("Media url");
102 avQueueItem.SetDescription(description);
103 playInfos.push_back(avQueueItem);
104 }
105 mediaInfoHolder.SetPlayInfos(playInfos);
106 EXPECT_FALSE(mediaInfoHolder.Marshalling(parcel));
107 MediaInfoHolder *result = mediaInfoHolder.Unmarshalling(parcel);
108 EXPECT_EQ(result, nullptr);
109 }
110
111 } // namespace AVSession
112 } // namespace OHOS