+++ /dev/null
-#include <glib.h>
-#include <clutter/clutter.h>
-#include <string.h>
-
-#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));
-}
-
/* 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)
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);
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 */
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);
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.
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);
}
static PangoLayout *
-make_layout_like_label (ClutterLabel *label)
+make_layout_like_label (ClutterText *label)
{
PangoLayout *label_layout, *new_layout;
PangoContext *context;
/* 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);
}
void
-test_label_cache (TestConformSimpleFixture *fixture,
- gconstpointer _data)
+test_text_cache (TestConformSimpleFixture *fixture,
+ gconstpointer _data)
{
CallbackData data;
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);