From f6fe0952f04b0f13fb878a7a8b02e1fa66ca7385 Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Sun, 21 Feb 2010 20:56:54 +0100 Subject: [PATCH] [tests] Completed the AdgEntity property checks Added the missing entries to check all the AdgEntity properties. --- tests/test-entity.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/tests/test-entity.c b/tests/test-entity.c index 9f0c0b97..f8c91750 100644 --- a/tests/test-entity.c +++ b/tests/test-entity.c @@ -62,6 +62,135 @@ _adg_test_parent(void) g_object_unref(valid_container); } +static void +_adg_test_global_map(void) +{ + AdgEntity *entity; + const AdgMatrix *identity_map; + AdgMatrix null_map; + const AdgMatrix *global_map; + + entity = ADG_ENTITY(adg_logo_new()); + identity_map = adg_matrix_identity(); + + /* A null map is a kind of degenerated matrix: it must be + * treated as valid value by the API */ + cairo_matrix_init(&null_map, 0, 0, 0, 0, 0, 0); + + /* Using the public APIs */ + adg_entity_set_global_map(entity, &null_map); + global_map = adg_entity_get_global_map(entity); + g_assert(adg_matrix_equal(global_map, &null_map)); + + adg_entity_set_global_map(entity, NULL); + global_map = adg_entity_get_global_map(entity); + g_assert(adg_matrix_equal(global_map, &null_map)); + + adg_entity_set_global_map(entity, identity_map); + global_map = adg_entity_get_global_map(entity); + g_assert(adg_matrix_equal(global_map, identity_map)); + + /* Using GObject property methods */ + g_object_set(entity, "global-map", &null_map, NULL); + g_object_get(entity, "global-map", &global_map, NULL); + g_assert(adg_matrix_equal(global_map, &null_map)); + + g_object_set(entity, "global-map", NULL, NULL); + g_object_get(entity, "global-map", &global_map, NULL); + g_assert(adg_matrix_equal(global_map, &null_map)); + + g_object_set(entity, "global-map", identity_map, NULL); + g_object_get(entity, "global-map", &global_map, NULL); + g_assert(adg_matrix_equal(global_map, identity_map)); + + g_object_unref(entity); +} + +static void +_adg_test_local_map(void) +{ + AdgEntity *entity; + const AdgMatrix *identity_map; + AdgMatrix null_map; + const AdgMatrix *local_map; + + entity = ADG_ENTITY(adg_logo_new()); + identity_map = adg_matrix_identity(); + + /* A null map is a kind of degenerated matrix: it must be + * treated as valid value by the API */ + cairo_matrix_init(&null_map, 0, 0, 0, 0, 0, 0); + + /* Using the public APIs */ + adg_entity_set_local_map(entity, &null_map); + local_map = adg_entity_get_local_map(entity); + g_assert(adg_matrix_equal(local_map, &null_map)); + + adg_entity_set_local_map(entity, NULL); + local_map = adg_entity_get_local_map(entity); + g_assert(adg_matrix_equal(local_map, &null_map)); + + adg_entity_set_local_map(entity, identity_map); + local_map = adg_entity_get_local_map(entity); + g_assert(adg_matrix_equal(local_map, identity_map)); + + /* Using GObject property methods */ + g_object_set(entity, "local-map", &null_map, NULL); + g_object_get(entity, "local-map", &local_map, NULL); + g_assert(adg_matrix_equal(local_map, &null_map)); + + g_object_set(entity, "local-map", NULL, NULL); + g_object_get(entity, "local-map", &local_map, NULL); + g_assert(adg_matrix_equal(local_map, &null_map)); + + g_object_set(entity, "local-map", identity_map, NULL); + g_object_get(entity, "local-map", &local_map, NULL); + g_assert(adg_matrix_equal(local_map, identity_map)); + + g_object_unref(entity); +} + +static void +_adg_test_local_method(void) +{ + AdgEntity *entity; + AdgMixMethod valid_method1, valid_method2, invalid_method; + AdgMixMethod local_method; + + entity = ADG_ENTITY(adg_logo_new()); + valid_method1 = ADG_MIX_UNDEFINED; + valid_method2 = ADG_MIX_ANCESTORS_NORMALIZED; + invalid_method = G_MAXINT; + + /* Using the public APIs */ + adg_entity_set_local_method(entity, valid_method1); + local_method = adg_entity_get_local_method(entity); + g_assert_cmpint(local_method, ==, valid_method1); + + adg_entity_set_local_method(entity, invalid_method); + local_method = adg_entity_get_local_method(entity); + g_assert_cmpint(local_method, !=, invalid_method); + + adg_entity_set_local_method(entity, valid_method2); + local_method = adg_entity_get_local_method(entity); + g_assert_cmpint(local_method, ==, valid_method2); + + /* Using GObject property methods */ + g_object_set(entity, "local-method", valid_method1, NULL); + g_object_get(entity, "local-method", &local_method, NULL); + g_assert_cmpint(local_method, ==, valid_method1); + + g_object_set(entity, "local-method", invalid_method, NULL); + g_object_get(entity, "local-method", &local_method, NULL); + g_assert_cmpint(local_method, ==, valid_method1); + + g_object_set(entity, "local-method", valid_method2, NULL); + g_object_get(entity, "local-method", &local_method, NULL); + g_assert_cmpint(local_method, ==, valid_method2); + + g_object_unref(entity); +} + int main(int argc, char *argv[]) @@ -69,6 +198,9 @@ main(int argc, char *argv[]) adg_test_init(&argc, &argv); g_test_add_func("/adg/entity/parent", _adg_test_parent); + g_test_add_func("/adg/entity/global-map", _adg_test_global_map); + g_test_add_func("/adg/entity/local-map", _adg_test_local_map); + g_test_add_func("/adg/entity/local-method", _adg_test_local_method); return g_test_run(); } -- 2.11.4.GIT