Unit test case for update key pair 91/233691/1
authorMukunth A <a.mukunth@samsung.com>
Thu, 14 May 2020 15:45:08 +0000 (21:15 +0530)
committerMukunth A <a.mukunth@samsung.com>
Mon, 18 May 2020 08:19:47 +0000 (08:19 +0000)
Code Coverage > 80%

Change-Id: Idd3182b2c04d09f3bd4117e15a507897fe5f1039
Signed-off-by: Mukunth A <a.mukunth@samsung.com>
(cherry picked from commit 7f53d9e013c3914f0c7658ee243671702cafaa8a)

CMain/src/orchestration_dbus_server.c
CMain/unittest/Makefile
CMain/unittest/test_orchestration_server.cpp

index ec11fe0b4d84d500eb0e7a1afefde4de17761606..9894f78de4ccde14b409b44a7bca14d3516bf09a 100644 (file)
@@ -187,32 +187,36 @@ static void _handle_method_call(
     gpointer user_data)
 {
     int ret = ORCH_ERROR_NONE;
-    int origin_client_pid;
 
-    origin_client_pid = get_pid_with_connection(sender);
-    if (origin_client_pid < 0) {
-        DEBUG("get_pid_with_connection error!!\n");
-    }
+    if (sender != NULL && method_name != NULL) {
+        int origin_client_pid;
+        origin_client_pid = get_pid_with_connection(sender);
+        if (origin_client_pid < 0) {
+            DEBUG("get_pid_with_connection error!!\n");
+        }
 
 
-    if (g_strcmp0(method_name, "request_service") == 0)
-    {
-        DEBUG("receive method request_service\n");
-        ret = _request_service(parameters, origin_client_pid);
-    }
-    else if (g_strcmp0(method_name, "update_key_pair") == 0)
-    {
-        DEBUG("receive method update key pair\n");
-        ret = _update_key_pair(parameters, origin_client_pid);
-    }
+        if (g_strcmp0(method_name, "request_service") == 0)
+        {
+            DEBUG("receive method request_service\n");
+            ret = _request_service(parameters, origin_client_pid);
+        }
+        else if (g_strcmp0(method_name, "update_key_pair") == 0)
+        {
+            DEBUG("receive method update key pair\n");
+            ret = _update_key_pair(parameters, origin_client_pid);
+        }
 
-    if (ret == ORCH_ERROR_NONE)
-    {
-        printf("Orchestration service Success, method name : %s\n", method_name);
-    }
-    else
-    {
-        printf("Orchestration service fail, method name : %s\n", method_name);
+        if (ret == ORCH_ERROR_NONE)
+        {
+            printf("Orchestration service Success, method name : %s\n", method_name);
+        }
+        else
+        {
+            printf("Orchestration service fail, method name : %s\n", method_name);
+        }
+    } else {
+        ret = ORCH_ERROR_INVALID_PARAMETER;
     }
     _gdbus.invocation_return_value(invocation, g_variant_new("(i)", ret));
 }
index d7ba9b1202d1db6834f8a8088e5ad058c18a1c8c..79da8e05869f96f4be6f6dd6cc503dc7ab27b2d0 100644 (file)
@@ -26,14 +26,14 @@ execute:
 lcov:
        # lcov -c --directory . --output-file orchestration_server.info --no-external
        lcov -c --directory . --output-file orchestration_server.info
-       lcov --remove orchestration_server.info '*/test_orchestration_server.cpp' '/usr/include/*' -o orchestration_server.info
+       lcov --remove orchestration_server.info '*/test_orchestration_server.cpp' '*/main.go' '/usr/include/*' -o orchestration_server.info
        genhtml orchestration_server.info --output-directory out
 
 clean:
        -rm -f *.gcno
        -rm -f *.gcda
-       -rm -f *.info 
+       -rm -f *.info
        -rm -f $(EXEC_FILE)
 #      -rm -rf out
 
-.PHONY: build clean
\ No newline at end of file
+.PHONY: build clean
index ab6a029229cdef6067bf39179666153209486a74..2225da4a6bb5e211a336a38759e11e024ea479e4 100644 (file)
@@ -32,10 +32,11 @@ GDBusConnection *valid_GDBusConnection;
 GDBusNodeInfo *valid_GDBusNodeInfo;
 GDBusInterfaceInfo *valid_GDBusinterface;
 gboolean requestCbResult;
+int invocation_return_value;
 
 int fake_request_cb(char* app_name, bool self_select, RequestServiceInfo service_info[], int count, char * client_pname)
 {
-    if (!strcmp(app_name, APP_NAME) && 
+    if (!strcmp(app_name, APP_NAME) &&
         count == 1 &&
         !strcmp(service_info[0].ExecutionType, EXECUTE_TYPE) &&
         !strcmp(service_info[0].ExeCmd, EXECUTE_COMMAND))
@@ -51,10 +52,12 @@ int fake_request_cb(char* app_name, bool self_select, RequestServiceInfo service
 }
 
 int fake_update_key_pair(char* id, char* key, char* client_pname) {
-       if (id != NULL && key != NULL && client_pname != NULL) {
-               return 1;
-       }
-       return -1;
+
+    if (id != NULL && key != NULL && client_pname != NULL) {
+        return 0;
+    } else {
+        return -1;
+    }
 }
 
 GDBusConnection *fake_get_sync_return_NULL(GBusType bus_type, GCancellable *cancellable, GError **error)
@@ -136,11 +139,12 @@ guint fake_connection_register_object_success(GDBusConnection *connection,
 void fake_invocation_return_value(GDBusMethodInvocation *invocation,
                                   GVariant *parameters)
 {
+    g_variant_get(parameters, "(i)", &invocation_return_value);
 }
 
 void fake_error_free(GError *error)
 {
-    
+
 }
 
 GVariant *
@@ -367,6 +371,82 @@ TEST_F(OrchestrationServerTests, WhenCalledHandleMethodCall_WithRequestServiceMe
     }
 }
 
+TEST_F(OrchestrationServerTests, WhenCalledHandleMethodCall_WithUpdateKeyPair_WithInvalidParam_ExpectedReturnError)
+{
+    set_default_dbus_interface();
+    _gdbus.get_sync = fake_get_sync_success;
+    _gdbus.own_name_on_connection = fake_own_name_success;
+    _gdbus.node_info_new_for_xml = fake_node_info_new_for_xml_success;
+    _gdbus.connection_register_object = fake_connection_register_object_success;
+    _gdbus.invocation_return_value = fake_invocation_return_value;
+    _gdbus.error_free = fake_error_free;
+    _gdbus.connection_call_sync = fake_g_dbus_connection_call_sync;
+
+    int client_pid = 1;
+    GVariant *services;
+    services = g_variant_new ("(ssi)", NULL, NULL, client_pid);
+
+    _handle_method_call(NULL,
+                        NULL,
+                        NULL,
+                        NULL,
+                        "update_key_pair",
+                        services,
+                        NULL,
+                        NULL);
+
+    EXPECT_EQ(invocation_return_value, ORCH_ERROR_INVALID_PARAMETER);
+
+    if (valid_GDBusConnection != NULL)
+    {
+        free(valid_GDBusConnection);
+        valid_GDBusConnection = NULL;
+    }
+    if (valid_GDBusNodeInfo != NULL)
+    {
+        free(valid_GDBusNodeInfo);
+        valid_GDBusNodeInfo = NULL;
+    }
+}
+
+TEST_F(OrchestrationServerTests, WhenCalledHandleMethodCall_WithUpdateKeyPair_WithValidParam_ExpectedReturnSuccess)
+{
+    set_default_dbus_interface();
+    _gdbus.get_sync = fake_get_sync_success;
+    _gdbus.own_name_on_connection = fake_own_name_success;
+    _gdbus.node_info_new_for_xml = fake_node_info_new_for_xml_success;
+    _gdbus.connection_register_object = fake_connection_register_object_success;
+    _gdbus.invocation_return_value = fake_invocation_return_value;
+    _gdbus.error_free = fake_error_free;
+    _gdbus.connection_call_sync = fake_g_dbus_connection_call_sync;
+
+    int client_pid = 1;
+    GVariant *services;
+    services = g_variant_new ("(ssi)", "key", "pair", client_pid);
+
+    _handle_method_call(NULL,
+                        "edge_orchestration_sample",
+                        NULL,
+                        NULL,
+                        "update_key_pair",
+                        services,
+                        NULL,
+                        NULL);
+
+    EXPECT_EQ(invocation_return_value, ORCH_ERROR_NONE);
+
+    if (valid_GDBusConnection != NULL)
+    {
+        free(valid_GDBusConnection);
+        valid_GDBusConnection = NULL;
+    }
+    if (valid_GDBusNodeInfo != NULL)
+    {
+        free(valid_GDBusNodeInfo);
+        valid_GDBusNodeInfo = NULL;
+    }
+}
+
 int main(int argc, char **argv)
 {
     testing::InitGoogleTest(&argc, argv);