From 06b00f9dfcaa35acf01723fce0e5e224acdadba7 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 11 Dec 2008 12:13:26 +0000 Subject: [PATCH] Remove units for Entry and Label ClutterText should supercede all unit tests for ClutterLabel and ClutterEntry. --- tests/conform/Makefile.am | 5 +- tests/conform/test-clutter-entry.c | 370 ------------------ tests/conform/test-conform-main.c | 16 +- .../{test-label-cache.c => test-text-cache.c} | 42 +- 4 files changed, 24 insertions(+), 409 deletions(-) delete mode 100644 tests/conform/test-clutter-entry.c rename tests/conform/{test-label-cache.c => test-text-cache.c} (84%) diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am index 774156cfc..0586daf4c 100644 --- a/tests/conform/Makefile.am +++ b/tests/conform/Makefile.am @@ -15,15 +15,14 @@ test_conformance_SOURCES = \ test-mesh-mutability.c \ test-path.c \ test-pick.c \ - test-label-cache.c \ - test-clutter-entry.c \ test-clutter-rectangle.c \ test-clutter-fixed.c \ test-actor-invariants.c \ test-paint-opacity.c \ test-backface-culling.c \ test-binding-pool.c \ - test-clutter-text.c + test-clutter-text.c \ + test-text-cache.c # For convenience, this provides a way to easily run individual unit tests: .PHONY: wrappers diff --git a/tests/conform/test-clutter-entry.c b/tests/conform/test-clutter-entry.c deleted file mode 100644 index a12d46b75..000000000 --- a/tests/conform/test-clutter-entry.c +++ /dev/null @@ -1,370 +0,0 @@ -#include -#include -#include - -#include "test-conform-common.h" - -typedef struct { - gunichar unichar; - const char bytes[6]; - gint nbytes; -} TestData; - -static const TestData -test_data[] = { - { 0xe4, "\xc3\xa4", 2 }, /* LATIN SMALL LETTER A WITH DIAERESIS */ - { 0x2665, "\xe2\x99\xa5", 3 } /* BLACK HEART SUIT */ -}; - -void -test_entry_utf8_validation (TestConformSimpleFixture *fixture, - gconstpointer data) -{ - int i; - - for (i = 0; i < G_N_ELEMENTS (test_data); i++) - { - const TestData *t = &test_data[i]; - gunichar unichar; - char bytes[6]; - int nbytes; - - g_assert (g_unichar_validate (t->unichar)); - - nbytes = g_unichar_to_utf8 (t->unichar, bytes); - bytes[nbytes] = '\0'; - g_assert (nbytes == t->nbytes); - g_assert (memcmp (t->bytes, bytes, nbytes) == 0); - - unichar = g_utf8_get_char_validated (bytes, nbytes); - g_assert (unichar == t->unichar); - } -} - -static int -get_nbytes (ClutterEntry *entry) -{ - const char *s = clutter_entry_get_text (entry); - return strlen (s); -} - -static int -get_nchars (ClutterEntry *entry) -{ - const char *s = clutter_entry_get_text (entry); - g_assert (g_utf8_validate (s, -1, NULL)); - return g_utf8_strlen (s, -1); -} - -#define DONT_MOVE_CURSOR (-2) - -static void -insert_unichar (ClutterEntry *entry, gunichar unichar, int position) -{ - if (position > DONT_MOVE_CURSOR) - { - clutter_entry_set_cursor_position (entry, position); - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, position); - } - - clutter_entry_insert_unichar (entry, unichar); -} - -void -test_entry_empty (TestConformSimpleFixture *fixture, - gconstpointer data) -{ - ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ()); - - g_assert (clutter_entry_get_text (entry) == NULL); - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1); - - clutter_actor_destroy (CLUTTER_ACTOR (entry)); -} - -void -test_entry_set_empty (TestConformSimpleFixture *fixture, - gconstpointer data) -{ - ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ()); - - /* annoyingly slightly different from initially empty */ - clutter_entry_set_text (entry, ""); - g_assert_cmpint (get_nchars (entry), ==, 0); - g_assert_cmpint (get_nbytes (entry), ==, 0); - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1); - - clutter_actor_destroy (CLUTTER_ACTOR (entry)); -} - -void -test_entry_set_text (TestConformSimpleFixture *fixture, - gconstpointer data) -{ - ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ()); - - clutter_entry_set_text (entry, "abcdef"); - g_assert_cmpint (get_nchars (entry), ==, 6); - g_assert_cmpint (get_nbytes (entry), ==, 6); - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1); - - clutter_entry_set_cursor_position (entry, 5); - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 5); - - clutter_entry_set_text (entry, ""); - /* FIXME: cursor position should be -1? - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1); - */ - - clutter_actor_destroy (CLUTTER_ACTOR (entry)); -} - -void -test_entry_append_some (TestConformSimpleFixture *fixture, - gconstpointer data) -{ - ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ()); - int i; - - for (i = 0; i < G_N_ELEMENTS (test_data); i++) - { - const TestData *t = &test_data[i]; - int j; - - for (j = 1; j <= 4; j++) - { - insert_unichar (entry, t->unichar, DONT_MOVE_CURSOR); - g_assert_cmpint (get_nchars (entry), ==, j); - g_assert_cmpint (get_nbytes (entry), ==, j * t->nbytes); - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1); - } - - clutter_entry_set_text (entry, ""); - } - - clutter_actor_destroy (CLUTTER_ACTOR (entry)); -} - -void -test_entry_prepend_some (TestConformSimpleFixture *fixture, - gconstpointer data) -{ - ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ()); - int i; - - for (i = 0; i < G_N_ELEMENTS (test_data); i++) - { - const TestData *t = &test_data[i]; - int j; - - clutter_entry_insert_unichar (entry, t->unichar); - g_assert_cmpint (get_nchars (entry), ==, 1); - g_assert_cmpint (get_nbytes (entry), ==, 1 * t->nbytes); - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1); - - for (j = 2; j <= 4; j++) - { - insert_unichar (entry, t->unichar, 0); - g_assert_cmpint (get_nchars (entry), ==, j); - g_assert_cmpint (get_nbytes (entry), ==, j * t->nbytes); - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 1); - } - - clutter_entry_set_text (entry, ""); - } - - clutter_actor_destroy (CLUTTER_ACTOR (entry)); -} - -void -test_entry_insert (TestConformSimpleFixture *fixture, - gconstpointer data) -{ - ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ()); - int i; - - for (i = 0; i < G_N_ELEMENTS (test_data); i++) - { - const TestData *t = &test_data[i]; - - clutter_entry_insert_unichar (entry, t->unichar); - clutter_entry_insert_unichar (entry, t->unichar); - - insert_unichar (entry, t->unichar, 1); - g_assert_cmpint (get_nchars (entry), ==, 3); - g_assert_cmpint (get_nbytes (entry), ==, 3 * t->nbytes); - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 2); - - clutter_entry_set_text (entry, ""); - } - - clutter_actor_destroy (CLUTTER_ACTOR (entry)); -} - -void -test_entry_delete_chars (TestConformSimpleFixture *fixture, - gconstpointer data) -{ - ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ()); - int i; - - for (i = 0; i < G_N_ELEMENTS (test_data); i++) - { - const TestData *t = &test_data[i]; - int j; - - for (j = 0; j < 4; j++) - clutter_entry_insert_unichar (entry, t->unichar); - - clutter_entry_set_cursor_position (entry, 2); - clutter_entry_delete_chars (entry, 1); - g_assert_cmpint (get_nchars (entry), ==, 3); - g_assert_cmpint (get_nbytes (entry), ==, 3 * t->nbytes); - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 1); - - clutter_entry_set_cursor_position (entry, 2); - clutter_entry_delete_chars (entry, 1); - g_assert_cmpint (get_nchars (entry), ==, 2); - g_assert_cmpint (get_nbytes (entry), ==, 2 * t->nbytes); - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 1); - - clutter_entry_set_text (entry, ""); - } - - clutter_actor_destroy (CLUTTER_ACTOR (entry)); -} - -void -test_entry_delete_text (TestConformSimpleFixture *fixture, - gconstpointer data) -{ - ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ()); - int i; - - for (i = 0; i < G_N_ELEMENTS (test_data); i++) - { - const TestData *t = &test_data[i]; - int j; - - for (j = 0; j < 4; j++) - clutter_entry_insert_unichar (entry, t->unichar); - - clutter_entry_set_cursor_position (entry, 3); - clutter_entry_delete_text (entry, 2, 4); - - g_assert_cmpint (get_nchars (entry), ==, 2); - g_assert_cmpint (get_nbytes (entry), ==, 2 * t->nbytes); - - /* FIXME: cursor position should be -1? - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1); - */ - - clutter_entry_set_text (entry, ""); - } - - clutter_actor_destroy (CLUTTER_ACTOR (entry)); -} - -static void -init_event (ClutterKeyEvent *event) -{ - event->type = CLUTTER_KEY_PRESS; - event->time = 0; /* not needed */ - event->flags = CLUTTER_EVENT_FLAG_SYNTHETIC; - event->stage = NULL; /* not needed */ - event->source = NULL; /* not needed */ - event->modifier_state = 0; - event->hardware_keycode = 0; /* not needed */ -} - -static void -send_keyval (ClutterEntry *entry, int keyval) -{ - ClutterKeyEvent event; - - init_event (&event); - event.keyval = keyval; - event.unicode_value = 0; /* should be ignored for cursor keys etc. */ - - clutter_entry_handle_key_event (entry, &event); -} - -static inline void -send_unichar (ClutterEntry *entry, gunichar unichar) -{ - ClutterKeyEvent event; - - init_event (&event); - event.keyval = 0; /* should be ignored for printable characters */ - event.unicode_value = unichar; - - clutter_entry_handle_key_event (entry, &event); -} - -void -test_entry_cursor (TestConformSimpleFixture *fixture, - gconstpointer data) -{ - ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ()); - int i; - - for (i = 0; i < G_N_ELEMENTS (test_data); i++) - { - const TestData *t = &test_data[i]; - int j; - - for (j = 0; j < 4; ++j) - clutter_entry_insert_unichar (entry, t->unichar); - - clutter_entry_set_cursor_position (entry, 2); - - /* test cursor moves and is clamped */ - send_keyval (entry, CLUTTER_Left); - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 1); - - send_keyval (entry, CLUTTER_Left); - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 0); - - send_keyval (entry, CLUTTER_Left); - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 0); - - /* delete text containing the cursor */ - clutter_entry_set_cursor_position (entry, 3); - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 3); - - clutter_entry_delete_text (entry, 2, 4); - send_keyval (entry, CLUTTER_Left); - - /* FIXME: cursor position should be -1? - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1); - */ - - clutter_entry_set_text (entry, ""); - } - - clutter_actor_destroy (CLUTTER_ACTOR (entry)); -} - -void -test_entry_event (TestConformSimpleFixture *fixture, - gconstpointer data) -{ - ClutterEntry *entry = CLUTTER_ENTRY (clutter_entry_new ()); - int i; - - for (i = 0; i < G_N_ELEMENTS (test_data); i++) - { - const TestData *t = &test_data[i]; - - send_unichar (entry, t->unichar); - - g_assert_cmpint (get_nchars (entry), ==, 1); - g_assert_cmpint (get_nbytes (entry), ==, 1 * t->nbytes); - g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1); - - clutter_entry_set_text (entry, ""); - } - - clutter_actor_destroy (CLUTTER_ACTOR (entry)); -} - diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c index d12c4b83a..abf6280b2 100644 --- a/tests/conform/test-conform-main.c +++ b/tests/conform/test-conform-main.c @@ -68,21 +68,6 @@ main (int argc, char **argv) TEST_CONFORM_SIMPLE ("/picking", test_pick); - TEST_CONFORM_SIMPLE ("/label", test_label_cache); - - /* ClutterEntry */ - TEST_CONFORM_SIMPLE ("/entry", test_entry_utf8_validation); - TEST_CONFORM_SIMPLE ("/entry", test_entry_empty); - TEST_CONFORM_SIMPLE ("/entry", test_entry_set_empty); - TEST_CONFORM_SIMPLE ("/entry", test_entry_set_text); - TEST_CONFORM_SIMPLE ("/entry", test_entry_append_some); - TEST_CONFORM_SIMPLE ("/entry", test_entry_prepend_some); - TEST_CONFORM_SIMPLE ("/entry", test_entry_insert); - TEST_CONFORM_SIMPLE ("/entry", test_entry_delete_chars); - TEST_CONFORM_SIMPLE ("/entry", test_entry_delete_text); - TEST_CONFORM_SIMPLE ("/entry", test_entry_cursor); - TEST_CONFORM_SIMPLE ("/entry", test_entry_event); - /* ClutterText */ TEST_CONFORM_SIMPLE ("/text", test_text_utf8_validation); TEST_CONFORM_SIMPLE ("/text", test_text_empty); @@ -96,6 +81,7 @@ main (int argc, char **argv) TEST_CONFORM_SIMPLE ("/text", test_text_cursor); TEST_CONFORM_SIMPLE ("/text", test_text_event); TEST_CONFORM_SIMPLE ("/text", test_text_get_chars); + TEST_CONFORM_SIMPLE ("/text", test_text_cache); TEST_CONFORM_SIMPLE ("/rectangle", test_rect_set_size); TEST_CONFORM_SIMPLE ("/rectangle", test_rect_set_color); diff --git a/tests/conform/test-label-cache.c b/tests/conform/test-text-cache.c similarity index 84% rename from tests/conform/test-label-cache.c rename to tests/conform/test-text-cache.c index e9298f8fd..26687fc00 100644 --- a/tests/conform/test-label-cache.c +++ b/tests/conform/test-text-cache.c @@ -34,7 +34,7 @@ on_paint (ClutterActor *label, CallbackData *data) /* Check whether the layout used for this paint is different from the layout used for the last paint */ - new_layout = clutter_label_get_layout (CLUTTER_LABEL (data->label)); + new_layout = clutter_text_get_layout (CLUTTER_TEXT (data->label)); data->layout_changed = data->old_layout != new_layout; if (data->old_layout) @@ -119,12 +119,12 @@ do_tests (CallbackData *data) PangoAttribute *attr; /* TEST 1: change the text */ - clutter_label_set_text (CLUTTER_LABEL (data->label), "Counter 0"); + clutter_text_set_text (CLUTTER_TEXT (data->label), "Counter 0"); pango_layout_set_text (data->test_layout, "Counter 0", -1); check_result (data, "Change text", TRUE); /* TEST 2: change a single character */ - clutter_label_set_text (CLUTTER_LABEL (data->label), "Counter 1"); + clutter_text_set_text (CLUTTER_TEXT (data->label), "Counter 1"); pango_layout_set_text (data->test_layout, "Counter 1", -1); check_result (data, "Change a single character", TRUE); @@ -133,14 +133,14 @@ do_tests (CallbackData *data) check_result (data, "Move the label", FALSE); /* TEST 4: change the font */ - clutter_label_set_font_name (CLUTTER_LABEL (data->label), "Serif 15"); + clutter_text_set_font_name (CLUTTER_TEXT (data->label), "Serif 15"); fd = pango_font_description_from_string ("Serif 15"); pango_layout_set_font_description (data->test_layout, fd); pango_font_description_free (fd); check_result (data, "Change the font", TRUE); /* TEST 5: change the color */ - clutter_label_set_color (CLUTTER_LABEL (data->label), &red); + clutter_text_set_color (CLUTTER_TEXT (data->label), &red); check_result (data, "Change the color", FALSE); /* TEST 6: change the attributes */ @@ -150,21 +150,21 @@ do_tests (CallbackData *data) attr_list = pango_attr_list_new (); pango_attr_list_insert (attr_list, attr); attr_list_copy = pango_attr_list_copy (attr_list); - clutter_label_set_attributes (CLUTTER_LABEL (data->label), attr_list); + clutter_text_set_attributes (CLUTTER_TEXT (data->label), attr_list); pango_layout_set_attributes (data->test_layout, attr_list_copy); pango_attr_list_unref (attr_list_copy); pango_attr_list_unref (attr_list); check_result (data, "Change the attributes", TRUE); /* TEST 7: change the text again */ - clutter_label_set_attributes (CLUTTER_LABEL (data->label), NULL); - clutter_label_set_text (CLUTTER_LABEL (data->label), long_text); + clutter_text_set_attributes (CLUTTER_TEXT (data->label), NULL); + clutter_text_set_text (CLUTTER_TEXT (data->label), long_text); pango_layout_set_attributes (data->test_layout, NULL); pango_layout_set_text (data->test_layout, long_text, -1); check_result (data, "Change the text again", TRUE); /* TEST 8: enable markup */ - clutter_label_set_use_markup (CLUTTER_LABEL (data->label), TRUE); + clutter_text_set_use_markup (CLUTTER_TEXT (data->label), TRUE); pango_layout_set_markup (data->test_layout, long_text, -1); check_result (data, "Enable markup", TRUE); @@ -178,28 +178,28 @@ do_tests (CallbackData *data) force_redraw (data); /* TEST 9: enable ellipsize */ - clutter_label_set_ellipsize (CLUTTER_LABEL (data->label), + clutter_text_set_ellipsize (CLUTTER_TEXT (data->label), PANGO_ELLIPSIZE_END); pango_layout_set_ellipsize (data->test_layout, PANGO_ELLIPSIZE_END); check_result (data, "Enable ellipsize", TRUE); - clutter_label_set_ellipsize (CLUTTER_LABEL (data->label), + clutter_text_set_ellipsize (CLUTTER_TEXT (data->label), PANGO_ELLIPSIZE_NONE); pango_layout_set_ellipsize (data->test_layout, PANGO_ELLIPSIZE_NONE); force_redraw (data); /* TEST 10: enable line wrap */ - clutter_label_set_line_wrap (CLUTTER_LABEL (data->label), TRUE); + clutter_text_set_line_wrap (CLUTTER_TEXT (data->label), TRUE); pango_layout_set_wrap (data->test_layout, PANGO_WRAP_WORD); check_result (data, "Enable line wrap", TRUE); /* TEST 11: change wrap mode */ - clutter_label_set_line_wrap_mode (CLUTTER_LABEL (data->label), + clutter_text_set_line_wrap_mode (CLUTTER_TEXT (data->label), PANGO_WRAP_CHAR); pango_layout_set_wrap (data->test_layout, PANGO_WRAP_CHAR); check_result (data, "Change wrap mode", TRUE); /* TEST 12: enable justify */ - clutter_label_set_justify (CLUTTER_LABEL (data->label), TRUE); + clutter_text_set_justify (CLUTTER_TEXT (data->label), TRUE); pango_layout_set_justify (data->test_layout, TRUE); /* Pango appears to have a bug which means that you can't change the justification after setting the text but this fixes it. @@ -208,7 +208,7 @@ do_tests (CallbackData *data) check_result (data, "Enable justify", TRUE); /* TEST 13: change alignment */ - clutter_label_set_alignment (CLUTTER_LABEL (data->label), PANGO_ALIGN_RIGHT); + clutter_text_set_alignment (CLUTTER_TEXT (data->label), PANGO_ALIGN_RIGHT); pango_layout_set_alignment (data->test_layout, PANGO_ALIGN_RIGHT); check_result (data, "Change alignment", TRUE); @@ -218,7 +218,7 @@ do_tests (CallbackData *data) } static PangoLayout * -make_layout_like_label (ClutterLabel *label) +make_layout_like_label (ClutterText *label) { PangoLayout *label_layout, *new_layout; PangoContext *context; @@ -226,7 +226,7 @@ make_layout_like_label (ClutterLabel *label) /* Make another layout using the same context as the layout from the label */ - label_layout = clutter_label_get_layout (label); + label_layout = clutter_text_get_layout (label); context = pango_layout_get_context (label_layout); new_layout = pango_layout_new (context); fd = pango_font_description_from_string (TEST_FONT); @@ -237,8 +237,8 @@ make_layout_like_label (ClutterLabel *label) } void -test_label_cache (TestConformSimpleFixture *fixture, - gconstpointer _data) +test_text_cache (TestConformSimpleFixture *fixture, + gconstpointer _data) { CallbackData data; @@ -246,9 +246,9 @@ test_label_cache (TestConformSimpleFixture *fixture, data.stage = clutter_stage_get_default (); - data.label = clutter_label_new_with_text (TEST_FONT, ""); + data.label = clutter_text_new_with_text (TEST_FONT, ""); - data.test_layout = make_layout_like_label (CLUTTER_LABEL (data.label)); + data.test_layout = make_layout_like_label (CLUTTER_TEXT (data.label)); g_signal_connect (data.label, "paint", G_CALLBACK (on_paint), &data);