]> git.draconx.ca Git - gob-dx.git/blob - t/str.gob
Pull in dxcommon for library tests.
[gob-dx.git] / t / str.gob
1 // A simple string class, a lot like GString but with full GObject
2 // machinery and really short method names for the lazy :)
3
4 %{
5 #include <stdio.h>
6 %}
7
8 class :Str from G:Object {
9  
10   private GString *contents;
11
12   public
13   void
14   print (self)
15   {
16     g_print ("%s", self->_priv->contents->str);
17   }
18
19    public
20    GObject *
21    new (const char *format (check null), ...) attr {G_GNUC_PRINTF (1, 2)}
22      onerror NULL defreturn NULL
23    {
24      va_list ap;
25      va_start (ap, format);
26      gchar *tmp = g_strdup_vprintf (format, ap);
27      va_end (ap);
28      
29      Self *self = (Self *) GET_NEW;
30      
31      self->_priv->contents = g_string_new (tmp);
32      
33      g_free (tmp);
34      
35      return G_OBJECT (self);
36    }
37
38    // It seems gob accepts defreturn on non-virtual non-signal types
39    // without complaint, though from the man page I'm not sure the
40    // resulting behavior is well defined.
41    public
42    char *
43    nonvirt_test (self, const char *format (check null), ...)
44      attr {G_GNUC_PRINTF (2,3)}
45      defreturn NULL
46    {
47      return NULL;
48    }
49
50    private
51    char *
52    private_test_method (self, const char *format (check null), ...)   
53      attr {G_GNUC_PRINTF (2, 3)}
54      defreturn NULL
55    {
56      return NULL;
57    }
58
59    public
60    char *
61    private_method_caller (self)
62    {
63      int much_too_general = 42;
64
65      // This should trigger a warning.
66      self_private_test_method (self, "want a string: %s", much_too_general);
67
68      // So should this.
69      str_private_test_method (self, "want a string: %s", much_too_general);
70
71      return NULL;
72    }
73 }