Add the testcases for server 81/186781/1
authorsinikang <sinikang@samsung.com>
Tue, 14 Aug 2018 08:59:14 +0000 (17:59 +0900)
committersinikang <sinikang@samsung.com>
Tue, 14 Aug 2018 08:59:14 +0000 (17:59 +0900)
Change-Id: Ia2dc22ea3328f40e4890150376b4d9be4c45aa1f

gtest/unittest.cpp
include/communicator.h [changed mode: 0755->0644]
include/server.h

index 89043f0..53fd835 100644 (file)
@@ -30,6 +30,9 @@
 #include <hal.h>
 #include <queue.h>
 #include <user_request.h>
+#include <manager.h>
+#include <communicator.h>
+#include <storage.h>
 
 
 using ::testing::EmptyTestEventListener;
@@ -45,12 +48,146 @@ void tcore_log(enum tcore_log_type type, enum tcore_log_priority priority, const
 {
 }
 
-TEST(LIBTCORE_COMMON, tcore_server_get_modems_count)
+
+/* Plug-in descriptor */
+struct tcore_plugin_define_desc test_plugin_define_desc = {
+       .name = "TEST_PLUGIN",
+       .priority = TCORE_PLUGIN_PRIORITY_MID,
+       .version = 1,
+       .load = NULL,
+       .init = NULL,
+       .unload = NULL
+};
+
+static enum tcore_hook_return __on_request_hook_callback(Server *s, UserRequest *ur, void *user_data)
 {
-       gint modem_count = 1;
-       //Server *tcore_running_server = NULL;
-       //modem_count = tcore_server_get_modems_count(tcore_running_server);
-       ASSERT_TRUE(modem_count > 0);
+       std::cout <<"   __on_request_hook_callback()" << std::endl;
+
+       return TCORE_HOOK_RETURN_CONTINUE;
+}
+
+static enum tcore_hook_return __on_notification_hook_callback(Server *s, CoreObject *source,
+       enum tcore_notification_command command,
+       unsigned int data_len, void *data, void *user_data)
+{
+       std::cout <<"   __on_notification_hook_callback()" << std::endl;
+
+       return TCORE_HOOK_RETURN_CONTINUE;
+}
+
+TEST(LIBTCORE_SERVER, test_server)
+{
+       Server *s;
+       Manager *m;
+       TcorePlugin *p, *modem_plugin;
+       Communicator *c;
+       TcoreHal *h;
+       Storage *strg;
+       TReturn ret;
+
+       /* create sever handle */
+       s = tcore_server_new();
+       ASSERT_TRUE(s);
+
+       /* add plugin */
+       p = tcore_plugin_new(s, &test_plugin_define_desc, "test_plugin", NULL);
+       ASSERT_TRUE(p);
+       ret = tcore_server_add_plugin(s, p);
+       EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+       EXPECT_TRUE(tcore_server_ref_plugins(s));
+
+       TcorePlugin *ref_plugin = tcore_server_search_plugin_list(s, "TEST_PLUGIN");
+       EXPECT_EQ(ref_plugin, p);
+
+       /* add manager */
+       m = tcore_manager_new(p);
+       ASSERT_TRUE(m);
+       ret = tcore_server_set_manager(s, m);
+       EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+       EXPECT_TRUE(tcore_server_ref_manager(s));
+
+       /* add communicator */
+       c = tcore_communicator_new(p, "test_communicator", NULL);
+       ASSERT_TRUE(c);
+       ret = tcore_server_add_communicator(s, c);
+       EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+       EXPECT_TRUE(tcore_server_ref_communicators(s));
+       EXPECT_EQ(tcore_server_find_communicator(s, "test_communicator"), c);
+
+       ret = tcore_server_remove_communicator(s, c);
+       EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+       tcore_communicator_free(c);
+
+       /* add storage */
+       strg = tcore_storage_new(NULL, "test_storage", NULL);
+       ASSERT_TRUE(strg);
+       ret = tcore_server_add_storage(s, strg);
+       EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+       EXPECT_TRUE(tcore_server_ref_storages(s));
+
+       /* find storage */
+       Storage *ref_strg = tcore_server_find_storage(s, "test_storage");
+       EXPECT_EQ(ref_strg, strg);
+
+       /* add Hal */
+       h = tcore_hal_new(NULL, "test_hal", NULL, TCORE_HAL_MODE_CUSTOM);
+       ASSERT_TRUE(h);
+       ret = tcore_server_add_hal(s, h);
+       EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+       EXPECT_TRUE(tcore_server_ref_hals(s));
+
+       /* find Hal */
+       TcoreHal *ref_hal = tcore_server_find_hal(s, "test_hal");
+       EXPECT_EQ(ref_hal, h);
+
+       /* remove Hal */
+       ret = tcore_server_remove_hal(s, h);
+       EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+       tcore_hal_free(h);
+       h = NULL;
+
+       /* register modem plugin*/
+       modem_plugin = tcore_plugin_new(s, NULL, "test_modem_plugin", NULL);
+       ASSERT_TRUE(modem_plugin);
+       TcoreModem *modem = tcore_server_register_modem(s, modem_plugin);
+       ASSERT_TRUE(modem);
+
+       /* Get modem count */
+       gint modem_count = tcore_server_get_modems_count(s);
+       std::cout << std::endl << "     [server] modem count: " << modem_count << std::endl;
+
+       EXPECT_TRUE(tcore_server_get_cp_name_list(s));
+       tcore_server_print_modems(s);
+
+       /* Add hook function */
+       ret = tcore_server_add_request_hook(s, TREQ_CUSTOM, __on_request_hook_callback, NULL);
+       EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+       ret = tcore_server_add_notification_hook(s, TNOTI_CUSTOM, __on_notification_hook_callback, NULL);
+       EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+       /* dispatch user request */
+       UserRequest * ur;
+       ur = tcore_user_request_new(NULL, NULL);
+       ASSERT_TRUE(ur);
+       ret = tcore_user_request_set_command(ur, TREQ_CUSTOM);
+       EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+       tcore_server_dispatch_request(s, ur);
+
+       /* send notification */
+       tcore_server_send_notification(s, NULL, TNOTI_CUSTOM, 0, NULL);
+
+       /* Remove hook function */
+       ret = tcore_server_remove_request_hook(s, __on_request_hook_callback);
+       EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+       ret = tcore_server_remove_notification_hook(s, __on_notification_hook_callback);
+       EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+       /* unregister modem plugin */
+       tcore_server_unload_modem_plugin(s, modem);
+
+       /* free server */
+       tcore_server_free(s);
+
 }
 
 TEST(LIBTCORE_OBJECT, test_object_new)
@@ -1371,6 +1508,70 @@ TEST(LIBTCORE_QUEUE, test_hal_queue_callback)
 
 }
 
+static enum tcore_manager_return __on_manager_request_handler(Manager *manager, UserRequest *ur)
+{
+       struct dbus_request_info *user_info;
+
+       std::cout << std::endl << "     __on_manager_request_handler()" << std::endl;
+
+       user_info = (struct dbus_request_info *)tcore_user_request_ref_user_info(ur);
+       if (user_info)
+               free(user_info);
+
+       return TCORE_MANAGER_RETURN_CONTINUE;
+
+}
+
+static enum tcore_manager_return __on_manager_notification_handler(Manager *manager,
+               CoreObject *source,
+               enum tcore_notification_command command,
+               unsigned int data_len, void *data)
+{
+       std::cout << std::endl << "     __on_manager_notification_handler()" << std::endl;
+       if (command == TNOTI_CUSTOM)
+               std::cout  << " command = TNOTI_CUSTOM" << std::endl;
+
+       if (data_len > 0 && data) {
+               char *noti_data = (char *)data;
+               std::cout << "  noti data = " << noti_data << std::endl;
+       }
+
+       return TCORE_MANAGER_RETURN_CONTINUE;
+}
+
+TEST(LIBTCORE_MANAGER, test_manager)
+{
+       TcorePlugin *p;
+       Manager *m;
+       TReturn ret;
+
+       p = tcore_plugin_new(NULL, NULL, NULL, NULL);
+       ASSERT_TRUE(p);
+
+       m = tcore_manager_new(p);
+       ASSERT_TRUE(m);
+
+       TcorePlugin *ref_plugin = tcore_manager_get_plugin(m);
+       EXPECT_EQ(ref_plugin, p);
+
+       ret = tcore_manager_set_request_dispatcher(m, __on_manager_request_handler);
+       EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+       ret = tcore_manager_set_notification_handler(m, __on_manager_notification_handler);
+       EXPECT_EQ(ret, TCORE_RETURN_SUCCESS);
+
+       enum tcore_manager_return mgr_ret;
+       mgr_ret = tcore_manager_dispatch_request(m, NULL);
+       std::cout << "  tcore_manager_dispatch_request() return = " << mgr_ret << std::endl;
+
+       char noti_data[] = "manager_noti_data";
+       mgr_ret = tcore_manager_send_notification(m, NULL, TNOTI_CUSTOM, strlen(noti_data), noti_data);
+       std::cout << "  tcore_manager_send_notification() return = " << mgr_ret << std::endl;
+
+
+       tcore_manager_free(p, m);
+       tcore_plugin_free(p);
+}
 
 int main(int argc, char **argv)
 {
old mode 100755 (executable)
new mode 100644 (file)
index 41cf704..3ea7efa
@@ -39,7 +39,7 @@ struct tcore_communicator_operations {
 
 Communicator *tcore_communicator_new(TcorePlugin *plugin,
        const char *name, struct tcore_communicator_operations *ops);
-void tcore_communicator_free();
+void tcore_communicator_free(Communicator *comm);
 
 TcorePlugin *tcore_communicator_ref_plugin(Communicator *comm);
 const char *tcore_communicator_ref_name(Communicator *comm);
index 3cd08af..1800b54 100644 (file)
@@ -82,8 +82,6 @@ TReturn tcore_server_remove_notification_hook(Server *s,
 
 TcoreModem *tcore_server_register_modem(Server *s, TcorePlugin *modem_iface_plugin);
 void tcore_server_unregister_modem(Server *s, TcoreModem *modem);
-gboolean tcore_server_update_modem_plugin(TcorePlugin *modem_iface_plugin,
-       TcorePlugin *modem_plugin);
 GSList *tcore_server_get_cp_name_list(Server *s);
 const char *tcore_server_get_cp_name_by_plugin(TcorePlugin *modem_plugin);