[gobject-introspection/wip/transformer] gimarshallingtests: Fix (inout) test cases, drop unsupported API



commit 1510402cee8380d74099327bd121367a35f784bf
Author: Colin Walters <walters verbum org>
Date:   Mon Aug 23 14:27:44 2010 -0400

    gimarshallingtests: Fix (inout) test cases, drop unsupported API
    
    First, (inout) doesn't mean "mutates the argument".  It means "I take an
    input argument here, and will also return a *new* argument in this position."
    
    C API which mutates e.g. structures is just unannotated.  Mutation of
    containers like GList, GHashTable is simply disallowed.
    
    Secondly, we can't support C API which returns non-boxed structures with
    a transfer other than (none).  The scanner will warn about this in the future.

 tests/gimarshallingtests.c |  213 ++++++++++++-------------------------------
 1 files changed, 60 insertions(+), 153 deletions(-)
---
diff --git a/tests/gimarshallingtests.c b/tests/gimarshallingtests.c
index 6f965d9..8992a3d 100644
--- a/tests/gimarshallingtests.c
+++ b/tests/gimarshallingtests.c
@@ -1422,20 +1422,6 @@ gi_marshalling_tests_garray_utf8_none_in (GArray *array_)
 }
 
 /**
- * gi_marshalling_tests_garray_utf8_container_in:
- * @array_: (element-type utf8) (transfer container):
- */
-void
-gi_marshalling_tests_garray_utf8_container_in (GArray *array_)
-{
-    g_assert (array_->len == 3);
-    g_assert (strcmp (g_array_index (array_, gchar*, 0), "0") == 0);
-    g_assert (strcmp (g_array_index (array_, gchar*, 1), "1") == 0);
-    g_assert (strcmp (g_array_index (array_, gchar*, 2), "2") == 0);
-    g_array_free (array_, TRUE);
-}
-
-/**
  * gi_marshalling_tests_garray_utf8_full_in:
  * @array_: (element-type utf8) (transfer full):
  */
@@ -1542,16 +1528,20 @@ gi_marshalling_tests_garray_utf8_container_inout (GArray **array_)
 {
     static gchar *val1 = "-1";
     static gchar *val2 = "-2";
+    GArray *result;
 
     g_assert ((*array_)->len == 3);
     g_assert (strcmp (g_array_index (*array_, gchar*, 0), "0") == 0);
     g_assert (strcmp (g_array_index (*array_, gchar*, 1), "1") == 0);
     g_assert (strcmp (g_array_index (*array_, gchar*, 2), "2") == 0);
 
-    g_array_remove_index (*array_, (*array_)->len - 1);
+    result = g_array_new (TRUE, TRUE, sizeof (gchar *));
+    g_array_append_val (result, val2);
+    g_array_append_val (result, val1);
+    g_array_append_val (result, "0");
+    g_array_append_val (result, "1");
 
-    g_array_prepend_val (*array_, val1);
-    g_array_prepend_val (*array_, val2);
+    *array_ = result;
 }
 
 /**
@@ -1564,20 +1554,24 @@ gi_marshalling_tests_garray_utf8_full_inout (GArray **array_)
     static gchar *val1 = "-1";
     static gchar *val2 = "-2";
     gchar *val;
+    GArray *result;
 
     g_assert ((*array_)->len == 3);
     g_assert (strcmp (g_array_index (*array_, gchar*, 0), "0") == 0);
     g_assert (strcmp (g_array_index (*array_, gchar*, 1), "1") == 0);
     g_assert (strcmp (g_array_index (*array_, gchar*, 2), "2") == 0);
 
-    g_free (g_array_index (*array_, gchar*, (*array_)->len - 1));
-    g_array_remove_index (*array_, (*array_)->len - 1);
-
+    result = g_array_new (TRUE, TRUE, sizeof (gchar *));
+    val = g_strdup (val2);
+    g_array_append_val(result, val);
     val = g_strdup (val1);
-    g_array_prepend_val (*array_, val);
+    g_array_append_val(result, val);
+    val = g_strdup ("0");
+    g_array_append_val(result, val);
+    val = g_strdup ("1");
+    g_array_append_val(result, val);
 
-    val = g_strdup (val2);
-    g_array_prepend_val (*array_, val);
+    *array_ = result;
 }
 
 /**
@@ -1876,15 +1870,19 @@ gi_marshalling_tests_glist_utf8_none_inout (GList **list)
 void
 gi_marshalling_tests_glist_utf8_container_inout (GList **list)
 {
+    GList *result = NULL;
+
     g_assert(g_list_length(*list) == 3);
     g_assert(strcmp(g_list_nth_data(*list, 0), "0") == 0);
     g_assert(strcmp(g_list_nth_data(*list, 1), "1") == 0);
     g_assert(strcmp(g_list_nth_data(*list, 2), "2") == 0);
 
-    *list = g_list_remove_link(*list, g_list_last(*list));
+    result = g_list_prepend(result, "-1");
+    result = g_list_prepend(result, "-2");
+    result = g_list_prepend(result, "0");
+    result = g_list_prepend(result, "1");
 
-    *list = g_list_prepend(*list, "-1");
-    *list = g_list_prepend(*list, "-2");
+    *list = result;
 }
 
 /**
@@ -1894,19 +1892,19 @@ gi_marshalling_tests_glist_utf8_container_inout (GList **list)
 void
 gi_marshalling_tests_glist_utf8_full_inout (GList **list)
 {
-    gpointer *data;
+    GList *result = NULL;
 
     g_assert(g_list_length(*list) == 3);
     g_assert(strcmp(g_list_nth_data(*list, 0), "0") == 0);
     g_assert(strcmp(g_list_nth_data(*list, 1), "1") == 0);
     g_assert(strcmp(g_list_nth_data(*list, 2), "2") == 0);
 
-    data = g_list_last(*list)->data;
-    *list = g_list_remove(*list, data);
-    g_free(data);
+    result = g_list_prepend(result, g_strdup("-1"));
+    result = g_list_prepend(result, g_strdup("-2"));
+    result = g_list_prepend(result, g_strdup("0"));
+    result = g_list_prepend(result, g_strdup("1"));
 
-    *list = g_list_prepend(*list, g_strdup("-1"));
-    *list = g_list_prepend(*list, g_strdup("-2"));
+    *list = result;
 }
 
 
@@ -2122,15 +2120,19 @@ gi_marshalling_tests_gslist_utf8_none_inout (GSList **list)
 void
 gi_marshalling_tests_gslist_utf8_container_inout (GSList **list)
 {
+    GSList *result = NULL;
+
     g_assert(g_slist_length(*list) == 3);
     g_assert(strcmp(g_slist_nth_data(*list, 0), "0") == 0);
     g_assert(strcmp(g_slist_nth_data(*list, 1), "1") == 0);
     g_assert(strcmp(g_slist_nth_data(*list, 2), "2") == 0);
 
-    *list = g_slist_remove_link(*list, g_slist_last(*list));
+    result = g_slist_prepend(*list, "-1");
+    result = g_slist_prepend(*list, "-2");
+    result = g_slist_prepend(*list, "0");
+    result = g_slist_prepend(*list, "1");
 
-    *list = g_slist_prepend(*list, "-1");
-    *list = g_slist_prepend(*list, "-2");
+    *list = result;
 }
 
 /**
@@ -2140,19 +2142,19 @@ gi_marshalling_tests_gslist_utf8_container_inout (GSList **list)
 void
 gi_marshalling_tests_gslist_utf8_full_inout (GSList **list)
 {
-    gpointer *data;
+    GSList *result = NULL;
 
     g_assert(g_slist_length(*list) == 3);
     g_assert(strcmp(g_slist_nth_data(*list, 0), "0") == 0);
     g_assert(strcmp(g_slist_nth_data(*list, 1), "1") == 0);
     g_assert(strcmp(g_slist_nth_data(*list, 2), "2") == 0);
 
-    data = g_slist_last(*list)->data;
-    *list = g_slist_remove(*list, data);
-    g_free(data);
+    result = g_slist_prepend(*list, g_strdup("-1"));
+    result = g_slist_prepend(*list, g_strdup("-2"));
+    result = g_slist_prepend(*list, g_strdup("0"));
+    result = g_slist_prepend(*list, g_strdup("1"));
 
-    *list = g_slist_prepend(*list, g_strdup("-1"));
-    *list = g_slist_prepend(*list, g_strdup("-2"));
+    *list = result;
 }
 
 
@@ -2377,14 +2379,18 @@ gi_marshalling_tests_ghashtable_utf8_none_inout (GHashTable **hash_table)
 void
 gi_marshalling_tests_ghashtable_utf8_container_inout (GHashTable **hash_table)
 {
+    GHashTable *result = g_hash_table_new(g_str_hash, g_str_equal);
+
     g_assert(strcmp(g_hash_table_lookup(*hash_table, "-1"), "1") == 0);
     g_assert(strcmp(g_hash_table_lookup(*hash_table, "0"), "0") == 0);
     g_assert(strcmp(g_hash_table_lookup(*hash_table, "1"), "-1") == 0);
     g_assert(strcmp(g_hash_table_lookup(*hash_table, "2"), "-2") == 0);
 
-    g_hash_table_steal(*hash_table, "2");
-    g_hash_table_steal(*hash_table, "1");
-    g_hash_table_insert(*hash_table, "1", "1");
+    g_hash_table_insert(result, "-1", "1");
+    g_hash_table_insert(result, "0", "0");
+    g_hash_table_insert(result, "1", "-1");
+
+    *hash_table = result;
 }
 
 /**
@@ -2394,14 +2400,19 @@ gi_marshalling_tests_ghashtable_utf8_container_inout (GHashTable **hash_table)
 void
 gi_marshalling_tests_ghashtable_utf8_full_inout (GHashTable **hash_table)
 {
+    GHashTable *result = g_hash_table_new_full(g_str_hash, g_str_equal,
+					       g_free, g_free);
+
     g_assert(strcmp(g_hash_table_lookup(*hash_table, "-1"), "1") == 0);
     g_assert(strcmp(g_hash_table_lookup(*hash_table, "0"), "0") == 0);
     g_assert(strcmp(g_hash_table_lookup(*hash_table, "1"), "-1") == 0);
     g_assert(strcmp(g_hash_table_lookup(*hash_table, "2"), "-2") == 0);
 
-    g_hash_table_steal(*hash_table, "2");
-    g_hash_table_steal(*hash_table, "1");
-    g_hash_table_insert(*hash_table, "1", g_strdup("1"));
+    g_hash_table_insert(result, g_strdup("-1"), g_strdup("1"));
+    g_hash_table_insert(result, g_strdup("0"), g_strdup("0"));
+    g_hash_table_insert(result, g_strdup("1"), g_strdup("-1"));
+
+    *hash_table = result;
 }
 
 
@@ -2679,39 +2690,6 @@ gi_marshalling_tests__simple_struct_in (GIMarshallingTestsSimpleStruct *struct_)
     g_assert(struct_->int8 == 7);
 }
 
-/**
- * gi_marshalling_tests__simple_struct_out:
- * @struct_: (out) (transfer none):
- */
-void
-gi_marshalling_tests__simple_struct_out (GIMarshallingTestsSimpleStruct **struct_)
-{
-    static GIMarshallingTestsSimpleStruct *new_struct = NULL;
-
-    if (new_struct == NULL) {
-        new_struct = g_new(GIMarshallingTestsSimpleStruct, 1);
-
-        new_struct->long_ = 6;
-        new_struct->int8 = 7;
-    }
-
-    *struct_ = new_struct;
-}
-
-/**
- * gi_marshalling_tests__simple_struct_inout:
- * @struct_: (inout) (transfer none):
- */
-void
-gi_marshalling_tests__simple_struct_inout (GIMarshallingTestsSimpleStruct **struct_)
-{
-    g_assert((*struct_)->long_ == 6);
-    g_assert((*struct_)->int8 == 7);
-
-    (*struct_)->long_ = 7;
-    (*struct_)->int8 = 6;
-}
-
 void
 gi_marshalling_tests_simple_struct_method (GIMarshallingTestsSimpleStruct *struct_)
 {
@@ -2760,37 +2738,6 @@ gi_marshalling_tests__pointer_struct_in (GIMarshallingTestsPointerStruct *struct
     g_assert(struct_->long_ == 42);
 }
 
-/**
- * gi_marshalling_tests__pointer_struct_out:
- * @struct_: (out) (transfer none):
- */
-void
-gi_marshalling_tests__pointer_struct_out (GIMarshallingTestsPointerStruct **struct_)
-{
-    static GIMarshallingTestsPointerStruct *new_struct = NULL;
-
-    if (new_struct == NULL) {
-        new_struct = g_new(GIMarshallingTestsPointerStruct, 1);
-
-        new_struct->long_ = 42;
-    }
-
-    *struct_ = new_struct;
-}
-
-/**
- * gi_marshalling_tests__pointer_struct_inout:
- * @struct_: (inout) (transfer none):
- */
-void
-gi_marshalling_tests__pointer_struct_inout (GIMarshallingTestsPointerStruct **struct_)
-{
-    g_assert((*struct_)->long_ == 42);
-
-    (*struct_)->long_ = 0;
-}
-
-
 static GIMarshallingTestsBoxedStruct *
 gi_marshalling_tests_boxed_struct_copy (GIMarshallingTestsBoxedStruct *struct_)
 {
@@ -2882,13 +2829,14 @@ gi_marshalling_tests__boxed_struct_out (GIMarshallingTestsBoxedStruct **struct_)
 
 /**
  * gi_marshalling_tests__boxed_struct_inout:
- * @struct_: (inout) (transfer none):
+ * @struct_: (inout) (transfer full):
  */
 void
 gi_marshalling_tests__boxed_struct_inout (GIMarshallingTestsBoxedStruct **struct_)
 {
     g_assert((*struct_)->long_ == 42);
 
+    (*struct_) = g_slice_new (GIMarshallingTestsBoxedStruct);
     (*struct_)->long_ = 0;
 }
 
@@ -2952,36 +2900,6 @@ gi_marshalling_tests__union_in (GIMarshallingTestsUnion *union_)
     g_assert(union_->long_ == 42);
 }
 
-/**
- * gi_marshalling_tests__union_out:
- * @union_: (out) (transfer none):
- */
-void
-gi_marshalling_tests__union_out (GIMarshallingTestsUnion **union_)
-{
-    static GIMarshallingTestsUnion *new_union = NULL;
-
-    if (new_union == NULL) {
-        new_union = g_new(GIMarshallingTestsUnion, 1);
-
-        new_union->long_ = 42;
-    }
-
-    *union_ = new_union;
-}
-
-/**
- * gi_marshalling_tests__union_inout:
- * @union_: (inout) (transfer none):
- */
-void
-gi_marshalling_tests__union_inout (GIMarshallingTestsUnion **union_)
-{
-    g_assert((*union_)->long_ == 42);
-
-    (*union_)->long_ = 0;
-}
-
 void
 gi_marshalling_tests_union_method (GIMarshallingTestsUnion *union_)
 {
@@ -3293,17 +3211,6 @@ gi_marshalling_tests__object_full_inout (GIMarshallingTestsObject **object)
 }
 
 /**
- * gi_marshalling_tests__object_inout_same:
- * @object: (inout):
- */
-void
-gi_marshalling_tests__object_inout_same (GIMarshallingTestsObject **object)
-{
-    g_assert((*object)->int_ == 42);
-    (*object)->int_ = 0;
-}
-
-/**
  * gi_marshalling_tests__object_test_int8_in:
  * @in: (in):
  */



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