mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 07:23:41 +02:00
Allow passing unset GValues to g_value_unset()
This makes it more useful as an autocleanup func. Also, add a minimal test of g_value_init/g_value_reset/g_value_unset. https://bugzilla.gnome.org/show_bug.cgi?id=755766
This commit is contained in:
2
gobject/tests/.gitignore
vendored
2
gobject/tests/.gitignore
vendored
@@ -12,6 +12,6 @@ reference
|
||||
signals
|
||||
threadtests
|
||||
type
|
||||
valuearray
|
||||
value
|
||||
private
|
||||
marshalers.[ch]
|
||||
|
@@ -17,7 +17,7 @@ test_programs = \
|
||||
binding \
|
||||
properties \
|
||||
reference \
|
||||
valuearray \
|
||||
value \
|
||||
type \
|
||||
private \
|
||||
closure \
|
||||
|
@@ -1,6 +1,36 @@
|
||||
#define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_30
|
||||
#include <glib-object.h>
|
||||
|
||||
static void
|
||||
test_value_basic (void)
|
||||
{
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
g_assert_false (G_IS_VALUE (&value));
|
||||
g_assert_false (G_VALUE_HOLDS_INT (&value));
|
||||
g_value_unset (&value);
|
||||
g_assert_false (G_IS_VALUE (&value));
|
||||
g_assert_false (G_VALUE_HOLDS_INT (&value));
|
||||
|
||||
g_value_init (&value, G_TYPE_INT);
|
||||
g_assert_true (G_IS_VALUE (&value));
|
||||
g_assert_true (G_VALUE_HOLDS_INT (&value));
|
||||
g_assert_false (G_VALUE_HOLDS_UINT (&value));
|
||||
g_assert_cmpint (g_value_get_int (&value), ==, 0);
|
||||
|
||||
g_value_set_int (&value, 10);
|
||||
g_assert_cmpint (g_value_get_int (&value), ==, 10);
|
||||
|
||||
g_value_reset (&value);
|
||||
g_assert_true (G_IS_VALUE (&value));
|
||||
g_assert_true (G_VALUE_HOLDS_INT (&value));
|
||||
g_assert_cmpint (g_value_get_int (&value), ==, 0);
|
||||
|
||||
g_value_unset (&value);
|
||||
g_assert_false (G_IS_VALUE (&value));
|
||||
g_assert_false (G_VALUE_HOLDS_INT (&value));
|
||||
}
|
||||
|
||||
static gint
|
||||
cmpint (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
@@ -11,7 +41,7 @@ cmpint (gconstpointer a, gconstpointer b)
|
||||
}
|
||||
|
||||
static void
|
||||
test_basic (void)
|
||||
test_valuearray_basic (void)
|
||||
{
|
||||
GValueArray *a;
|
||||
GValueArray *a2;
|
||||
@@ -58,7 +88,8 @@ main (int argc, char *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/valuearray/basic", test_basic);
|
||||
g_test_add_func ("/value/basic", test_value_basic);
|
||||
g_test_add_func ("/value/array/basic", test_valuearray_basic);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
Reference in New Issue
Block a user