1 /*
2  * Copyright (c) 2023-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 #include <pipeline/core/event.h>
18 #include <pipeline/core/type_define.h>
19 #include "pipeline/filters/common/plugin_utils.h"
20 
21 namespace OHOS {
22 namespace Media {
23 namespace Test {
24 using namespace OHOS::Media::Pipeline;
25 using namespace testing::ext;
26 
27 HWTEST(TestMeta, get_byte_per_sample, TestSize.Level1)
28 {
29     uint8_t bytes = GetBytesPerSample(Plugin::AudioSampleFormat::S64);
30     ASSERT_EQ(bytes, 8);
31     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::S64P);
32     ASSERT_EQ(bytes, 8);
33     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::U64);
34     ASSERT_EQ(bytes, 8);
35     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::U64P);
36     ASSERT_EQ(bytes, 8);
37     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::F64);
38     ASSERT_EQ(bytes, 8);
39     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::F64P);
40     ASSERT_EQ(bytes, 8);
41 
42     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::F32);
43     ASSERT_EQ(bytes, 4);
44     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::F32P);
45     ASSERT_EQ(bytes, 4);
46     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::S32);
47     ASSERT_EQ(bytes, 4);
48     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::S32P);
49     ASSERT_EQ(bytes, 4);
50     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::U32);
51     ASSERT_EQ(bytes, 4);
52     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::U32P);
53     ASSERT_EQ(bytes, 4);
54 
55     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::S24);
56     ASSERT_EQ(bytes, 3);
57     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::S24P);
58     ASSERT_EQ(bytes, 3);
59     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::U24);
60     ASSERT_EQ(bytes, 3);
61     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::U24P);
62     ASSERT_EQ(bytes, 3);
63 
64     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::S16);
65     ASSERT_EQ(bytes, 2);
66     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::S16P);
67     ASSERT_EQ(bytes, 2);
68     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::U16);
69     ASSERT_EQ(bytes, 2);
70     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::U16P);
71     ASSERT_EQ(bytes, 2);
72     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::S8);
73     ASSERT_EQ(bytes, 1);
74     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::S8P);
75     ASSERT_EQ(bytes, 1);
76     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::U8);
77     ASSERT_EQ(bytes, 1);
78     bytes = GetBytesPerSample(Plugin::AudioSampleFormat::U8P);
79     ASSERT_EQ(bytes, 1);
80 }
81 
82 HWTEST(TestMeta, return_type_if_type_is_existed, TestSize.Level1)
83 {
84     EventType eventType = EventType::EVENT_READY;
85     ASSERT_STREQ(GetEventName(eventType), "EVENT_READY");
86     eventType = EventType::EVENT_AUDIO_PROGRESS;
87     ASSERT_STREQ(GetEventName(eventType), "EVENT_AUDIO_PROGRESS");
88     eventType = EventType::EVENT_VIDEO_PROGRESS;
89     ASSERT_STREQ(GetEventName(eventType), "EVENT_VIDEO_PROGRESS");
90     eventType = EventType::EVENT_COMPLETE;
91     ASSERT_STREQ(GetEventName(eventType), "EVENT_COMPLETE");
92     eventType = EventType::EVENT_ERROR;
93     ASSERT_STREQ(GetEventName(eventType), "EVENT_ERROR");
94     eventType = EventType::EVENT_PLUGIN_ERROR;
95     ASSERT_STREQ(GetEventName(eventType), "EVENT_PLUGIN_ERROR");
96     eventType = EventType::EVENT_PLUGIN_EVENT;
97     ASSERT_STREQ(GetEventName(eventType), "EVENT_PLUGIN_EVENT");
98     eventType = EventType::EVENT_BUFFERING;
99     ASSERT_STREQ(GetEventName(eventType), "EVENT_BUFFERING");
100     eventType = EventType::EVENT_BUFFER_PROGRESS;
101     ASSERT_STREQ(GetEventName(eventType), "EVENT_BUFFER_PROGRESS");
102     eventType = EventType::EVENT_DECODER_ERROR;
103     ASSERT_STREQ(GetEventName(eventType), "EVENT_DECODER_ERROR");
104     eventType = EventType::EVENT_RESOLUTION_CHANGE;
105     ASSERT_STREQ(GetEventName(eventType), "EVENT_RESOLUTION_CHANGE");
106     eventType = EventType::EVENT_VIDEO_RENDERING_START;
107     ASSERT_STREQ(GetEventName(eventType), "EVENT_VIDEO_RENDERING_START");
108     eventType = EventType::EVENT_IS_LIVE_STREAM;
109     ASSERT_STREQ(GetEventName(eventType), "EVENT_IS_LIVE_STREAM");
110 }
111 } // namespace Test
112 } // namespace Media
113 } // namespace OHOS
114