mirror of
https://github.com/brl/mutter.git
synced 2024-11-23 00:20:42 -05:00
2008-11-08 Emmanuele Bassi <ebassi@linux.intel.com>
* tests/conform/Makefile.am: * tests/conform/test-actor-invariants.c: * tests/conform/test-conform-main.c: Move the actor invariants unit to the conform section of the test suite. * tests/interactive/Makefile.am: * tests/interactive/test-entry-auto.c: * tests/interactive/test-invariants.c: Remove the entry-auto and invariants test, since those two belong to the conform section.
This commit is contained in:
parent
603f936745
commit
d4573ba10c
13
ChangeLog
13
ChangeLog
@ -1,3 +1,16 @@
|
||||
2008-11-08 Emmanuele Bassi <ebassi@linux.intel.com>
|
||||
|
||||
* tests/conform/Makefile.am:
|
||||
* tests/conform/test-actor-invariants.c:
|
||||
* tests/conform/test-conform-main.c: Move the actor invariants
|
||||
unit to the conform section of the test suite.
|
||||
|
||||
* tests/interactive/Makefile.am:
|
||||
* tests/interactive/test-entry-auto.c:
|
||||
* tests/interactive/test-invariants.c: Remove the entry-auto
|
||||
and invariants test, since those two belong to the conform
|
||||
section.
|
||||
|
||||
2008-11-07 Robert Bragg <robert@linux.intel.com>
|
||||
|
||||
Bug 1162 - Re-works the tests/ to use the glib-2.16 unit testing
|
||||
|
@ -14,7 +14,8 @@ test_conformance_SOURCES = \
|
||||
test-label-cache.c \
|
||||
test-clutter-entry.c \
|
||||
test-clutter-rectangle.c \
|
||||
test-clutter-fixed.c
|
||||
test-clutter-fixed.c \
|
||||
test-actor-invariants.c
|
||||
|
||||
# For convenience, this provides a way to easily run individual unit tests:
|
||||
.PHONY: wrappers
|
||||
|
@ -1,87 +1,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <gmodule.h>
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
/* dummy unit testing API; to be replaced by GTest in 1.0 */
|
||||
typedef void (* test_func) (void);
|
||||
#include "test-conform-common.h"
|
||||
|
||||
typedef struct _TestUnit TestUnit;
|
||||
|
||||
struct _TestUnit
|
||||
{
|
||||
gchar *name;
|
||||
test_func func;
|
||||
};
|
||||
|
||||
static GSList *units = NULL;
|
||||
|
||||
static void
|
||||
test_init (gint *argc,
|
||||
gchar ***argv)
|
||||
{
|
||||
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL);
|
||||
|
||||
g_assert (clutter_init (argc, argv) == CLUTTER_INIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void
|
||||
test_add_func (const gchar *name,
|
||||
test_func func)
|
||||
{
|
||||
TestUnit *unit;
|
||||
|
||||
unit = g_slice_new (TestUnit);
|
||||
unit->name = g_strdup (name);
|
||||
unit->func = func;
|
||||
|
||||
units = g_slist_prepend (units, unit);
|
||||
}
|
||||
|
||||
static int
|
||||
test_run (void)
|
||||
{
|
||||
GSList *l;
|
||||
|
||||
units = g_slist_reverse (units);
|
||||
|
||||
for (l = units; l != NULL; l = l->next)
|
||||
{
|
||||
TestUnit *u = l->data;
|
||||
GString *test_name = g_string_sized_new (75);
|
||||
gsize len, i;
|
||||
|
||||
g_string_append (test_name, "Testing: ");
|
||||
g_string_append (test_name, u->name);
|
||||
len = 75 - test_name->len;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
g_string_append_c (test_name, '.');
|
||||
|
||||
g_print ("%s", test_name->str);
|
||||
|
||||
u->func ();
|
||||
|
||||
g_print ("OK\n");
|
||||
}
|
||||
|
||||
for (l = units; l != NULL; l = l->next)
|
||||
{
|
||||
TestUnit *u = l->data;
|
||||
|
||||
g_free (u->name);
|
||||
g_slice_free (TestUnit, u);
|
||||
}
|
||||
|
||||
g_slist_free (units);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/* test units */
|
||||
static void
|
||||
test_initial_state (void)
|
||||
void
|
||||
test_initial_state (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterActor *actor;
|
||||
|
||||
@ -94,8 +20,9 @@ test_initial_state (void)
|
||||
clutter_actor_destroy (actor);
|
||||
}
|
||||
|
||||
static void
|
||||
test_realized (void)
|
||||
void
|
||||
test_realized (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterActor *actor;
|
||||
|
||||
@ -113,9 +40,9 @@ test_realized (void)
|
||||
clutter_actor_destroy (actor);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_mapped (void)
|
||||
void
|
||||
test_mapped (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterActor *actor;
|
||||
|
||||
@ -134,8 +61,9 @@ test_mapped (void)
|
||||
clutter_actor_destroy (actor);
|
||||
}
|
||||
|
||||
static void
|
||||
test_show_on_set_parent (void)
|
||||
void
|
||||
test_show_on_set_parent (TestConformSimpleFixture *fixture,
|
||||
gconstpointer data)
|
||||
{
|
||||
ClutterActor *actor, *group;
|
||||
gboolean show_on_set_parent;
|
||||
@ -173,16 +101,3 @@ test_show_on_set_parent (void)
|
||||
clutter_actor_destroy (actor);
|
||||
clutter_actor_destroy (group);
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT int
|
||||
test_invariants_main (int argc, char *argv[])
|
||||
{
|
||||
test_init (&argc, &argv);
|
||||
|
||||
test_add_func ("/invariants/initial-state", test_initial_state);
|
||||
test_add_func ("/invariants/realized", test_realized);
|
||||
test_add_func ("/invariants/mapped", test_mapped);
|
||||
test_add_func ("/invariants/show-on-set-parent", test_show_on_set_parent);
|
||||
|
||||
return test_run ();
|
||||
}
|
@ -75,6 +75,11 @@ main (int argc, char **argv)
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/fixed", test_fixed_constants);
|
||||
|
||||
TEST_CONFORM_SIMPLE ("/invariants", test_initial_state);
|
||||
TEST_CONFORM_SIMPLE ("/invatiants", test_realized);
|
||||
TEST_CONFORM_SIMPLE ("/invariants", test_mapped);
|
||||
TEST_CONFORM_SIMPLE ("/invariants", test_show_on_set_parent);
|
||||
|
||||
g_test_run ();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -35,9 +35,7 @@ UNIT_TESTS = \
|
||||
test-clip.c \
|
||||
test-paint-wrapper.c \
|
||||
test-texture-quality.c \
|
||||
test-entry-auto.c \
|
||||
test-layout.c \
|
||||
test-invariants.c
|
||||
test-layout.c
|
||||
|
||||
#FIXME - this is is a bit of a yukky way of ensuring the tests find our data:
|
||||
test-script.json:
|
||||
@ -52,6 +50,7 @@ wrappers: test-interactive
|
||||
do \
|
||||
ln -sf $(top_srcdir)/tests/interactive/wrapper.sh $${i%*.c}; \
|
||||
done
|
||||
|
||||
# NB: BUILT_SOURCES here a misnomer. We aren't building source, just inserting
|
||||
# a phony rule that will generate symlink scripts for running individual tests
|
||||
BUILT_SOURCES = wrappers redhand.png test-script.json
|
||||
|
@ -1,301 +0,0 @@
|
||||
#include <gmodule.h>
|
||||
#include <clutter/clutter.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef g_assert_cmpint
|
||||
# define g_assert_cmpint(x,y,z) g_assert((x) y (z))
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
gunichar unichar;
|
||||
const char bytes[6];
|
||||
gint nbytes;
|
||||
} TestData;
|
||||
|
||||
const TestData
|
||||
test_data[] = {
|
||||
{ 0xe4, "\xc3\xa4", 2 }, /* LATIN SMALL LETTER A WITH DIAERESIS */
|
||||
{ 0x2665, "\xe2\x99\xa5", 3 } /* BLACK HEART SUIT */
|
||||
};
|
||||
|
||||
static void
|
||||
selfcheck (const TestData *t)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
static void
|
||||
test_empty (ClutterEntry *entry, const TestData *unused)
|
||||
{
|
||||
g_assert (clutter_entry_get_text (entry) == NULL);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
}
|
||||
|
||||
static void
|
||||
test_set_empty (ClutterEntry *entry, const TestData *unused)
|
||||
{
|
||||
/* 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);
|
||||
}
|
||||
|
||||
static void
|
||||
test_set_text (ClutterEntry *entry, const TestData *unused)
|
||||
{
|
||||
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);
|
||||
*/
|
||||
}
|
||||
|
||||
static void
|
||||
test_insert (ClutterEntry *entry, const TestData *t)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
static void
|
||||
test_append_some (ClutterEntry *entry, const TestData *t)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 1; i <= 4; i++)
|
||||
{
|
||||
insert_unichar (entry, t->unichar, DONT_MOVE_CURSOR);
|
||||
g_assert_cmpint (get_nchars (entry), ==, i);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, i * t->nbytes);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, -1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_prepend_some (ClutterEntry *entry, const TestData *t)
|
||||
{
|
||||
int i;
|
||||
|
||||
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 (i = 2; i <= 4; i++)
|
||||
{
|
||||
insert_unichar (entry, t->unichar, 0);
|
||||
g_assert_cmpint (get_nchars (entry), ==, i);
|
||||
g_assert_cmpint (get_nbytes (entry), ==, i * t->nbytes);
|
||||
g_assert_cmpint (clutter_entry_get_cursor_position (entry), ==, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_delete_chars (ClutterEntry *entry, const TestData *t)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
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);
|
||||
}
|
||||
|
||||
static void
|
||||
test_delete_text (ClutterEntry *entry, const TestData *t)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
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);
|
||||
*/
|
||||
}
|
||||
|
||||
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 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);
|
||||
}
|
||||
|
||||
static void
|
||||
test_cursor (ClutterEntry *entry, const TestData *t)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 4; ++i)
|
||||
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);
|
||||
*/
|
||||
}
|
||||
|
||||
static void
|
||||
test_event (ClutterEntry *entry, const TestData *t)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
static void
|
||||
run (void (*test_func)(ClutterEntry *, const TestData *), const TestData *t)
|
||||
{
|
||||
ClutterActor *entry;
|
||||
|
||||
entry = clutter_entry_new ();
|
||||
test_func (CLUTTER_ENTRY (entry), t);
|
||||
clutter_actor_destroy (entry);
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT int
|
||||
test_entry_auto_main (int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); ++i)
|
||||
selfcheck (&test_data[i]);
|
||||
|
||||
clutter_init (&argc, &argv);
|
||||
|
||||
run (test_empty, NULL);
|
||||
run (test_set_empty, NULL);
|
||||
run (test_set_text, NULL);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (test_data); ++i)
|
||||
{
|
||||
const TestData *t = &test_data[i];
|
||||
|
||||
run (test_append_some, t);
|
||||
run (test_prepend_some, t);
|
||||
run (test_insert, t);
|
||||
run (test_delete_chars, t);
|
||||
run (test_delete_text, t);
|
||||
run (test_cursor, t);
|
||||
run (test_event, t);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user