~ted/ubuntu-app-launch/uri-splitting

« back to all changes in this revision

Viewing changes to tests/zg-test.cc

  • Committer: Tarmac
  • Author(s): Ted Gould
  • Date: 2013-11-19 15:55:35 UTC
  • mfrom: (80.3.10 zg-reenable)
  • Revision ID: tarmac-20131119155535-v9yr6nttf5ggk187
Reenable ZG and port to libzg-2.0. Fixes: https://bugs.launchpad.net/bugs/1197569.

Approved by Charles Kerr, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 3, as published
 
6
 * by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License along
 
14
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authors:
 
17
 *     Ted Gould <ted.gould@canonical.com>
 
18
 */
 
19
 
 
20
#include <gtest/gtest.h>
 
21
#include <gio/gio.h>
 
22
#include <libdbustest/dbus-test.h>
 
23
 
 
24
TEST(ZGEvent, OpenTest)
 
25
{
 
26
        DbusTestService * service = dbus_test_service_new(NULL);
 
27
 
 
28
        DbusTestDbusMock * mock = dbus_test_dbus_mock_new("org.gnome.zeitgeist.Engine");
 
29
        DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/org/gnome/zeitgeist/log/activity", "org.gnome.zeitgeist.Log", NULL);
 
30
 
 
31
        dbus_test_dbus_mock_object_add_method(mock, obj,
 
32
                "InsertEvents",
 
33
                G_VARIANT_TYPE("a(asaasay)"),
 
34
                G_VARIANT_TYPE("au"),
 
35
                "ret = [ 0 ]",
 
36
                NULL);
 
37
 
 
38
        dbus_test_service_add_task(service, DBUS_TEST_TASK(mock));
 
39
 
 
40
        DbusTestProcess * zgevent = dbus_test_process_new(ZG_EVENT_TOOL);
 
41
        dbus_test_process_append_param(zgevent, "open");
 
42
        g_setenv("APP_ID", "foo", 1);
 
43
        dbus_test_task_set_wait_for(DBUS_TEST_TASK(zgevent), "org.gnome.zeitgeist.Engine");
 
44
        dbus_test_task_set_name(DBUS_TEST_TASK(zgevent), "ZGEvent");
 
45
 
 
46
        dbus_test_service_add_task(service, DBUS_TEST_TASK(zgevent));
 
47
 
 
48
        dbus_test_service_start_tasks(service);
 
49
 
 
50
        /* Give it time to send the event and exit */
 
51
        g_usleep(100000);
 
52
        while (g_main_pending()) {
 
53
                g_main_iteration(TRUE);
 
54
        }
 
55
 
 
56
        ASSERT_EQ(dbus_test_task_get_state(DBUS_TEST_TASK(zgevent)), DBUS_TEST_TASK_STATE_FINISHED);
 
57
        ASSERT_TRUE(dbus_test_task_passed(DBUS_TEST_TASK(zgevent)));
 
58
 
 
59
        guint numcalls = 0;
 
60
        const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "InsertEvents", &numcalls, NULL);
 
61
 
 
62
        ASSERT_NE(calls, nullptr);
 
63
        ASSERT_EQ(numcalls, 1);
 
64
 
 
65
        g_object_unref(zgevent);
 
66
        g_object_unref(mock);
 
67
        g_object_unref(service);
 
68
}