1
0
mirror of https://gitlab.gnome.org/GNOME/glib.git synced 2025-11-17 16:08:21 +01:00
Files
debian
docs
gio
glib
gmodule
gobject
gthread
m4macros
po
tests
bookmarks
collate
gobject
Makefile.am
accumulator.c
defaultiface.c
deftype.c
dynamictype.c
gvalue-test.c
ifacecheck.c
ifaceinherit.c
ifaceinit.c
ifaceproperties.c
override.c
paramspec-test.c
references.c
singleton.c
testcommon.h
testmarshal.list
testmodule.c
testmodule.h
markups
refcount
Makefile.am
array-test.c
asyncqueue-test.c
atomic-test.c
base64-test.c
bit-test.c
bookmarkfile-test.c
casefold.txt
casemap.txt
checksum-test.c
child-test.c
completion-test.c
convert-test.c
cxx-test.C
date-test.c
dirname-test.c
env-test.c
errorcheck-mutex-test.c
file-test.c
gen-casefold-txt.pl
gen-casemap-txt.pl
gio-ls.c
gio-test.c
hash-test.c
iochannel-test-infile
iochannel-test.c
keyfile-test.c
libmoduletestplugin_a.c
libmoduletestplugin_b.c
list-test.c
mainloop-test.c
makefile.msc.in
mapping-test.c
markup-collect.c
markup-escape-test.c
markup-test.c
memchunks.c
module-test.c
node-test.c
onceinit.c
option-test.c
patterntest.c
printf-test.c
qsort-test.c
queue-test.c
rand-test.c
regex-test.c
relation-test.c
run-bookmark-test.sh
run-collate-tests.sh
run-markup-tests.sh
scannerapi.c
sequence-test.c
shell-test.c
slice-color.c
slice-concurrent.c
slice-test.c
slice-threadinit.c
slist-test.c
spawn-test-win32-gui.c
spawn-test.c
strfunc-test.c
string-test.c
strtod-test.c
strtoll-test.c
testgdate.c
testgdateparser.c
testglib.c
thread-test.c
threadpool-test.c
timeloop-basic.c
timeloop-closure.c
timeloop.c
tree-test.c
type-test.c
unicode-caseconv.c
unicode-collate.c
unicode-encoding.c
unicode-normalize.c
uri-test.c
utf8-pointer.c
utf8-validate.c
utf8.txt
.gitignore
AUTHORS
COPYING
ChangeLog
ChangeLog.pre-1-2
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-14
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
HACKING
INSTALL
INSTALL.in
MAINTAINERS
Makefile.am
Makefile.decl
NEWS
NEWS.pre-1-3
README
README.in
README.win32
acglib.m4
acinclude.m4
autogen.sh
config.h.win32.in
configure.in
gio-2.0-uninstalled.pc.in
gio-2.0.pc.in
gio-unix-2.0-uninstalled.pc.in
gio-unix-2.0.pc.in
glib-2.0-uninstalled.pc.in
glib-2.0.pc.in
glib-gettextize.in
glib-zip.in
glibconfig.h.win32.in
gmodule-2.0-uninstalled.pc.in
gmodule-2.0.pc.in
gmodule-export-2.0.pc.in
gmodule-no-export-2.0-uninstalled.pc.in
gmodule-no-export-2.0.pc.in
gobject-2.0-uninstalled.pc.in
gobject-2.0.pc.in
gthread-2.0-uninstalled.pc.in
gthread-2.0.pc.in
makefile.msc
mkinstalldirs
msvc_recommended_pragmas.h
sanity_check
win32-fixup.pl
glib/tests/gobject/paramspec-test.c

221 lines
6.5 KiB
C
Raw Normal View History

/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#undef G_DISABLE_ASSERT
#undef G_LOG_DOMAIN
#include <string.h>
#include <glib.h>
#include <glib-object.h>
static void
test_param_spec_char (void)
{
GParamSpec *pspec;
GValue value = { 0, };
gboolean modified;
pspec = g_param_spec_char ("char", "nick", "blurb",
20, 40, 30, G_PARAM_READWRITE);
g_assert (strcmp (g_param_spec_get_name (pspec), "char") == 0);
g_assert (strcmp (g_param_spec_get_nick (pspec), "nick") == 0);
g_assert (strcmp (g_param_spec_get_blurb (pspec), "blurb") == 0);
g_value_init (&value, G_TYPE_CHAR);
g_value_set_char (&value, 30);
g_assert (g_param_value_defaults (pspec, &value));
g_value_set_char (&value, 0);
modified = g_param_value_validate (pspec, &value);
g_assert (modified && g_value_get_char (&value) == 20);
g_value_set_char (&value, 20);
modified = g_param_value_validate (pspec, &value);
g_assert (!modified && g_value_get_char (&value) == 20);
g_value_set_char (&value, 40);
modified = g_param_value_validate (pspec, &value);
g_assert (!modified && g_value_get_char (&value) == 40);
g_value_set_char (&value, 60);
modified = g_param_value_validate (pspec, &value);
g_assert (modified && g_value_get_char (&value) == 40);
g_param_spec_unref (pspec);
}
static void
test_param_spec_string (void)
{
GParamSpec *pspec;
GValue value = { 0, };
gboolean modified;
pspec = g_param_spec_string ("string", "nick", "blurb",
NULL, G_PARAM_READWRITE);
g_value_init (&value, G_TYPE_STRING);
g_value_set_string (&value, "foobar");
modified = g_param_value_validate (pspec, &value);
g_assert (!modified);
g_value_set_string (&value, "");
modified = g_param_value_validate (pspec, &value);
g_assert (!modified && g_value_get_string (&value) != NULL);
/* test ensure_non_null */
G_PARAM_SPEC_STRING (pspec)->ensure_non_null = TRUE;
g_value_set_string (&value, NULL);
modified = g_param_value_validate (pspec, &value);
g_assert (modified && g_value_get_string (&value) != NULL);
G_PARAM_SPEC_STRING (pspec)->ensure_non_null = FALSE;
/* test null_fold_if_empty */
G_PARAM_SPEC_STRING (pspec)->null_fold_if_empty = TRUE;
g_value_set_string (&value, "");
modified = g_param_value_validate (pspec, &value);
g_assert (modified && g_value_get_string (&value) == NULL);
g_value_set_static_string (&value, "");
modified = g_param_value_validate (pspec, &value);
g_assert (modified && g_value_get_string (&value) == NULL);
G_PARAM_SPEC_STRING (pspec)->null_fold_if_empty = FALSE;
/* test cset_first */
G_PARAM_SPEC_STRING (pspec)->cset_first = g_strdup ("abc");
G_PARAM_SPEC_STRING (pspec)->substitutor = '-';
g_value_set_string (&value, "ABC");
modified = g_param_value_validate (pspec, &value);
g_assert (modified && g_value_get_string (&value)[0] == '-');
g_value_set_static_string (&value, "ABC");
modified = g_param_value_validate (pspec, &value);
g_assert (modified && g_value_get_string (&value)[0] == '-');
/* test cset_nth */
G_PARAM_SPEC_STRING (pspec)->cset_nth = g_strdup ("abc");
g_value_set_string (&value, "aBC");
modified = g_param_value_validate (pspec, &value);
g_assert (modified && g_value_get_string (&value)[1] == '-');
g_value_set_static_string (&value, "aBC");
modified = g_param_value_validate (pspec, &value);
g_assert (modified && g_value_get_string (&value)[1] == '-');
g_value_unset (&value);
g_param_spec_unref (pspec);
}
static void
test_param_spec_override (void)
{
GParamSpec *ospec, *pspec;
GValue value = { 0, };
gboolean modified;
ospec = g_param_spec_char ("char", "nick", "blurb",
20, 40, 30, G_PARAM_READWRITE);
pspec = g_param_spec_override ("override", ospec);
g_assert (strcmp (g_param_spec_get_name (pspec), "override") == 0);
g_assert (strcmp (g_param_spec_get_nick (pspec), "nick") == 0);
g_assert (strcmp (g_param_spec_get_blurb (pspec), "blurb") == 0);
g_value_init (&value, G_TYPE_CHAR);
g_value_set_char (&value, 30);
g_assert (g_param_value_defaults (pspec, &value));
g_value_set_char (&value, 0);
modified = g_param_value_validate (pspec, &value);
g_assert (modified && g_value_get_char (&value) == 20);
g_value_set_char (&value, 20);
modified = g_param_value_validate (pspec, &value);
g_assert (!modified && g_value_get_char (&value) == 20);
g_value_set_char (&value, 40);
modified = g_param_value_validate (pspec, &value);
g_assert (!modified && g_value_get_char (&value) == 40);
g_value_set_char (&value, 60);
modified = g_param_value_validate (pspec, &value);
g_assert (modified && g_value_get_char (&value) == 40);
g_param_spec_unref (pspec);
}
static void
test_param_spec_gtype (void)
{
GParamSpec *pspec;
GValue value = { 0, };
gboolean modified;
pspec = g_param_spec_gtype ("gtype", "nick", "blurb",
G_TYPE_PARAM, G_PARAM_READWRITE);
g_value_init (&value, G_TYPE_GTYPE);
g_value_set_gtype (&value, G_TYPE_NONE);
g_assert (g_param_value_defaults (pspec, &value));
g_value_set_gtype (&value, G_TYPE_INT);
modified = g_param_value_validate (pspec, &value);
g_assert (modified && g_value_get_gtype (&value) == G_TYPE_NONE);
g_value_set_gtype (&value, G_TYPE_PARAM_INT);
modified = g_param_value_validate (pspec, &value);
g_assert (!modified && g_value_get_gtype (&value) == G_TYPE_PARAM_INT);
}
int
main (int argc, char *argv[])
{
g_type_init ();
test_param_spec_char ();
test_param_spec_string ();
test_param_spec_override ();
test_param_spec_gtype ();
return 0;
}