7fd5319cca88b7350b67117a7af3254d332effdd
[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         char *err_attr_name = NULL;
55         int p = 0;
56
57         ret = mm_file_create_content_attrs(&content_attrs, GTEST_VIDEO_FILE_PATH);
58         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
59
60         ret = mm_file_get_attrs(content_attrs, &err_attr_name, MM_FILE_CONTENT_DURATION, &p, NULL);
61         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
62         EXPECT_EQ(p, 11883);
63
64         ret = mm_file_get_attrs(content_attrs, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &p, NULL);
65         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
66         EXPECT_EQ(p, 909428);
67
68         ret = mm_file_get_attrs(content_attrs, &err_attr_name, MM_FILE_CONTENT_VIDEO_FPS, &p, NULL);
69         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
70         EXPECT_EQ(p, 30);
71
72         ret = mm_file_get_attrs(content_attrs, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &p, NULL);
73         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
74         EXPECT_EQ(p, 320);
75
76         ret = mm_file_get_attrs(content_attrs, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &p, NULL);
77         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
78         EXPECT_EQ(p, 240);
79
80         ret = mm_file_destroy_content_attrs(content_attrs);
81         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
82 }
83
84 TEST(libmm_fileinfo_Test, mm_file_create_tag_attrs_p)
85 {
86         int ret = FILEINFO_ERROR_NONE;
87         MMHandleType tag_attrs;
88
89         ret = mm_file_create_tag_attrs(&tag_attrs, GTEST_VIDEO_FILE_PATH);
90         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
91
92         ret = mm_file_destroy_tag_attrs(tag_attrs);
93         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
94 }
95
96 TEST(libmm_fileinfo_Test, mm_file_get_tag_attrs_p)
97 {
98         int ret = FILEINFO_ERROR_NONE;
99         MMHandleType tag_attrs;
100         char *err_attr_name = NULL;
101         char *p = NULL;
102         unsigned int size = 0;
103
104         ret = mm_file_create_tag_attrs(&tag_attrs, GTEST_VIDEO_FILE_PATH);
105         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
106
107         ret = mm_file_get_attrs(tag_attrs, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
108         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
109         EXPECT_STREQ(p, "Test");
110
111         ret = mm_file_get_attrs(tag_attrs, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
112         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
113         EXPECT_STREQ(p, "Test");
114
115         ret = mm_file_get_attrs(tag_attrs, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
116         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
117         EXPECT_STREQ(p, "Test");
118
119         ret = mm_file_get_attrs(tag_attrs, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
120         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
121         EXPECT_STREQ(p, "Test");
122
123         ret = mm_file_destroy_tag_attrs(tag_attrs);
124         EXPECT_EQ(ret, FILEINFO_ERROR_NONE);
125 }
126
127 int main(int argc, char **argv)
128 {
129         InitGoogleTest(&argc, argv);
130
131         return RUN_ALL_TESTS();
132 }