1 /*
2 * Copyright (c) 2021-2021 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 #define private public
19 #define protected public
20 #define UNIT_TEST 1
21
22 #include "pipeline/core/pipeline_core.h"
23 #include "plugin/core/plugin_meta.h"
24
25 namespace OHOS {
26 namespace Media {
27 namespace Test {
TEST(Test_meta_bundle,GetNull_before_Update)28 TEST(Test_meta_bundle, GetNull_before_Update)
29 {
30 Pipeline::MetaBundle bundle;
31 ASSERT_TRUE(bundle.GetGlobalMeta() == nullptr);
32 ASSERT_TRUE(bundle.GeTrackMeta(0) == nullptr);
33 }
34
TEST(Test_meta_bundle,GetGlobalMeta_after_Update)35 TEST(Test_meta_bundle, GetGlobalMeta_after_Update)
36 {
37 Plugin::Meta meta;
38 std::string title("title");
39 std::string album("album");
40 int32_t channels = 64;
41 meta.SetString(Media::Plugin::MetaID::MEDIA_TITLE, title);
42 meta.SetString(Media::Plugin::MetaID::MEDIA_ALBUM, album);
43 meta.SetInt32(Media::Plugin::MetaID::AUDIO_CHANNELS, channels);
44
45 Pipeline::MetaBundle bundle;
46 ASSERT_TRUE(bundle.GetGlobalMeta() == nullptr);
47 ASSERT_TRUE(bundle.GeTrackMeta(0) == nullptr);
48 bundle.UpdateGlobalMeta(meta);
49 auto out = bundle.GetGlobalMeta();
50 ASSERT_TRUE(out != nullptr);
51 std::string outString;
52 ASSERT_TRUE(out->GetString(Media::Plugin::MetaID::MEDIA_TITLE, outString));
53 ASSERT_STREQ("title", outString.c_str());
54 ASSERT_TRUE(out->GetString(Media::Plugin::MetaID::MEDIA_ALBUM, outString));
55 ASSERT_STREQ("album", outString.c_str());
56 int32_t oChannel = 0;
57 ASSERT_TRUE(out->GetInt32(Media::Plugin::MetaID::AUDIO_CHANNELS, oChannel));
58 ASSERT_EQ(channels, oChannel);
59 }
60
TEST(Test_meta_bundle,GetStreamMeta_after_Update)61 TEST(Test_meta_bundle, GetStreamMeta_after_Update)
62 {
63 Plugin::Meta meta;
64 std::string mime("audio/mpeg");
65 std::string language("zh");
66 meta.SetString(Media::Plugin::MetaID::MIME, mime);
67 meta.SetString(Media::Plugin::MetaID::MEDIA_LANGUAGE, language);
68
69 Pipeline::MetaBundle bundle;
70 ASSERT_TRUE(bundle.GetGlobalMeta() == nullptr);
71 ASSERT_TRUE(bundle.GeTrackMeta(0) == nullptr);
72 bundle.UpdateTrackMeta(meta);
73 auto out = bundle.GeTrackMeta(0);
74 ASSERT_TRUE(out == nullptr);
75 meta.SetUint32(Media::Plugin::MetaID::TRACK_ID, 1);
76 bundle.UpdateTrackMeta(meta);
77 out = bundle.GeTrackMeta(1);
78 std::string outString;
79 ASSERT_TRUE(out->GetString(Media::Plugin::MetaID::MIME, outString));
80 ASSERT_STREQ("audio/mpeg", outString.c_str());
81 ASSERT_TRUE(out->GetString(Media::Plugin::MetaID::MEDIA_LANGUAGE, outString));
82 ASSERT_STREQ("zh", outString.c_str());
83 int32_t oChannel = 0;
84 ASSERT_FALSE(out->GetInt32(Media::Plugin::MetaID::AUDIO_CHANNELS, oChannel));
85 uint32_t sIndex = 0;
86 ASSERT_TRUE(out->GetUint32(Media::Plugin::MetaID::TRACK_ID, sIndex));
87 ASSERT_EQ(sIndex, 1);
88 }
89 } // namespace Test
90 } // namespace Media
91 } // namespace OHOS