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));
}
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))
}
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)
void fake_invocation_return_value(GDBusMethodInvocation *invocation,
GVariant *parameters)
{
+ g_variant_get(parameters, "(i)", &invocation_return_value);
}
void fake_error_free(GError *error)
{
-
+
}
GVariant *
}
}
+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);