diff --git a/tests/check/elements/ac3parse.c b/tests/check/elements/ac3parse.c new file mode 100644 index 0000000000..03e8e1dc85 --- /dev/null +++ b/tests/check/elements/ac3parse.c @@ -0,0 +1,163 @@ +/* + * GStreamer + * + * unit test for ac3parse + * + * Copyright (C) 2008 Nokia Corporation. All rights reserved. + * + * Contact: Stefan Kost + * + * 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 +#include "parser.h" + +#define SRC_CAPS_TMPL "audio/x-ac3, framed=(boolean)false" +#define SINK_CAPS_TMPL "audio/x-ac3, framed=(boolean)true" + +GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (SINK_CAPS_TMPL) + ); + +GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (SRC_CAPS_TMPL) + ); + +/* some data */ + +static guint8 ac3_frame[512] = { + 0x0b, 0x77, 0xb6, 0xa8, 0x10, 0x40, 0x2f, 0x84, + 0x29, 0xcb, 0xfe, 0x75, 0x7c, 0xf9, 0xf3, 0xe7, + 0xcf, 0x9f, 0x3e, 0x7c, 0xf9, 0xf3, 0xe7, 0xcf, + 0x9f, 0x3e, 0x7c, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f, + 0x3e, 0x7c, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 0x3e, + 0x7c, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 0x3e, 0x7c, + 0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 0x3e, 0x7c, 0xf9, + 0xf3, 0xe7, 0xcf, 0x9f, 0x3e, 0x7c, 0xf9, 0xf3, + 0xe7, 0xcf, 0x9f, 0x3e, 0x7c, 0xf9, 0xf3, 0xe7, + 0xcf, 0x9f, 0x3e, 0x32, 0xd3, 0xff, 0xc0, 0x06, + 0xe9, 0x40, 0x00, 0x6e, 0x94, 0x00, 0x06, 0xe9, + 0x40, 0x00, 0x6e, 0x94, 0x00, 0x06, 0xe9, 0x40, + 0x00, 0x6e, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +static guint8 garbage_frame[] = { + 0xff, 0xff, 0xff, 0xff, 0xff +}; + + +GST_START_TEST (test_parse_normal) +{ + gst_parser_test_normal (ac3_frame, sizeof (ac3_frame)); +} + +GST_END_TEST; + + +GST_START_TEST (test_parse_drain_single) +{ + gst_parser_test_drain_single (ac3_frame, sizeof (ac3_frame)); +} + +GST_END_TEST; + + +GST_START_TEST (test_parse_drain_garbage) +{ + gst_parser_test_drain_garbage (ac3_frame, sizeof (ac3_frame), + garbage_frame, sizeof (garbage_frame)); +} + +GST_END_TEST; + + +GST_START_TEST (test_parse_split) +{ + gst_parser_test_split (ac3_frame, sizeof (ac3_frame)); +} + +GST_END_TEST; + + +GST_START_TEST (test_parse_skip_garbage) +{ + gst_parser_test_skip_garbage (ac3_frame, sizeof (ac3_frame), + garbage_frame, sizeof (garbage_frame)); +} + +GST_END_TEST; + + +GST_START_TEST (test_parse_detect_stream) +{ + gst_parser_test_output_caps (ac3_frame, sizeof (ac3_frame), + NULL, SINK_CAPS_TMPL ",channels=1,rate=48000"); +} + +GST_END_TEST; + + +static Suite * +ac3parse_suite (void) +{ + Suite *s = suite_create ("ac3parse"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_parse_normal); + tcase_add_test (tc_chain, test_parse_drain_single); + tcase_add_test (tc_chain, test_parse_drain_garbage); + tcase_add_test (tc_chain, test_parse_split); + tcase_add_test (tc_chain, test_parse_skip_garbage); + tcase_add_test (tc_chain, test_parse_detect_stream); + + return s; +} + + +/* + * TODO: + * - Both push- and pull-modes need to be tested + * * Pull-mode & EOS + */ + +int +main (int argc, char **argv) +{ + int nf; + + Suite *s = ac3parse_suite (); + SRunner *sr = srunner_create (s); + + gst_check_init (&argc, &argv); + + /* init test context */ + ctx_factory = "ac3parse"; + ctx_sink_template = &sinktemplate; + ctx_src_template = &srctemplate; + + srunner_run_all (sr, CK_NORMAL); + nf = srunner_ntests_failed (sr); + srunner_free (sr); + + return nf; +} diff --git a/tests/check/elements/mpegaudioparse.c b/tests/check/elements/mpegaudioparse.c new file mode 100644 index 0000000000..69a08640fc --- /dev/null +++ b/tests/check/elements/mpegaudioparse.c @@ -0,0 +1,172 @@ +/* + * GStreamer + * + * unit test for aacparse + * + * Copyright (C) 2008 Nokia Corporation. All rights reserved. + * + * Contact: Stefan Kost + * + * 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 +#include "parser.h" + +#define SRC_CAPS_TMPL "audio/mpeg, parsed=(boolean)false, mpegversion=(int)1" +#define SINK_CAPS_TMPL "audio/mpeg, parsed=(boolean)true, mpegversion=(int)1" + +GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (SINK_CAPS_TMPL) + ); + +GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (SRC_CAPS_TMPL) + ); + +const gchar *factory = "aacparse"; + +/* some data */ +static guint8 mp3_frame[384] = { + 0xff, 0xfb, 0x94, 0xc4, 0xff, 0x83, 0xc0, 0x00, + 0x01, 0xa4, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, + 0x34, 0x80, 0x00, 0x00, 0x04, 0x00, +}; + +static guint8 garbage_frame[] = { + 0xff, 0xff, 0xff, 0xff, 0xff +}; + + +GST_START_TEST (test_parse_normal) +{ + gst_parser_test_normal (mp3_frame, sizeof (mp3_frame)); +} + +GST_END_TEST; + + +GST_START_TEST (test_parse_drain_single) +{ + gst_parser_test_drain_single (mp3_frame, sizeof (mp3_frame)); +} + +GST_END_TEST; + + +GST_START_TEST (test_parse_drain_garbage) +{ + gst_parser_test_drain_garbage (mp3_frame, sizeof (mp3_frame), + garbage_frame, sizeof (garbage_frame)); +} + +GST_END_TEST; + + +GST_START_TEST (test_parse_split) +{ + gst_parser_test_split (mp3_frame, sizeof (mp3_frame)); +} + +GST_END_TEST; + + +GST_START_TEST (test_parse_skip_garbage) +{ + gst_parser_test_skip_garbage (mp3_frame, sizeof (mp3_frame), + garbage_frame, sizeof (garbage_frame)); +} + +GST_END_TEST; + + +#define structure_get_int(s,f) \ + (g_value_get_int(gst_structure_get_value(s,f))) +#define fail_unless_structure_field_int_equals(s,field,num) \ + fail_unless_equals_int (structure_get_int(s,field), num) + +GST_START_TEST (test_parse_detect_stream) +{ + GstStructure *s; + GstCaps *caps; + + caps = gst_parser_test_get_output_caps (mp3_frame, sizeof (mp3_frame), NULL); + + fail_unless (caps != NULL); + + GST_LOG ("mpegaudio output caps: %" GST_PTR_FORMAT, caps); + s = gst_caps_get_structure (caps, 0); + fail_unless (gst_structure_has_name (s, "audio/mpeg")); + fail_unless_structure_field_int_equals (s, "mpegversion", 1); + fail_unless_structure_field_int_equals (s, "layer", 3); + fail_unless_structure_field_int_equals (s, "channels", 1); + fail_unless_structure_field_int_equals (s, "rate", 48000); + + gst_caps_unref (caps); +} + +GST_END_TEST; + + +static Suite * +mpegaudioparse_suite (void) +{ + Suite *s = suite_create ("mpegaudioparse"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_parse_normal); + tcase_add_test (tc_chain, test_parse_drain_single); + tcase_add_test (tc_chain, test_parse_drain_garbage); + tcase_add_test (tc_chain, test_parse_split); + tcase_add_test (tc_chain, test_parse_skip_garbage); + tcase_add_test (tc_chain, test_parse_detect_stream); + + return s; +} + + +/* + * TODO: + * - Both push- and pull-modes need to be tested + * * Pull-mode & EOS + */ + +int +main (int argc, char **argv) +{ + int nf; + + Suite *s = mpegaudioparse_suite (); + SRunner *sr = srunner_create (s); + + gst_check_init (&argc, &argv); + + /* init test context */ + ctx_factory = "mpegaudioparse"; + ctx_sink_template = &sinktemplate; + ctx_src_template = &srctemplate; + + srunner_run_all (sr, CK_NORMAL); + nf = srunner_ntests_failed (sr); + srunner_free (sr); + + return nf; +}