Add return value check in ID3v1
[platform/core/multimedia/libmm-fileinfo.git] / unittest / libmm_fileinfo_unittest.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "libmm_fileinfo_unittest.h"
18 #include "mm_file.h"
19
20 #define GTEST_VIDEO_FILE_PATH           "/usr/bin/libmm-fileinfo-unittest.mp4"
21 #define GTEST_SOUND_FILE_PATH           "/usr/bin/libmm-fileinfo-unittest.mp3"
22
23 using ::testing::InitGoogleTest;
24 using ::testing::Test;
25 using ::testing::TestCase;
26
27 class libmm_fileinfo_Test : public ::testing::Test {
28         protected:
29                 void SetUp() {
30                         std::cout << "SetUp()" << std::endl;
31                 }
32
33                 void TearDown() {
34                         std::cout << "TearDown()" << std::endl;
35                 }
36 };
37
38 TEST(libmm_fileinfo_Test, mm_file_create_content_attrs_p)
39 {
40         int ret = FILEINFO_ERROR_NONE;
41         MMHandleType content_attrs;
42
43         ret = mm_file_create_content_attrs(&content_attrs, GTEST_VIDEO_FILE_PATH);
44         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
45
46         ret = mm_file_destroy_content_attrs(content_attrs);
47         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
48 }
49
50 TEST(libmm_fileinfo_Test, mm_file_get_content_attrs_p)
51 {
52         int ret = FILEINFO_ERROR_NONE;
53         MMHandleType content_attrs;
54         int p = 0;
55
56         ret = mm_file_create_content_attrs(&content_attrs, GTEST_VIDEO_FILE_PATH);
57         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
58
59         ret = mm_file_get_attrs(content_attrs, MM_FILE_CONTENT_DURATION, &p, NULL);
60         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
61         EXPECT_EQ(p, 11883);
62
63         ret = mm_file_get_attrs(content_attrs, MM_FILE_CONTENT_VIDEO_BITRATE, &p, NULL);
64         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
65         EXPECT_EQ(p, 909428);
66
67         ret = mm_file_get_attrs(content_attrs, MM_FILE_CONTENT_VIDEO_FPS, &p, NULL);
68         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
69         EXPECT_EQ(p, 30);
70
71         ret = mm_file_get_attrs(content_attrs, MM_FILE_CONTENT_VIDEO_WIDTH, &p, NULL);
72         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
73         EXPECT_EQ(p, 320);
74
75         ret = mm_file_get_attrs(content_attrs, MM_FILE_CONTENT_VIDEO_HEIGHT, &p, NULL);
76         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
77         EXPECT_EQ(p, 240);
78
79         ret = mm_file_destroy_content_attrs(content_attrs);
80         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
81 }
82
83 TEST(libmm_fileinfo_Test, mm_file_create_tag_attrs_p)
84 {
85         int ret = FILEINFO_ERROR_NONE;
86         MMHandleType tag_attrs;
87
88         ret = mm_file_create_tag_attrs(&tag_attrs, GTEST_VIDEO_FILE_PATH);
89         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
90
91         ret = mm_file_destroy_tag_attrs(tag_attrs);
92         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
93 }
94
95 TEST(libmm_fileinfo_Test, mm_file_get_tag_attrs_p)
96 {
97         int ret = FILEINFO_ERROR_NONE;
98         MMHandleType tag_attrs;
99         char *p = NULL;
100         unsigned int size = 0;
101
102         ret = mm_file_create_tag_attrs(&tag_attrs, GTEST_VIDEO_FILE_PATH);
103         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
104
105         ret = mm_file_get_attrs(tag_attrs, MM_FILE_TAG_ARTIST, &p, &size, NULL);
106         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
107         EXPECT_STREQ(p, "Test");
108
109         ret = mm_file_get_attrs(tag_attrs, MM_FILE_TAG_TITLE, &p, &size, NULL);
110         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
111         EXPECT_STREQ(p, "Test");
112
113         ret = mm_file_get_attrs(tag_attrs, MM_FILE_TAG_ALBUM, &p, &size, NULL);
114         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
115         EXPECT_STREQ(p, "Test");
116
117         ret = mm_file_get_attrs(tag_attrs, MM_FILE_TAG_GENRE, &p, &size, NULL);
118         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
119         EXPECT_STREQ(p, "Test");
120
121         ret = mm_file_destroy_tag_attrs(tag_attrs);
122         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
123 }
124
125 int main(int argc, char **argv)
126 {
127         InitGoogleTest(&argc, argv);
128
129         return RUN_ALL_TESTS();
130 }