From 603f9367459a4ca8ca7f5d5ebb937fe96dba5df6 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Fri, 7 Nov 2008 19:32:28 +0000 Subject: [PATCH] Bug 1162 - Re-works the tests/ to use the glib-2.16 unit testing framework * configure.ac: * tests/*: The tests have been reorganised into different categories: conformance, interactive and micro benchmarks. - conformance tests can be run as part of automated tests - interactive tests are basically all the existing tests - micro benchmarks focus on a single performance metric I converted the timeline tests to conformance tests and also added some tests from Neil Roberts and Ebassi. Note: currently only the conformance tests use the glib test APIs, though the micro benchmarks should too. The other change is to make the unit tests link into monolithic binaries which makes the build time for unit tests considerably faster. To deal with the extra complexity this adds to debugging individual tests I have added some sugar to the makefiles so all the tests can be run directly via a symlink and when an individual test is run this way, then a note is printed to the terminal explaining exactly how that test may be debugged using GDB. There is a convenience make rule: 'make test-report', that will run all the conformance tests and hopefully even open the results in your web browser. It skips some of the slower timeline tests, but you can run those using 'make full-report' --- ChangeLog | 32 ++ Makefile.am | 4 + configure.ac | 9 +- tests/Makefile.am | 85 +--- tests/README | 12 + tests/conform/ADDING_NEW_TESTS | 31 ++ tests/conform/Makefile.am | 52 +++ tests/conform/test-clutter-entry.c | 370 ++++++++++++++++++ tests/conform/test-clutter-fixed.c | 18 + tests/conform/test-clutter-rectangle.c | 56 +++ tests/conform/test-conform-common.c | 29 ++ tests/conform/test-conform-common.h | 25 ++ tests/conform/test-conform-main.c | 81 ++++ tests/{ => conform}/test-label-cache.c | 15 +- tests/conform/test-pick.c | 106 +++++ .../{ => conform}/test-timeline-dup-frames.c | 68 ++-- .../{ => conform}/test-timeline-interpolate.c | 110 +++--- tests/{ => conform}/test-timeline-rewind.c | 36 +- .../{ => conform}/test-timeline-smoothness.c | 86 ++-- tests/conform/test-timeline.c | 140 +++++++ tests/conform/wrapper.sh | 15 + tests/data/Makefile.am | 5 + tests/{ => data}/redhand.png | Bin tests/{ => data}/test-script.json | 0 tests/interactive/Makefile.am | 69 ++++ tests/{ => interactive}/test-actors.c | 5 +- tests/{ => interactive}/test-behave.c | 5 +- tests/{ => interactive}/test-clip.c | 5 +- tests/{ => interactive}/test-cogl-offscreen.c | 9 +- .../{ => interactive}/test-cogl-primitives.c | 9 +- .../{ => interactive}/test-cogl-tex-convert.c | 9 +- .../{ => interactive}/test-cogl-tex-foreign.c | 9 +- .../{ => interactive}/test-cogl-tex-getset.c | 9 +- .../{ => interactive}/test-cogl-tex-polygon.c | 9 +- tests/{ => interactive}/test-cogl-tex-tile.c | 9 +- tests/{ => interactive}/test-depth.c | 5 +- tests/{ => interactive}/test-devices.c | 5 +- tests/{ => interactive}/test-effects.c | 5 +- tests/{ => interactive}/test-entry-auto.c | 6 +- tests/{ => interactive}/test-entry.c | 5 +- tests/{ => interactive}/test-events.c | 5 +- tests/{ => interactive}/test-fbo.c | 6 +- tests/{ => interactive}/test-fullscreen.c | 5 +- tests/{ => interactive}/test-grab.c | 5 +- tests/{ => interactive}/test-invariants.c | 6 +- tests/{ => interactive}/test-layout.c | 6 +- tests/interactive/test-main.c | 37 ++ tests/{ => interactive}/test-model.c | 5 +- tests/{ => interactive}/test-multistage.c | 5 +- tests/{ => interactive}/test-offscreen.c | 5 +- tests/{ => interactive}/test-opacity.c | 5 +- tests/{ => interactive}/test-paint-wrapper.c | 5 +- tests/{ => interactive}/test-perspective.c | 5 +- tests/{ => interactive}/test-pixmap.c | 5 +- tests/{ => interactive}/test-project.c | 7 +- tests/{ => interactive}/test-random-text.c | 5 +- tests/{ => interactive}/test-rotate.c | 5 +- tests/{ => interactive}/test-scale.c | 5 +- tests/{ => interactive}/test-score.c | 5 +- tests/{ => interactive}/test-script.c | 5 +- tests/{ => interactive}/test-shader.c | 6 +- .../test-stage-read-pixels.c | 5 +- .../{ => interactive}/test-texture-quality.c | 5 +- tests/{ => interactive}/test-textures.c | 5 +- tests/{ => interactive}/test-threads.c | 5 +- tests/{ => interactive}/test-unproject.c | 7 +- tests/{ => interactive}/test-viewport.c | 5 +- tests/interactive/wrapper.sh | 13 + tests/micro-bench/Makefile.am | 10 + tests/{ => micro-bench}/test-text.c | 0 tests/test-pick.c | 99 ----- tests/test-timeline.c | 293 -------------- tests/tools/Makefile.am | 2 + tests/tools/README | 2 + 74 files changed, 1434 insertions(+), 718 deletions(-) create mode 100644 tests/README create mode 100644 tests/conform/ADDING_NEW_TESTS create mode 100644 tests/conform/Makefile.am create mode 100644 tests/conform/test-clutter-entry.c create mode 100644 tests/conform/test-clutter-fixed.c create mode 100644 tests/conform/test-clutter-rectangle.c create mode 100644 tests/conform/test-conform-common.c create mode 100644 tests/conform/test-conform-common.h create mode 100644 tests/conform/test-conform-main.c rename tests/{ => conform}/test-label-cache.c (97%) create mode 100644 tests/conform/test-pick.c rename tests/{ => conform}/test-timeline-dup-frames.c (55%) rename tests/{ => conform}/test-timeline-interpolate.c (62%) rename tests/{ => conform}/test-timeline-rewind.c (64%) rename tests/{ => conform}/test-timeline-smoothness.c (53%) create mode 100644 tests/conform/test-timeline.c create mode 100755 tests/conform/wrapper.sh create mode 100644 tests/data/Makefile.am rename tests/{ => data}/redhand.png (100%) rename tests/{ => data}/test-script.json (100%) create mode 100644 tests/interactive/Makefile.am rename tests/{ => interactive}/test-actors.c (98%) rename tests/{ => interactive}/test-behave.c (98%) rename tests/{ => interactive}/test-clip.c (97%) rename tests/{ => interactive}/test-cogl-offscreen.c (96%) rename tests/{ => interactive}/test-cogl-primitives.c (97%) rename tests/{ => interactive}/test-cogl-tex-convert.c (96%) rename tests/{ => interactive}/test-cogl-tex-foreign.c (96%) rename tests/{ => interactive}/test-cogl-tex-getset.c (97%) rename tests/{ => interactive}/test-cogl-tex-polygon.c (98%) rename tests/{ => interactive}/test-cogl-tex-tile.c (97%) rename tests/{ => interactive}/test-depth.c (98%) rename tests/{ => interactive}/test-devices.c (96%) rename tests/{ => interactive}/test-effects.c (97%) rename tests/{ => interactive}/test-entry-auto.c (98%) rename tests/{ => interactive}/test-entry.c (94%) rename tests/{ => interactive}/test-events.c (99%) rename tests/{ => interactive}/test-fbo.c (98%) rename tests/{ => interactive}/test-fullscreen.c (96%) rename tests/{ => interactive}/test-grab.c (98%) rename tests/{ => interactive}/test-invariants.c (97%) rename tests/{ => interactive}/test-layout.c (99%) create mode 100644 tests/interactive/test-main.c rename tests/{ => interactive}/test-model.c (98%) rename tests/{ => interactive}/test-multistage.c (97%) rename tests/{ => interactive}/test-offscreen.c (88%) rename tests/{ => interactive}/test-opacity.c (97%) rename tests/{ => interactive}/test-paint-wrapper.c (98%) rename tests/{ => interactive}/test-perspective.c (94%) rename tests/{ => interactive}/test-pixmap.c (98%) rename tests/{ => interactive}/test-project.c (98%) rename tests/{ => interactive}/test-random-text.c (95%) rename tests/{ => interactive}/test-rotate.c (96%) rename tests/{ => interactive}/test-scale.c (96%) rename tests/{ => interactive}/test-score.c (97%) rename tests/{ => interactive}/test-script.c (98%) rename tests/{ => interactive}/test-shader.c (99%) rename tests/{ => interactive}/test-stage-read-pixels.c (97%) rename tests/{ => interactive}/test-texture-quality.c (97%) rename tests/{ => interactive}/test-textures.c (96%) rename tests/{ => interactive}/test-threads.c (98%) rename tests/{ => interactive}/test-unproject.c (97%) rename tests/{ => interactive}/test-viewport.c (95%) create mode 100755 tests/interactive/wrapper.sh create mode 100644 tests/micro-bench/Makefile.am rename tests/{ => micro-bench}/test-text.c (100%) delete mode 100644 tests/test-pick.c delete mode 100644 tests/test-timeline.c create mode 100644 tests/tools/Makefile.am create mode 100644 tests/tools/README diff --git a/ChangeLog b/ChangeLog index 68303f544..f5bdf54de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,35 @@ +2008-11-07 Robert Bragg + + Bug 1162 - Re-works the tests/ to use the glib-2.16 unit testing + framework + + * configure.ac: + * tests/*: + The tests have been reorganised into different categories: conformance, + interactive and micro benchmarks. + - conformance tests can be run as part of automated tests + - interactive tests are basically all the existing tests + - micro benchmarks focus on a single performance metric + + I converted the timeline tests to conformance tests and also added some + tests from Neil Roberts and Ebassi. + + Note: currently only the conformance tests use the glib test APIs, + though the micro benchmarks should too. + + The other change is to make the unit tests link into monolithic binaries + which makes the build time for unit tests considerably faster. To deal + with the extra complexity this adds to debugging individual tests I + have added some sugar to the makefiles so all the tests can be run + directly via a symlink and when an individual test is run this way, + then a note is printed to the terminal explaining exactly how that test + may be debugged using GDB. + + There is a convenience make rule: 'make test-report', that will run all + the conformance tests and hopefully even open the results in your web + browser. It skips some of the slower timeline tests, but you can run + those using 'make full-report' + 2008-11-07 Emmanuele Bassi * clutter/clutter-media.c: Improve documentation of the diff --git a/Makefile.am b/Makefile.am index fb6b7fa5b..6f3663053 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,6 +21,10 @@ clutter-$(CLUTTER_API_VERSION).pc: clutter.pc clutter-$(CLUTTER_FLAVOUR)-$(CLUTTER_API_VERSION).pc: clutter.pc @cp $< $@ +.PHONY: test-report full-report +test-report full-report: + $(MAKE) -C tests/conform $(@) + pkgconfig_DATA = $(pcfiles) pkgconfigdir = $(libdir)/pkgconfig diff --git a/configure.ac b/configure.ac index 368c9a219..9ac8920ea 100644 --- a/configure.ac +++ b/configure.ac @@ -56,7 +56,7 @@ AC_SUBST(CLUTTER_LT_LDFLAGS) dnl ======================================================================== # Checks for programs. -AC_PROG_CC +AM_PROG_CC_C_O #_AM_DEPENDENCIES([OBJC]) #AC_PROG_OBJC AC_DISABLE_STATIC @@ -520,7 +520,7 @@ fi AC_SUBST(JSON_PREFIX) AM_CONDITIONAL(LOCAL_JSON_GLIB, test "x$have_json" = "xno") -CLUTTER_REQUIRES="pangocairo >= 1.18 gobject-2.0 >= 2.14 gthread-2.0 gmodule-no-export-2.0 $BACKEND_PC_FILES $JSON_GLIB_PC" +CLUTTER_REQUIRES="pangocairo >= 1.18 gobject-2.0 >= 2.16 gthread-2.0 gmodule-no-export-2.0 $BACKEND_PC_FILES $JSON_GLIB_PC" if test "x$imagebackend" = "xgdk-pixbuf"; then CLUTTER_REQUIRES="$CLUTTER_REQUIRES gdk-pixbuf-2.0" @@ -663,6 +663,11 @@ AC_CONFIG_FILES([ clutter/json/Makefile clutter/pango/Makefile tests/Makefile + tests/conform/Makefile + tests/data/Makefile + tests/interactive/Makefile + tests/micro-bench/Makefile + tests/tools/Makefile doc/Makefile doc/reference/Makefile doc/reference/clutter/Makefile diff --git a/tests/Makefile.am b/tests/Makefile.am index 23b7baa69..cdebda58f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,78 +1,15 @@ -noinst_PROGRAMS = test-textures test-events test-offscreen test-scale \ - test-actors test-behave test-text test-entry test-project \ - test-perspective test-rotate test-depth \ - test-threads test-timeline test-timeline-dup-frames \ - test-timeline-interpolate test-timeline-rewind \ - test-timeline-smoothness \ - test-threads test-timeline test-score test-script \ - test-model test-grab test-effects test-fullscreen \ - test-shader test-unproject test-viewport test-fbo \ - test-opacity test-multistage \ - test-cogl-primitives test-cogl-tex-tile \ - test-cogl-tex-convert test-cogl-tex-foreign \ - test-cogl-tex-getset test-cogl-offscreen \ - test-cogl-tex-polygon test-stage-read-pixels \ - test-random-text test-clip test-paint-wrapper \ - test-texture-quality test-entry-auto test-layout \ - test-invariants test-label-cache test-pick -if X11_TESTS -noinst_PROGRAMS += test-pixmap -noinst_PROGRAMS += test-devices -endif +SUBDIRS = data conform interactive micro-bench tools -INCLUDES = -I$(top_srcdir)/ -I$(top_srcdir)/clutter -I$(top_builddir)/clutter -LDADD = $(top_builddir)/clutter/libclutter-@CLUTTER_FLAVOUR@-@CLUTTER_MAJORMINOR@.la -AM_CFLAGS = $(CLUTTER_CFLAGS) -AM_LDFLAGS = $(CLUTTER_LIBS) +EXTRA_DIST = README -test_textures_SOURCES = test-textures.c -test_events_SOURCES = test-events.c -test_offscreen_SOURCES = test-offscreen.c -test_scale_SOURCES = test-scale.c -test_actors_SOURCES = test-actors.c -test_grab_SOURCES = test-grab.c -test_behave_SOURCES = test-behave.c -test_text_SOURCES = test-text.c -test_entry_SOURCES = test-entry.c -test_project_SOURCES = test-project.c -test_unproject_SOURCES = test-unproject.c -test_perspective_SOURCES = test-perspective.c -test_rotate_SOURCES = test-rotate.c -test_depth_SOURCES = test-depth.c -test_threads_SOURCES = test-threads.c -test_timeline_SOURCES = test-timeline.c -test_timeline_dup_frames_SOURCES = test-timeline-dup-frames.c -test_timeline_interpolate_SOURCES = test-timeline-interpolate.c -test_timeline_rewind_SOURCES = test-timeline-rewind.c -test_timeline_smoothness_SOURCES = test-timeline-smoothness.c -test_shader_SOURCES = test-shader.c -test_score_SOURCES = test-score.c -test_script_SOURCES = test-script.c -test_model_SOURCES = test-model.c -test_effects_SOURCES = test-effects.c -test_fullscreen_SOURCES = test-fullscreen.c -test_viewport_SOURCES = test-viewport.c -test_fbo_SOURCES = test-fbo.c -test_opacity_SOURCES = test-opacity.c -test_multistage_SOURCES = test-multistage.c -test_pixmap_SOURCES = test-pixmap.c -test_pixmap_LDFLAGS = -lXcomposite -test_cogl_primitives_SOURCES = test-cogl-primitives.c -test_cogl_tex_tile_SOURCES = test-cogl-tex-tile.c -test_cogl_tex_convert_SOURCES = test-cogl-tex-convert.c -test_cogl_tex_foreign_SOURCES = test-cogl-tex-foreign.c -test_cogl_tex_getset_SOURCES = test-cogl-tex-getset.c -test_cogl_offscreen_SOURCES = test-cogl-offscreen.c -test_stage_read_pixels_SOURCES = test-stage-read-pixels.c -test_random_text_SOURCES = test-random-text.c -test_paint_wrapper_SOURCES = test-paint-wrapper.c -test_texture_quality_SOURCES = test-texture-quality.c -test_entry_auto_SOURCES = test-entry-auto.c -test_layout_SOURCES = test-layout.c -test_invariants_SOURCES = test-invariants.c -test_devices_SOURCES = test-devices.c -test_label_cache_SOURCES = test-label-cache.c -test_pick_SOURCES = test-pick.c +.PHONY: test conform +test conform: + $(MAKE) -C ./conform test +.PHONY: test-report full-report +test-report full-report: + $(MAKE) -C ./conform $(@) + +# run make test as part of make check +check-local: test -EXTRA_DIST = redhand.png test-script.json diff --git a/tests/README b/tests/README new file mode 100644 index 000000000..5904884da --- /dev/null +++ b/tests/README @@ -0,0 +1,12 @@ + +Outline of test categories: + +The conform/ tests should be non-interactive unit-tests that verify a single feature is behaving as documented. See conform/ADDING_NEW_TESTS for more details. + +The micro-bench/ tests should be focused perfomance test, ideally testing a single metric. Please never forget that these tests are synthetec and if you are using them then you understand what metric is being tested. They probably don't reflect any real world application loads and the intention is that you use these tests once you have already determined the crux of your problem and need focused feedback that your changes are indeed improving matters. There is no exit status requirements for these tests, but they should give clear feedback as to their performance. If the framerate is the feedback metric, then the test should forcibly enable FPS debugging. + +The interactive/ tests are any tests whos status can not be determined without a user looking at some visual output, or providing some manual input etc. This covers most of the original Clutter tests. Ideally some of these tests will be migrated into the conformance/ directory so they can be used in automated nightly tests. + +Other notes: +All tests should ideally include a detailed description in the source explaining exactly what the test is for, how the test was designed to work, and possibly a rationale for the aproach taken for testing. + diff --git a/tests/conform/ADDING_NEW_TESTS b/tests/conform/ADDING_NEW_TESTS new file mode 100644 index 000000000..8b5dc71f7 --- /dev/null +++ b/tests/conform/ADDING_NEW_TESTS @@ -0,0 +1,31 @@ + +How: +---- + +You should including the following at the top of your new unit test: +#include "test-conform-common.h" + +Instead of a main () function add an entry point with a prototype as follows: + +void +test_blah (TestConformSimpleFixture *fixture, + gconstpointer data) +{ + +} + +Add a TEST_CONFORM_SIMPLE() entry in test-conform-main.c + + +Notes: +------ + +NB: A test fails if it exists. (regardless of the exist status) + +Don't call clutter_init since that is handled in test-conform-common.c + +Make sure you clean up *everything* you create. Noteable things you might miss +include timelines, behaviours, and all actors you add to the stage. This is important because otherwise you can cause cascading failures in other tests. + +Use stage = clutter_stage_new () with a corresponding clutter_actor_destroy instead of clutter_stage_get_default (). + diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am new file mode 100644 index 000000000..05995f0c3 --- /dev/null +++ b/tests/conform/Makefile.am @@ -0,0 +1,52 @@ +noinst_PROGRAMS = test-conformance + +test_conformance_SOURCES = \ + test-conform-main.c \ + test-conform-common.c \ + test-conform-common.h \ + \ + test-timeline-dup-frames.c \ + test-timeline-interpolate.c \ + test-timeline-rewind.c \ + test-timeline-smoothness.c \ + test-timeline.c \ + test-pick.c \ + test-label-cache.c \ + test-clutter-entry.c \ + test-clutter-rectangle.c \ + test-clutter-fixed.c + +# For convenience, this provides a way to easily run individual unit tests: +.PHONY: wrappers +wrappers: test-conformance + for i in `./test-conformance -l`; \ + do \ + ln -sf $(top_srcdir)/tests/conform/wrapper.sh `basename $$i`; \ + 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 + +test_conformance_CFLAGS = \ + -I$(top_srcdir)/ \ + -I$(top_srcdir)/clutter \ + -I$(top_builddir)/clutter \ + $(CLUTTER_CFLAGS) +test_conformance_LDADD = $(top_builddir)/clutter/libclutter-@CLUTTER_FLAVOUR@-@CLUTTER_MAJORMINOR@.la + +.PHONY: test test-report full-report +test: + gtester -o=test-conformance-results.xml ./test-conformance + +test-report: + gtester -o=test-conformance-results.xml -k ./test-conformance \ + && gtester-report test-conformance-results.xml > test-conformance-results.html \ + && gnome-open ./test-conformance-results.html + +full-report: + gtester -o=test-conformance-results.xml -k -m=slow ./test-conformance \ + && gtester-report test-conformance-results.xml > test-conformance-results.html \ + && gnome-open ./test-conformance-results.html + +EXTRA_DIST = ADDING_NEW_TESTS + diff --git a/tests/conform/test-clutter-entry.c b/tests/conform/test-clutter-entry.c new file mode 100644 index 000000000..6562836b1 --- /dev/null +++ b/tests/conform/test-clutter-entry.c @@ -0,0 +1,370 @@ +#include +#include +#include + +#include "test-conform-common.h" + +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 */ +}; + +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-clutter-fixed.c b/tests/conform/test-clutter-fixed.c new file mode 100644 index 000000000..e34872101 --- /dev/null +++ b/tests/conform/test-clutter-fixed.c @@ -0,0 +1,18 @@ +#include +#include + +#include "test-conform-common.h" + +void +test_fixed_constants (TestConformSimpleFixture *fixture, + gconstpointer data) +{ + g_assert_cmpint (CFX_ONE, ==, CLUTTER_FLOAT_TO_FIXED (1.0)); + g_assert_cmpint (CFX_ONE, ==, CLUTTER_INT_TO_FIXED (1)); + + g_assert_cmpint (CFX_HALF, ==, CLUTTER_FLOAT_TO_FIXED (0.5)); + + g_assert_cmpfloat (CLUTTER_FIXED_TO_FLOAT (CFX_ONE), ==, 1.0); + g_assert_cmpfloat (CLUTTER_FIXED_TO_FLOAT (CFX_HALF), ==, 0.5); +} + diff --git a/tests/conform/test-clutter-rectangle.c b/tests/conform/test-clutter-rectangle.c new file mode 100644 index 000000000..8f70887ef --- /dev/null +++ b/tests/conform/test-clutter-rectangle.c @@ -0,0 +1,56 @@ +#include +#include +#include + +#include + +#include + +#include "test-conform-common.h" + +void +test_rect_set_size (TestConformSimpleFixture *fixture, + gconstpointer data) +{ + ClutterActor *rect = clutter_rectangle_new (); + + /* initial positioning */ + g_assert_cmpint (clutter_actor_get_x (rect), ==, 0); + g_assert_cmpint (clutter_actor_get_y (rect), ==, 0); + + clutter_actor_set_size (rect, 100, 100); + + /* make sure that changing the size does not affect the + * rest of the bounding box + */ + g_assert_cmpint (clutter_actor_get_x (rect), ==, 0); + g_assert_cmpint (clutter_actor_get_y (rect), ==, 0); + + g_assert_cmpint (clutter_actor_get_width (rect), ==, 100); + g_assert_cmpint (clutter_actor_get_height (rect), ==, 100); + + clutter_actor_destroy (rect); +} + +void +test_rect_set_color (TestConformSimpleFixture *fixture, + gconstpointer data) +{ + ClutterActor *rect = clutter_rectangle_new (); + ClutterColor white = { 255, 255, 255, 255 }; + ClutterColor black = { 0, 0, 0, 255 }; + ClutterColor check = { 0, }; + + clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect), &black); + clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &check); + g_assert_cmpint (check.blue, ==, black.blue); + + clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect), &white); + clutter_rectangle_get_color (CLUTTER_RECTANGLE (rect), &check); + g_assert_cmpint (check.green, ==, white.green); + + g_assert_cmpint (clutter_actor_get_opacity (rect), ==, white.alpha); + + clutter_actor_destroy (rect); +} + diff --git a/tests/conform/test-conform-common.c b/tests/conform/test-conform-common.c new file mode 100644 index 000000000..3fcd234f0 --- /dev/null +++ b/tests/conform/test-conform-common.c @@ -0,0 +1,29 @@ +#include + +#include "test-conform-common.h" + +/** + * test_conform_simple_fixture_setup: + * + * Initialise stuff before each test is run + */ +void +test_conform_simple_fixture_setup (TestConformSimpleFixture *fixture, + gconstpointer data) +{ + /* const TestConformSharedState *shared_state = data; */ +} + + +/** + * test_conform_simple_fixture_teardown: + * + * Cleanup stuff after each test has finished + */ +void +test_conform_simple_fixture_teardown (TestConformSimpleFixture *fixture, + gconstpointer data) +{ + /* const TestConformSharedState *shared_state = data; */ +} + diff --git a/tests/conform/test-conform-common.h b/tests/conform/test-conform-common.h new file mode 100644 index 000000000..eb98f205e --- /dev/null +++ b/tests/conform/test-conform-common.h @@ -0,0 +1,25 @@ + +/* Stuff you put in here is setup once in main() and gets passed around to + * all test functions and fixture setup/teardown functions in the data + * argument */ +typedef struct _TestConformSharedState +{ + int *argc_addr; + char ***argv_addr; +} TestConformSharedState; + + +/* This fixture structure is allocated by glib, and before running each test + * the test_conform_simple_fixture_setup func (see below) is called to + * initialise it, and test_conform_simple_fixture_teardown is called when + * the test is finished. */ +typedef struct _TestConformSimpleFixture +{ + /**/ +} TestConformSimpleFixture; + +void test_conform_simple_fixture_setup (TestConformSimpleFixture *fixture, + gconstpointer data); +void test_conform_simple_fixture_teardown (TestConformSimpleFixture *fixture, + gconstpointer data); + diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c new file mode 100644 index 000000000..a6f1f3659 --- /dev/null +++ b/tests/conform/test-conform-main.c @@ -0,0 +1,81 @@ +#include + +#include +#include + +#include "test-conform-common.h" + + +/* This is a bit of sugar for adding new conformance tests: + * + * - It adds an extern function definition just to save maintaining a header + * that lists test entry points. + * - It sets up callbacks for a fixture, which lets us share initialization + * *code* between tests. (see test-conform-common.c) + * - It passes in a shared *data* pointer that is initialised once in main(), + * that gets passed to the fixture setup and test functions. (See the + * definition in test-conform-common.h) + */ +#define TEST_CONFORM_SIMPLE(NAMESPACE, FUNC) \ + extern void FUNC (TestConformSimpleFixture *fixture, gconstpointer data); \ + g_test_add ("/conform" NAMESPACE "/" #FUNC, \ + TestConformSimpleFixture, \ + shared_state, /* data argument for test */ \ + test_conform_simple_fixture_setup, \ + FUNC, \ + test_conform_simple_fixture_teardown); + + +int +main (int argc, char **argv) +{ + TestConformSharedState *shared_state = g_new0 (TestConformSharedState, 1); + + g_test_init (&argc, &argv, NULL); + + g_test_bug_base ("http://bugzilla.openedhand.com/show_bug.cgi?id=%s"); + + g_assert (clutter_init (shared_state->argc_addr, shared_state->argv_addr) + == CLUTTER_INIT_SUCCESS); + + /* Initialise the state you need to share with everything. + */ + shared_state->argc_addr = &argc; + shared_state->argv_addr = &argv; + + if (g_test_slow ()) + { + TEST_CONFORM_SIMPLE ("/timeline", test_timeline_dup_frames); + TEST_CONFORM_SIMPLE ("/timeline", test_timeline_interpolate); + TEST_CONFORM_SIMPLE ("/timeline", test_timeline_rewind); + TEST_CONFORM_SIMPLE ("/timeline", test_timeline_smoothness); + } + + TEST_CONFORM_SIMPLE ("/picking", test_pick); + + TEST_CONFORM_SIMPLE ("/label", test_label_cache); + + 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); + + TEST_CONFORM_SIMPLE ("/rectangle", test_rect_set_size); + TEST_CONFORM_SIMPLE ("/rectangle", test_rect_set_color); + + TEST_CONFORM_SIMPLE ("/fixed", test_fixed_constants); + + g_test_run (); + return EXIT_SUCCESS; +} + diff --git a/tests/test-label-cache.c b/tests/conform/test-label-cache.c similarity index 97% rename from tests/test-label-cache.c rename to tests/conform/test-label-cache.c index 793a12720..9f9a687e1 100644 --- a/tests/test-label-cache.c +++ b/tests/conform/test-label-cache.c @@ -1,5 +1,8 @@ #include #include +#include + +#include "test-conform-common.h" #define TEST_FONT "Sans 10" @@ -217,16 +220,15 @@ make_layout_like_label (ClutterLabel *label) return new_layout; } -int -main (int argc, char **argv) +void +test_label_cache (TestConformSimpleFixture *fixture, + gconstpointer _data) { CallbackData data; int ret = 0; memset (&data, 0, sizeof (data)); - clutter_init (&argc, &argv); - data.stage = clutter_stage_get_default (); data.label = clutter_label_new_with_text (TEST_FONT, ""); @@ -248,10 +250,11 @@ main (int argc, char **argv) if (data.test_failed) { printf ("FAIL\n"); - ret = 1; + exit (1); } else printf ("pass\n"); - return ret; + return; } + diff --git a/tests/conform/test-pick.c b/tests/conform/test-pick.c new file mode 100644 index 000000000..1fdd938fd --- /dev/null +++ b/tests/conform/test-pick.c @@ -0,0 +1,106 @@ +#include + +#include "test-conform-common.h" + +#define STAGE_WIDTH 320 +#define STAGE_HEIGHT 200 +#define ACTORS_X 12 +#define ACTORS_Y 16 + +typedef struct _State State; + +struct _State +{ + ClutterActor *stage; + int y, x; + guint32 gids[ACTORS_X * ACTORS_Y]; + guint actor_width, actor_height; + int ret; +}; + +static gboolean +on_timeout (State *state) +{ + int y, x; + + for (y = 0; y < ACTORS_Y; y++) + for (x = 0; x < ACTORS_X; x++) + { + gboolean pass = FALSE; + guint32 gid; + ClutterActor *actor + = clutter_stage_get_actor_at_pos (CLUTTER_STAGE (state->stage), + x * state->actor_width + + state->actor_width / 2, + y * state->actor_height + + state->actor_height / 2); + + printf ("actor %u -> ", state->gids[y * ACTORS_X + x]); + + if (actor == NULL) + printf ("NULL: FAIL\n"); + else + { + gid = clutter_actor_get_gid (actor); + if (gid == state->gids[y * ACTORS_X + x]) + pass = TRUE; + printf ("% 8i: %s\n", gid, pass ? "pass" : "FAIL"); + } + + if (!pass) + state->ret = 1; + } + + clutter_main_quit (); + + return FALSE; +} + +void +test_pick (TestConformSimpleFixture *fixture, + gconstpointer data) +{ + int y, x; + State state; + + state.ret = 0; + + state.stage = clutter_stage_new (); + + clutter_actor_set_size (state.stage, STAGE_WIDTH, STAGE_HEIGHT); + state.actor_width = STAGE_WIDTH / ACTORS_X; + state.actor_height = STAGE_HEIGHT / ACTORS_Y; + + for (y = 0; y < ACTORS_Y; y++) + for (x = 0; x < ACTORS_X; x++) + { + ClutterColor color = { x * 255 / (ACTORS_X - 1), + y * 255 / (ACTORS_Y - 1), + 128, 255 }; + ClutterGeometry geom = { x * state.actor_width, y * state.actor_height, + state.actor_width, state.actor_height }; + ClutterActor *rect = clutter_rectangle_new_with_color (&color); + + clutter_actor_set_geometry (rect, &geom); + + clutter_container_add (CLUTTER_CONTAINER (state.stage), rect, NULL); + + state.gids[y * ACTORS_X + x] = clutter_actor_get_gid (rect); + } + + clutter_actor_show (state.stage); + + g_timeout_add (250, (GSourceFunc) on_timeout, &state); + + clutter_main (); + + clutter_actor_destroy (state.stage); + + printf ("end result: %s\n", state.ret ? "FAIL" : "pass"); + + if (state.ret) + exit (state.ret); + + return; +} + diff --git a/tests/test-timeline-dup-frames.c b/tests/conform/test-timeline-dup-frames.c similarity index 55% rename from tests/test-timeline-dup-frames.c rename to tests/conform/test-timeline-dup-frames.c index eb7c90bb8..32a906084 100644 --- a/tests/test-timeline-dup-frames.c +++ b/tests/conform/test-timeline-dup-frames.c @@ -2,6 +2,8 @@ #include #include +#include "test-conform-common.h" + /* We use a nice slow timeline for this test since we * dont want the timeouts to interpolate the timeline * forward multiple frames */ @@ -23,17 +25,20 @@ new_frame_cb (ClutterTimeline *timeline, { gint current_frame = clutter_timeline_get_current_frame (state->timeline); - if (state->prev_frame != clutter_timeline_get_current_frame (state->timeline)) + if (state->prev_frame + != clutter_timeline_get_current_frame (state->timeline)) { - g_print("timeline previous frame=%-4i actual frame=%-4i (OK)\n", - state->prev_frame, - current_frame); + g_test_message ("timeline previous frame=%-4i " + "actual frame=%-4i (OK)\n", + state->prev_frame, + current_frame); } else { - g_print("timeline previous frame=%-4i actual frame=%-4i (FAILED)\n", - state->prev_frame, - current_frame); + g_test_message ("timeline previous frame=%-4i " + "actual frame=%-4i (FAILED)\n", + state->prev_frame, + current_frame); state->passed = FALSE; } @@ -44,54 +49,53 @@ new_frame_cb (ClutterTimeline *timeline, static void completed_cb (ClutterTimeline *timeline, - TestState *state) + TestState *state) { state->completion_count++; if (state->completion_count == 2) { - if (state->passed) - { - g_print("Passed\n"); - exit(EXIT_SUCCESS); - } - else - { - g_print("Failed\n"); - exit(EXIT_FAILURE); - } + if (state->passed) + { + g_test_message ("Passed\n"); + clutter_main_quit (); + } + else + { + g_test_message ("Failed\n"); + exit (EXIT_FAILURE); + } } } -int -main(int argc, char **argv) +void +test_timeline_dup_frames (TestConformSimpleFixture *fixture, + gconstpointer data) { TestState state; - clutter_init(&argc, &argv); - state.timeline = clutter_timeline_new (TEST_TIMELINE_FRAME_COUNT, - TEST_TIMELINE_FPS); + TEST_TIMELINE_FPS); clutter_timeline_set_loop (state.timeline, TRUE); g_signal_connect (G_OBJECT(state.timeline), - "new-frame", - G_CALLBACK(new_frame_cb), - &state); + "new-frame", + G_CALLBACK(new_frame_cb), + &state); g_signal_connect (G_OBJECT(state.timeline), - "completed", - G_CALLBACK(completed_cb), - &state); + "completed", + G_CALLBACK(completed_cb), + &state); state.prev_frame = -1; state.completion_count = 0; state.passed = TRUE; clutter_timeline_start (state.timeline); - + clutter_main(); - - return EXIT_FAILURE; + + g_object_unref (state.timeline); } diff --git a/tests/test-timeline-interpolate.c b/tests/conform/test-timeline-interpolate.c similarity index 62% rename from tests/test-timeline-interpolate.c rename to tests/conform/test-timeline-interpolate.c index bfc55d07c..56af892ef 100644 --- a/tests/test-timeline-interpolate.c +++ b/tests/conform/test-timeline-interpolate.c @@ -2,6 +2,8 @@ #include #include +#include "test-conform-common.h" + /* We ask for 1 frame per millisecond. * Whenever this rate can't be achieved then the timeline * will interpolate the number frames that should have @@ -25,7 +27,7 @@ typedef struct _TestState { static void new_frame_cb (ClutterTimeline *timeline, - gint frame_num, + gint frame_num, TestState *state) { GTimeVal current_time; @@ -33,14 +35,14 @@ new_frame_cb (ClutterTimeline *timeline, glong msec_diff; gint loop_overflow = 0; static gint step = 1; - + g_get_current_time (¤t_time); current_frame = clutter_timeline_get_current_frame (state->timeline); - + msec_diff = (current_time.tv_sec - state->start_time.tv_sec) * 1000; msec_diff += (current_time.tv_usec - state->start_time.tv_usec)/1000; - + /* If we expect to have interpolated past the end of the timeline * we keep track of the overflow so we can determine when * the next timeout will happen. We then clip expected_frames @@ -49,48 +51,57 @@ new_frame_cb (ClutterTimeline *timeline, * looping */ if (state->expected_frame > TEST_TIMELINE_FRAME_COUNT) { - loop_overflow = state->expected_frame - TEST_TIMELINE_FRAME_COUNT; - state->expected_frame = TEST_TIMELINE_FRAME_COUNT; + loop_overflow = state->expected_frame - TEST_TIMELINE_FRAME_COUNT; + state->expected_frame = TEST_TIMELINE_FRAME_COUNT; } if (current_frame >= (state->expected_frame-TEST_ERROR_TOLERANCE) && current_frame <= (state->expected_frame+TEST_ERROR_TOLERANCE)) { - g_print ("\nelapsed milliseconds=%-5li expected frame=%-4i actual frame=%-4i (OK)\n", - msec_diff, - state->expected_frame, - current_frame); + g_test_message ("\nelapsed milliseconds=%-5li " + "expected frame=%-4i actual frame=%-4i (OK)\n", + msec_diff, + state->expected_frame, + current_frame); } else { - g_print ("\nelapsed milliseconds=%-5li expected frame=%-4i actual frame=%-4i (FAILED)\n", - msec_diff, - state->expected_frame, - current_frame); + g_test_message ("\nelapsed milliseconds=%-5li " + "expected frame=%-4i actual frame=%-4i (FAILED)\n", + msec_diff, + state->expected_frame, + current_frame); state->passed = FALSE; } - + if (step>0) { state->expected_frame = current_frame + (TEST_TIMELINE_FPS / 4); - g_print ("Sleeping for 250ms so next frame should be (%i + %i) = %i\n", - current_frame, (TEST_TIMELINE_FPS / 4), state->expected_frame); + g_test_message ("Sleeping for 250ms " + "so next frame should be (%i + %i) = %i\n", + current_frame, + (TEST_TIMELINE_FPS / 4), + state->expected_frame); g_usleep (250000); } else { state->expected_frame = current_frame + TEST_TIMELINE_FPS; - g_print ("Sleeping for 1sec so next frame should be (%i + %i) = %i\n", - current_frame, TEST_TIMELINE_FPS, state->expected_frame); + g_test_message ("Sleeping for 1sec " + "so next frame should be (%i + %i) = %i\n", + current_frame, + TEST_TIMELINE_FPS, + state->expected_frame); g_usleep (1000000); } - + if (current_frame >= TEST_TIMELINE_FRAME_COUNT) { state->expected_frame += loop_overflow; state->expected_frame -= TEST_TIMELINE_FRAME_COUNT; - g_print ("End of timeline reached: Wrapping expected frame too %i\n", - state->expected_frame); + g_test_message ("End of timeline reached: " + "Wrapping expected frame too %i\n", + state->expected_frame); } state->new_frame_counter++; @@ -100,45 +111,44 @@ new_frame_cb (ClutterTimeline *timeline, static void completed_cb (ClutterTimeline *timeline, - TestState *state) + TestState *state) { - state->completion_count++; + state->completion_count++; - if (state->completion_count == 2) - { - if (state->passed) - { - g_print("Passed\n"); - exit(EXIT_SUCCESS); - } - else - { - g_print("Failed\n"); - exit(EXIT_FAILURE); - } - } + if (state->completion_count == 2) + { + if (state->passed) + { + g_test_message ("Passed\n"); + clutter_main_quit (); + } + else + { + g_test_message ("Failed\n"); + exit (EXIT_FAILURE); + } + } } -int -main (int argc, char **argv) +void +test_timeline_interpolate (TestConformSimpleFixture *fixture, + gconstpointer data) { TestState state; - clutter_init (&argc, &argv); - state.timeline = clutter_timeline_new (TEST_TIMELINE_FRAME_COUNT, - TEST_TIMELINE_FPS); + TEST_TIMELINE_FPS); clutter_timeline_set_loop (state.timeline, TRUE); g_signal_connect (G_OBJECT(state.timeline), - "new-frame", - G_CALLBACK(new_frame_cb), - &state); + "new-frame", + G_CALLBACK(new_frame_cb), + &state); g_signal_connect (G_OBJECT(state.timeline), - "completed", - G_CALLBACK(completed_cb), - &state); + "completed", + G_CALLBACK(completed_cb), + &state); state.completion_count = 0; state.new_frame_counter = 0; @@ -147,9 +157,9 @@ main (int argc, char **argv) g_get_current_time (&state.start_time); clutter_timeline_start (state.timeline); - + clutter_main(); - return EXIT_FAILURE; + g_object_unref (state.timeline); } diff --git a/tests/test-timeline-rewind.c b/tests/conform/test-timeline-rewind.c similarity index 64% rename from tests/test-timeline-rewind.c rename to tests/conform/test-timeline-rewind.c index 77edf0d84..26ac93387 100644 --- a/tests/test-timeline-rewind.c +++ b/tests/conform/test-timeline-rewind.c @@ -2,6 +2,8 @@ #include #include +#include "test-conform-common.h" + #define TEST_TIMELINE_FPS 10 #define TEST_TIMELINE_FRAME_COUNT 5 #define TEST_WATCHDOG_KICK_IN_SECONDS 10 @@ -15,18 +17,18 @@ typedef struct _TestState { static gboolean watchdog_timeout (TestState *state) { - g_print ("Watchdog timer kicking in\n"); - g_print ("rewind_count=%i\n", state->rewind_count); + g_test_message ("Watchdog timer kicking in\n"); + g_test_message ("rewind_count=%i\n", state->rewind_count); if (state->rewind_count <= 3) { /* The test has hung */ - g_print ("Failed (This test shouldn't have hung!)\n"); + g_test_message ("Failed (This test shouldn't have hung!)\n"); exit (EXIT_FAILURE); } else { - g_print ("Passed\n"); - exit (EXIT_SUCCESS); + g_test_message ("Passed\n"); + clutter_main_quit (); } return FALSE; @@ -42,8 +44,8 @@ new_frame_cb (ClutterTimeline *timeline, if (current_frame == TEST_TIMELINE_FRAME_COUNT) { - g_print ("new-frame signal recieved (end of timeline)\n"); - g_print ("Rewinding timeline\n"); + g_test_message ("new-frame signal recieved (end of timeline)\n"); + g_test_message ("Rewinding timeline\n"); clutter_timeline_rewind (timeline); state->rewind_count++; } @@ -51,29 +53,28 @@ new_frame_cb (ClutterTimeline *timeline, { if (current_frame == 0) { - g_print ("new-frame signal recieved (start of timeline)\n"); + g_test_message ("new-frame signal recieved (start of timeline)\n"); } else { - g_print ("new-frame signal recieved (mid frame)\n"); + g_test_message ("new-frame signal recieved (mid frame)\n"); } if (state->rewind_count >= 2) { - g_print ("Sleeping for 1 second\n"); + g_test_message ("Sleeping for 1 second\n"); g_usleep (1000000); } } } -int -main (int argc, char **argv) +void +test_timeline_rewind (TestConformSimpleFixture *fixture, + gconstpointer data) { TestState state; - clutter_init (&argc, &argv); - state.timeline = clutter_timeline_new (TEST_TIMELINE_FRAME_COUNT, TEST_TIMELINE_FPS); @@ -81,7 +82,8 @@ main (int argc, char **argv) "new-frame", G_CALLBACK(new_frame_cb), &state); - g_print ("Installing a watchdog timeout to determin if this test hangs\n"); + g_test_message ("Installing a watchdog timeout " + "to determine if this test hangs\n"); g_timeout_add (TEST_WATCHDOG_KICK_IN_SECONDS*1000, (GSourceFunc)watchdog_timeout, &state); @@ -90,7 +92,7 @@ main (int argc, char **argv) clutter_timeline_start (state.timeline); clutter_main(); - - return EXIT_FAILURE; + + g_object_unref (state.timeline); } diff --git a/tests/test-timeline-smoothness.c b/tests/conform/test-timeline-smoothness.c similarity index 53% rename from tests/test-timeline-smoothness.c rename to tests/conform/test-timeline-smoothness.c index 30917643e..9b0b5ae47 100644 --- a/tests/test-timeline-smoothness.c +++ b/tests/conform/test-timeline-smoothness.c @@ -2,6 +2,8 @@ #include #include +#include "test-conform-common.h" + #define TEST_TIMELINE_FPS 10 #define TEST_TIMELINE_FRAME_COUNT 20 #define TEST_ERROR_TOLERANCE 5 @@ -25,33 +27,34 @@ new_frame_cb (ClutterTimeline *timeline, glong total_elapsed_ms; glong frame_elapsed_ms = 0; gchar *bump = ""; - + g_get_current_time (¤t_time); - + total_elapsed_ms = (current_time.tv_sec - state->start_time.tv_sec) * 1000; total_elapsed_ms += (current_time.tv_usec - state->start_time.tv_usec)/1000; if (state->frame>0) { - frame_elapsed_ms = - (current_time.tv_sec - state->prev_frame_time.tv_sec) * 1000; - frame_elapsed_ms += - (current_time.tv_usec - state->prev_frame_time.tv_usec)/1000; + frame_elapsed_ms = + (current_time.tv_sec - state->prev_frame_time.tv_sec) * 1000; + frame_elapsed_ms += + (current_time.tv_usec - state->prev_frame_time.tv_usec)/1000; - if (ABS(frame_elapsed_ms - (1000/TEST_TIMELINE_FPS)) - > TEST_ERROR_TOLERANCE) - { - state->passed = FALSE; - bump = " (BUMP)"; - } + if (ABS(frame_elapsed_ms - (1000/TEST_TIMELINE_FPS)) + > TEST_ERROR_TOLERANCE) + { + state->passed = FALSE; + bump = " (BUMP)"; + } } - - g_print ("timeline frame=%-2d total elapsed=%-4li(ms) since last frame=%-4li(ms)%s\n", - clutter_timeline_get_current_frame(state->timeline), - total_elapsed_ms, - frame_elapsed_ms, - bump); - + + g_test_message ("timeline frame=%-2d total elapsed=%-4li(ms) " + "since last frame=%-4li(ms)%s\n", + clutter_timeline_get_current_frame(state->timeline), + total_elapsed_ms, + frame_elapsed_ms, + bump); + state->prev_frame_time = current_time; state->frame++; } @@ -59,45 +62,44 @@ new_frame_cb (ClutterTimeline *timeline, static void completed_cb (ClutterTimeline *timeline, - TestState *state) + TestState *state) { state->completion_count++; if (state->completion_count == 2) { - if (state->passed) - { - g_print("Passed\n"); - exit(EXIT_SUCCESS); - } - else - { - g_print("Failed\n"); - exit(EXIT_FAILURE); - } + if (state->passed) + { + g_test_message ("Passed\n"); + clutter_main_quit (); + } + else + { + g_test_message ("Failed\n"); + exit (EXIT_FAILURE); + } } } -int -main(int argc, char **argv) +void +test_timeline_smoothness (TestConformSimpleFixture *fixture, + gconstpointer data) { TestState state; - clutter_init (&argc, &argv); - state.timeline = clutter_timeline_new (TEST_TIMELINE_FRAME_COUNT, - TEST_TIMELINE_FPS); + TEST_TIMELINE_FPS); clutter_timeline_set_loop (state.timeline, TRUE); g_signal_connect (G_OBJECT(state.timeline), - "new-frame", - G_CALLBACK(new_frame_cb), - &state); + "new-frame", + G_CALLBACK(new_frame_cb), + &state); g_signal_connect (G_OBJECT(state.timeline), - "completed", - G_CALLBACK(completed_cb), - &state); + "completed", + G_CALLBACK(completed_cb), + &state); state.frame = 0; state.completion_count = 0; @@ -108,6 +110,6 @@ main(int argc, char **argv) clutter_main(); - return EXIT_FAILURE; + g_object_unref (state.timeline); } diff --git a/tests/conform/test-timeline.c b/tests/conform/test-timeline.c new file mode 100644 index 000000000..7ea8f2438 --- /dev/null +++ b/tests/conform/test-timeline.c @@ -0,0 +1,140 @@ +#include +#include +#include +#include +#include + +static void +timeline_1_complete (ClutterTimeline *timeline) +{ + g_debug ("1: Completed"); +} + +static void +timeline_2_complete (ClutterTimeline *timeline) +{ + g_debug ("2: Completed"); +} + +static void +timeline_3_complete (ClutterTimeline *timeline) +{ + g_debug ("3: Completed"); +} + +static void +timeline_1_new_frame_cb (ClutterTimeline *timeline, gint frame_no) +{ + g_debug ("1: Doing frame %d.", frame_no); +} + +static void +timeline_2_new_frame_cb (ClutterTimeline *timeline, gint frame_no) +{ + g_debug ("2: Doing frame %d.", frame_no); +} + +static void +timeline_3_new_frame_cb (ClutterTimeline *timeline, gint frame_no) +{ + g_debug ("3: Doing frame %d.", frame_no); +} + +static void +timeline_1_marker_reached (ClutterTimeline *timeline, + const gchar *marker_name, + guint frame_num) +{ + g_print ("1: Marker `%s' (%d) reached\n", marker_name, frame_num); +} + +static void +timeline_2_marker_reached (ClutterTimeline *timeline, + const gchar *marker_name, + guint frame_num) +{ + g_print ("2: Marker `%s' (%d) reached\n", marker_name, frame_num); +} + +static void +timeline_3_marker_reached (ClutterTimeline *timeline, + const gchar *marker_name, + guint frame_num) +{ + g_print ("3: Marker `%s' (%d) reached\n", marker_name, frame_num); +} + +G_MODULE_EXPORT int +test_timeline_main (int argc, char **argv) +{ + ClutterTimeline *timeline_1; + ClutterTimeline *timeline_2; + ClutterTimeline *timeline_3; + gchar **markers; + gsize n_markers; + + clutter_init (&argc, &argv); + + timeline_1 = clutter_timeline_new (10, 120); + clutter_timeline_add_marker_at_frame (timeline_1, "foo", 5); + clutter_timeline_add_marker_at_frame (timeline_1, "bar", 5); + clutter_timeline_add_marker_at_frame (timeline_1, "baz", 5); + markers = clutter_timeline_list_markers (timeline_1, 5, &n_markers); + g_assert (markers != NULL); + g_assert (n_markers == 3); + g_strfreev (markers); + + timeline_2 = clutter_timeline_clone (timeline_1); + clutter_timeline_add_marker_at_frame (timeline_2, "bar", 2); + markers = clutter_timeline_list_markers (timeline_2, -1, &n_markers); + g_assert (markers != NULL); + g_assert (n_markers == 1); + g_assert (strcmp (markers[0], "bar") == 0); + g_strfreev (markers); + + timeline_3 = clutter_timeline_clone (timeline_1); + clutter_timeline_set_direction (timeline_3, CLUTTER_TIMELINE_BACKWARD); + clutter_timeline_add_marker_at_frame (timeline_3, "baz", 8); + + g_signal_connect (timeline_1, + "marker-reached", G_CALLBACK (timeline_1_marker_reached), + NULL); + g_signal_connect (timeline_1, + "new-frame", G_CALLBACK (timeline_1_new_frame_cb), + NULL); + g_signal_connect (timeline_1, + "completed", G_CALLBACK (timeline_1_complete), + NULL); + + g_signal_connect (timeline_2, + "marker-reached::bar", G_CALLBACK (timeline_2_marker_reached), + NULL); + g_signal_connect (timeline_2, + "new-frame", G_CALLBACK (timeline_2_new_frame_cb), + NULL); + g_signal_connect (timeline_2, + "completed", G_CALLBACK (timeline_2_complete), + NULL); + + g_signal_connect (timeline_3, + "marker-reached", G_CALLBACK (timeline_3_marker_reached), + NULL); + g_signal_connect (timeline_3, + "new-frame", G_CALLBACK (timeline_3_new_frame_cb), + NULL); + g_signal_connect (timeline_3, + "completed", G_CALLBACK (timeline_3_complete), + NULL); + + clutter_timeline_start (timeline_1); + clutter_timeline_start (timeline_2); + clutter_timeline_start (timeline_3); + + clutter_main (); + + g_object_unref (timeline_1); + g_object_unref (timeline_2); + g_object_unref (timeline_3); + + return EXIT_SUCCESS; +} diff --git a/tests/conform/wrapper.sh b/tests/conform/wrapper.sh new file mode 100755 index 000000000..589db08ef --- /dev/null +++ b/tests/conform/wrapper.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +UNIT_TEST=`basename $0` +UNIT_TEST_PATH=`./test-conformance -l |grep $UNIT_TEST` + +echo "Running: gtester -p $UNIT_TEST_PATH ./test-conformance" +echo "" +gtester -p $UNIT_TEST_PATH ./test-conformance + +echo "" +echo "NOTE: For debugging purposes, you can run this single test as follows:" +echo "$ libtool --mode=execute \\" +echo " gdb --eval-command=\"b $UNIT_TEST\" \\" +echo " --args ./test-conformance -p $UNIT_TEST_PATH" + diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am new file mode 100644 index 000000000..c69042d19 --- /dev/null +++ b/tests/data/Makefile.am @@ -0,0 +1,5 @@ + +EXTRA_DIST = \ + redhand.png \ + test-script.json + diff --git a/tests/redhand.png b/tests/data/redhand.png similarity index 100% rename from tests/redhand.png rename to tests/data/redhand.png diff --git a/tests/test-script.json b/tests/data/test-script.json similarity index 100% rename from tests/test-script.json rename to tests/data/test-script.json diff --git a/tests/interactive/Makefile.am b/tests/interactive/Makefile.am new file mode 100644 index 000000000..9d8e39b12 --- /dev/null +++ b/tests/interactive/Makefile.am @@ -0,0 +1,69 @@ + +UNIT_TESTS = \ + test-textures.c \ + test-events.c \ + test-offscreen.c \ + test-scale.c \ + test-actors.c \ + test-behave.c \ + test-entry.c \ + test-project.c \ + test-perspective.c \ + test-rotate.c \ + test-depth.c \ + test-threads.c \ + test-score.c \ + test-script.c \ + test-model.c \ + test-grab.c \ + test-effects.c \ + test-fullscreen.c \ + test-shader.c \ + test-unproject.c \ + test-viewport test-fbo.c \ + test-opacity.c \ + test-multistage.c \ + test-cogl-primitives.c \ + test-cogl-tex-tile.c \ + test-cogl-tex-convert.c \ + test-cogl-tex-foreign.c \ + test-cogl-tex-getset.c \ + test-cogl-offscreen.c \ + test-cogl-tex-polygon.c \ + test-stage-read-pixels.c \ + test-random-text.c \ + test-clip.c \ + test-paint-wrapper.c \ + test-texture-quality.c \ + test-entry-auto.c \ + test-layout.c \ + test-invariants.c + +#FIXME - this is is a bit of a yukky way of ensuring the tests find our data: +test-script.json: + ln -sf $(top_srcdir)/tests/data/test-script.json +redhand.png: + ln -sf $(top_srcdir)/tests/data/redhand.png + +# For convenience, this provides a way to easily run individual unit tests: +.PHONY: wrappers +wrappers: test-interactive + for i in $(UNIT_TESTS); \ + 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 + +INCLUDES = -I$(top_srcdir)/ -I$(top_srcdir)/clutter -I$(top_builddir)/clutter +LDADD = $(top_builddir)/clutter/libclutter-@CLUTTER_FLAVOUR@-@CLUTTER_MAJORMINOR@.la +AM_CFLAGS = $(CLUTTER_CFLAGS) +AM_LDFLAGS = $(CLUTTER_LIBS) + +noinst_PROGRAMS = test-interactive + +test_interactive_SOURCES = \ + test-main.c \ + $(UNIT_TESTS) +test_interactive_LDFLAGS = -export-dynamic diff --git a/tests/test-actors.c b/tests/interactive/test-actors.c similarity index 98% rename from tests/test-actors.c rename to tests/interactive/test-actors.c index 964a5b19b..ffe4f37b3 100644 --- a/tests/test-actors.c +++ b/tests/interactive/test-actors.c @@ -8,6 +8,7 @@ #include #include #include +#include #define TRAILS 0 #define NHANDS 6 @@ -122,8 +123,8 @@ frame_cb (ClutterTimeline *timeline, } } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_actors_main (int argc, char *argv[]) { ClutterTimeline *timeline; ClutterAlpha *alpha; diff --git a/tests/test-behave.c b/tests/interactive/test-behave.c similarity index 98% rename from tests/test-behave.c rename to tests/interactive/test-behave.c index 678742641..c3e5d09b3 100644 --- a/tests/test-behave.c +++ b/tests/interactive/test-behave.c @@ -3,6 +3,7 @@ #include #include +#include #include @@ -67,8 +68,8 @@ typedef enum { #define MAGIC 0.551784 #define RADIUS 200 -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_behave_main (int argc, char *argv[]) { ClutterTimeline *timeline; ClutterAlpha *alpha; diff --git a/tests/test-clip.c b/tests/interactive/test-clip.c similarity index 97% rename from tests/test-clip.c rename to tests/interactive/test-clip.c index 48246fd3a..0db145931 100644 --- a/tests/test-clip.c +++ b/tests/interactive/test-clip.c @@ -2,6 +2,7 @@ #include #include #include +#include #define TL_SCALE 5.0f @@ -58,8 +59,8 @@ on_new_frame (ClutterTimeline *tl, int frame_num, CallbackData *data) } } -int -main (int argc, char **argv) +G_MODULE_EXPORT int +test_clip_main (int argc, char **argv) { ClutterGeometry geom; ClutterTimeline *tl; diff --git a/tests/test-cogl-offscreen.c b/tests/interactive/test-cogl-offscreen.c similarity index 96% rename from tests/test-cogl-offscreen.c rename to tests/interactive/test-cogl-offscreen.c index 12d14fcca..fba4cbbda 100644 --- a/tests/test-cogl-offscreen.c +++ b/tests/interactive/test-cogl-offscreen.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -54,7 +55,7 @@ struct _TestCoglboxClass void (*_test_coglbox4) (void); }; -GType test_coglbox_get_type (void) G_GNUC_CONST; +static GType test_coglbox_get_type (void) G_GNUC_CONST; G_END_DECLS @@ -186,14 +187,14 @@ test_coglbox_class_init (TestCoglboxClass *klass) g_type_class_add_private (gobject_class, sizeof (TestCoglboxPrivate)); } -ClutterActor* +static ClutterActor* test_coglbox_new (void) { return g_object_new (TEST_TYPE_COGLBOX, NULL); } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_cogl_offscreen_main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *coglbox; diff --git a/tests/test-cogl-primitives.c b/tests/interactive/test-cogl-primitives.c similarity index 97% rename from tests/test-cogl-primitives.c rename to tests/interactive/test-cogl-primitives.c index 84947dc01..ae76e83b8 100644 --- a/tests/test-cogl-primitives.c +++ b/tests/interactive/test-cogl-primitives.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -54,7 +55,7 @@ struct _TestCoglboxClass void (*_test_coglbox4) (void); }; -GType test_coglbox_get_type (void) G_GNUC_CONST; +static GType test_coglbox_get_type (void) G_GNUC_CONST; G_END_DECLS @@ -257,7 +258,7 @@ test_coglbox_class_init (TestCoglboxClass *klass) g_type_class_add_private (gobject_class, sizeof (TestCoglboxPrivate)); } -ClutterActor* +static ClutterActor* test_coglbox_new (void) { return g_object_new (TEST_TYPE_COGLBOX, NULL); @@ -266,8 +267,8 @@ test_coglbox_new (void) #define SPIN() while (g_main_context_pending (NULL)) \ g_main_context_iteration (NULL, FALSE); -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_cogl_primitives_main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *coglbox; diff --git a/tests/test-cogl-tex-convert.c b/tests/interactive/test-cogl-tex-convert.c similarity index 96% rename from tests/test-cogl-tex-convert.c rename to tests/interactive/test-cogl-tex-convert.c index 89d64bb05..8b91f0ce7 100644 --- a/tests/test-cogl-tex-convert.c +++ b/tests/interactive/test-cogl-tex-convert.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -54,7 +55,7 @@ struct _TestCoglboxClass void (*_test_coglbox4) (void); }; -GType test_coglbox_get_type (void) G_GNUC_CONST; +static GType test_coglbox_get_type (void) G_GNUC_CONST; G_END_DECLS @@ -192,14 +193,14 @@ test_coglbox_class_init (TestCoglboxClass *klass) g_type_class_add_private (gobject_class, sizeof (TestCoglboxPrivate)); } -ClutterActor* +static ClutterActor* test_coglbox_new (void) { return g_object_new (TEST_TYPE_COGLBOX, NULL); } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_cogl_tex_convert_main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *coglbox; diff --git a/tests/test-cogl-tex-foreign.c b/tests/interactive/test-cogl-tex-foreign.c similarity index 96% rename from tests/test-cogl-tex-foreign.c rename to tests/interactive/test-cogl-tex-foreign.c index 97c05260f..79afd4c15 100644 --- a/tests/test-cogl-tex-foreign.c +++ b/tests/interactive/test-cogl-tex-foreign.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -54,7 +55,7 @@ struct _TestCoglboxClass void (*_test_coglbox4) (void); }; -GType test_coglbox_get_type (void) G_GNUC_CONST; +static GType test_coglbox_get_type (void) G_GNUC_CONST; G_END_DECLS @@ -182,14 +183,14 @@ test_coglbox_class_init (TestCoglboxClass *klass) g_type_class_add_private (gobject_class, sizeof (TestCoglboxPrivate)); } -ClutterActor* +static ClutterActor* test_coglbox_new (void) { return g_object_new (TEST_TYPE_COGLBOX, NULL); } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_cogl_tex_foreign_main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *coglbox; diff --git a/tests/test-cogl-tex-getset.c b/tests/interactive/test-cogl-tex-getset.c similarity index 97% rename from tests/test-cogl-tex-getset.c rename to tests/interactive/test-cogl-tex-getset.c index bf988d1e2..125dc645f 100644 --- a/tests/test-cogl-tex-getset.c +++ b/tests/interactive/test-cogl-tex-getset.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -54,7 +55,7 @@ struct _TestCoglboxClass void (*_test_coglbox4) (void); }; -GType test_coglbox_get_type (void) G_GNUC_CONST; +static GType test_coglbox_get_type (void) G_GNUC_CONST; G_END_DECLS @@ -240,14 +241,14 @@ test_coglbox_class_init (TestCoglboxClass *klass) g_type_class_add_private (gobject_class, sizeof (TestCoglboxPrivate)); } -ClutterActor* +static ClutterActor* test_coglbox_new (void) { return g_object_new (TEST_TYPE_COGLBOX, NULL); } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_cogl_tex_getset_main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *coglbox; diff --git a/tests/test-cogl-tex-polygon.c b/tests/interactive/test-cogl-tex-polygon.c similarity index 98% rename from tests/test-cogl-tex-polygon.c rename to tests/interactive/test-cogl-tex-polygon.c index 805687944..7c4dcc58e 100644 --- a/tests/test-cogl-tex-polygon.c +++ b/tests/interactive/test-cogl-tex-polygon.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -54,7 +55,7 @@ struct _TestCoglboxClass void (*_test_coglbox4) (void); }; -GType test_coglbox_get_type (void) G_GNUC_CONST; +static GType test_coglbox_get_type (void) G_GNUC_CONST; G_END_DECLS @@ -282,7 +283,7 @@ test_coglbox_class_init (TestCoglboxClass *klass) g_type_class_add_private (gobject_class, sizeof (TestCoglboxPrivate)); } -ClutterActor* +static ClutterActor* test_coglbox_new (void) { return g_object_new (TEST_TYPE_COGLBOX, NULL); @@ -334,8 +335,8 @@ make_toggle (const char *label_text, gboolean *toggle_val) return group; } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_cogl_tex_polygon_main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *coglbox; diff --git a/tests/test-cogl-tex-tile.c b/tests/interactive/test-cogl-tex-tile.c similarity index 97% rename from tests/test-cogl-tex-tile.c rename to tests/interactive/test-cogl-tex-tile.c index 8841bb7a7..70a131cbe 100644 --- a/tests/test-cogl-tex-tile.c +++ b/tests/interactive/test-cogl-tex-tile.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -54,7 +55,7 @@ struct _TestCoglboxClass void (*_test_coglbox4) (void); }; -GType test_coglbox_get_type (void) G_GNUC_CONST; +static GType test_coglbox_get_type (void) G_GNUC_CONST; G_END_DECLS @@ -177,7 +178,7 @@ test_coglbox_class_init (TestCoglboxClass *klass) g_type_class_add_private (gobject_class, sizeof (TestCoglboxPrivate)); } -ClutterActor* +static ClutterActor* test_coglbox_new (void) { return g_object_new (TEST_TYPE_COGLBOX, NULL); @@ -194,8 +195,8 @@ frame_cb (ClutterTimeline *timeline, clutter_actor_queue_redraw (CLUTTER_ACTOR (data)); } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_cogl_tex_tile_main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *coglbox; diff --git a/tests/test-depth.c b/tests/interactive/test-depth.c similarity index 98% rename from tests/test-depth.c rename to tests/interactive/test-depth.c index 9b8a27966..ab13975c0 100644 --- a/tests/test-depth.c +++ b/tests/interactive/test-depth.c @@ -1,4 +1,5 @@ #include +#include #include /* each time the timeline animating the label completes, swap the direction */ @@ -106,8 +107,8 @@ janus_group (const gchar *front_text, } -gint -main (int argc, char *argv[]) +G_MODULE_EXPORT gint +test_depth_main (int argc, char *argv[]) { ClutterTimeline *timeline; ClutterBehaviour *d_behave; diff --git a/tests/test-devices.c b/tests/interactive/test-devices.c similarity index 96% rename from tests/test-devices.c rename to tests/interactive/test-devices.c index 78f384076..504109d8d 100644 --- a/tests/test-devices.c +++ b/tests/interactive/test-devices.c @@ -1,3 +1,4 @@ +#include #include #include @@ -24,8 +25,8 @@ stage_motion_event_cb (ClutterActor *actor, return FALSE; } -int -main (int argc, char **argv) +G_MODULE_EXPORT int +test_devices_main (int argc, char **argv) { ClutterActor *stage = NULL; GSList *stage_devices = NULL; diff --git a/tests/test-effects.c b/tests/interactive/test-effects.c similarity index 97% rename from tests/test-effects.c rename to tests/interactive/test-effects.c index bf2b56cff..08db46694 100644 --- a/tests/test-effects.c +++ b/tests/interactive/test-effects.c @@ -1,11 +1,12 @@ #include +#include #include static ClutterEffectTemplate *tmpl = NULL; static ClutterTimeline *timeline = NULL; -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_effects_main (int argc, char *argv[]) { ClutterActor *stage, *actor; ClutterContainer *container; diff --git a/tests/test-entry-auto.c b/tests/interactive/test-entry-auto.c similarity index 98% rename from tests/test-entry-auto.c rename to tests/interactive/test-entry-auto.c index f340953d8..dd12b64c9 100644 --- a/tests/test-entry-auto.c +++ b/tests/interactive/test-entry-auto.c @@ -1,4 +1,4 @@ - +#include #include #include @@ -267,8 +267,8 @@ run (void (*test_func)(ClutterEntry *, const TestData *), const TestData *t) clutter_actor_destroy (entry); } -int -main (int argc, char **argv) +G_MODULE_EXPORT int +test_entry_auto_main (int argc, char **argv) { int i; diff --git a/tests/test-entry.c b/tests/interactive/test-entry.c similarity index 94% rename from tests/test-entry.c rename to tests/interactive/test-entry.c index 8806d02c3..a4ea1ddd7 100644 --- a/tests/test-entry.c +++ b/tests/interactive/test-entry.c @@ -1,3 +1,4 @@ +#include #include static void @@ -6,8 +7,8 @@ on_entry_activated (ClutterEntry *entry, gpointer null) g_print ("Activated: %s\n", clutter_entry_get_text (entry)); } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_entry_main (int argc, char *argv[]) { ClutterActor *entry; ClutterActor *stage; diff --git a/tests/test-events.c b/tests/interactive/test-events.c similarity index 99% rename from tests/test-events.c rename to tests/interactive/test-events.c index b689fea43..010594ea8 100644 --- a/tests/test-events.c +++ b/tests/interactive/test-events.c @@ -1,3 +1,4 @@ +#include #include #include @@ -189,8 +190,8 @@ input_cb (ClutterActor *actor, return FALSE; } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_events_main (int argc, char *argv[]) { ClutterActor *stage, *actor, *focus_box, *group; ClutterColor rcol = { 0xff, 0, 0, 0xff}, diff --git a/tests/test-fbo.c b/tests/interactive/test-fbo.c similarity index 98% rename from tests/test-fbo.c rename to tests/interactive/test-fbo.c index eb6097a59..9bbb4190e 100644 --- a/tests/test-fbo.c +++ b/tests/interactive/test-fbo.c @@ -26,6 +26,7 @@ #include #include #include +#include ClutterActor* make_source(void) @@ -97,9 +98,8 @@ make_shader(void) return shader; } -gint -main (gint argc, - gchar *argv[]) +G_MODULE_EXPORT gint +test_fbo_main (gint argc, gchar *argv[]) { ClutterColor blue = {0x33, 0x44, 0x55, 0xff}; diff --git a/tests/test-fullscreen.c b/tests/interactive/test-fullscreen.c similarity index 96% rename from tests/test-fullscreen.c rename to tests/interactive/test-fullscreen.c index 35406e8a1..36948cf74 100644 --- a/tests/test-fullscreen.c +++ b/tests/interactive/test-fullscreen.c @@ -1,4 +1,5 @@ #include +#include #include enum @@ -66,8 +67,8 @@ toggle_fullscreen (gpointer dummy) return FALSE; } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_fullscreen_main (int argc, char *argv[]) { ClutterActor *stage; diff --git a/tests/test-grab.c b/tests/interactive/test-grab.c similarity index 98% rename from tests/test-grab.c rename to tests/interactive/test-grab.c index a245ce62e..8dbd38c06 100644 --- a/tests/test-grab.c +++ b/tests/interactive/test-grab.c @@ -1,3 +1,4 @@ +#include #include static void @@ -144,8 +145,8 @@ cyan_press_cb (ClutterActor *actor, -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_grab_main (int argc, char *argv[]) { ClutterActor *stage, *actor; ClutterColor rcol = { 0xff, 0, 0, 0xff}, diff --git a/tests/test-invariants.c b/tests/interactive/test-invariants.c similarity index 97% rename from tests/test-invariants.c rename to tests/interactive/test-invariants.c index 094280a5e..98f712022 100644 --- a/tests/test-invariants.c +++ b/tests/interactive/test-invariants.c @@ -1,6 +1,7 @@ #include #include +#include #include /* dummy unit testing API; to be replaced by GTest in 1.0 */ @@ -173,9 +174,8 @@ test_show_on_set_parent (void) clutter_actor_destroy (group); } -int -main (int argc, - char *argv[]) +G_MODULE_EXPORT int +test_invariants_main (int argc, char *argv[]) { test_init (&argc, &argv); diff --git a/tests/test-layout.c b/tests/interactive/test-layout.c similarity index 99% rename from tests/test-layout.c rename to tests/interactive/test-layout.c index 1b1d35f08..704bae706 100644 --- a/tests/test-layout.c +++ b/tests/interactive/test-layout.c @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -743,9 +744,8 @@ relayout_on_frame (ClutterTimeline *timeline) clutter_actor_queue_relayout (box); } -int -main (int argc, - char *argv[]) +G_MODULE_EXPORT int +test_layout_main (int argc, char *argv[]) { ClutterActor *stage, *instructions; gint i; diff --git a/tests/interactive/test-main.c b/tests/interactive/test-main.c new file mode 100644 index 000000000..f219a2d77 --- /dev/null +++ b/tests/interactive/test-main.c @@ -0,0 +1,37 @@ +#include +#include + + +int +main (int argc, char **argv) +{ + GModule *module; + char *unit_test; + char *main_symbol_name; + int (*unit_test_main) (int argc, char **argv); + int ret; + + if (argc != 2) + g_error ("Usage: %s unit_test"); + + module = g_module_open (NULL, 0); + if (!module) + g_error ("Failed to open self for symbol lookup"); + + unit_test = g_path_get_basename (argv[1]); + + main_symbol_name = g_strdup_printf ("%s_main", unit_test); + main_symbol_name = g_strdelimit (main_symbol_name, "-", '_'); + + if (!g_module_symbol (module, main_symbol_name, &unit_test_main)) + g_error ("Failed to look up main symbol for the test: %s", unit_test); + + ret = unit_test_main (argc - 1, argv + 1); + + g_free (unit_test); + g_free (main_symbol_name); + g_module_close (module); + + return ret; +} + diff --git a/tests/test-model.c b/tests/interactive/test-model.c similarity index 98% rename from tests/test-model.c rename to tests/interactive/test-model.c index 307b02a67..d7b645795 100644 --- a/tests/test-model.c +++ b/tests/interactive/test-model.c @@ -1,3 +1,4 @@ +#include #include #include @@ -205,8 +206,8 @@ on_filter_changed (ClutterModel *model) g_print ("*** Filter Changed ***\n\n"); } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_model_main (int argc, char *argv[]) { ClutterModel *model; diff --git a/tests/test-multistage.c b/tests/interactive/test-multistage.c similarity index 97% rename from tests/test-multistage.c rename to tests/interactive/test-multistage.c index ae6b28bc9..3395c3445 100644 --- a/tests/test-multistage.c +++ b/tests/interactive/test-multistage.c @@ -1,3 +1,4 @@ +#include #include static gint n_stages = 1; @@ -96,8 +97,8 @@ on_button_press (ClutterActor *actor, return TRUE; } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_multistage_main (int argc, char *argv[]) { ClutterActor *stage_default; ClutterActor *label; diff --git a/tests/test-offscreen.c b/tests/interactive/test-offscreen.c similarity index 88% rename from tests/test-offscreen.c rename to tests/interactive/test-offscreen.c index 39b276fa0..f89a422a3 100644 --- a/tests/test-offscreen.c +++ b/tests/interactive/test-offscreen.c @@ -1,9 +1,10 @@ +#include #include /* Very simple test just to see what happens setting up offscreen rendering */ -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_offscreen_main (int argc, char *argv[]) { ClutterActor *stage; gboolean offscreen; diff --git a/tests/test-opacity.c b/tests/interactive/test-opacity.c similarity index 97% rename from tests/test-opacity.c rename to tests/interactive/test-opacity.c index bff5ba41f..cef053446 100644 --- a/tests/test-opacity.c +++ b/tests/interactive/test-opacity.c @@ -2,11 +2,12 @@ #include #include +#include #include -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_opacity_main (int argc, char *argv[]) { ClutterActor *stage, *group1, *group2, *label, *rect; ClutterColor label_color = { 255, 0, 0, 128 }; diff --git a/tests/test-paint-wrapper.c b/tests/interactive/test-paint-wrapper.c similarity index 98% rename from tests/test-paint-wrapper.c rename to tests/interactive/test-paint-wrapper.c index a355616dc..067b85c92 100644 --- a/tests/test-paint-wrapper.c +++ b/tests/interactive/test-paint-wrapper.c @@ -1,3 +1,4 @@ +#include #include #if defined (_MSC_VER) && !defined (_USE_MATH_DEFINES) @@ -155,8 +156,8 @@ hand_post_paint (ClutterActor *actor, hand_pre_paint_guard = FALSE; } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_paint_wrapper_main (int argc, char *argv[]) { ClutterTimeline *timeline; ClutterAlpha *alpha; diff --git a/tests/test-perspective.c b/tests/interactive/test-perspective.c similarity index 94% rename from tests/test-perspective.c rename to tests/interactive/test-perspective.c index 8425d452e..5f467e591 100644 --- a/tests/test-perspective.c +++ b/tests/interactive/test-perspective.c @@ -1,7 +1,8 @@ +#include #include -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_perspective_main (int argc, char *argv[]) { ClutterActor *rect; ClutterActor *stage; diff --git a/tests/test-pixmap.c b/tests/interactive/test-pixmap.c similarity index 98% rename from tests/test-pixmap.c rename to tests/interactive/test-pixmap.c index 262bf839c..cd6bc5785 100644 --- a/tests/test-pixmap.c +++ b/tests/interactive/test-pixmap.c @@ -2,6 +2,7 @@ #include #include +#include #if HAVE_CLUTTER_GLX @@ -177,8 +178,8 @@ create_pixmap (guint *width, guint *height, guint *depth) } # endif /* USE_GDKPIXBUF */ -int -main (int argc, char **argv) +G_MODULE_EXPORT int +test_pixmap_main (int argc, char **argv) { #ifdef USE_GDKPIXBUF GOptionContext *context; diff --git a/tests/test-project.c b/tests/interactive/test-project.c similarity index 98% rename from tests/test-project.c rename to tests/interactive/test-project.c index 7c36a9fa0..1ac2176b7 100644 --- a/tests/test-project.c +++ b/tests/interactive/test-project.c @@ -1,6 +1,7 @@ #include #include #include +#include static ClutterActor *main_stage, *rect, *p[5]; @@ -93,7 +94,7 @@ find_handle_index (ClutterActor * a) return -1; } -gboolean +static gboolean on_event (ClutterStage *stage, ClutterEvent *event, gpointer user_data) @@ -202,8 +203,8 @@ on_event (ClutterStage *stage, } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_project_main (int argc, char *argv[]) { ClutterActor *label; diff --git a/tests/test-random-text.c b/tests/interactive/test-random-text.c similarity index 95% rename from tests/test-random-text.c rename to tests/interactive/test-random-text.c index 27c8d8454..18ebefff0 100644 --- a/tests/test-random-text.c +++ b/tests/interactive/test-random-text.c @@ -1,3 +1,4 @@ +#include #include #include @@ -66,8 +67,8 @@ on_idle (gpointer data) return TRUE; } -int -main (int argc, char **argv) +G_MODULE_EXPORT int +test_random_text_main (int argc, char **argv) { ClutterActor *stage; diff --git a/tests/test-rotate.c b/tests/interactive/test-rotate.c similarity index 96% rename from tests/test-rotate.c rename to tests/interactive/test-rotate.c index 94e9ce2b6..371cf54fc 100644 --- a/tests/test-rotate.c +++ b/tests/interactive/test-rotate.c @@ -3,11 +3,12 @@ #include #include +#include #include -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_rotate_main (int argc, char *argv[]) { ClutterTimeline *timeline; ClutterAlpha *alpha; diff --git a/tests/test-scale.c b/tests/interactive/test-scale.c similarity index 96% rename from tests/test-scale.c rename to tests/interactive/test-scale.c index 4ed38f780..5b806deab 100644 --- a/tests/test-scale.c +++ b/tests/interactive/test-scale.c @@ -1,4 +1,5 @@ #include +#include #include static const ClutterGravity gravities[] = { @@ -28,8 +29,8 @@ on_timeline_completed (ClutterTimeline *cluttertimeline, clutter_actor_move_anchor_point_from_gravity (actor, gravities[gindex]); } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_scale_main (int argc, char *argv[]) { ClutterActor *stage, *rect; ClutterColor stage_color = { 0x0, 0x0, 0x0, 0xff }; diff --git a/tests/test-score.c b/tests/interactive/test-score.c similarity index 97% rename from tests/test-score.c rename to tests/interactive/test-score.c index ef84a1bf2..c6493476e 100644 --- a/tests/test-score.c +++ b/tests/interactive/test-score.c @@ -1,5 +1,6 @@ #include #include +#include #include static gint level = 1; @@ -34,8 +35,8 @@ on_timeline_completed (ClutterScore *score, (gchar *) g_object_get_data (G_OBJECT (timeline), "timeline-name")); } -int -main (int argc, char **argv) +G_MODULE_EXPORT int +test_score_main (int argc, char **argv) { ClutterScore *score; ClutterTimeline *timeline_1; diff --git a/tests/test-script.c b/tests/interactive/test-script.c similarity index 98% rename from tests/test-script.c rename to tests/interactive/test-script.c index 659d464c0..b457bb429 100644 --- a/tests/test-script.c +++ b/tests/interactive/test-script.c @@ -2,6 +2,7 @@ #include #include +#include #include @@ -101,8 +102,8 @@ red_button_press (ClutterActor *actor, return TRUE; } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_script_main (int argc, char *argv[]) { GObject *stage, *blue_button, *red_button; GError *error = NULL; diff --git a/tests/test-shader.c b/tests/interactive/test-shader.c similarity index 99% rename from tests/test-shader.c rename to tests/interactive/test-shader.c index 1c4406d5e..6a8b46540 100644 --- a/tests/test-shader.c +++ b/tests/interactive/test-shader.c @@ -6,6 +6,7 @@ #include #include #include +#include /* Dynamic branching appeared in "Shader Model 3.0" that low-end IGPs * don't support. @@ -293,9 +294,8 @@ timeout_cb (gpointer data) } #endif /* HAVE_COGL_GLES2 */ -gint -main (gint argc, - gchar *argv[]) +G_MODULE_EXPORT gint +test_shader_main (gint argc, gchar *argv[]) { ClutterActor *actor; ClutterActor *stage; diff --git a/tests/test-stage-read-pixels.c b/tests/interactive/test-stage-read-pixels.c similarity index 97% rename from tests/test-stage-read-pixels.c rename to tests/interactive/test-stage-read-pixels.c index 89e78d79d..f13b7ebe7 100644 --- a/tests/test-stage-read-pixels.c +++ b/tests/interactive/test-stage-read-pixels.c @@ -1,3 +1,4 @@ +#include #include #include @@ -124,8 +125,8 @@ on_motion (ClutterActor *stage, ClutterMotionEvent *event, CallbackData *data) return FALSE; } -int -main (int argc, char **argv) +G_MODULE_EXPORT int +test_stage_read_pixels_main (int argc, char **argv) { CallbackData data; diff --git a/tests/test-texture-quality.c b/tests/interactive/test-texture-quality.c similarity index 97% rename from tests/test-texture-quality.c rename to tests/interactive/test-texture-quality.c index baeae2aec..11f189d78 100644 --- a/tests/test-texture-quality.c +++ b/tests/interactive/test-texture-quality.c @@ -1,4 +1,5 @@ #include +#include #include /* each time the timeline animating the label completes, swap the direction */ @@ -38,8 +39,8 @@ change_filter (gpointer actor) return TRUE; } -gint -main (int argc, char *argv[]) +G_MODULE_EXPORT gint +test_texture_quality_main (int argc, char *argv[]) { ClutterTimeline *timeline; ClutterBehaviour *depth_behavior; diff --git a/tests/test-textures.c b/tests/interactive/test-textures.c similarity index 96% rename from tests/test-textures.c rename to tests/interactive/test-textures.c index ea5dfa250..58a601d58 100644 --- a/tests/test-textures.c +++ b/tests/interactive/test-textures.c @@ -3,6 +3,7 @@ #endif #include +#include #include @@ -53,8 +54,8 @@ make_rgba_data (int width, int height, int bpp, int has_alpha, int *rowstride_p) #define SPIN() while (g_main_context_pending (NULL)) \ g_main_context_iteration (NULL, FALSE); -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_textures_main (int argc, char *argv[]) { ClutterActor *texture; ClutterActor *stage; diff --git a/tests/test-threads.c b/tests/interactive/test-threads.c similarity index 98% rename from tests/test-threads.c rename to tests/interactive/test-threads.c index c188b1467..b8647e946 100644 --- a/tests/test-threads.c +++ b/tests/interactive/test-threads.c @@ -1,5 +1,6 @@ #include #include +#include #include typedef struct @@ -167,8 +168,8 @@ on_key_press_event (ClutterStage *stage, } } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_threads_main (int argc, char *argv[]) { ClutterActor *stage; ClutterActor *rect; diff --git a/tests/test-unproject.c b/tests/interactive/test-unproject.c similarity index 97% rename from tests/test-unproject.c rename to tests/interactive/test-unproject.c index 617ea60af..422647e84 100644 --- a/tests/test-unproject.c +++ b/tests/interactive/test-unproject.c @@ -3,6 +3,7 @@ #include #include #include +#include ClutterActor *label; @@ -11,7 +12,7 @@ ClutterActor *label; #define RECT_W 320 #define RECT_H 240 -gboolean +static gboolean on_event (ClutterStage *stage, ClutterEvent *event, gpointer user_data) @@ -68,8 +69,8 @@ on_event (ClutterStage *stage, } -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_unproject_main (int argc, char *argv[]) { gchar *txt; ClutterActor *rect, *stage, *label0; diff --git a/tests/test-viewport.c b/tests/interactive/test-viewport.c similarity index 95% rename from tests/test-viewport.c rename to tests/interactive/test-viewport.c index 0e08981b5..6d2a6305f 100644 --- a/tests/test-viewport.c +++ b/tests/interactive/test-viewport.c @@ -3,11 +3,12 @@ #include #include +#include #include -int -main (int argc, char *argv[]) +G_MODULE_EXPORT int +test_viewport_main (int argc, char *argv[]) { ClutterTimeline *timeline; ClutterAlpha *alpha; diff --git a/tests/interactive/wrapper.sh b/tests/interactive/wrapper.sh new file mode 100755 index 000000000..4cfaa6bf5 --- /dev/null +++ b/tests/interactive/wrapper.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +UNIT_TEST=`basename $0` + +echo "Running ./test-interactive $UNIT_TEST $@" +echo "" +echo "NOTE: For debugging purposes, you can run this single test as follows:" +echo "$ libtool --mode=execute \\" +echo " gdb --eval-command=\"b `echo $UNIT_TEST|tr '-' '_'`_main\" \\" +echo " --args ./test-interactive $UNIT_TEST" + +./test-interactive $UNIT_TEST "$@" + diff --git a/tests/micro-bench/Makefile.am b/tests/micro-bench/Makefile.am new file mode 100644 index 000000000..8ae34cc9c --- /dev/null +++ b/tests/micro-bench/Makefile.am @@ -0,0 +1,10 @@ +noinst_PROGRAMS = \ + test-text + +INCLUDES = -I$(top_srcdir)/ -I$(top_srcdir)/clutter -I$(top_builddir)/clutter +LDADD = $(top_builddir)/clutter/libclutter-@CLUTTER_FLAVOUR@-@CLUTTER_MAJORMINOR@.la +AM_CFLAGS = $(CLUTTER_CFLAGS) -DTESTS_DATA_DIR=$(top_srcdir)/tests/data/ +AM_LDFLAGS = $(CLUTTER_LIBS) + +test_text_SOURCES = test-text.c + diff --git a/tests/test-text.c b/tests/micro-bench/test-text.c similarity index 100% rename from tests/test-text.c rename to tests/micro-bench/test-text.c diff --git a/tests/test-pick.c b/tests/test-pick.c deleted file mode 100644 index 6af7268d9..000000000 --- a/tests/test-pick.c +++ /dev/null @@ -1,99 +0,0 @@ -#include - -#define STAGE_WIDTH 320 -#define STAGE_HEIGHT 200 -#define ACTORS_X 12 -#define ACTORS_Y 16 - -typedef struct _Data Data; - -struct _Data -{ - ClutterActor *stage; - int y, x; - guint32 gids[ACTORS_X * ACTORS_Y]; - guint actor_width, actor_height; - int ret; -}; - -static gboolean -on_timeout (Data *data) -{ - int y, x; - - for (y = 0; y < ACTORS_Y; y++) - for (x = 0; x < ACTORS_X; x++) - { - gboolean pass = FALSE; - guint32 gid; - ClutterActor *actor - = clutter_stage_get_actor_at_pos (CLUTTER_STAGE (data->stage), - x * data->actor_width - + data->actor_width / 2, - y * data->actor_height - + data->actor_height / 2); - - printf ("actor %u -> ", data->gids[y * ACTORS_X + x]); - - if (actor == NULL) - printf ("NULL: FAIL\n"); - else - { - gid = clutter_actor_get_gid (actor); - if (gid == data->gids[y * ACTORS_X + x]) - pass = TRUE; - printf ("% 8i: %s\n", gid, pass ? "pass" : "FAIL"); - } - - if (!pass) - data->ret = 1; - } - - clutter_main_quit (); - - return FALSE; -} - -int -main (int argc, char **argv) -{ - int y, x; - Data data; - - data.ret = 0; - - clutter_init (&argc, &argv); - - data.stage = clutter_stage_get_default (); - - clutter_actor_set_size (data.stage, STAGE_WIDTH, STAGE_HEIGHT); - data.actor_width = STAGE_WIDTH / ACTORS_X; - data.actor_height = STAGE_HEIGHT / ACTORS_Y; - - for (y = 0; y < ACTORS_Y; y++) - for (x = 0; x < ACTORS_X; x++) - { - ClutterColor color = { x * 255 / (ACTORS_X - 1), - y * 255 / (ACTORS_Y - 1), - 128, 255 }; - ClutterGeometry geom = { x * data.actor_width, y * data.actor_height, - data.actor_width, data.actor_height }; - ClutterActor *rect = clutter_rectangle_new_with_color (&color); - - clutter_actor_set_geometry (rect, &geom); - - clutter_container_add (CLUTTER_CONTAINER (data.stage), rect, NULL); - - data.gids[y * ACTORS_X + x] = clutter_actor_get_gid (rect); - } - - clutter_actor_show (data.stage); - - g_timeout_add (250, (GSourceFunc) on_timeout, &data); - - clutter_main (); - - printf ("end result: %s\n", data.ret ? "FAIL" : "pass"); - - return data.ret; -} diff --git a/tests/test-timeline.c b/tests/test-timeline.c deleted file mode 100644 index 218dcaa57..000000000 --- a/tests/test-timeline.c +++ /dev/null @@ -1,293 +0,0 @@ -#include -#include -#include -#include - -/* This test runs three timelines at 30 fps with 10 frames. Some of - the timelines have markers. Once the timelines are run it then - checks that all of the frames were hit, all of the markers were hit - and that the completed signal was fired. The timelines are then run - again but this time with a timeout source that introduces a - delay. This should cause some frames to be skipped. The test is run - again but only the markers and the completed signal is checked - for. */ - -#define FRAME_COUNT 10 - -typedef struct _TimelineData TimelineData; - -struct _TimelineData -{ - int timeline_num; - - guint frame_hit_count[FRAME_COUNT + 1]; - GSList *markers_hit; - guint completed_count; -}; - -static void -timeline_data_init (TimelineData *data, int timeline_num) -{ - memset (data, 0, sizeof (TimelineData)); - data->timeline_num = timeline_num; -} - -static void -timeline_data_destroy (TimelineData *data) -{ - g_slist_foreach (data->markers_hit, (GFunc) g_free, NULL); - g_slist_free (data->markers_hit); -} - -static void -timeline_complete_cb (ClutterTimeline *timeline, - TimelineData *data) -{ - printf ("%i: Completed\n", data->timeline_num); - data->completed_count++; -} - -static void -timeline_new_frame_cb (ClutterTimeline *timeline, - gint frame_no, - TimelineData *data) -{ - printf ("%i: Doing frame %d, delta = %i\n", - data->timeline_num, frame_no, - clutter_timeline_get_delta (timeline, NULL)); - data->frame_hit_count[frame_no]++; -} - -static void -timeline_marker_reached_cb (ClutterTimeline *timeline, - const gchar *marker_name, - guint frame_num, - TimelineData *data) -{ - printf ("%i: Marker `%s' (%d) reached, delta = %i\n", - data->timeline_num, marker_name, frame_num, - clutter_timeline_get_delta (timeline, NULL)); - data->markers_hit = g_slist_prepend (data->markers_hit, - g_strdup (marker_name)); -} - -static gboolean -check_timeline (ClutterTimeline *timeline, - TimelineData *data, - gboolean check_missed_frames) -{ - gchar **markers; - gsize n_markers; - guint *marker_reached_count; - gboolean succeeded = TRUE; - GSList *node; - int i; - int missed_frame_count = 0; - int frame_offset; - - if (clutter_timeline_get_direction (timeline) == CLUTTER_TIMELINE_BACKWARD) - frame_offset = 0; - else - frame_offset = 1; - - markers = clutter_timeline_list_markers (timeline, -1, &n_markers); - marker_reached_count = g_new0 (guint, n_markers); - - for (node = data->markers_hit; node; node = node->next) - { - for (i = 0; i < n_markers; i++) - if (!strcmp (node->data, markers[i])) - break; - - if (i < n_markers) - marker_reached_count[i]++; - else - { - printf ("FAIL: unknown marker '%s' hit for %i\n", - (char *) node->data, data->timeline_num); - succeeded = FALSE; - } - } - - for (i = 0; i < n_markers; i++) - if (marker_reached_count[i] != 1) - { - printf ("FAIL: marker '%s' hit %i times for %i\n", - markers[i], marker_reached_count[i], data->timeline_num); - succeeded = FALSE; - } - - if (check_missed_frames) - { - for (i = 0; i < FRAME_COUNT; i++) - if (data->frame_hit_count[i + frame_offset] != 1) - missed_frame_count++; - - if (missed_frame_count) - { - printf ("FAIL: missed %i frame%s for %i\n", - missed_frame_count, missed_frame_count == 1 ? "" : "s", - data->timeline_num); - succeeded = FALSE; - } - } - - if (data->completed_count != 1) - { - printf ("FAIL: timeline %i completed %i times\n", - data->timeline_num, data->completed_count); - succeeded = FALSE; - } - - g_strfreev (markers); - g_free (marker_reached_count); - - return succeeded; -} - -static gboolean -timeout_cb (gpointer data) -{ - clutter_main_quit (); - - return FALSE; -} - -static gboolean -delay_cb (gpointer data) -{ - /* Waste a bit of time so that it will skip frames */ - g_usleep (G_USEC_PER_SEC * 66 / 1000); - - return TRUE; -} - -int -main (int argc, char **argv) -{ - ClutterTimeline *timeline_1; - TimelineData data_1; - ClutterTimeline *timeline_2; - TimelineData data_2; - ClutterTimeline *timeline_3; - TimelineData data_3; - gchar **markers; - gsize n_markers; - int ret = EXIT_SUCCESS; - - clutter_init (&argc, &argv); - - timeline_data_init (&data_1, 1); - timeline_1 = clutter_timeline_new (FRAME_COUNT, 30); - clutter_timeline_add_marker_at_frame (timeline_1, "foo", 5); - clutter_timeline_add_marker_at_frame (timeline_1, "bar", 5); - clutter_timeline_add_marker_at_frame (timeline_1, "baz", 5); - clutter_timeline_add_marker_at_frame (timeline_1, "near-end-marker", 9); - clutter_timeline_add_marker_at_frame (timeline_1, "end-marker", 10); - markers = clutter_timeline_list_markers (timeline_1, 5, &n_markers); - g_assert (markers != NULL); - g_assert (n_markers == 3); - g_strfreev (markers); - - timeline_data_init (&data_2, 2); - timeline_2 = clutter_timeline_clone (timeline_1); - clutter_timeline_add_marker_at_frame (timeline_2, "bar", 2); - markers = clutter_timeline_list_markers (timeline_2, -1, &n_markers); - g_assert (markers != NULL); - g_assert (n_markers == 1); - g_assert (strcmp (markers[0], "bar") == 0); - g_strfreev (markers); - - timeline_data_init (&data_3, 3); - timeline_3 = clutter_timeline_clone (timeline_1); - clutter_timeline_set_direction (timeline_3, CLUTTER_TIMELINE_BACKWARD); - clutter_timeline_add_marker_at_frame (timeline_3, "foo", 5); - clutter_timeline_add_marker_at_frame (timeline_3, "baz", 8); - clutter_timeline_add_marker_at_frame (timeline_3, "near-end-marker", 1); - clutter_timeline_add_marker_at_frame (timeline_3, "end-marker", 0); - - g_signal_connect (timeline_1, - "marker-reached", G_CALLBACK (timeline_marker_reached_cb), - &data_1); - g_signal_connect (timeline_1, - "new-frame", G_CALLBACK (timeline_new_frame_cb), - &data_1); - g_signal_connect (timeline_1, - "completed", G_CALLBACK (timeline_complete_cb), - &data_1); - - g_signal_connect (timeline_2, - "marker-reached::bar", - G_CALLBACK (timeline_marker_reached_cb), - &data_2); - g_signal_connect (timeline_2, - "new-frame", G_CALLBACK (timeline_new_frame_cb), - &data_2); - g_signal_connect (timeline_2, - "completed", G_CALLBACK (timeline_complete_cb), - &data_2); - - g_signal_connect (timeline_3, - "marker-reached", G_CALLBACK (timeline_marker_reached_cb), - &data_3); - g_signal_connect (timeline_3, - "new-frame", G_CALLBACK (timeline_new_frame_cb), - &data_3); - g_signal_connect (timeline_3, - "completed", G_CALLBACK (timeline_complete_cb), - &data_3); - - printf ("Without delay...\n"); - - clutter_timeline_start (timeline_1); - clutter_timeline_start (timeline_2); - clutter_timeline_start (timeline_3); - - clutter_threads_add_timeout (2000, timeout_cb, NULL); - - clutter_main (); - - if (!check_timeline (timeline_1, &data_1, TRUE)) - ret = EXIT_FAILURE; - if (!check_timeline (timeline_2, &data_2, TRUE)) - ret = EXIT_FAILURE; - if (!check_timeline (timeline_3, &data_3, TRUE)) - ret = EXIT_FAILURE; - - printf ("With delay...\n"); - - timeline_data_destroy (&data_1); - timeline_data_init (&data_1, 1); - timeline_data_destroy (&data_2); - timeline_data_init (&data_2, 2); - timeline_data_destroy (&data_3); - timeline_data_init (&data_3, 3); - - clutter_timeline_start (timeline_1); - clutter_timeline_start (timeline_2); - clutter_timeline_start (timeline_3); - - clutter_threads_add_timeout (2000, timeout_cb, NULL); - clutter_threads_add_timeout (99, delay_cb, NULL); - - clutter_main (); - - if (!check_timeline (timeline_1, &data_1, FALSE)) - ret = EXIT_FAILURE; - if (!check_timeline (timeline_2, &data_2, FALSE)) - ret = EXIT_FAILURE; - if (!check_timeline (timeline_3, &data_3, FALSE)) - ret = EXIT_FAILURE; - - g_object_unref (timeline_1); - g_object_unref (timeline_2); - g_object_unref (timeline_3); - - timeline_data_destroy (&data_1); - timeline_data_destroy (&data_2); - timeline_data_destroy (&data_3); - - printf ("Overall result: %s\n", ret == EXIT_SUCCESS ? "PASS" : "FAIL"); - - return ret; -} diff --git a/tests/tools/Makefile.am b/tests/tools/Makefile.am new file mode 100644 index 000000000..93d6c488e --- /dev/null +++ b/tests/tools/Makefile.am @@ -0,0 +1,2 @@ + +EXTRA_DIST = README diff --git a/tests/tools/README b/tests/tools/README new file mode 100644 index 000000000..455a8cdea --- /dev/null +++ b/tests/tools/README @@ -0,0 +1,2 @@ +This is a place holder for tools such as gltrace like libraries +