• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "plugin/core/plugin_meta.h"
23 
24 namespace OHOS {
25 namespace Media {
26 namespace Test {
27 using namespace OHOS::Media::Plugin;
28 
TEST(TestMeta,set_then_get_uint32)29 TEST(TestMeta, set_then_get_uint32)
30 {
31     Meta meta;
32     int32_t channels = 64;
33     meta.SetInt32(MetaID::AUDIO_CHANNELS, channels);
34     int32_t outChannels = 0;
35     ASSERT_TRUE(meta.GetInt32(MetaID::AUDIO_CHANNELS, outChannels));
36     ASSERT_EQ(channels, outChannels);
37 
38     uint32_t canNotGet = 0;
39     ASSERT_FALSE(meta.GetUint32(MetaID::AUDIO_CHANNELS, canNotGet));
40 }
41 
TEST(TestMeta,set_then_get_cstring)42 TEST(TestMeta, set_then_get_cstring)
43 {
44     Meta meta;
45     std::string artist("abcd");
46     meta.SetString(MetaID::MEDIA_TITLE, artist);
47     std::string outArtist;
48     ASSERT_TRUE(meta.GetString(MetaID::MEDIA_TITLE, outArtist));
49     ASSERT_STREQ(artist.c_str(), outArtist.c_str());
50 }
51 
TEST(TestMeta,set_then_get_float)52 TEST(TestMeta, set_then_get_float)
53 {
54     Meta meta;
55     float in = 9.9999f;
56     meta.SetFloat(MetaID::MEDIA_ARTIST, in); // this is only for test, normally MEDIA_ARTIST should be string
57     float out = 0;
58     ASSERT_TRUE(meta.GetFloat(MetaID::MEDIA_ARTIST, out));
59     ASSERT_FLOAT_EQ(in, out);
60 }
61 
TEST(TestMeta,fail_to_get_unexisted_data)62 TEST(TestMeta, fail_to_get_unexisted_data)
63 {
64     Meta meta;
65     int32_t channels = 64;
66     meta.SetInt32(MetaID::AUDIO_CHANNELS, channels);
67     int64_t bitRate = 1876411;
68     ASSERT_FALSE(meta.GetInt64(MetaID::MEDIA_BITRATE, bitRate));
69 }
70 
TEST(TestMeta,remove_data)71 TEST(TestMeta, remove_data)
72 {
73     Meta meta;
74     int32_t channels = 64;
75     meta.SetInt32(MetaID::AUDIO_CHANNELS, channels);
76     ASSERT_TRUE(meta.Remove(MetaID::AUDIO_CHANNELS));
77     ASSERT_FALSE(meta.Remove(MetaID::MEDIA_BITRATE));
78 }
79 
TEST(TestMeta,clear_data)80 TEST(TestMeta, clear_data)
81 {
82     Meta meta;
83     std::string title("title");
84     std::string album("album");
85     int32_t channels = 64;
86     meta.SetString(MetaID::MEDIA_TITLE, title);
87     meta.SetString(MetaID::MEDIA_ALBUM, album);
88     meta.SetInt32(MetaID::AUDIO_CHANNELS, channels);
89     meta.Clear();
90     std::string out;
91     ASSERT_FALSE(meta.GetString(MetaID::MEDIA_TITLE, out));
92     ASSERT_TRUE(out.empty());
93     ASSERT_FALSE(meta.GetString(MetaID::MEDIA_ALBUM, out));
94     ASSERT_TRUE(out.empty());
95     int32_t oChannels = 0;
96     ASSERT_FALSE(meta.GetInt32(MetaID::AUDIO_CHANNELS, oChannels));
97     ASSERT_EQ(0u, oChannels);
98 }
99 
TEST(TestMeta,update_meta)100 TEST(TestMeta, update_meta)
101 {
102     Meta meta;
103     std::string title("title");
104     std::string album("album");
105     int32_t channels = 64;
106     meta.SetString(MetaID::MEDIA_TITLE, title);
107     meta.SetString(MetaID::MEDIA_ALBUM, album);
108     meta.SetUint32(MetaID::AUDIO_CHANNELS, channels);
109 
110     Meta meta2;
111     int32_t channels2 = 32;
112     meta.SetInt32(MetaID::AUDIO_CHANNELS, channels2);
113 
114     meta.Update(meta2);
115     std::string out;
116     ASSERT_TRUE(meta.GetString(MetaID::MEDIA_TITLE, out));
117     ASSERT_STREQ("title", out.c_str());
118     ASSERT_TRUE(meta.GetString(MetaID::MEDIA_ALBUM, out));
119     ASSERT_STREQ("album", out.c_str());
120     int32_t oChannel = 0;
121     ASSERT_TRUE(meta.GetInt32(MetaID::AUDIO_CHANNELS, oChannel));
122     ASSERT_EQ(channels2, oChannel);
123 }
124 } // namespace Test
125 } // namespace Media
126 } // namespace OHOS
127