~indicator-applet-developers/dbus-test-runner/trunk.16.10

« back to all changes in this revision

Viewing changes to libdbustest/dbus-mock.c

  • Committer: CI Train Bot
  • Author(s): Ted Gould
  • Date: 2015-02-02 17:37:57 UTC
  • mfrom: (89.1.7 dbusmock-system-bus)
  • Revision ID: ci-train-bot@canonical.com-20150202173757-cyn03ddwx7z9opzm
Make watching the task use the same bus the task is on 
Approved by: Charles Kerr, PS Jenkins bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
145
145
static void
146
146
constructed (GObject * object)
147
147
{
148
 
        DbusTestDbusMock * self = DBUS_TEST_DBUS_MOCK(object);
149
 
        const gchar * paramval = NULL;
150
 
 
151
148
        if (mock_cnt == 0) {
152
149
                dbus_test_task_set_name(DBUS_TEST_TASK(object), "DBusMock");
153
150
        } else {
157
154
        }
158
155
        mock_cnt++;
159
156
 
160
 
        /* Execute: python3 -m dbusmock $name / com.canonical.DbusTest.DbusMock */
161
 
        g_object_set(object, "executable", "python3", NULL);
162
 
 
163
 
        GArray * params = g_array_new(TRUE, TRUE, sizeof(gchar *));
164
 
        /* NOTE: No free func, none of the memory is managed by the array */
165
 
 
166
 
        paramval = "-m"; g_array_append_val(params, paramval);
167
 
        paramval = "dbusmock"; g_array_append_val(params, paramval);
168
 
 
169
 
        /* If we're set for system, go there, otherwise default to session */
170
 
        if (dbus_test_task_get_bus(DBUS_TEST_TASK(self)) == DBUS_TEST_SERVICE_BUS_SYSTEM) {
171
 
                paramval = "-s"; g_array_append_val(params, paramval);
172
 
        }
173
 
 
174
 
        g_array_append_val(params, self->priv->name);
175
 
        paramval = "/"; g_array_append_val(params, paramval);
176
 
        paramval = "com.canonical.DbusTest.DbusMock"; g_array_append_val(params, paramval);
177
 
 
178
 
        g_object_set(object, "parameters", params, NULL);
179
 
        g_array_unref(params);
180
 
 
181
157
        return;
182
158
}
183
159
 
446
422
        return;
447
423
}
448
424
 
 
425
/* Configure the executable and parameters for the mock */
 
426
static void
 
427
configure_process (DbusTestDbusMock * self)
 
428
{
 
429
        const gchar * paramval = NULL;
 
430
 
 
431
        /* Execute: python3 -m dbusmock $name / com.canonical.DbusTest.DbusMock */
 
432
        g_object_set(G_OBJECT(self), "executable", "python3", NULL);
 
433
 
 
434
        GArray * params = g_array_new(TRUE, TRUE, sizeof(gchar *));
 
435
        /* NOTE: No free func, none of the memory is managed by the array */
 
436
 
 
437
        paramval = "-m"; g_array_append_val(params, paramval);
 
438
        paramval = "dbusmock"; g_array_append_val(params, paramval);
 
439
 
 
440
        /* If we're set for system, go there, otherwise default to session */
 
441
        if (dbus_test_task_get_bus(DBUS_TEST_TASK(self)) == DBUS_TEST_SERVICE_BUS_SYSTEM) {
 
442
                paramval = "--system"; g_array_append_val(params, paramval);
 
443
        }
 
444
 
 
445
        g_array_append_val(params, self->priv->name);
 
446
        paramval = "/"; g_array_append_val(params, paramval);
 
447
        paramval = "com.canonical.DbusTest.DbusMock"; g_array_append_val(params, paramval);
 
448
 
 
449
        g_object_set(G_OBJECT(self), "parameters", params, NULL);
 
450
        g_array_unref(params);
 
451
}
 
452
 
449
453
/* Run the mock */
450
454
static void
451
455
run (DbusTestTask * task)
454
458
        DbusTestDbusMock * self = DBUS_TEST_DBUS_MOCK(task);
455
459
 
456
460
        /* Grab the new bus */
457
 
        self->priv->bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
 
461
        if (dbus_test_task_get_bus(DBUS_TEST_TASK(self)) == DBUS_TEST_SERVICE_BUS_SYSTEM) {
 
462
                self->priv->bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
 
463
        } else {
 
464
                self->priv->bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
 
465
        }
 
466
 
 
467
        if (error != NULL) {
 
468
                g_warning("Unable to get bus to start DBus Mock: %s", error->message);
 
469
                g_error_free(error);
 
470
                return;
 
471
        }
458
472
 
459
473
        /* Use the process code to get the process running */
 
474
        configure_process(self);
460
475
        DBUS_TEST_TASK_CLASS (dbus_test_dbus_mock_parent_class)->run (task);
461
476
 
462
477
        /**** Initialize the DBus Mock instance ****/