Imported Upstream version 3.25.1
[platform/upstream/pygobject2.git] / tests / gimarshallingtestsextra.c
1 /* gimarshallingtestsextra.c
2  *
3  * Copyright (C) 2016 Thibault Saunier <tsaunier@gnome.org>
4  *
5  * This file is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as
7  * published by the Free Software Foundation; either version 3 of the
8  * License, or (at your option) any later version.
9  *
10  * This file is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include "gimarshallingtestsextra.h"
20 #include <string.h>
21
22 void
23 gi_marshalling_tests_compare_two_gerrors_in_gvalue (GValue *v, GValue *v1)
24 {
25   GError *error, * error1;
26
27   g_assert_cmpstr (g_type_name (G_VALUE_TYPE (v)), ==,
28                    g_type_name (G_TYPE_ERROR));
29   g_assert_cmpstr (g_type_name (G_VALUE_TYPE (v1)), ==,
30                    g_type_name (G_TYPE_ERROR));
31
32   error = (GError*) g_value_get_boxed (v);
33   error1 = (GError*) g_value_get_boxed (v1);
34
35   g_assert_cmpint (error->domain, ==, error1->domain);
36   g_assert_cmpint (error->code, ==, error1->code);
37   g_assert_cmpstr (error->message, ==, error1->message);
38 }
39
40 /**
41  * gi_marshalling_tests_ghashtable_enum_none_in:
42  * @hash_table: (element-type gint GIMarshallingTestsExtraEnum) (transfer none):
43  */
44 void
45 gi_marshalling_tests_ghashtable_enum_none_in (GHashTable *hash_table)
46 {
47   g_assert_cmpint (GPOINTER_TO_INT (g_hash_table_lookup (hash_table, GINT_TO_POINTER (1))), ==, GI_MARSHALLING_TESTS_EXTRA_ENUM_VALUE1);
48   g_assert_cmpint (GPOINTER_TO_INT (g_hash_table_lookup (hash_table, GINT_TO_POINTER (2))), ==, GI_MARSHALLING_TESTS_EXTRA_ENUM_VALUE2);
49   g_assert_cmpint (GPOINTER_TO_INT (g_hash_table_lookup (hash_table, GINT_TO_POINTER (3))), ==, GI_MARSHALLING_TESTS_EXTRA_ENUM_VALUE3);
50 }
51
52 /**
53  * gi_marshalling_tests_ghashtable_enum_none_return:
54  *
55  * Returns: (element-type gint GIMarshallingTestsExtraEnum) (transfer none):
56  */
57 GHashTable *
58 gi_marshalling_tests_ghashtable_enum_none_return (void)
59 {
60   static GHashTable *hash_table = NULL;
61
62   if (hash_table == NULL)
63     {
64       hash_table = g_hash_table_new (NULL, NULL);
65       g_hash_table_insert (hash_table, GINT_TO_POINTER (1), GINT_TO_POINTER (GI_MARSHALLING_TESTS_EXTRA_ENUM_VALUE1));
66       g_hash_table_insert (hash_table, GINT_TO_POINTER (2), GINT_TO_POINTER (GI_MARSHALLING_TESTS_EXTRA_ENUM_VALUE2));
67       g_hash_table_insert (hash_table, GINT_TO_POINTER (3), GINT_TO_POINTER (GI_MARSHALLING_TESTS_EXTRA_ENUM_VALUE3));
68     }
69
70   return hash_table;
71 }
72
73 /**
74  * gi_marshalling_tests_filename_copy:
75  * @path_in: (type filename) (nullable)
76  *
77  * Returns: (type filename) (nullable)
78  */
79 gchar *
80 gi_marshalling_tests_filename_copy (gchar *path_in)
81 {
82   return g_strdup (path_in);
83 }
84
85 /**
86  * gi_marshalling_tests_filename_to_glib_repr:
87  * @path_in: (type filename) (nullable)
88  *
89  * Returns: (array length=len) (element-type guint8)
90  */
91 gchar *
92 gi_marshalling_tests_filename_to_glib_repr (gchar *path_in, gsize *len)
93 {
94   *len = strlen(path_in);
95   return g_strdup (path_in);
96 }
97
98 /**
99  * gi_marshalling_tests_filename_exists:
100  * @path: (type filename)
101  */
102 gboolean
103 gi_marshalling_tests_filename_exists (gchar *path)
104 {
105   return g_file_test (path, G_FILE_TEST_EXISTS);
106 }