File: t_signals.c

package info (click to toggle)
webp-pixbuf-loader 0.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,144 kB
  • sloc: ansic: 1,194; sh: 17; makefile: 7
file content (98 lines) | stat: -rw-r--r-- 2,687 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <gdk-pixbuf/gdk-pixbuf.h>

typedef struct
{
  gint area_prepared_cb_count;
  gint area_updated_cb_count;
  gint closed_cb_count;
  gint size_prepared_cb_count;
} SignalsCounters;

void
area_prepared_cb (GdkPixbufLoader *self, gpointer user_data)
{
  SignalsCounters *counters = (SignalsCounters *) user_data;

  counters->area_prepared_cb_count++;
}

void
area_updated_cb (GdkPixbufLoader *self, gint x, gint y, gint width, gint height, gpointer user_data)
{
  SignalsCounters *counters = (SignalsCounters *) user_data;

  counters->area_updated_cb_count++;

  g_assert_cmpint (x, ==, 0);
  g_assert_cmpint (y, ==, 0);
  g_assert_cmpint (width, ==, 200);
  g_assert_cmpint (height, ==, 200);
}

void
closed_cb (GdkPixbufLoader *self, gpointer user_data)
{
  SignalsCounters *counters = (SignalsCounters *) user_data;

  counters->closed_cb_count++;
}

void
size_prepared_cb (GdkPixbufLoader *self, gint width, gint height, gpointer user_data)
{
  SignalsCounters *counters = (SignalsCounters *) user_data;

  counters->size_prepared_cb_count++;

  g_assert_cmpint (width, ==, 200);
  g_assert_cmpint (height, ==, 200);
}

gint
main (gint argc, gchar **argv)
{
  gchar          **env = g_get_environ ();
  GError          *error = NULL;
  gsize            pixbuf_size;
  guchar          *pixbuf_data = NULL;
  SignalsCounters  counters = { 0 };

  GdkPixbufLoader *loader = gdk_pixbuf_loader_new ();

  g_signal_connect (G_OBJECT (loader), "area-prepared",
                    G_CALLBACK (area_prepared_cb), &counters);
  g_signal_connect (G_OBJECT (loader), "area-updated",
                    G_CALLBACK (area_updated_cb), &counters);
  g_signal_connect (G_OBJECT (loader), "closed", G_CALLBACK (closed_cb), &counters);
  g_signal_connect (G_OBJECT (loader), "size-prepared",
                    G_CALLBACK (size_prepared_cb), &counters);

  g_file_get_contents (g_environ_getenv (env, "TEST_FILE"),
                       (gchar **) &pixbuf_data, &pixbuf_size, &error);
  if (error)
    g_error ("%s", error->message);
  g_assert (error == NULL);

  gdk_pixbuf_loader_write (loader, pixbuf_data, pixbuf_size, &error);
  if (error)
    g_error ("%s", error->message);
  g_assert (error == NULL);

  g_clear_pointer (&pixbuf_data, g_free);

  gdk_pixbuf_loader_close (loader, &error);
  if (error)
    g_error ("%s", error->message);
  g_assert (error == NULL);

  g_clear_object (&loader);

  g_clear_pointer (&env, g_strfreev);

  g_assert_cmpint (counters.area_prepared_cb_count, ==, 1);
  g_assert_cmpint (counters.area_updated_cb_count, ==, 1);
  g_assert_cmpint (counters.closed_cb_count, ==, 1);
  g_assert_cmpint (counters.size_prepared_cb_count, ==, 1);

  return 0;
}