From b021f518c18eb142791238cb4ecde8b1ea3707c0 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 22 Dec 2008 13:29:10 +0000 Subject: [PATCH] Use "" as the default value for the :text property This follows the convention of GtkLabel/GtkEntry in GTK+ and the old ClutterEntry. It makes it easier to use strlen/strcmp etc on the output, since we can assume that it is always a string. This commit also updates the test unit for ClutterText to verify that the clutter_text_get_text() function also returns an empty string when a ClutterText actor has been created. --- clutter/clutter-text.c | 12 +++++++++--- tests/conform/test-clutter-text.c | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/clutter/clutter-text.c b/clutter/clutter-text.c index ab2e323d7..480ce65e7 100644 --- a/clutter/clutter-text.c +++ b/clutter/clutter-text.c @@ -1519,7 +1519,7 @@ clutter_text_class_init (ClutterTextClass *klass) pspec = g_param_spec_string ("text", "Text", "The text to render", - NULL, + "", CLUTTER_PARAM_READWRITE); g_object_class_install_property (gobject_class, PROP_TEXT, pspec); @@ -1981,7 +1981,11 @@ clutter_text_init (ClutterText *self) for (i = 0; i < N_CACHED_LAYOUTS; i++) priv->cached_layouts[i].layout = NULL; - priv->text = NULL; + /* default to "" so that clutter_text_get_text() will + * return a valid string and we can safely call strlen() + * or strcmp() on it + */ + priv->text = g_strdup (""); priv->text_color = default_text_color; priv->cursor_color = default_cursor_color; @@ -2640,7 +2644,9 @@ clutter_text_get_text (ClutterText *self) * @self: a #ClutterText * @text: the text to set * - * Sets the contents of a #ClutterText actor. + * Sets the contents of a #ClutterText actor. The @text string + * must not be %NULL; to unset the current contents of the + * #ClutterText actor simply pass "" (an empty string). * * Since: 1.0 */ diff --git a/tests/conform/test-clutter-text.c b/tests/conform/test-clutter-text.c index b47002a40..20cdb538c 100644 --- a/tests/conform/test-clutter-text.c +++ b/tests/conform/test-clutter-text.c @@ -76,7 +76,8 @@ test_text_empty (TestConformSimpleFixture *fixture, { ClutterText *text = CLUTTER_TEXT (clutter_text_new ()); - g_assert (clutter_text_get_text (text) == NULL); + g_assert_cmpstr (clutter_text_get_text (text), ==, ""); + g_assert_cmpint (*clutter_text_get_text (text), ==, '\0'); g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1); clutter_actor_destroy (CLUTTER_ACTOR (text));