typedef void (*_g_error_free)(GError *error);
typedef void (*_g_dbus_method_invocation_return_value)(GDBusMethodInvocation *invocation,
GVariant *parameters);
+typedef GVariant * (*_g_dbus_connection_call_sync)(GDBusConnection *connection,
+ const gchar *bus_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ const GVariantType *reply_type,
+ GDBusCallFlags flags,
+ gint timeout_msec,
+ GCancellable *cancellable,
+ GError **error);
/* ---------------------------------------------------------------------------------------------------- */
typedef struct
_g_dbus_connection_register_object connection_register_object;
_g_error_free error_free;
_g_dbus_method_invocation_return_value invocation_return_value;
+ _g_dbus_connection_call_sync connection_call_sync;
} _gdbus_interface;
#ifdef __cplusplus
connection = g_variant_new ("(s)", sender);
GVariant *result =
- g_dbus_connection_call_sync (_gdbus_conn,
+ _gdbus.connection_call_sync (_gdbus_conn,
_FREEDESKTOP_BUS_NAME,
_FREEDESKTOP_OBJECT_PATH,
_FREEDESKTOP_INTERFACE,
_gdbus.connection_register_object = g_dbus_connection_register_object;
_gdbus.error_free = g_error_free;
_gdbus.invocation_return_value = g_dbus_method_invocation_return_value;
+ _gdbus.connection_call_sync = g_dbus_connection_call_sync;
}
static int _request_service(GVariant *parameters, int origin_client_pid)
GDBusInterfaceInfo *valid_GDBusinterface;
gboolean requestCbResult;
-int fake_request_cb(char* app_name, RequestServiceInfo service_info[], int count)
+int fake_request_cb(char* app_name, bool self_select, RequestServiceInfo service_info[], int count, int client_pid)
{
- if (app_name == APP_NAME && count == 1 && service_info[0].ExecutionType == EXECUTE_TYPE &&
- service_info[0].ExeCmd == EXECUTE_COMMAND)
+ if (!strcmp(app_name, APP_NAME) &&
+ count == 1 &&
+ !strcmp(service_info[0].ExecutionType, EXECUTE_TYPE) &&
+ !strcmp(service_info[0].ExeCmd, EXECUTE_COMMAND))
{
+ requestCbResult = 1;
return 1;
}
else
{
+ requestCbResult = -1;
return -1;
}
}
void fake_error_free(GError *error)
{
+
+}
+
+GVariant *
+fake_g_dbus_connection_call_sync (GDBusConnection *connection,
+ const gchar *bus_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ const GVariantType *reply_type,
+ GDBusCallFlags flags,
+ gint timeout_msec,
+ GCancellable *cancellable,
+ GError **error)
+{
+ *error = NULL;
+ return g_variant_new ("(u)", 1);
}
class OrchestrationServerTests : public testing::Test
}
}
+TEST_F(OrchestrationServerTests, WhenCalledHandleMethodCall_WithRequestServiceMethod_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 idx;
+ int count = 1, client_pid = 1;
+ GVariant *services;
+ GVariantBuilder *builder;
+ builder = g_variant_builder_new (G_VARIANT_TYPE ("a(ss)"));
+ for (idx = 0; idx < count; idx++) {
+ g_variant_builder_add (
+ builder,
+ "(ss)",
+ EXECUTE_TYPE,
+ EXECUTE_COMMAND
+ );
+ }
+ services = g_variant_new ("(sia(ss)ii)", APP_NAME, 1, builder, count, client_pid);
+
+ _handle_method_call(NULL,
+ "edge_orchestration_sample",
+ NULL,
+ NULL,
+ "request_service",
+ services,
+ NULL,
+ NULL);
+
+ EXPECT_EQ(requestCbResult, true);
+ g_variant_builder_unref (builder);
+
+ 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);