[0.6.283] Fix the problem that not play until the end in gapless mode
[platform/core/multimedia/libmm-player.git] / unittest / 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 <gmock/gmock.h>
18 #include <gtest/gtest.h>
19 #include <iostream>
20 #include "mm_error.h"
21 #include "mm_player_priv.h"
22 #include "gtest_mm_player.h"
23 #include "gtest_mm_player_priv.h"
24
25 using ::testing::InitGoogleTest;
26 using ::testing::Test;
27 using ::testing::TestCase;
28
29 TEST(MMPlayerPreTest, Create_p)
30 {
31         int ret = MM_ERROR_NONE;
32         MMPlayer player;
33
34         ret = player.Create();
35         EXPECT_EQ(ret, MM_ERROR_NONE);
36 }
37
38 TEST(MMPlayerPreTest, Destroy_p)
39 {
40         int ret = MM_ERROR_NONE;
41         MMPlayer player;
42
43         ret = player.Create();
44         EXPECT_EQ(ret, MM_ERROR_NONE);
45
46         ret = player.Destroy();
47         EXPECT_EQ(ret, MM_ERROR_NONE);
48 }
49
50 TEST(MMPlayerPrePrivTest, Create_p)
51 {
52         int ret = MM_ERROR_NONE;
53         MMPlayerPriv player;
54
55         ret = player.Create();
56         EXPECT_EQ(ret, MM_ERROR_NONE);
57 }
58
59 TEST(MMPlayerPrePrivTest, Destroy_p)
60 {
61         int ret = MM_ERROR_NONE;
62         MMPlayerPriv player;
63
64         ret = player.Create();
65         EXPECT_EQ(ret, MM_ERROR_NONE);
66
67         ret = player.Destroy();
68         EXPECT_EQ(ret, MM_ERROR_NONE);
69 }
70
71 class MMPlayerPrivTest : public ::testing::Test {
72         public:
73                 virtual void SetUp();
74                 virtual void TearDown();
75
76         protected:
77                 MMPlayerPriv priv_player;
78 };
79
80 void MMPlayerPrivTest::SetUp()
81 {
82         int ret = MM_ERROR_NONE;
83         ret = priv_player.Create();
84         EXPECT_EQ(ret, MM_ERROR_NONE);
85 }
86
87 void MMPlayerPrivTest::TearDown()
88 {
89         int ret = MM_ERROR_NONE;
90         mmplayer_state_e state = MM_PLAYER_STATE_NULL;
91
92         ret = priv_player.GetCurrentState(&state);
93         if (ret != MM_ERROR_NONE)
94                 LOGE("failed to get current state");
95
96         if (state > MM_PLAYER_STATE_NULL) {
97                 ret = priv_player.Unrealize();
98                 if (ret != MM_ERROR_NONE)
99                         LOGE("failed to unrealize");
100         }
101
102         ret = priv_player.Destroy();
103         if (ret != MM_ERROR_NONE)
104                 LOGE("failed to destroy");
105 }
106
107 TEST_F(MMPlayerPrivTest, Realize_P)
108 {
109         int ret = MM_ERROR_NONE;
110         const gchar *uri = "http://test-url.mp4";
111
112         ret = priv_player.SetUri(uri);
113         EXPECT_EQ(ret, MM_ERROR_NONE);
114
115         ret = priv_player.Realize();
116         EXPECT_EQ(ret, MM_ERROR_NONE);
117 }
118
119 TEST_F(MMPlayerPrivTest, Realize_N)
120 {
121         int ret = MM_ERROR_NONE;
122         ret = priv_player.Realize();
123         EXPECT_EQ(ret, MM_ERROR_PLAYER_INVALID_URI);
124 }
125
126 TEST_F(MMPlayerPrivTest, ParseProfile_p)
127 {
128         int ret = MM_ERROR_NONE;
129         const gchar *uri = "http://test-url";
130         int uri_type = MM_PLAYER_URI_TYPE_NONE;
131
132         ret = priv_player.ParseProfile(uri, &uri_type);
133
134         EXPECT_EQ(ret, MM_ERROR_NONE);
135         EXPECT_EQ(uri_type, MM_PLAYER_URI_TYPE_URL_HTTP);
136 }
137
138 TEST_F(MMPlayerPrivTest, ParseProfile_n)
139 {
140         int ret = MM_ERROR_NONE;
141         const gchar *uri = "file://non-existing-file.mp4";
142
143         ret = priv_player.ParseProfile(uri, NULL);
144
145         EXPECT_EQ(ret, MM_ERROR_PLAYER_FILE_NOT_FOUND);
146 }
147
148 gint main(gint argc, gchar **argv)
149 {
150         InitGoogleTest(&argc, argv);
151
152         return RUN_ALL_TESTS();
153 }