diff --git a/ChangeLog b/ChangeLog index 76b2309a6d..92d77cf00d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-06-21 Thomas Vander Stichele + + * check/Makefile.am: + * check/gst/gstvalue.c: (START_TEST), (gst_value_suite), (main): + * testsuite/Makefile.am: + * testsuite/caps/Makefile.am: + * testsuite/caps/value_serialize.c: + * testsuite/test_gst_init.c: + move a value_serialize test over + 2005-06-20 Wim Taymans * gst/gstpad.c: diff --git a/check/Makefile.am b/check/Makefile.am index 847befdf33..89e82dbfea 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -23,6 +23,7 @@ clean-local: done TESTS = $(top_builddir)/tools/gst-register \ + gst/gst \ gst/gstbin \ gst/gstbuffer \ gst/gstbus \ @@ -34,6 +35,7 @@ TESTS = $(top_builddir)/tools/gst-register \ gst/gstpad \ gst/gstsystemclock \ gst/gsttag \ + gst/gstvalue \ pipelines/simple_launch_lines \ pipelines/cleanup \ gst-libs/gdp diff --git a/check/gst/gstvalue.c b/check/gst/gstvalue.c new file mode 100644 index 0000000000..9aeaac6234 --- /dev/null +++ b/check/gst/gstvalue.c @@ -0,0 +1,143 @@ +/* GStreamer + * Copyright (C) <2004> David Schleef + * + * gstvalue.c: Unit tests for GstValue + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#include "../gstcheck.h" + + +START_TEST (test_deserialize_buffer) +{ + GValue value = { 0 }; + + g_value_init (&value, GST_TYPE_BUFFER); + fail_unless (gst_value_deserialize (&value, "1234567890abcdef")); +} + +END_TEST; + +START_TEST (test_string) +{ + gchar *try[] = { + "Dude", + "Hi, I'm a string", + "tüüüt!" + }; + gchar *tmp; + GValue v = { 0, }; + guint i; + + g_value_init (&v, G_TYPE_STRING); + for (i = 0; i < G_N_ELEMENTS (try); i++) { + g_value_set_string (&v, try[i]); + tmp = gst_value_serialize (&v); + fail_if (tmp == NULL, "couldn't serialize: %s\n", try[i]); + fail_unless (gst_value_deserialize (&v, tmp), + "couldn't deserialize: %s\n", tmp); + g_free (tmp); + + fail_unless (g_str_equal (g_value_get_string (&v), try[i]), + "\nserialized : %s\ndeserialized: %s", try[i], + g_value_get_string (&v)); + } + g_value_unset (&v); +} + +END_TEST; + +START_TEST (test_deserialize_string) +{ + struct + { + gchar *from; + gchar *to; + } tests[] = { + { + "", ""}, { + "\"\"", ""}, + /* FAILURES */ + { + "\"", NULL}, /* missing second quote */ + { + "\"Hello\\ World", NULL}, /* missing second quote */ + { + "\"\\", NULL}, /* quote at end, missing second quote */ + { + "\"\\0", NULL}, /* missing second quote */ + { + "\"\\0\"", NULL}, /* unfinished escaped character */ + { + "\" \"", NULL}, /* spaces must be escaped */ +#if 0 + /* FIXME 0.9: this test should fail, but it doesn't */ + { + "tüüt", NULL} /* string with special chars must be escaped */ +#endif + }; + guint i; + GValue v = { 0, }; + gboolean ret = TRUE; + + g_value_init (&v, G_TYPE_STRING); + for (i = 0; i < G_N_ELEMENTS (tests); i++) { + if (gst_value_deserialize (&v, tests[i].from)) { + fail_if (tests[i].to == NULL, + "I got %s instead of a failure", g_value_get_string (&v)); + fail_unless (g_str_equal (g_value_get_string (&v), tests[i].to), + "\nwanted: %s\ngot : %s", tests[i].to, g_value_get_string (&v)); + } else { + fail_if (tests[i].to != NULL, "failed, but wanted: %s", tests[i].to); + ret = FALSE; + } + } + g_value_unset (&v); +} + +END_TEST; + +Suite * +gst_value_suite (void) +{ + Suite *s = suite_create ("GstValue"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_deserialize_buffer); + tcase_add_test (tc_chain, test_string); + tcase_add_test (tc_chain, test_deserialize_string); + return s; +} + +int +main (int argc, char **argv) +{ + int nf; + + Suite *s = gst_value_suite (); + SRunner *sr = srunner_create (s); + + gst_check_init (&argc, &argv); + + srunner_run_all (sr, CK_NORMAL); + nf = srunner_ntests_failed (sr); + srunner_free (sr); + + return nf; +} diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 847befdf33..89e82dbfea 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -23,6 +23,7 @@ clean-local: done TESTS = $(top_builddir)/tools/gst-register \ + gst/gst \ gst/gstbin \ gst/gstbuffer \ gst/gstbus \ @@ -34,6 +35,7 @@ TESTS = $(top_builddir)/tools/gst-register \ gst/gstpad \ gst/gstsystemclock \ gst/gsttag \ + gst/gstvalue \ pipelines/simple_launch_lines \ pipelines/cleanup \ gst-libs/gdp diff --git a/tests/check/gst/gstvalue.c b/tests/check/gst/gstvalue.c new file mode 100644 index 0000000000..9aeaac6234 --- /dev/null +++ b/tests/check/gst/gstvalue.c @@ -0,0 +1,143 @@ +/* GStreamer + * Copyright (C) <2004> David Schleef + * + * gstvalue.c: Unit tests for GstValue + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#include "../gstcheck.h" + + +START_TEST (test_deserialize_buffer) +{ + GValue value = { 0 }; + + g_value_init (&value, GST_TYPE_BUFFER); + fail_unless (gst_value_deserialize (&value, "1234567890abcdef")); +} + +END_TEST; + +START_TEST (test_string) +{ + gchar *try[] = { + "Dude", + "Hi, I'm a string", + "tüüüt!" + }; + gchar *tmp; + GValue v = { 0, }; + guint i; + + g_value_init (&v, G_TYPE_STRING); + for (i = 0; i < G_N_ELEMENTS (try); i++) { + g_value_set_string (&v, try[i]); + tmp = gst_value_serialize (&v); + fail_if (tmp == NULL, "couldn't serialize: %s\n", try[i]); + fail_unless (gst_value_deserialize (&v, tmp), + "couldn't deserialize: %s\n", tmp); + g_free (tmp); + + fail_unless (g_str_equal (g_value_get_string (&v), try[i]), + "\nserialized : %s\ndeserialized: %s", try[i], + g_value_get_string (&v)); + } + g_value_unset (&v); +} + +END_TEST; + +START_TEST (test_deserialize_string) +{ + struct + { + gchar *from; + gchar *to; + } tests[] = { + { + "", ""}, { + "\"\"", ""}, + /* FAILURES */ + { + "\"", NULL}, /* missing second quote */ + { + "\"Hello\\ World", NULL}, /* missing second quote */ + { + "\"\\", NULL}, /* quote at end, missing second quote */ + { + "\"\\0", NULL}, /* missing second quote */ + { + "\"\\0\"", NULL}, /* unfinished escaped character */ + { + "\" \"", NULL}, /* spaces must be escaped */ +#if 0 + /* FIXME 0.9: this test should fail, but it doesn't */ + { + "tüüt", NULL} /* string with special chars must be escaped */ +#endif + }; + guint i; + GValue v = { 0, }; + gboolean ret = TRUE; + + g_value_init (&v, G_TYPE_STRING); + for (i = 0; i < G_N_ELEMENTS (tests); i++) { + if (gst_value_deserialize (&v, tests[i].from)) { + fail_if (tests[i].to == NULL, + "I got %s instead of a failure", g_value_get_string (&v)); + fail_unless (g_str_equal (g_value_get_string (&v), tests[i].to), + "\nwanted: %s\ngot : %s", tests[i].to, g_value_get_string (&v)); + } else { + fail_if (tests[i].to != NULL, "failed, but wanted: %s", tests[i].to); + ret = FALSE; + } + } + g_value_unset (&v); +} + +END_TEST; + +Suite * +gst_value_suite (void) +{ + Suite *s = suite_create ("GstValue"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_deserialize_buffer); + tcase_add_test (tc_chain, test_string); + tcase_add_test (tc_chain, test_deserialize_string); + return s; +} + +int +main (int argc, char **argv) +{ + int nf; + + Suite *s = gst_value_suite (); + SRunner *sr = srunner_create (s); + + gst_check_init (&argc, &argv); + + srunner_run_all (sr, CK_NORMAL); + nf = srunner_ntests_failed (sr); + srunner_free (sr); + + return nf; +} diff --git a/tests/old/testsuite/Makefile.am b/tests/old/testsuite/Makefile.am index 1b285880d2..e50583c758 100644 --- a/tests/old/testsuite/Makefile.am +++ b/tests/old/testsuite/Makefile.am @@ -29,7 +29,7 @@ DIST_SUBDIRS = \ parse \ plugin refcounting schedulers states threads trigger -tests_pass = test_gst_init +tests_pass = tests_fail = tests_ignore = diff --git a/tests/old/testsuite/caps/Makefile.am b/tests/old/testsuite/caps/Makefile.am index d6fb78a90e..1616323ecc 100644 --- a/tests/old/testsuite/caps/Makefile.am +++ b/tests/old/testsuite/caps/Makefile.am @@ -16,7 +16,6 @@ tests_pass = \ caps \ value_compare \ value_intersect \ - value_serialize \ audioscale \ filtercaps \ eratosthenes \ diff --git a/tests/old/testsuite/caps/value_serialize.c b/tests/old/testsuite/caps/value_serialize.c deleted file mode 100644 index c621568c73..0000000000 --- a/tests/old/testsuite/caps/value_serialize.c +++ /dev/null @@ -1,125 +0,0 @@ -#include - -static void -test1 (void) -{ - GValue value = { 0 }; - gboolean ret; - - g_value_init (&value, GST_TYPE_BUFFER); - ret = gst_value_deserialize (&value, "1234567890abcdef"); - g_assert (ret); -} - -static gboolean -test_string_serialization (void) -{ - gchar *try[] = { - "Dude", - "Hi, I'm a string", - "tüüüt!" - }; - gchar *tmp; - GValue v = { 0, }; - guint i; - gboolean ret = TRUE; - - g_value_init (&v, G_TYPE_STRING); - for (i = 0; i < G_N_ELEMENTS (try); i++) { - g_value_set_string (&v, try[i]); - tmp = gst_value_serialize (&v); - if (!tmp) { - g_print ("couldn't serialize: %s\n", try[i]); - ret = FALSE; - continue; - } - if (!gst_value_deserialize (&v, tmp)) { - g_print ("couldn't deserialize: %s\n", tmp); - g_free (tmp); - ret = FALSE; - continue; - } - g_free (tmp); - if (!g_str_equal (g_value_get_string (&v), try[i])) { - g_print ("serialized : %s\n", try[i]); - g_print ("deserialized: %s\n", g_value_get_string (&v)); - ret = FALSE; - continue; - } - } - g_value_unset (&v); - return ret; - -} - -static gboolean -test_string_deserialization (void) -{ - struct - { - gchar *from; - gchar *to; - } tests[] = { - { - "", ""}, { - "\"\"", ""}, - /* FAILURES */ - { - "\"", NULL}, /* missing second quote */ - { - "\"Hello\\ World", NULL}, /* missing second quote */ - { - "\"\\", NULL}, /* quote at end, missing second quote */ - { - "\"\\0", NULL}, /* missing second quote */ - { - "\"\\0\"", NULL}, /* unfinished escaped character */ - { - "\" \"", NULL}, /* spaces must be escaped */ -#if 0 - /* FIXME 0.9: this test should fail, but it doesn't */ - { - "tüüt", NULL} /* string with special chars must be escaped */ -#endif - }; - guint i; - GValue v = { 0, }; - gboolean ret = TRUE; - - g_value_init (&v, G_TYPE_STRING); - for (i = 0; i < G_N_ELEMENTS (tests); i++) { - if (gst_value_deserialize (&v, tests[i].from)) { - if (tests[i].to == NULL) { - g_print ("should fail\n"); - g_print ("but got: %s\n", g_value_get_string (&v)); - ret = FALSE; - } else if (!g_str_equal (g_value_get_string (&v), tests[i].to)) { - g_print ("wanted: %s\n", tests[i].to); - g_print ("got : %s\n", g_value_get_string (&v)); - ret = FALSE; - } - } else { - if (tests[i].to != NULL) { - g_print ("failed\n"); - g_print ("but wanted: %s\n", tests[i].to); - ret = FALSE; - } - } - } - g_value_unset (&v); - return ret; -} - -int -main (int argc, char *argv[]) -{ - gboolean ret = TRUE; - - gst_init (&argc, &argv); - - test1 (); - ret &= test_string_serialization (); - ret &= test_string_deserialization (); - - return ret ? 0 : 1; -} diff --git a/tests/old/testsuite/test_gst_init.c b/tests/old/testsuite/test_gst_init.c deleted file mode 100644 index 3331c3def3..0000000000 --- a/tests/old/testsuite/test_gst_init.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -/* This tests that gst_init() doesn't segfault when passed two NULLs as - * parameters, and that it doesn't fail if gst_init() happens to get called - * a second time. */ -int -main (int argc, char *argv[]) -{ - gst_init (NULL, NULL); - gst_init (&argc, &argv); - - return 0; -} diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index 1b285880d2..e50583c758 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -29,7 +29,7 @@ DIST_SUBDIRS = \ parse \ plugin refcounting schedulers states threads trigger -tests_pass = test_gst_init +tests_pass = tests_fail = tests_ignore = diff --git a/testsuite/caps/Makefile.am b/testsuite/caps/Makefile.am index d6fb78a90e..1616323ecc 100644 --- a/testsuite/caps/Makefile.am +++ b/testsuite/caps/Makefile.am @@ -16,7 +16,6 @@ tests_pass = \ caps \ value_compare \ value_intersect \ - value_serialize \ audioscale \ filtercaps \ eratosthenes \ diff --git a/testsuite/caps/value_serialize.c b/testsuite/caps/value_serialize.c deleted file mode 100644 index c621568c73..0000000000 --- a/testsuite/caps/value_serialize.c +++ /dev/null @@ -1,125 +0,0 @@ -#include - -static void -test1 (void) -{ - GValue value = { 0 }; - gboolean ret; - - g_value_init (&value, GST_TYPE_BUFFER); - ret = gst_value_deserialize (&value, "1234567890abcdef"); - g_assert (ret); -} - -static gboolean -test_string_serialization (void) -{ - gchar *try[] = { - "Dude", - "Hi, I'm a string", - "tüüüt!" - }; - gchar *tmp; - GValue v = { 0, }; - guint i; - gboolean ret = TRUE; - - g_value_init (&v, G_TYPE_STRING); - for (i = 0; i < G_N_ELEMENTS (try); i++) { - g_value_set_string (&v, try[i]); - tmp = gst_value_serialize (&v); - if (!tmp) { - g_print ("couldn't serialize: %s\n", try[i]); - ret = FALSE; - continue; - } - if (!gst_value_deserialize (&v, tmp)) { - g_print ("couldn't deserialize: %s\n", tmp); - g_free (tmp); - ret = FALSE; - continue; - } - g_free (tmp); - if (!g_str_equal (g_value_get_string (&v), try[i])) { - g_print ("serialized : %s\n", try[i]); - g_print ("deserialized: %s\n", g_value_get_string (&v)); - ret = FALSE; - continue; - } - } - g_value_unset (&v); - return ret; - -} - -static gboolean -test_string_deserialization (void) -{ - struct - { - gchar *from; - gchar *to; - } tests[] = { - { - "", ""}, { - "\"\"", ""}, - /* FAILURES */ - { - "\"", NULL}, /* missing second quote */ - { - "\"Hello\\ World", NULL}, /* missing second quote */ - { - "\"\\", NULL}, /* quote at end, missing second quote */ - { - "\"\\0", NULL}, /* missing second quote */ - { - "\"\\0\"", NULL}, /* unfinished escaped character */ - { - "\" \"", NULL}, /* spaces must be escaped */ -#if 0 - /* FIXME 0.9: this test should fail, but it doesn't */ - { - "tüüt", NULL} /* string with special chars must be escaped */ -#endif - }; - guint i; - GValue v = { 0, }; - gboolean ret = TRUE; - - g_value_init (&v, G_TYPE_STRING); - for (i = 0; i < G_N_ELEMENTS (tests); i++) { - if (gst_value_deserialize (&v, tests[i].from)) { - if (tests[i].to == NULL) { - g_print ("should fail\n"); - g_print ("but got: %s\n", g_value_get_string (&v)); - ret = FALSE; - } else if (!g_str_equal (g_value_get_string (&v), tests[i].to)) { - g_print ("wanted: %s\n", tests[i].to); - g_print ("got : %s\n", g_value_get_string (&v)); - ret = FALSE; - } - } else { - if (tests[i].to != NULL) { - g_print ("failed\n"); - g_print ("but wanted: %s\n", tests[i].to); - ret = FALSE; - } - } - } - g_value_unset (&v); - return ret; -} - -int -main (int argc, char *argv[]) -{ - gboolean ret = TRUE; - - gst_init (&argc, &argv); - - test1 (); - ret &= test_string_serialization (); - ret &= test_string_deserialization (); - - return ret ? 0 : 1; -} diff --git a/testsuite/test_gst_init.c b/testsuite/test_gst_init.c deleted file mode 100644 index 3331c3def3..0000000000 --- a/testsuite/test_gst_init.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -/* This tests that gst_init() doesn't segfault when passed two NULLs as - * parameters, and that it doesn't fail if gst_init() happens to get called - * a second time. */ -int -main (int argc, char *argv[]) -{ - gst_init (NULL, NULL); - gst_init (&argc, &argv); - - return 0; -}