2008-12-11 11:45:37 +00:00
|
|
|
#include <glib.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
gunichar unichar;
|
|
|
|
const char bytes[6];
|
|
|
|
gint nbytes;
|
|
|
|
} TestData;
|
|
|
|
|
|
|
|
static const TestData
|
2008-12-11 11:51:28 +00:00
|
|
|
test_text_data[] = {
|
2008-12-11 11:45:37 +00:00
|
|
|
{ 0xe4, "\xc3\xa4", 2 }, /* LATIN SMALL LETTER A WITH DIAERESIS */
|
|
|
|
{ 0x2665, "\xe2\x99\xa5", 3 } /* BLACK HEART SUIT */
|
|
|
|
};
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
2010-10-12 16:31:15 +00:00
|
|
|
text_utf8_validation (void)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2008-12-11 11:51:28 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
2008-12-11 11:51:28 +00:00
|
|
|
const TestData *t = &test_text_data[i];
|
2008-12-11 11:45:37 +00:00
|
|
|
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';
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpint (nbytes, ==, t->nbytes);
|
2008-12-11 11:45:37 +00:00
|
|
|
g_assert (memcmp (t->bytes, bytes, nbytes) == 0);
|
|
|
|
|
|
|
|
unichar = g_utf8_get_char_validated (bytes, nbytes);
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpint (unichar, ==, t->unichar);
|
2008-12-11 11:45:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_nbytes (ClutterText *text)
|
|
|
|
{
|
|
|
|
const char *s = clutter_text_get_text (text);
|
|
|
|
return strlen (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_nchars (ClutterText *text)
|
|
|
|
{
|
|
|
|
const char *s = clutter_text_get_text (text);
|
|
|
|
g_assert (g_utf8_validate (s, -1, NULL));
|
|
|
|
return g_utf8_strlen (s, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DONT_MOVE_CURSOR (-2)
|
|
|
|
|
|
|
|
static void
|
|
|
|
insert_unichar (ClutterText *text, gunichar unichar, int position)
|
|
|
|
{
|
|
|
|
if (position > DONT_MOVE_CURSOR)
|
|
|
|
{
|
|
|
|
clutter_text_set_cursor_position (text, position);
|
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, position);
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_text_insert_unichar (text, unichar);
|
|
|
|
}
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
2010-10-12 16:31:15 +00:00
|
|
|
text_set_empty (void)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
|
|
|
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
2013-12-12 15:05:16 +00:00
|
|
|
g_object_ref_sink (text);
|
2008-12-11 11:45:37 +00:00
|
|
|
|
2008-12-22 13:29:10 +00:00
|
|
|
g_assert_cmpstr (clutter_text_get_text (text), ==, "");
|
|
|
|
g_assert_cmpint (*clutter_text_get_text (text), ==, '\0');
|
2008-12-11 11:45:37 +00:00
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
|
|
|
|
|
|
|
clutter_text_set_text (text, "");
|
|
|
|
g_assert_cmpint (get_nchars (text), ==, 0);
|
|
|
|
g_assert_cmpint (get_nbytes (text), ==, 0);
|
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
|
|
|
|
|
|
|
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
|
|
|
}
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
2010-10-12 16:31:15 +00:00
|
|
|
text_set_text (void)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
|
|
|
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
2013-12-12 15:05:16 +00:00
|
|
|
g_object_ref_sink (text);
|
2008-12-11 11:45:37 +00:00
|
|
|
|
|
|
|
clutter_text_set_text (text, "abcdef");
|
|
|
|
g_assert_cmpint (get_nchars (text), ==, 6);
|
|
|
|
g_assert_cmpint (get_nbytes (text), ==, 6);
|
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
|
|
|
|
|
|
|
clutter_text_set_cursor_position (text, 5);
|
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 5);
|
|
|
|
|
|
|
|
/* FIXME: cursor position should be -1?
|
2008-12-11 11:51:28 +00:00
|
|
|
clutter_text_set_text (text, "");
|
2008-12-11 11:45:37 +00:00
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
|
|
|
*/
|
|
|
|
|
|
|
|
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
|
|
|
}
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
2010-10-12 16:31:15 +00:00
|
|
|
text_append_some (void)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
|
|
|
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
|
|
|
int i;
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
g_object_ref_sink (text);
|
|
|
|
|
2008-12-11 11:51:28 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
2008-12-11 11:51:28 +00:00
|
|
|
const TestData *t = &test_text_data[i];
|
2008-12-11 11:45:37 +00:00
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 1; j <= 4; j++)
|
|
|
|
{
|
|
|
|
insert_unichar (text, t->unichar, DONT_MOVE_CURSOR);
|
2008-12-11 11:51:28 +00:00
|
|
|
|
2008-12-11 11:45:37 +00:00
|
|
|
g_assert_cmpint (get_nchars (text), ==, j);
|
|
|
|
g_assert_cmpint (get_nbytes (text), ==, j * t->nbytes);
|
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_text_set_text (text, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
|
|
|
}
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
2010-10-12 16:31:15 +00:00
|
|
|
text_prepend_some (void)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
|
|
|
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
|
|
|
int i;
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
g_object_ref_sink (text);
|
|
|
|
|
2008-12-11 11:51:28 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
2008-12-11 11:51:28 +00:00
|
|
|
const TestData *t = &test_text_data[i];
|
2008-12-11 11:45:37 +00:00
|
|
|
int j;
|
|
|
|
|
|
|
|
clutter_text_insert_unichar (text, t->unichar);
|
2008-12-11 11:56:44 +00:00
|
|
|
|
2008-12-11 11:45:37 +00:00
|
|
|
g_assert_cmpint (get_nchars (text), ==, 1);
|
|
|
|
g_assert_cmpint (get_nbytes (text), ==, 1 * t->nbytes);
|
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
|
|
|
|
|
|
|
for (j = 2; j <= 4; j++)
|
|
|
|
{
|
|
|
|
insert_unichar (text, t->unichar, 0);
|
2008-12-11 11:56:44 +00:00
|
|
|
|
2008-12-11 11:45:37 +00:00
|
|
|
g_assert_cmpint (get_nchars (text), ==, j);
|
|
|
|
g_assert_cmpint (get_nbytes (text), ==, j * t->nbytes);
|
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_text_set_text (text, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
|
|
|
}
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
2010-10-12 16:31:15 +00:00
|
|
|
text_insert (void)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
|
|
|
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
|
|
|
int i;
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
g_object_ref_sink (text);
|
|
|
|
|
2008-12-11 11:51:28 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
2008-12-11 11:51:28 +00:00
|
|
|
const TestData *t = &test_text_data[i];
|
2008-12-11 11:45:37 +00:00
|
|
|
|
|
|
|
clutter_text_insert_unichar (text, t->unichar);
|
|
|
|
clutter_text_insert_unichar (text, t->unichar);
|
|
|
|
|
|
|
|
insert_unichar (text, t->unichar, 1);
|
2008-12-11 11:51:28 +00:00
|
|
|
|
2008-12-11 11:45:37 +00:00
|
|
|
g_assert_cmpint (get_nchars (text), ==, 3);
|
|
|
|
g_assert_cmpint (get_nbytes (text), ==, 3 * t->nbytes);
|
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 2);
|
|
|
|
|
|
|
|
clutter_text_set_text (text, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
|
|
|
}
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
2010-10-12 16:31:15 +00:00
|
|
|
text_delete_chars (void)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
|
|
|
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
|
|
|
int i;
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
g_object_ref_sink (text);
|
|
|
|
|
2008-12-11 11:51:28 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
2008-12-11 11:51:28 +00:00
|
|
|
const TestData *t = &test_text_data[i];
|
2008-12-11 11:45:37 +00:00
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
clutter_text_insert_unichar (text, t->unichar);
|
|
|
|
|
2014-01-24 18:49:00 +00:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("text: %s\n", clutter_text_get_text (text));
|
|
|
|
|
2008-12-11 11:45:37 +00:00
|
|
|
clutter_text_set_cursor_position (text, 2);
|
|
|
|
clutter_text_delete_chars (text, 1);
|
2014-01-24 18:49:00 +00:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("text: %s (cursor at: %d)\n",
|
|
|
|
clutter_text_get_text (text),
|
|
|
|
clutter_text_get_cursor_position (text));
|
2008-12-11 11:45:37 +00:00
|
|
|
g_assert_cmpint (get_nchars (text), ==, 3);
|
|
|
|
g_assert_cmpint (get_nbytes (text), ==, 3 * t->nbytes);
|
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 1);
|
|
|
|
|
|
|
|
clutter_text_set_cursor_position (text, 2);
|
|
|
|
clutter_text_delete_chars (text, 1);
|
2014-01-24 18:49:00 +00:00
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("text: %s (cursor at: %d)\n",
|
|
|
|
clutter_text_get_text (text),
|
|
|
|
clutter_text_get_cursor_position (text));
|
2008-12-11 11:45:37 +00:00
|
|
|
g_assert_cmpint (get_nchars (text), ==, 2);
|
|
|
|
g_assert_cmpint (get_nbytes (text), ==, 2 * t->nbytes);
|
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 1);
|
|
|
|
|
|
|
|
clutter_text_set_text (text, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
|
|
|
}
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
2010-10-12 16:31:15 +00:00
|
|
|
text_get_chars (void)
|
2008-12-11 11:59:50 +00:00
|
|
|
{
|
|
|
|
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
|
|
|
gchar *chars;
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
g_object_ref_sink (text);
|
|
|
|
|
2008-12-11 11:59:50 +00:00
|
|
|
clutter_text_set_text (text, "00abcdef11");
|
|
|
|
g_assert_cmpint (get_nchars (text), ==, 10);
|
|
|
|
g_assert_cmpint (get_nbytes (text), ==, 10);
|
|
|
|
g_assert_cmpstr (clutter_text_get_text (text), ==, "00abcdef11");
|
|
|
|
|
|
|
|
chars = clutter_text_get_chars (text, 2, -1);
|
|
|
|
g_assert_cmpstr (chars, ==, "abcdef11");
|
|
|
|
g_free (chars);
|
|
|
|
|
|
|
|
chars = clutter_text_get_chars (text, 0, 8);
|
|
|
|
g_assert_cmpstr (chars, ==, "00abcdef");
|
|
|
|
g_free (chars);
|
|
|
|
|
|
|
|
chars = clutter_text_get_chars (text, 2, 8);
|
|
|
|
g_assert_cmpstr (chars, ==, "abcdef");
|
|
|
|
g_free (chars);
|
|
|
|
|
|
|
|
chars = clutter_text_get_chars (text, 8, 12);
|
|
|
|
g_assert_cmpstr (chars, ==, "11");
|
|
|
|
g_free (chars);
|
|
|
|
|
|
|
|
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
|
|
|
}
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
2010-10-12 16:31:15 +00:00
|
|
|
text_delete_text (void)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
|
|
|
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
|
|
|
int i;
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
g_object_ref_sink (text);
|
|
|
|
|
2008-12-11 11:51:28 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
2008-12-11 11:51:28 +00:00
|
|
|
const TestData *t = &test_text_data[i];
|
2008-12-11 11:45:37 +00:00
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
clutter_text_insert_unichar (text, t->unichar);
|
|
|
|
|
|
|
|
clutter_text_set_cursor_position (text, 3);
|
|
|
|
clutter_text_delete_text (text, 2, 4);
|
|
|
|
|
|
|
|
g_assert_cmpint (get_nchars (text), ==, 2);
|
|
|
|
g_assert_cmpint (get_nbytes (text), ==, 2 * t->nbytes);
|
|
|
|
|
|
|
|
/* FIXME: cursor position should be -1?
|
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
|
|
|
*/
|
|
|
|
|
|
|
|
clutter_text_set_text (text, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
|
|
|
}
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
2010-10-12 16:31:15 +00:00
|
|
|
text_password_char (void)
|
2009-01-06 15:30:31 +00:00
|
|
|
{
|
|
|
|
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
g_object_ref_sink (text);
|
|
|
|
|
2009-01-06 15:30:31 +00:00
|
|
|
g_assert_cmpint (clutter_text_get_password_char (text), ==, 0);
|
|
|
|
|
|
|
|
clutter_text_set_text (text, "hello");
|
|
|
|
g_assert_cmpstr (clutter_text_get_text (text), ==, "hello");
|
|
|
|
|
|
|
|
clutter_text_set_password_char (text, '*');
|
|
|
|
g_assert_cmpint (clutter_text_get_password_char (text), ==, '*');
|
|
|
|
|
|
|
|
g_assert_cmpstr (clutter_text_get_text (text), ==, "hello");
|
|
|
|
|
|
|
|
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
|
|
|
}
|
|
|
|
|
2011-02-22 17:12:34 +00:00
|
|
|
static ClutterEvent *
|
|
|
|
init_event (void)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
2011-02-22 17:12:34 +00:00
|
|
|
ClutterEvent *retval = clutter_event_new (CLUTTER_KEY_PRESS);
|
|
|
|
|
|
|
|
clutter_event_set_time (retval, CLUTTER_CURRENT_TIME);
|
|
|
|
clutter_event_set_flags (retval, CLUTTER_EVENT_FLAG_SYNTHETIC);
|
|
|
|
|
|
|
|
return retval;
|
2008-12-11 11:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_keyval (ClutterText *text, int keyval)
|
|
|
|
{
|
2011-02-22 17:12:34 +00:00
|
|
|
ClutterEvent *event = init_event ();
|
2008-12-11 11:45:37 +00:00
|
|
|
|
2011-02-22 17:12:34 +00:00
|
|
|
/* Unicode should be ignored for cursor keys etc. */
|
|
|
|
clutter_event_set_key_unicode (event, 0);
|
|
|
|
clutter_event_set_key_symbol (event, keyval);
|
2008-12-11 11:45:37 +00:00
|
|
|
|
2011-02-22 17:12:34 +00:00
|
|
|
clutter_actor_event (CLUTTER_ACTOR (text), event, FALSE);
|
|
|
|
|
|
|
|
clutter_event_free (event);
|
2008-12-11 11:45:37 +00:00
|
|
|
}
|
|
|
|
|
2008-12-11 11:51:28 +00:00
|
|
|
static void
|
2008-12-11 11:45:37 +00:00
|
|
|
send_unichar (ClutterText *text, gunichar unichar)
|
|
|
|
{
|
2011-02-22 17:12:34 +00:00
|
|
|
ClutterEvent *event = init_event ();
|
|
|
|
|
|
|
|
/* Key symbol should be ignored for printable characters */
|
|
|
|
clutter_event_set_key_symbol (event, 0);
|
|
|
|
clutter_event_set_key_unicode (event, unichar);
|
2008-12-11 11:45:37 +00:00
|
|
|
|
2011-02-22 17:12:34 +00:00
|
|
|
clutter_actor_event (CLUTTER_ACTOR (text), event, FALSE);
|
2008-12-11 11:45:37 +00:00
|
|
|
|
2011-02-22 17:12:34 +00:00
|
|
|
clutter_event_free (event);
|
2008-12-11 11:45:37 +00:00
|
|
|
}
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
2010-10-12 16:31:15 +00:00
|
|
|
text_cursor (void)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
|
|
|
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
|
|
|
int i;
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
g_object_ref_sink (text);
|
|
|
|
|
2008-12-11 11:56:44 +00:00
|
|
|
/* only editable entries listen to events */
|
2008-12-11 11:51:28 +00:00
|
|
|
clutter_text_set_editable (text, TRUE);
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
2008-12-11 11:51:28 +00:00
|
|
|
const TestData *t = &test_text_data[i];
|
2008-12-11 11:45:37 +00:00
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < 4; ++j)
|
|
|
|
clutter_text_insert_unichar (text, t->unichar);
|
|
|
|
|
|
|
|
clutter_text_set_cursor_position (text, 2);
|
|
|
|
|
|
|
|
/* test cursor moves and is clamped */
|
2010-09-10 12:41:49 +00:00
|
|
|
send_keyval (text, CLUTTER_KEY_Left);
|
2008-12-11 11:45:37 +00:00
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 1);
|
|
|
|
|
2010-09-10 12:41:49 +00:00
|
|
|
send_keyval (text, CLUTTER_KEY_Left);
|
2008-12-11 11:45:37 +00:00
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 0);
|
|
|
|
|
2010-09-10 12:41:49 +00:00
|
|
|
send_keyval (text, CLUTTER_KEY_Left);
|
2008-12-11 11:45:37 +00:00
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 0);
|
|
|
|
|
|
|
|
/* delete text containing the cursor */
|
|
|
|
clutter_text_set_cursor_position (text, 3);
|
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, 3);
|
|
|
|
|
|
|
|
clutter_text_delete_text (text, 2, 4);
|
2010-09-10 12:41:49 +00:00
|
|
|
send_keyval (text, CLUTTER_KEY_Left);
|
2008-12-11 11:45:37 +00:00
|
|
|
|
|
|
|
/* FIXME: cursor position should be -1?
|
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
|
|
|
*/
|
|
|
|
|
|
|
|
clutter_text_set_text (text, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
|
|
|
}
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
2010-10-12 16:31:15 +00:00
|
|
|
text_event (void)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
|
|
|
ClutterText *text = CLUTTER_TEXT (clutter_text_new ());
|
|
|
|
int i;
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
g_object_ref_sink (text);
|
|
|
|
|
2008-12-11 11:56:44 +00:00
|
|
|
/* only editable entries listen to events */
|
2008-12-11 11:51:28 +00:00
|
|
|
clutter_text_set_editable (text, TRUE);
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (test_text_data); i++)
|
2008-12-11 11:45:37 +00:00
|
|
|
{
|
2008-12-11 11:51:28 +00:00
|
|
|
const TestData *t = &test_text_data[i];
|
2008-12-11 11:45:37 +00:00
|
|
|
|
|
|
|
send_unichar (text, t->unichar);
|
|
|
|
|
|
|
|
g_assert_cmpint (get_nchars (text), ==, 1);
|
|
|
|
g_assert_cmpint (get_nbytes (text), ==, 1 * t->nbytes);
|
|
|
|
g_assert_cmpint (clutter_text_get_cursor_position (text), ==, -1);
|
|
|
|
|
|
|
|
clutter_text_set_text (text, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
|
|
|
}
|
|
|
|
|
text: Make :use-markup set idempotent
Setting :use-markup and :text is currently not idempotent, and it
depends on the ordering, e.g.:
g_object_set (actor, "use-markup", TRUE, "text", value, NULL);
does not yield the same results as:
g_object_set (actor, "text", value, "use-markup", TRUE, NULL);
This is particularly jarring when using ClutterText from ClutterScript,
but in general GObject properties should not rely on the order when used
from g_object_set().
The fix is to store the contents of the ClutterText as a separate string
from the displayed text, and use the contents, instead of the displayed
text, when toggling the :use-markup property.
Let's also add a unit test for good measure, to try and catch
regressions.
https://bugzilla.gnome.org/show_bug.cgi?id=651940
2011-09-06 11:45:41 +00:00
|
|
|
static inline void
|
|
|
|
validate_markup_attributes (ClutterText *text,
|
|
|
|
PangoAttrType attr_type,
|
|
|
|
int start_index,
|
|
|
|
int end_index)
|
|
|
|
{
|
|
|
|
PangoLayout *layout;
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
PangoAttrIterator *iter;
|
|
|
|
|
|
|
|
layout = clutter_text_get_layout (text);
|
|
|
|
g_assert (layout != NULL);
|
|
|
|
|
|
|
|
attrs = pango_layout_get_attributes (layout);
|
|
|
|
g_assert (attrs != NULL);
|
|
|
|
|
|
|
|
iter = pango_attr_list_get_iterator (attrs);
|
|
|
|
while (pango_attr_iterator_next (iter))
|
|
|
|
{
|
|
|
|
GSList *attributes = pango_attr_iterator_get_attrs (iter);
|
|
|
|
PangoAttribute *a;
|
|
|
|
|
|
|
|
if (attributes == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
g_assert (attributes->data != NULL);
|
|
|
|
|
|
|
|
a = attributes->data;
|
|
|
|
|
|
|
|
g_assert (a->klass->type == attr_type);
|
|
|
|
g_assert_cmpint (a->start_index, ==, start_index);
|
|
|
|
g_assert_cmpint (a->end_index, ==, end_index);
|
|
|
|
|
|
|
|
g_slist_free_full (attributes, (GDestroyNotify) pango_attribute_destroy);
|
|
|
|
}
|
|
|
|
|
|
|
|
pango_attr_iterator_destroy (iter);
|
|
|
|
}
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
2012-02-27 12:54:23 +00:00
|
|
|
text_idempotent_use_markup (void)
|
text: Make :use-markup set idempotent
Setting :use-markup and :text is currently not idempotent, and it
depends on the ordering, e.g.:
g_object_set (actor, "use-markup", TRUE, "text", value, NULL);
does not yield the same results as:
g_object_set (actor, "text", value, "use-markup", TRUE, NULL);
This is particularly jarring when using ClutterText from ClutterScript,
but in general GObject properties should not rely on the order when used
from g_object_set().
The fix is to store the contents of the ClutterText as a separate string
from the displayed text, and use the contents, instead of the displayed
text, when toggling the :use-markup property.
Let's also add a unit test for good measure, to try and catch
regressions.
https://bugzilla.gnome.org/show_bug.cgi?id=651940
2011-09-06 11:45:41 +00:00
|
|
|
{
|
|
|
|
ClutterText *text;
|
|
|
|
const char *contents = "foo <b>bar</b>";
|
|
|
|
const char *display = "foo bar";
|
|
|
|
int bar_start_index = strstr (display, "bar") - display;
|
|
|
|
int bar_end_index = bar_start_index + strlen ("bar");
|
|
|
|
|
|
|
|
/* case 1: text -> use_markup */
|
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("text: '%s' -> use-markup: TRUE\n", contents);
|
|
|
|
|
|
|
|
text = g_object_new (CLUTTER_TYPE_TEXT,
|
|
|
|
"text", contents, "use-markup", TRUE,
|
|
|
|
NULL);
|
2013-12-12 15:05:16 +00:00
|
|
|
g_object_ref_sink (text);
|
text: Make :use-markup set idempotent
Setting :use-markup and :text is currently not idempotent, and it
depends on the ordering, e.g.:
g_object_set (actor, "use-markup", TRUE, "text", value, NULL);
does not yield the same results as:
g_object_set (actor, "text", value, "use-markup", TRUE, NULL);
This is particularly jarring when using ClutterText from ClutterScript,
but in general GObject properties should not rely on the order when used
from g_object_set().
The fix is to store the contents of the ClutterText as a separate string
from the displayed text, and use the contents, instead of the displayed
text, when toggling the :use-markup property.
Let's also add a unit test for good measure, to try and catch
regressions.
https://bugzilla.gnome.org/show_bug.cgi?id=651940
2011-09-06 11:45:41 +00:00
|
|
|
|
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("Contents: '%s' (expected: '%s')\n",
|
|
|
|
clutter_text_get_text (text),
|
|
|
|
display);
|
|
|
|
|
|
|
|
g_assert_cmpstr (clutter_text_get_text (text), ==, display);
|
|
|
|
|
|
|
|
validate_markup_attributes (text,
|
|
|
|
PANGO_ATTR_WEIGHT,
|
|
|
|
bar_start_index,
|
|
|
|
bar_end_index);
|
|
|
|
|
|
|
|
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
|
|
|
|
|
|
|
/* case 2: use_markup -> text */
|
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("use-markup: TRUE -> text: '%s'\n", contents);
|
|
|
|
|
|
|
|
text = g_object_new (CLUTTER_TYPE_TEXT,
|
|
|
|
"use-markup", TRUE, "text", contents,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("Contents: '%s' (expected: '%s')\n",
|
|
|
|
clutter_text_get_text (text),
|
|
|
|
display);
|
|
|
|
|
|
|
|
g_assert_cmpstr (clutter_text_get_text (text), ==, display);
|
|
|
|
|
|
|
|
validate_markup_attributes (text,
|
|
|
|
PANGO_ATTR_WEIGHT,
|
|
|
|
bar_start_index,
|
|
|
|
bar_end_index);
|
|
|
|
|
|
|
|
clutter_actor_destroy (CLUTTER_ACTOR (text));
|
|
|
|
}
|
2013-12-12 15:05:16 +00:00
|
|
|
|
|
|
|
CLUTTER_TEST_SUITE (
|
|
|
|
CLUTTER_TEST_UNIT ("/text/utf8-validation", text_utf8_validation)
|
|
|
|
CLUTTER_TEST_UNIT ("/text/set-empty", text_set_empty)
|
|
|
|
CLUTTER_TEST_UNIT ("/text/set-text", text_set_text)
|
|
|
|
CLUTTER_TEST_UNIT ("/text/append-some", text_append_some)
|
|
|
|
CLUTTER_TEST_UNIT ("/text/prepend-some", text_prepend_some)
|
|
|
|
CLUTTER_TEST_UNIT ("/text/insert", text_insert)
|
|
|
|
CLUTTER_TEST_UNIT ("/text/delete-chars", text_delete_chars)
|
|
|
|
CLUTTER_TEST_UNIT ("/text/get-chars", text_get_chars)
|
|
|
|
CLUTTER_TEST_UNIT ("/text/delete-text", text_delete_text)
|
|
|
|
CLUTTER_TEST_UNIT ("/text/password-char", text_password_char)
|
|
|
|
CLUTTER_TEST_UNIT ("/text/cursor", text_cursor)
|
|
|
|
CLUTTER_TEST_UNIT ("/text/event", text_event)
|
|
|
|
CLUTTER_TEST_UNIT ("/text/idempotent-use-markup", text_idempotent_use_markup)
|
|
|
|
)
|