672d77a18d92086853112dee4273bcdd83ebfde4
[gnome.gobject-introspection] / tests / invoke / testfns.c
1 #include <string.h>
2
3 #include <glib.h>
4 #include <glib/gprintf.h>
5
6 typedef struct {
7     int foo;
8 } TestStruct;
9
10 gint test1 (gint in);
11 void test2 (gint in, gint *out);
12 void test3 (gint *inout);
13 void test4 (const gchar *blurb);
14 void test5 (gchar **blurb, gint *len);
15 gint test6 (GList *list);
16 char *test7 (GList *list);
17 TestStruct * test8 (int foo);
18 void test9 (TestStruct *test_struct, int *out);
19
20 gint test1 (gint in)
21 {
22   return in + 4;
23 }
24
25 void test2 (gint in, gint *out)
26 {
27   *out = in + 4;
28 }
29
30 void test3 (gint *inout)
31 {
32   *inout = *inout + 4;
33 }
34
35 void test4 (const gchar *blurb)
36 {
37   g_printf (blurb);
38 }
39
40 void test5 (gchar **blurb, gint *len)
41 {
42   *blurb = g_strdup ("hey there");
43   *len = strlen (*blurb);
44 }
45
46 gint test6 (GList *list)
47 {
48   return g_list_length(list);
49 }
50
51 char *test7 (GList *list)
52 {
53   GList *lp;
54   GString *string = g_string_new("");
55
56   for (lp=list; lp ; lp=lp->next)
57     {
58       g_string_append(string, (const char *)lp->data);
59     }
60   return g_string_free (string, FALSE);
61 }
62
63 /* constructor */
64 TestStruct * test8 (int foo)
65 {
66   TestStruct *ret;
67
68   ret = g_new(TestStruct, 1);
69   ret->foo = foo;
70   return ret;
71 }
72
73 void test9 (TestStruct *test_struct, int *out)
74 {
75   *out = test_struct->foo;
76 }