From 85c9f6bd5982a7e43f851454f6e75f68f2950d56 Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Mon, 4 Mar 2013 15:15:51 +0100 Subject: [PATCH] adg: properly initialize AdgTable:local-mix AdgTable must use a custom default value for local-mix: set it properly also when using g_object_new(). --- src/adg/adg-table.c | 20 ++++++++++++++------ src/adg/tests/test-table.c | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/adg/adg-table.c b/src/adg/adg-table.c index f86617b8..534df53d 100644 --- a/src/adg/adg-table.c +++ b/src/adg/adg-table.c @@ -28,6 +28,11 @@ * To define a table, you should add to it a serie of one or more * #AdgTableRow by using the #AdgTableRow specific APIs. * + * + * By default, the #AdgText:local-mix property is set to + * #ADG_MIX_DISABLED on #AdgTable entities. + * + * * Since: 1.0 **/ @@ -53,6 +58,7 @@ #include "adg-stroke.h" #include "adg-container.h" #include "adg-alignment.h" +#include "adg-entity-private.h" #include "adg-table.h" #include "adg-table-private.h" @@ -158,6 +164,7 @@ adg_table_init(AdgTable *table) AdgTablePrivate *data = G_TYPE_INSTANCE_GET_PRIVATE(table, ADG_TYPE_TABLE, AdgTablePrivate); + AdgEntityPrivate *entity_data = ((AdgEntity *) table)->data; data->table_dress = ADG_DRESS_TABLE; data->has_frame = TRUE; @@ -169,6 +176,11 @@ adg_table_init(AdgTable *table) data->cell_names = NULL; table->data = data; + + /* Initialize to custom default some AdgEntity field by directly + * accessing the private struct to avoid notify signal emissions + */ + entity_data->local_mix = ADG_MIX_DISABLED; } static void @@ -257,9 +269,7 @@ _adg_set_property(GObject *object, guint prop_id, /** * adg_table_new: * - * Creates a new empty table entity. The #AdgEntity:local-mix - * property is set by default to #ADG_MIX_DISABLED, that is the - * table is not subject to any local transformations. + * Creates a new empty table entity. * * Returns: the newly created table entity * @@ -268,9 +278,7 @@ _adg_set_property(GObject *object, guint prop_id, AdgTable * adg_table_new(void) { - return g_object_new(ADG_TYPE_TABLE, - "local-mix", ADG_MIX_DISABLED, - NULL); + return g_object_new(ADG_TYPE_TABLE, NULL); } /** diff --git a/src/adg/tests/test-table.c b/src/adg/tests/test-table.c index 78a2f959..cb37c206 100644 --- a/src/adg/tests/test-table.c +++ b/src/adg/tests/test-table.c @@ -22,6 +22,31 @@ static void +_adg_test_local_mix(void) +{ + AdgTable *table; + AdgEntity *entity; + + /* Check default local mix method */ + table = adg_table_new(); + entity = (AdgEntity *) table; + g_assert_cmpint(adg_entity_get_local_mix(entity), ==, ADG_MIX_DISABLED); + adg_entity_destroy(entity); + + /* Check local mix method overriding */ + table = g_object_new(ADG_TYPE_TABLE, "local-mix", ADG_MIX_ANCESTORS_NORMALIZED, NULL); + entity = (AdgEntity *) table; + g_assert_cmpint(adg_entity_get_local_mix(entity), ==, ADG_MIX_ANCESTORS_NORMALIZED); + adg_entity_destroy(entity); + + /* Check default mix using GObject methods */ + table = g_object_new(ADG_TYPE_TABLE, NULL); + entity = (AdgEntity *) table; + g_assert_cmpint(adg_entity_get_local_mix(entity), ==, ADG_MIX_DISABLED); + adg_entity_destroy(entity); +} + +static void _adg_test_table_dress(void) { AdgTable *table; @@ -98,6 +123,7 @@ main(int argc, char *argv[]) { adg_test_init(&argc, &argv); + adg_test_add_func("/adg/table/local-mix", _adg_test_local_mix); adg_test_add_func("/adg/table/table-dress", _adg_test_table_dress); adg_test_add_func("/adg/table/has-frame", _adg_test_has_frame); -- 2.11.4.GIT