mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01: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:
parent
b4a3c1bb11
commit
4b2d92a864
@ -254,16 +254,19 @@ g_value_reset (GValue *value)
|
||||
* g_value_unset:
|
||||
* @value: An initialized #GValue structure.
|
||||
*
|
||||
* Clears the current value in @value and "unsets" the type,
|
||||
* this releases all resources associated with this GValue.
|
||||
* An unset value is the same as an uninitialized (zero-filled)
|
||||
* #GValue structure.
|
||||
* Clears the current value in @value (if any) and "unsets" the type,
|
||||
* this releases all resources associated with this GValue. An unset
|
||||
* value is the same as an uninitialized (zero-filled) #GValue
|
||||
* structure.
|
||||
*/
|
||||
void
|
||||
g_value_unset (GValue *value)
|
||||
{
|
||||
GTypeValueTable *value_table;
|
||||
|
||||
if (value->g_type == 0)
|
||||
return;
|
||||
|
||||
g_return_if_fail (G_IS_VALUE (value));
|
||||
|
||||
value_table = g_type_value_table_peek (G_VALUE_TYPE (value));
|
||||
|
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 ();
|
||||
}
|
Loading…
Reference in New Issue
Block a user