~ubuntu-branches/ubuntu/trusty/glib2.0/trusty-proposed

« back to all changes in this revision

Viewing changes to gio/tests/application.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-06-18 13:50:39 UTC
  • mfrom: (1.30.1 upstream) (3.4.16 experimental)
  • Revision ID: james.westby@ubuntu.com-20100618135039-546pvldpgilh981h
Tags: 2.25.9-1ubuntu1
* Resync on Debian
* debian/patches/90_git_fix_typo.patch:
  - the change is in the new version
* debian/patches/80-gtester-subunit.patch:
  - the change is in the new version 

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#include <gio.h>
3
3
#include <gstdio.h>
4
4
 
 
5
#include "gdbus-sessionbus.h"
 
6
 
5
7
enum
6
8
{
7
9
  INVOKE_ACTION,
19
21
static void
20
22
on_app_action (GApplication *application,
21
23
               const gchar  *action_name,
22
 
               guint         action_timestamp)
 
24
               GVariant     *platform_data)
23
25
{
 
26
  gboolean found_timestamp;
 
27
  GVariantIter *iter;
 
28
  const char *key;
 
29
  guint action_timestamp;
 
30
  GVariant *value;
 
31
  
24
32
  if (g_test_verbose ())
25
 
    g_print ("Action '%s' invoked (timestamp: %u, expected: %u)\n",
26
 
             action_name,
27
 
             action_timestamp,
28
 
             timestamp);
 
33
    {
 
34
      char *str = g_variant_print (platform_data, FALSE);
 
35
      g_print ("Action '%s' invoked (data: %s, expected: %u)\n",
 
36
               action_name,
 
37
               str,
 
38
               timestamp);
 
39
      g_free (str);
 
40
    }
29
41
 
30
42
  g_assert_cmpstr (action_name, ==, "About");
31
 
  g_assert_cmpint (action_timestamp, ==, timestamp);
 
43
 
 
44
  g_variant_get (platform_data, "a{sv}", &iter);
 
45
  found_timestamp = FALSE;
 
46
  while (g_variant_iter_next (iter, "{&sv}",
 
47
                              &key, &value))
 
48
    {
 
49
      if (g_strcmp0 ("timestamp", key) == 0)
 
50
        {
 
51
          found_timestamp = TRUE;
 
52
          g_variant_get (value, "u", &action_timestamp);
 
53
          break;
 
54
        }
 
55
    }
 
56
 
 
57
  g_variant_iter_free (iter);
 
58
 
 
59
  g_assert_cmpuint (timestamp, ==, action_timestamp);
32
60
 
33
61
  action_invoked = TRUE;
34
62
}
35
63
 
 
64
static GVariant *
 
65
create_timestamp_data ()
 
66
{
 
67
  GVariantBuilder builder;
 
68
 
 
69
  timestamp = 42 + timestamp;
 
70
 
 
71
  g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
 
72
  g_variant_builder_add (&builder, "{sv}",
 
73
                         "timestamp", g_variant_new ("u", timestamp));
 
74
  
 
75
  return g_variant_builder_end (&builder);
 
76
}
 
77
 
36
78
static gboolean
37
79
check_invoke_action (gpointer data)
38
80
{
40
82
 
41
83
  if (state == INVOKE_ACTION)
42
84
    {
43
 
      timestamp = (guint) time (NULL);
44
 
 
45
85
      if (g_test_verbose ())
46
86
        g_print ("Invoking About...\n");
47
87
 
48
 
      g_application_invoke_action (application, "About", timestamp);
 
88
      g_application_invoke_action (application, "About", create_timestamp_data ());
 
89
      
49
90
      state = CHECK_ACTION;
50
91
      return TRUE;
51
92
    }
76
117
      if (g_test_verbose ())
77
118
        g_print ("Invoking disabled About action...\n");
78
119
 
79
 
      g_application_invoke_action (application, "About", (guint) time (NULL));
 
120
      g_application_invoke_action (application, "About", create_timestamp_data ());
80
121
      state = CHECK_DISABLED_ACTION;
81
122
      return TRUE;
82
123
    }
96
137
      if (g_test_verbose ())
97
138
        g_print ("Test complete\n");
98
139
 
99
 
      g_application_quit (application, (guint) time (NULL));
 
140
      g_application_quit_with_data (application, create_timestamp_data ());
100
141
      return FALSE;
101
142
    }
102
143
 
108
149
{
109
150
  GApplication *app;
110
151
 
111
 
  app = g_application_new_and_register ("org.gtk.TestApplication", 0, NULL);
 
152
  app = g_application_new ("org.gtk.TestApplication", 0, NULL);
112
153
  g_application_add_action (app, "About", "Print an about message");
113
154
 
114
 
  g_signal_connect (app, "action::About", G_CALLBACK (on_app_action), NULL);
 
155
  g_signal_connect (app, "action-with-data::About", G_CALLBACK (on_app_action), NULL);
115
156
 
116
157
  state = INVOKE_ACTION;
117
158
  g_timeout_add (100, check_invoke_action, app);
125
166
int
126
167
main (int argc, char *argv[])
127
168
{
 
169
  gint ret;
 
170
 
128
171
  g_type_init ();
129
172
  g_test_init (&argc, &argv, NULL);
130
173
 
 
174
  g_unsetenv ("DISPLAY");
 
175
  g_setenv ("DBUS_SESSION_BUS_ADDRESS", session_bus_get_temporary_address (), TRUE);
 
176
 
 
177
  session_bus_up ();
 
178
 
131
179
  g_test_add_func ("/application/basic", test_basic);
132
180
 
133
 
  return g_test_run ();
 
181
  ret = g_test_run ();
 
182
 
 
183
  session_bus_down ();
 
184
 
 
185
  return ret;
134
186
}