From 750345e8d9e65e3c954dda853e3f52418dbaee1c Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Wed, 28 Jan 2015 18:27:11 +0100 Subject: [PATCH] tests: rendering checks on local/global space changes Checking the extents when the local or global space changes. --- src/adg/tests/test-adim.c | 9 ++++ src/adg/tests/test-alignment.c | 9 ++++ src/adg/tests/test-container.c | 8 +++ src/adg/tests/test-hatch.c | 11 ++++ src/adg/tests/test-ldim.c | 7 +++ src/adg/tests/test-logo.c | 3 ++ src/adg/tests/test-projection.c | 5 ++ src/adg/tests/test-rdim.c | 7 +++ src/adg/tests/test-stroke.c | 11 ++++ src/adg/tests/test-text.c | 2 + src/adg/tests/test-title-block.c | 2 + src/adg/tests/test-toy-text.c | 2 + src/tests/adg-test.c | 110 +++++++++++++++++++++++++++++++++++++++ src/tests/adg-test.h | 4 ++ 14 files changed, 190 insertions(+) diff --git a/src/adg/tests/test-adim.c b/src/adg/tests/test-adim.c index 3deb106f..69786af1 100644 --- a/src/adg/tests/test-adim.c +++ b/src/adg/tests/test-adim.c @@ -267,6 +267,15 @@ main(int argc, char *argv[]) adg_test_add_object_checks("/adg/adim/type/object", ADG_TYPE_ADIM); adg_test_add_entity_checks("/adg/adim/type/entity", ADG_TYPE_ADIM); + adg_test_add_global_space_checks("/adg/adim/behavior/global-space", + adg_adim_new_full_explicit(1, 2, 3, 4, + 9, 6, 7, 8, + 9, 10)); + adg_test_add_local_space_checks("/adg/adim/behavior/local-space", + adg_adim_new_full_explicit(4, 3, 2, 1, + 8, 7, 6, 9, + 10, 9)); + adg_test_add_func("/adg/adim/property/org1", _adg_test_org1); adg_test_add_func("/adg/adim/property/org2", _adg_test_org2); adg_test_add_func("/adg/adim/property/has-extension1", _adg_test_has_extension1); diff --git a/src/adg/tests/test-alignment.c b/src/adg/tests/test-alignment.c index 5b4d0e8a..7c3c6c7d 100644 --- a/src/adg/tests/test-alignment.c +++ b/src/adg/tests/test-alignment.c @@ -76,11 +76,20 @@ _adg_alignment_factor(void) int main(int argc, char *argv[]) { + AdgAlignment *alignment; + adg_test_init(&argc, &argv); adg_test_add_object_checks("/adg/alignment/type/object", ADG_TYPE_ALIGNMENT); adg_test_add_entity_checks("/adg/alignment/type/entity", ADG_TYPE_ALIGNMENT); + alignment = adg_alignment_new_explicit(0.5, 0.5); + adg_container_add(ADG_CONTAINER(alignment), ADG_ENTITY(adg_logo_new())); + adg_test_add_global_space_checks("/adg/alignment/behavior/global-space", alignment); + alignment = adg_alignment_new_explicit(0.5, 0.5); + adg_container_add(ADG_CONTAINER(alignment), ADG_ENTITY(adg_logo_new())); + adg_test_add_local_space_checks("/adg/alignment/behavior/local-space", alignment); + adg_test_add_func("/adg/alignment/property/factor", _adg_alignment_factor); return g_test_run(); diff --git a/src/adg/tests/test-container.c b/src/adg/tests/test-container.c index b1e9ea86..2f8cd81b 100644 --- a/src/adg/tests/test-container.c +++ b/src/adg/tests/test-container.c @@ -127,11 +127,19 @@ _adg_misc(void) int main(int argc, char *argv[]) { + AdgContainer *container; adg_test_init(&argc, &argv); adg_test_add_object_checks("/adg/container/type/object", ADG_TYPE_CONTAINER); adg_test_add_entity_checks("/adg/container/type/entity", ADG_TYPE_CONTAINER); + container = adg_container_new(); + adg_container_add(container, ADG_ENTITY(adg_logo_new())); + adg_test_add_global_space_checks("/adg/container/behavior/global-space", container); + container = adg_container_new(); + adg_container_add(container, ADG_ENTITY(adg_logo_new())); + adg_test_add_local_space_checks("/adg/container/behavior/local-space", container); + adg_test_add_func("/adg/container/property/child", _adg_property_child); adg_test_add_func("/adg/container/misc", _adg_misc); diff --git a/src/adg/tests/test-hatch.c b/src/adg/tests/test-hatch.c index 5ca9f979..dab98934 100644 --- a/src/adg/tests/test-hatch.c +++ b/src/adg/tests/test-hatch.c @@ -67,11 +67,22 @@ _adg_test_fill_dress(void) int main(int argc, char *argv[]) { + AdgPath *path; + adg_test_init(&argc, &argv); adg_test_add_object_checks("/adg/hatch/type/object", ADG_TYPE_HATCH); adg_test_add_entity_checks("/adg/hatch/type/entity", ADG_TYPE_HATCH); + path = adg_path_new(); + adg_path_move_to_explicit(path, 1, 2); + adg_path_line_to_explicit(path, 4, 5); + adg_path_line_to_explicit(path, 7, 8); + adg_path_close(path); + adg_test_add_global_space_checks("/adg/hatch/behavior/global-space", adg_hatch_new(ADG_TRAIL(path))); + adg_test_add_local_space_checks("/adg/hatch/behavior/local-space", adg_hatch_new(ADG_TRAIL(path))); + g_object_unref(path); + adg_test_add_func("/adg/hatch/property/fill-dress", _adg_test_fill_dress); return g_test_run(); diff --git a/src/adg/tests/test-ldim.c b/src/adg/tests/test-ldim.c index 9926d4b7..ee366fb0 100644 --- a/src/adg/tests/test-ldim.c +++ b/src/adg/tests/test-ldim.c @@ -168,6 +168,13 @@ main(int argc, char *argv[]) adg_test_add_object_checks("/adg/ldim/type/object", ADG_TYPE_LDIM); adg_test_add_entity_checks("/adg/ldim/type/entity", ADG_TYPE_LDIM); + adg_test_add_global_space_checks("/adg/ldim/behavior/global-space", + adg_ldim_new_full_explicit(1, 5, 2, 4, + 9, 7, 3)); + adg_test_add_local_space_checks("/adg/ldim/behavior/local-space", + adg_ldim_new_full_explicit(1, 5, 2, 4, + 9, 7, 3)); + adg_test_add_func("/adg/ldim/property/direction", _adg_test_direction); adg_test_add_func("/adg/ldim/property/has-extension1", _adg_test_has_extension1); adg_test_add_func("/adg/ldim/property/has-extension2", _adg_test_has_extension2); diff --git a/src/adg/tests/test-logo.c b/src/adg/tests/test-logo.c index 34aa467c..afe147c5 100644 --- a/src/adg/tests/test-logo.c +++ b/src/adg/tests/test-logo.c @@ -154,6 +154,9 @@ main(int argc, char *argv[]) adg_test_add_object_checks("/adg/logo/type/object", ADG_TYPE_LOGO); adg_test_add_entity_checks("/adg/logo/type/entity", ADG_TYPE_LOGO); + adg_test_add_global_space_checks("/adg/logo/behavior/global-space", adg_logo_new()); + adg_test_add_local_space_checks("/adg/logo/behavior/local-space", adg_logo_new()); + adg_test_add_func("/adg/logo/property/frame-dress", _adg_test_frame_dress); adg_test_add_func("/adg/logo/property/screen-dress", _adg_test_screen_dress); adg_test_add_func("/adg/logo/property/symbol-dress", _adg_test_symbol_dress); diff --git a/src/adg/tests/test-projection.c b/src/adg/tests/test-projection.c index 0ad6213a..edcecd10 100644 --- a/src/adg/tests/test-projection.c +++ b/src/adg/tests/test-projection.c @@ -154,6 +154,11 @@ main(int argc, char *argv[]) adg_test_add_object_checks("/adg/projection/type/object", ADG_TYPE_PROJECTION); adg_test_add_entity_checks("/adg/projection/type/entity", ADG_TYPE_PROJECTION); + adg_test_add_global_space_checks("/adg/projection/behavior/global-space", + adg_projection_new(ADG_PROJECTION_SCHEME_FIRST_ANGLE)); + adg_test_add_local_space_checks("/adg/projection/behavior/local-space", + adg_projection_new(ADG_PROJECTION_SCHEME_THIRD_ANGLE)); + adg_test_add_func("/adg/projection/property/axis-dress", _adg_test_axis_dress); adg_test_add_func("/adg/projection/property/scheme", _adg_test_scheme); adg_test_add_func("/adg/projection/property/symbol-dress", _adg_test_symbol_dress); diff --git a/src/adg/tests/test-rdim.c b/src/adg/tests/test-rdim.c index d97c4241..a56b1156 100644 --- a/src/adg/tests/test-rdim.c +++ b/src/adg/tests/test-rdim.c @@ -44,6 +44,13 @@ main(int argc, char *argv[]) adg_test_add_object_checks("/adg/rdim/type/object", ADG_TYPE_RDIM); adg_test_add_entity_checks("/adg/rdim/type/entity", ADG_TYPE_RDIM); + adg_test_add_global_space_checks("/adg/rdim/behavior/global-space", + adg_rdim_new_full_explicit(1, 5, 2, 4, 9, 7)); + /* Radial dimension does not enlarge on local space changes + * adg_test_add_local_space_checks("/adg/rdim/behavior/local-space", + * adg_rdim_new_full_explicit(1, 5, 2, 4, 9, 7)); + */ + adg_test_add_func("/adg/rdim/property/value", _adg_test_value); return g_test_run(); diff --git a/src/adg/tests/test-stroke.c b/src/adg/tests/test-stroke.c index 30b2da59..8584aa33 100644 --- a/src/adg/tests/test-stroke.c +++ b/src/adg/tests/test-stroke.c @@ -119,11 +119,22 @@ _adg_test_trail(void) int main(int argc, char *argv[]) { + AdgPath *path; + adg_test_init(&argc, &argv); adg_test_add_object_checks("/adg/stroke/type/object", ADG_TYPE_STROKE); adg_test_add_entity_checks("/adg/stroke/type/entity", ADG_TYPE_STROKE); + path = adg_path_new(); + adg_path_move_to_explicit(path, 1, 2); + adg_path_line_to_explicit(path, 4, 5); + adg_path_line_to_explicit(path, 7, 8); + adg_path_close(path); + adg_test_add_global_space_checks("/adg/stroke/behavior/global-space", adg_stroke_new(ADG_TRAIL(path))); + adg_test_add_local_space_checks("/adg/stroke/behavior/local-space", adg_stroke_new(ADG_TRAIL(path))); + g_object_unref(path); + adg_test_add_func("/adg/stroke/property/line-dress", _adg_test_line_dress); adg_test_add_func("/adg/stroke/property/trail", _adg_test_trail); diff --git a/src/adg/tests/test-text.c b/src/adg/tests/test-text.c index eaf14768..a00d19b2 100644 --- a/src/adg/tests/test-text.c +++ b/src/adg/tests/test-text.c @@ -146,6 +146,8 @@ main(int argc, char *argv[]) adg_test_add_object_checks("/adg/text/type/object", ADG_TYPE_TEXT); adg_test_add_entity_checks("/adg/text/type/entity", ADG_TYPE_TEXT); + adg_test_add_global_space_checks("/adg/text/behavior/global-space", adg_text_new("Testing")); + adg_test_add_func("/adg/text/property/local-mix", _adg_test_local_mix); adg_test_add_func("/adg/text/property/font-dress", _adg_test_font_dress); adg_test_add_func("/adg/text/property/string", _adg_test_text); diff --git a/src/adg/tests/test-title-block.c b/src/adg/tests/test-title-block.c index 571bb7a0..9f652032 100644 --- a/src/adg/tests/test-title-block.c +++ b/src/adg/tests/test-title-block.c @@ -417,6 +417,8 @@ main(int argc, char *argv[]) adg_test_add_object_checks("/adg/title-block/type/object", ADG_TYPE_TITLE_BLOCK); adg_test_add_entity_checks("/adg/title-block/type/entity", ADG_TYPE_TITLE_BLOCK); + adg_test_add_global_space_checks("/adg/title-block/behavior/global-space", adg_title_block_new()); + adg_test_add_func("/adg/title-block/property/local-mix", _adg_test_local_mix); adg_test_add_func("/adg/title-block/property/author", _adg_test_author); adg_test_add_func("/adg/title-block/property/date", _adg_test_date); diff --git a/src/adg/tests/test-toy-text.c b/src/adg/tests/test-toy-text.c index cd16f5fe..d1c95129 100644 --- a/src/adg/tests/test-toy-text.c +++ b/src/adg/tests/test-toy-text.c @@ -146,6 +146,8 @@ main(int argc, char *argv[]) adg_test_add_object_checks("/adg/toy-text/type/object", ADG_TYPE_TOY_TEXT); adg_test_add_entity_checks("/adg/toy-text/type/entity", ADG_TYPE_TOY_TEXT); + adg_test_add_global_space_checks("/adg/toy-text/behavior/global-space", adg_toy_text_new("Testing")); + adg_test_add_func("/adg/toy-text/property/local-mix", _adg_test_local_mix); adg_test_add_func("/adg/toy-text/property/font-dress", _adg_test_font_dress); adg_test_add_func("/adg/toy-text/property/text", _adg_test_text); diff --git a/src/tests/adg-test.c b/src/tests/adg-test.c index 857da212..30a2f6ad 100644 --- a/src/tests/adg-test.c +++ b/src/tests/adg-test.c @@ -238,3 +238,113 @@ adg_test_add_entity_checks(const gchar *testpath, GType type) G_CALLBACK(_adg_entity_checks), GINT_TO_POINTER(type)); } + +static cairo_t * +_adg_cairo_context(void) +{ + cairo_surface_t *surface; + cairo_t *cr; + + surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 800, 600); + cr = cairo_create(surface); + cairo_surface_destroy(surface); + + return cr; +} + +static void +_adg_global_space_checks(AdgEntity *entity) +{ + cairo_t *cr; + const CpmlExtents *extents; + cairo_matrix_t scale2X; + gdouble width, height; + + cr = _adg_cairo_context(); + cairo_matrix_init_scale(&scale2X, 2, 2); + + /* Store the original extents size in width/height */ + adg_entity_render(entity, cr); + extents = adg_entity_get_extents(entity); + g_assert_true(extents->is_defined); + width = extents->size.x; + height = extents->size.y; + + /* Check that a zoom in global space scales is roughly equivalent to + * the same zoom on extents too (not excactly because of fonts) */ + adg_entity_transform_global_map(entity, &scale2X, ADG_TRANSFORM_BEFORE); + adg_entity_invalidate(entity); + g_assert_false(extents->is_defined); + adg_entity_render(entity, cr); + extents = adg_entity_get_extents(entity); + g_assert_cmpfloat(extents->size.x, >, width * 1.7); + g_assert_cmpfloat(extents->size.x, <, width * 2.3); + g_assert_cmpfloat(extents->size.y, >, height * 1.7); + g_assert_cmpfloat(extents->size.y, <, height * 2.3); + + /* Restore the original global scale */ + cairo_matrix_invert(&scale2X); + adg_entity_transform_global_map(entity, &scale2X, ADG_TRANSFORM_BEFORE); + adg_entity_invalidate(entity); + g_assert_false(extents->is_defined); + adg_entity_render(entity, cr); + extents = adg_entity_get_extents(entity); + g_assert_cmpfloat(extents->size.x, ==, width); + g_assert_cmpfloat(extents->size.y, ==, height); + + cairo_destroy(cr); + g_object_unref(entity); +} + +void +adg_test_add_global_space_checks(const gchar *testpath, gpointer entity) +{ + adg_test_add_func_full(testpath, G_CALLBACK(_adg_global_space_checks), entity); +} + +static void +_adg_local_space_checks(AdgEntity *entity) +{ + cairo_t *cr; + const CpmlExtents *extents; + cairo_matrix_t scale2X; + gdouble width, height; + + cr = _adg_cairo_context(); + cairo_matrix_init_scale(&scale2X, 2, 2); + + /* Store the original extents size in width/height */ + adg_entity_render(entity, cr); + extents = adg_entity_get_extents(entity); + g_assert_true(extents->is_defined); + width = extents->size.x; + height = extents->size.y; + + /* Check that a scale in local space somewhat scales the extents too */ + adg_entity_transform_local_map(entity, &scale2X, ADG_TRANSFORM_BEFORE); + adg_entity_invalidate(entity); + g_assert_false(extents->is_defined); + adg_entity_render(entity, cr); + extents = adg_entity_get_extents(entity); + g_assert_cmpfloat(extents->size.x, >, width); + g_assert_cmpfloat(extents->size.y, >, height); + + /* Restore the original local scale */ + cairo_matrix_invert(&scale2X); + adg_entity_transform_local_map(entity, &scale2X, ADG_TRANSFORM_BEFORE); + adg_entity_invalidate(entity); + g_assert_false(extents->is_defined); + adg_entity_render(entity, cr); + extents = adg_entity_get_extents(entity); + g_assert_cmpfloat(extents->size.x, ==, width); + g_assert_cmpfloat(extents->size.y, ==, height); + + cairo_destroy(cr); + g_object_unref(entity); +} + +void +adg_test_add_local_space_checks(const gchar *testpath, gpointer entity) +{ + adg_test_add_func_full(testpath, G_CALLBACK(_adg_local_space_checks), entity); +} diff --git a/src/tests/adg-test.h b/src/tests/adg-test.h index 650327c8..1489fc0d 100644 --- a/src/tests/adg-test.h +++ b/src/tests/adg-test.h @@ -73,6 +73,10 @@ void adg_test_add_object_checks (const gchar *testpath, GType type); void adg_test_add_entity_checks (const gchar *testpath, GType type); +void adg_test_add_global_space_checks(const gchar *testpath, + gpointer entity); +void adg_test_add_local_space_checks (const gchar *testpath, + gpointer entity); G_END_DECLS -- 2.11.4.GIT