[vala/staging: 1/2] tests: Add "type-parameter property clash" test to increase coverage




commit c2a531611b0f928cc022322da1dec84dd1f4b95f
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Dec 14 10:38:37 2021 +0100

    tests: Add "type-parameter property clash" test to increase coverage
    
    This needs to be handled gracefully. So throwing an error is no option.

 tests/Makefile.am                                  |   1 +
 .../type-parameter-property-clash.c-expected       | 428 +++++++++++++++++++++
 tests/generics/type-parameter-property-clash.vala  |  13 +
 3 files changed, 442 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d261e6052..4042d989f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -749,6 +749,7 @@ TESTS = \
        generics/reference-transfer.vala \
        generics/string-literal-comparison.vala \
        generics/type-parameter-properties.vala \
+       generics/type-parameter-property-clash.vala \
        generics/value-pointer-type-access.vala \
        generics/bug640330.vala \
        generics/bug640330-2.test \
diff --git a/tests/generics/type-parameter-property-clash.c-expected 
b/tests/generics/type-parameter-property-clash.c-expected
new file mode 100644
index 000000000..f5659405a
--- /dev/null
+++ b/tests/generics/type-parameter-property-clash.c-expected
@@ -0,0 +1,428 @@
+/* generics_type_parameter_property_clash.c generated by valac, the Vala compiler
+ * generated from generics_type_parameter_property_clash.vala, do not modify */
+
+#include <glib-object.h>
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if !defined(VALA_EXTERN)
+#if defined(_MSC_VER)
+#define VALA_EXTERN __declspec(dllexport) extern
+#elif __GNUC__ >= 4
+#define VALA_EXTERN __attribute__((visibility("default"))) extern
+#else
+#define VALA_EXTERN extern
+#endif
+#endif
+
+#define TYPE_FOO (foo_get_type ())
+#define FOO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FOO, Foo))
+#define FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FOO, FooClass))
+#define IS_FOO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FOO))
+#define IS_FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FOO))
+#define FOO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FOO, FooClass))
+
+typedef struct _Foo Foo;
+typedef struct _FooClass FooClass;
+typedef struct _FooPrivate FooPrivate;
+enum  {
+       FOO_0_PROPERTY,
+       FOO_G_TYPE,
+       FOO_G_DUP_FUNC,
+       FOO_G_DESTROY_FUNC,
+       FOO_FOO_G_TYPE_PROPERTY,
+       FOO_NUM_PROPERTIES
+};
+static GParamSpec* foo_properties[FOO_NUM_PROPERTIES];
+
+#define TYPE_BAR (bar_get_type ())
+#define BAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_BAR, Bar))
+#define BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_BAR, BarClass))
+#define IS_BAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_BAR))
+#define IS_BAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_BAR))
+#define BAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_BAR, BarClass))
+
+typedef struct _Bar Bar;
+typedef struct _BarClass BarClass;
+typedef struct _BarPrivate BarPrivate;
+enum  {
+       BAR_0_PROPERTY,
+       BAR_G_TYPE,
+       BAR_G_DUP_FUNC,
+       BAR_G_DESTROY_FUNC,
+       BAR_BAR_G_TYPE_PROPERTY,
+       BAR_NUM_PROPERTIES
+};
+static GParamSpec* bar_properties[BAR_NUM_PROPERTIES];
+#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
+#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, 
__LINE__, G_STRFUNC, msg);
+#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, 
G_STRFUNC, msg); return; }
+#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning 
(G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
+#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, 
__LINE__, G_STRFUNC, msg);
+
+struct _Foo {
+       GObject parent_instance;
+       FooPrivate * priv;
+};
+
+struct _FooClass {
+       GObjectClass parent_class;
+};
+
+struct _FooPrivate {
+       GType g_type;
+       GBoxedCopyFunc g_dup_func;
+       GDestroyNotify g_destroy_func;
+};
+
+struct _Bar {
+       Foo parent_instance;
+       BarPrivate * priv;
+};
+
+struct _BarClass {
+       FooClass parent_class;
+};
+
+struct _BarPrivate {
+       GType g_type;
+       GBoxedCopyFunc g_dup_func;
+       GDestroyNotify g_destroy_func;
+};
+
+static gint Foo_private_offset;
+static gpointer foo_parent_class = NULL;
+static gint Bar_private_offset;
+static gpointer bar_parent_class = NULL;
+
+VALA_EXTERN GType foo_get_type (void) G_GNUC_CONST ;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (Foo, g_object_unref)
+VALA_EXTERN Foo* foo_new (GType g_type,
+              GBoxedCopyFunc g_dup_func,
+              GDestroyNotify g_destroy_func);
+VALA_EXTERN Foo* foo_construct (GType object_type,
+                    GType g_type,
+                    GBoxedCopyFunc g_dup_func,
+                    GDestroyNotify g_destroy_func);
+VALA_EXTERN GType foo_get_foo_g_type (Foo* self);
+static GType foo_get_type_once (void);
+static void _vala_foo_get_property (GObject * object,
+                             guint property_id,
+                             GValue * value,
+                             GParamSpec * pspec);
+static void _vala_foo_set_property (GObject * object,
+                             guint property_id,
+                             const GValue * value,
+                             GParamSpec * pspec);
+VALA_EXTERN GType bar_get_type (void) G_GNUC_CONST ;
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (Bar, g_object_unref)
+VALA_EXTERN Bar* bar_new (GType g_type,
+              GBoxedCopyFunc g_dup_func,
+              GDestroyNotify g_destroy_func);
+VALA_EXTERN Bar* bar_construct (GType object_type,
+                    GType g_type,
+                    GBoxedCopyFunc g_dup_func,
+                    GDestroyNotify g_destroy_func);
+VALA_EXTERN GType bar_get_bar_g_type (Bar* self);
+static GType bar_get_type_once (void);
+static void _vala_bar_get_property (GObject * object,
+                             guint property_id,
+                             GValue * value,
+                             GParamSpec * pspec);
+static void _vala_bar_set_property (GObject * object,
+                             guint property_id,
+                             const GValue * value,
+                             GParamSpec * pspec);
+static void _vala_main (void);
+
+static inline gpointer
+foo_get_instance_private (Foo* self)
+{
+       return G_STRUCT_MEMBER_P (self, Foo_private_offset);
+}
+
+Foo*
+foo_construct (GType object_type,
+               GType g_type,
+               GBoxedCopyFunc g_dup_func,
+               GDestroyNotify g_destroy_func)
+{
+       Foo * self = NULL;
+       self = (Foo*) g_object_new (object_type, NULL);
+       self->priv->g_type = g_type;
+       self->priv->g_dup_func = g_dup_func;
+       self->priv->g_destroy_func = g_destroy_func;
+       return self;
+}
+
+Foo*
+foo_new (GType g_type,
+         GBoxedCopyFunc g_dup_func,
+         GDestroyNotify g_destroy_func)
+{
+       return foo_construct (TYPE_FOO, g_type, g_dup_func, g_destroy_func);
+}
+
+GType
+foo_get_foo_g_type (Foo* self)
+{
+       GType result;
+       g_return_val_if_fail (IS_FOO (self), 0UL);
+       result = self->priv->g_type;
+       return result;
+}
+
+static void
+foo_class_init (FooClass * klass,
+                gpointer klass_data)
+{
+       foo_parent_class = g_type_class_peek_parent (klass);
+       g_type_class_adjust_private_offset (klass, &Foo_private_offset);
+       G_OBJECT_CLASS (klass)->get_property = _vala_foo_get_property;
+       G_OBJECT_CLASS (klass)->set_property = _vala_foo_set_property;
+       g_object_class_install_property (G_OBJECT_CLASS (klass), FOO_G_TYPE, g_param_spec_gtype ("g-type", 
"type", "type", G_TYPE_NONE, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property (G_OBJECT_CLASS (klass), FOO_G_DUP_FUNC, g_param_spec_pointer 
("g-dup-func", "dup func", "dup func", G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property (G_OBJECT_CLASS (klass), FOO_G_DESTROY_FUNC, g_param_spec_pointer 
("g-destroy-func", "destroy func", "destroy func", G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | 
G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property (G_OBJECT_CLASS (klass), FOO_FOO_G_TYPE_PROPERTY, 
foo_properties[FOO_FOO_G_TYPE_PROPERTY] = g_param_spec_gtype ("foo-g-type", "foo-g-type", "foo-g-type", 
G_TYPE_NONE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
+}
+
+static void
+foo_instance_init (Foo * self,
+                   gpointer klass)
+{
+       self->priv = foo_get_instance_private (self);
+}
+
+static GType
+foo_get_type_once (void)
+{
+       static const GTypeInfo g_define_type_info = { sizeof (FooClass), (GBaseInitFunc) NULL, 
(GBaseFinalizeFunc) NULL, (GClassInitFunc) foo_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Foo), 0, 
(GInstanceInitFunc) foo_instance_init, NULL };
+       GType foo_type_id;
+       foo_type_id = g_type_register_static (G_TYPE_OBJECT, "Foo", &g_define_type_info, 0);
+       Foo_private_offset = g_type_add_instance_private (foo_type_id, sizeof (FooPrivate));
+       return foo_type_id;
+}
+
+GType
+foo_get_type (void)
+{
+       static volatile gsize foo_type_id__volatile = 0;
+       if (g_once_init_enter (&foo_type_id__volatile)) {
+               GType foo_type_id;
+               foo_type_id = foo_get_type_once ();
+               g_once_init_leave (&foo_type_id__volatile, foo_type_id);
+       }
+       return foo_type_id__volatile;
+}
+
+static void
+_vala_foo_get_property (GObject * object,
+                        guint property_id,
+                        GValue * value,
+                        GParamSpec * pspec)
+{
+       Foo * self;
+       self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_FOO, Foo);
+       switch (property_id) {
+               case FOO_FOO_G_TYPE_PROPERTY:
+               g_value_set_gtype (value, foo_get_foo_g_type (self));
+               break;
+               case FOO_G_TYPE:
+               g_value_set_gtype (value, self->priv->g_type);
+               break;
+               case FOO_G_DUP_FUNC:
+               g_value_set_pointer (value, self->priv->g_dup_func);
+               break;
+               case FOO_G_DESTROY_FUNC:
+               g_value_set_pointer (value, self->priv->g_destroy_func);
+               break;
+               default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+               break;
+       }
+}
+
+static void
+_vala_foo_set_property (GObject * object,
+                        guint property_id,
+                        const GValue * value,
+                        GParamSpec * pspec)
+{
+       Foo * self;
+       self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_FOO, Foo);
+       switch (property_id) {
+               case FOO_G_TYPE:
+               self->priv->g_type = g_value_get_gtype (value);
+               break;
+               case FOO_G_DUP_FUNC:
+               self->priv->g_dup_func = g_value_get_pointer (value);
+               break;
+               case FOO_G_DESTROY_FUNC:
+               self->priv->g_destroy_func = g_value_get_pointer (value);
+               break;
+               default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+               break;
+       }
+}
+
+static inline gpointer
+bar_get_instance_private (Bar* self)
+{
+       return G_STRUCT_MEMBER_P (self, Bar_private_offset);
+}
+
+Bar*
+bar_construct (GType object_type,
+               GType g_type,
+               GBoxedCopyFunc g_dup_func,
+               GDestroyNotify g_destroy_func)
+{
+       Bar * self = NULL;
+       self = (Bar*) foo_construct (object_type, g_type, (GBoxedCopyFunc) g_dup_func, (GDestroyNotify) 
g_destroy_func);
+       self->priv->g_type = g_type;
+       self->priv->g_dup_func = g_dup_func;
+       self->priv->g_destroy_func = g_destroy_func;
+       return self;
+}
+
+Bar*
+bar_new (GType g_type,
+         GBoxedCopyFunc g_dup_func,
+         GDestroyNotify g_destroy_func)
+{
+       return bar_construct (TYPE_BAR, g_type, g_dup_func, g_destroy_func);
+}
+
+GType
+bar_get_bar_g_type (Bar* self)
+{
+       GType result;
+       g_return_val_if_fail (IS_BAR (self), 0UL);
+       result = self->priv->g_type;
+       return result;
+}
+
+static void
+bar_class_init (BarClass * klass,
+                gpointer klass_data)
+{
+       bar_parent_class = g_type_class_peek_parent (klass);
+       g_type_class_adjust_private_offset (klass, &Bar_private_offset);
+       G_OBJECT_CLASS (klass)->get_property = _vala_bar_get_property;
+       G_OBJECT_CLASS (klass)->set_property = _vala_bar_set_property;
+       g_object_class_install_property (G_OBJECT_CLASS (klass), BAR_G_TYPE, g_param_spec_gtype ("g-type", 
"type", "type", G_TYPE_NONE, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property (G_OBJECT_CLASS (klass), BAR_G_DUP_FUNC, g_param_spec_pointer 
("g-dup-func", "dup func", "dup func", G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property (G_OBJECT_CLASS (klass), BAR_G_DESTROY_FUNC, g_param_spec_pointer 
("g-destroy-func", "destroy func", "destroy func", G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | 
G_PARAM_CONSTRUCT_ONLY));
+       g_object_class_install_property (G_OBJECT_CLASS (klass), BAR_BAR_G_TYPE_PROPERTY, 
bar_properties[BAR_BAR_G_TYPE_PROPERTY] = g_param_spec_gtype ("bar-g-type", "bar-g-type", "bar-g-type", 
G_TYPE_NONE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
+}
+
+static void
+bar_instance_init (Bar * self,
+                   gpointer klass)
+{
+       self->priv = bar_get_instance_private (self);
+}
+
+static GType
+bar_get_type_once (void)
+{
+       static const GTypeInfo g_define_type_info = { sizeof (BarClass), (GBaseInitFunc) NULL, 
(GBaseFinalizeFunc) NULL, (GClassInitFunc) bar_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Bar), 0, 
(GInstanceInitFunc) bar_instance_init, NULL };
+       GType bar_type_id;
+       bar_type_id = g_type_register_static (TYPE_FOO, "Bar", &g_define_type_info, 0);
+       Bar_private_offset = g_type_add_instance_private (bar_type_id, sizeof (BarPrivate));
+       return bar_type_id;
+}
+
+GType
+bar_get_type (void)
+{
+       static volatile gsize bar_type_id__volatile = 0;
+       if (g_once_init_enter (&bar_type_id__volatile)) {
+               GType bar_type_id;
+               bar_type_id = bar_get_type_once ();
+               g_once_init_leave (&bar_type_id__volatile, bar_type_id);
+       }
+       return bar_type_id__volatile;
+}
+
+static void
+_vala_bar_get_property (GObject * object,
+                        guint property_id,
+                        GValue * value,
+                        GParamSpec * pspec)
+{
+       Bar * self;
+       self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_BAR, Bar);
+       switch (property_id) {
+               case BAR_BAR_G_TYPE_PROPERTY:
+               g_value_set_gtype (value, bar_get_bar_g_type (self));
+               break;
+               case BAR_G_TYPE:
+               g_value_set_gtype (value, self->priv->g_type);
+               break;
+               case BAR_G_DUP_FUNC:
+               g_value_set_pointer (value, self->priv->g_dup_func);
+               break;
+               case BAR_G_DESTROY_FUNC:
+               g_value_set_pointer (value, self->priv->g_destroy_func);
+               break;
+               default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+               break;
+       }
+}
+
+static void
+_vala_bar_set_property (GObject * object,
+                        guint property_id,
+                        const GValue * value,
+                        GParamSpec * pspec)
+{
+       Bar * self;
+       self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_BAR, Bar);
+       switch (property_id) {
+               case BAR_G_TYPE:
+               self->priv->g_type = g_value_get_gtype (value);
+               break;
+               case BAR_G_DUP_FUNC:
+               self->priv->g_dup_func = g_value_get_pointer (value);
+               break;
+               case BAR_G_DESTROY_FUNC:
+               self->priv->g_destroy_func = g_value_get_pointer (value);
+               break;
+               default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+               break;
+       }
+}
+
+static void
+_vala_main (void)
+{
+       Bar* bar = NULL;
+       Bar* _tmp0_;
+       GType _tmp1_;
+       GType _tmp2_;
+       GType _tmp3_;
+       GType _tmp4_;
+       _tmp0_ = bar_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free);
+       bar = _tmp0_;
+       _tmp1_ = bar_get_bar_g_type (bar);
+       _tmp2_ = _tmp1_;
+       _vala_assert (_tmp2_ == G_TYPE_STRING, "bar.bar_g_type == typeof (string)");
+       _tmp3_ = foo_get_foo_g_type (G_TYPE_CHECK_INSTANCE_CAST (bar, TYPE_FOO, Foo));
+       _tmp4_ = _tmp3_;
+       _vala_assert (_tmp4_ == G_TYPE_STRING, "bar.foo_g_type == typeof (string)");
+       _g_object_unref0 (bar);
+}
+
+int
+main (int argc,
+      char ** argv)
+{
+       _vala_main ();
+       return 0;
+}
+
diff --git a/tests/generics/type-parameter-property-clash.vala 
b/tests/generics/type-parameter-property-clash.vala
new file mode 100644
index 000000000..760f5d1fc
--- /dev/null
+++ b/tests/generics/type-parameter-property-clash.vala
@@ -0,0 +1,13 @@
+class Foo<G> : Object {
+       public Type foo_g_type { get { return typeof (G); } }
+}
+
+class Bar<G> : Foo<G> {
+       public Type bar_g_type { get { return typeof (G); } }
+}
+
+void main () {
+       var bar = new Bar<string> ();
+       assert (bar.bar_g_type == typeof (string));
+       assert (bar.foo_g_type == typeof (string));
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]