{
gint32 ret;
- ret = system("/bin/systemctl start pass.service");
+ ret = pass_test_method_call(DBUS_CORE_PATH, DBUS_CORE_INTERFACE,
+ "start", NULL);
ASSERT_EQ(ret, 0) << "PassServiceStart Failed";
- ret = system("/bin/systemctl stop pass.service");
+ ret = pass_test_method_call(DBUS_CORE_PATH, DBUS_CORE_INTERFACE,
+ "stop", NULL);
ASSERT_EQ(ret, 0) << "PassServiceStop Failed";
- ret = system("/bin/systemctl start pass.service");
+ ret = pass_test_method_call(DBUS_CORE_PATH, DBUS_CORE_INTERFACE,
+ "start", NULL);
ASSERT_EQ(ret, 0) << "PassServiceStart Failed";
}
#include <iostream>
#include <stdlib.h>
+#include <gio/gio.h>
#include <gtest/gtest.h>
+#include <pass/gdbus-definition.h>
extern "C" {
#include "pass-hal.h"
return 0;
}
+static gint32 pass_test_method_call(const gchar *path, const gchar *intf,
+ const gchar *method, GVariant *body)
+{
+ const gchar *type;
+ GVariant *ret;
+ GError *err = NULL;
+ GDBusMessage *msg, *reply;
+ GDBusConnection *conn;
+ gint32 r;
+
+ conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+ if (err)
+ return -1;
+
+ msg = g_dbus_message_new_method_call(DBUS_PASS_BUS_NAME, path,
+ intf, method);
+ if (!msg)
+ return -1;
+
+ if (body)
+ g_dbus_message_set_body(msg, body);
+
+ reply = g_dbus_connection_send_message_with_reply_sync(conn, msg,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+ G_MAXINT, NULL, NULL, &err);
+ if (err) {
+ g_object_unref(msg);
+ g_clear_error(&err);
+ return -1;
+ }
+
+ ret = g_variant_get_child_value(g_dbus_message_get_body(reply), 0);
+ type = g_variant_get_type_string(ret);
+ if (type[0] == 'i')
+ r = g_variant_get_int32(ret);
+ else
+ r = -1;
+
+ g_variant_unref(ret);
+
+ g_dbus_connection_flush(conn, NULL, NULL, NULL);
+ g_object_unref(msg);
+ g_object_unref(reply);
+ g_clear_error(&err);
+
+ return r;
+}
+
TEST_F(PowerHaltest, GetResourceConfig_HandlesValidInput)
{
int ret = 0;
char path[] = "/hal/etc/pass/pass.conf";
/* Stop PASS daemon before HAL testing */
- ret = system("/bin/systemctl stop pass.service");
+ ret = pass_test_method_call(DBUS_CORE_PATH, DBUS_CORE_INTERFACE,
+ "stop", NULL);
ASSERT_EQ(ret, 0) << "PassServiceStop Failed";
ret = pass_parser_get_resource_config(&g_pass, path);
}
/* Restart PASS daemon before HAL testing */
- ret = system("/bin/systemctl start pass.service");
+ ret = pass_test_method_call(DBUS_CORE_PATH, DBUS_CORE_INTERFACE,
+ "start", NULL);
ASSERT_EQ(ret, 0) << "PassServiceStart Failed";
}