2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <gtest/gtest.h>
18 #include <sticker_data.h>
19 #include <sticker_consumer.h>
26 #include "app_common_mock.h"
27 #include "cynara_mock.h"
30 static bool callback_result = false;
31 static sticker_data_h g_dh = NULL;
32 static sticker_consumer_h g_ch = NULL;
37 int __cynara_initialize(cynara** c, const cynara_configuration* conf) {
42 int __cynara_finish(cynara* c) {
46 int __cynara_check(cynara* c, const char* client, const char* client_session,
48 const char* privilege) {
49 return CYNARA_API_ACCESS_ALLOWED;
53 int __fake_app_get_id(char** app_id) {
55 *app_id = strdup("org.tizen.hello");
61 GDBusConnection* __fake_g_bus_get_sync(GBusType type,
62 GCancellable* cancel, GError** err) {
63 return (GDBusConnection*)calloc(1, 4);
66 const gchar * __fake_g_dbus_connection_get_unique_name(GDBusConnection *connection) {
70 guint __fake_g_bus_watch_name(
73 GBusNameWatcherFlags flags,
74 GBusNameAppearedCallback name_appeared_handler,
75 GBusNameVanishedCallback name_vanished_handler,
77 GDestroyNotify user_data_free_func)
79 name_appeared_handler(nullptr, "appear test", "test owner", user_data);
80 name_vanished_handler(nullptr, "vanish test", user_data);
85 guint __fake_g_dbus_connection_signal_subscribe(GDBusConnection* connection,
87 const gchar* interface_name,
89 const gchar* object_path,
91 GDBusSignalFlags flags,
92 GDBusSignalCallback callback,
94 GDestroyNotify user_data_free_func)
99 guint __fake_g_bus_watch_name_on_connection(GDBusConnection* connection,
101 GBusNameWatcherFlags flags,
102 GBusNameAppearedCallback name_appeared_handler,
103 GBusNameVanishedCallback name_vanished_handler,
105 GDestroyNotify user_data_free_func)
107 name_appeared_handler(nullptr, "appear test", "test owner", user_data);
108 name_vanished_handler(nullptr, "vanish test", user_data);
112 GDBusMessage* __fake_g_dbus_message_new_method_call(
113 const gchar* a, const gchar* b, const gchar* c, const gchar* d) {
114 return (GDBusMessage*)calloc(1, 4);
117 void __fake_g_dbus_message_set_body(GDBusMessage * m,
121 GDBusMessage* __fake_g_dbus_connection_send_message_with_reply_sync(
122 GDBusConnection* conn, GDBusMessage* m, GDBusSendMessageFlags f, gint a,
123 volatile guint32* b, GCancellable* c, GError* *d) {
124 return (GDBusMessage*)calloc(1, 4);
127 void __fake_g_object_unref(gpointer o) {
130 GVariant* __fake_g_dbus_message_get_body(GDBusMessage* m) {
131 return g_variant_new("(u)", 10);
134 void __fake_g_dbus_connection_signal_unsubscribe(GDBusConnection* c,
138 void __fake_g_bus_unwatch_name(guint a) {
141 class StickerConsumerTest : public testing::Test {
143 virtual void SetUp() {
145 cynara_initialize_fake.custom_fake = __cynara_initialize;
146 cynara_finish_fake.custom_fake = __cynara_finish;
147 cynara_check_fake.custom_fake = __cynara_check;
150 app_get_id_fake.custom_fake = __fake_app_get_id;
153 g_bus_watch_name_on_connection_fake.custom_fake = __fake_g_bus_watch_name_on_connection;
154 g_dbus_message_set_body_fake.custom_fake = __fake_g_dbus_message_set_body;
155 g_bus_get_sync_fake.custom_fake = __fake_g_bus_get_sync;
156 g_dbus_connection_get_unique_name_fake.custom_fake = __fake_g_dbus_connection_get_unique_name;
157 g_bus_watch_name_fake.custom_fake = __fake_g_bus_watch_name;
158 g_dbus_message_new_method_call_fake.custom_fake = __fake_g_dbus_message_new_method_call;
159 g_dbus_connection_send_message_with_reply_sync_fake.custom_fake = __fake_g_dbus_connection_send_message_with_reply_sync;
160 g_object_unref_fake.custom_fake = __fake_g_object_unref;
161 g_dbus_message_get_body_fake.custom_fake = __fake_g_dbus_message_get_body;
162 g_dbus_connection_signal_unsubscribe_fake.custom_fake = __fake_g_dbus_connection_signal_unsubscribe;
163 g_bus_unwatch_name_fake.custom_fake = __fake_g_bus_unwatch_name;
164 g_dbus_connection_signal_subscribe_fake.custom_fake = __fake_g_dbus_connection_signal_subscribe;
166 sticker_consumer_create(&g_ch);
167 sticker_data_create(&g_dh);
168 sticker_data_set_uri(g_dh, STICKER_DATA_URI_WEB_RESOURCE, "www.samsung.com");
169 sticker_data_add_keyword(g_dh, "smile");
170 sticker_data_add_keyword(g_dh, "face");
171 sticker_data_add_keyword(g_dh, "cute");
172 sticker_data_set_group_name(g_dh, "tizen");
173 sticker_data_set_thumbnail(g_dh, "/res/test.png");
174 sticker_data_set_description(g_dh, "TCT Test");
176 virtual void TearDown() {
177 sticker_data_destroy(g_dh);
178 sticker_consumer_destroy(g_ch);
184 TEST_F(StickerConsumerTest, utc_sticker_consumer_create_ERROR_NONE)
186 sticker_consumer_h sc_h = NULL;
187 int ret = sticker_consumer_create(&sc_h);
188 EXPECT_EQ(ret, STICKER_ERROR_NONE);
192 * @function utc_sticker_consumer_p
193 * @description Positive UTC of the function that creates sticker consumer handle
196 TEST_F(StickerConsumerTest, utc_sticker_consumer_create_p)
198 sticker_consumer_h sc_h = NULL;
199 int ret = sticker_consumer_create(&sc_h);
200 EXPECT_EQ(ret, STICKER_ERROR_NONE);
204 * @function utc_sticker_consumer_n
205 * @description Negative UTC of the function that creates sticker consumer handle
208 TEST_F(StickerConsumerTest, utc_sticker_consumer_n)
210 int ret = sticker_consumer_create(NULL);
211 EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
214 TEST_F(StickerConsumerTest, utc_sticker_consumer_destroy_p)
216 sticker_consumer_h sc_h = NULL;
217 int ret = sticker_consumer_create(&sc_h);
218 ASSERT_EQ(ret, STICKER_ERROR_NONE);
220 ret = sticker_consumer_destroy(sc_h);
221 EXPECT_EQ(ret, STICKER_ERROR_NONE);
224 TEST_F(StickerConsumerTest, utc_sticker_consumer_destroy_n)
226 int ret = sticker_consumer_destroy(NULL);
227 EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
230 static void sticker_data_foreach_cb(sticker_data_h data_handle, void *user_data)
232 callback_result = true;
236 * @testcase utc_sticker_consumer_data_foreach_all_p
238 * @description Positive UTC of the function that retrieves all sticker data.
240 TEST_F(StickerConsumerTest, utc_sticker_consumer_data_foreach_all_p)
243 callback_result = false;
244 int ret = sticker_consumer_data_foreach_all(g_ch, 0, 1000, &result, sticker_data_foreach_cb, NULL);
245 EXPECT_EQ(ret, STICKER_ERROR_NONE);
249 * @testcase utc_sticker_consumer_data_foreach_all_n
251 * @description Negative UTC of the function that retrieves all sticker data.
253 TEST_F(StickerConsumerTest, utc_sticker_consumer_data_foreach_all_n)
256 int ret = sticker_consumer_data_foreach_all(g_ch, -1, 0, &result, sticker_data_foreach_cb, NULL);
257 EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
261 * @testcase utc_sticker_consumer_data_foreach_by_keyword_n
263 * @description Negative UTC of the function that retrieves all sticker data using keyword.
265 TEST_F(StickerConsumerTest, utc_sticker_consumer_data_foreach_by_keyword_n)
268 int ret = sticker_consumer_data_foreach_by_keyword(g_ch, -1, 0, &result, "cute", sticker_data_foreach_cb, NULL);
269 EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
273 * @testcase utc_sticker_consumer_data_foreach_by_group_n
275 * @description Negative UTC of the function that retrieves all sticker data using group.
277 TEST_F(StickerConsumerTest, utc_sticker_consumer_data_foreach_by_group_n)
280 int ret = sticker_consumer_data_foreach_by_group(g_ch, -1, 0, &result, "tizen", sticker_data_foreach_cb, NULL);
281 EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
285 * @testcase utc_sticker_consumer_data_foreach_by_type_n
287 * @description Negative UTC of the function that retrieves all sticker data using type.
289 TEST_F(StickerConsumerTest, utc_sticker_consumer_data_foreach_by_type_n)
292 int ret = sticker_consumer_data_foreach_by_type(g_ch, -1, 0, &result, STICKER_DATA_URI_WEB_RESOURCE, sticker_data_foreach_cb, NULL);
293 EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
297 * @testcase utc_sticker_consumer_group_list_foreach_all_n
299 * @description Negative UTC of the function that retrieves all group name.
301 TEST_F(StickerConsumerTest, utc_sticker_consumer_group_list_foreach_all_n)
303 int ret = sticker_consumer_group_list_foreach_all(g_ch, NULL, NULL);
304 EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);
308 * @testcase utc_sticker_consumer_keyword_list_foreach_all_n
310 * @description Negative UTC of the function that retrieves all keyword.
312 TEST_F(StickerConsumerTest, utc_sticker_consumer_keyword_list_foreach_all_n)
314 int ret = sticker_consumer_keyword_list_foreach_all(g_ch, NULL, NULL);
315 EXPECT_EQ(ret, STICKER_ERROR_INVALID_PARAMETER);