upload tizen1.0 source
[framework/multimedia/gst-plugins-good0.10.git] / tests / check / elements / mpegaudioparse.c
1 /*
2  * GStreamer
3  *
4  * unit test for aacparse
5  *
6  * Copyright (C) 2008 Nokia Corporation. All rights reserved.
7  *
8  * Contact: Stefan Kost <stefan.kost@nokia.com>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  */
25
26 #include <gst/check/gstcheck.h>
27 #include "parser.h"
28
29 #define SRC_CAPS_TMPL   "audio/mpeg, parsed=(boolean)false, mpegversion=(int)1"
30 #define SINK_CAPS_TMPL  "audio/mpeg, parsed=(boolean)true, mpegversion=(int)1"
31
32 GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
33     GST_PAD_SINK,
34     GST_PAD_ALWAYS,
35     GST_STATIC_CAPS (SINK_CAPS_TMPL)
36     );
37
38 GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
39     GST_PAD_SRC,
40     GST_PAD_ALWAYS,
41     GST_STATIC_CAPS (SRC_CAPS_TMPL)
42     );
43
44 const gchar *factory = "aacparse";
45
46 /* some data */
47 static guint8 mp3_frame[384] = {
48   0xff, 0xfb, 0x94, 0xc4, 0xff, 0x83, 0xc0, 0x00,
49   0x01, 0xa4, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
50   0x34, 0x80, 0x00, 0x00, 0x04, 0x00,
51 };
52
53 static guint8 garbage_frame[] = {
54   0xff, 0xff, 0xff, 0xff, 0xff
55 };
56
57
58 GST_START_TEST (test_parse_normal)
59 {
60   gst_parser_test_normal (mp3_frame, sizeof (mp3_frame));
61 }
62
63 GST_END_TEST;
64
65
66 GST_START_TEST (test_parse_drain_single)
67 {
68   gst_parser_test_drain_single (mp3_frame, sizeof (mp3_frame));
69 }
70
71 GST_END_TEST;
72
73
74 GST_START_TEST (test_parse_drain_garbage)
75 {
76   gst_parser_test_drain_garbage (mp3_frame, sizeof (mp3_frame),
77       garbage_frame, sizeof (garbage_frame));
78 }
79
80 GST_END_TEST;
81
82
83 GST_START_TEST (test_parse_split)
84 {
85   gst_parser_test_split (mp3_frame, sizeof (mp3_frame));
86 }
87
88 GST_END_TEST;
89
90
91 GST_START_TEST (test_parse_skip_garbage)
92 {
93   gst_parser_test_skip_garbage (mp3_frame, sizeof (mp3_frame),
94       garbage_frame, sizeof (garbage_frame));
95 }
96
97 GST_END_TEST;
98
99
100 #define structure_get_int(s,f) \
101     (g_value_get_int(gst_structure_get_value(s,f)))
102 #define fail_unless_structure_field_int_equals(s,field,num) \
103     fail_unless_equals_int (structure_get_int(s,field), num)
104
105 GST_START_TEST (test_parse_detect_stream)
106 {
107   GstStructure *s;
108   GstCaps *caps;
109
110   caps = gst_parser_test_get_output_caps (mp3_frame, sizeof (mp3_frame), NULL);
111
112   fail_unless (caps != NULL);
113
114   GST_LOG ("mpegaudio output caps: %" GST_PTR_FORMAT, caps);
115   s = gst_caps_get_structure (caps, 0);
116   fail_unless (gst_structure_has_name (s, "audio/mpeg"));
117   fail_unless_structure_field_int_equals (s, "mpegversion", 1);
118   fail_unless_structure_field_int_equals (s, "layer", 3);
119   fail_unless_structure_field_int_equals (s, "channels", 1);
120   fail_unless_structure_field_int_equals (s, "rate", 48000);
121
122   gst_caps_unref (caps);
123 }
124
125 GST_END_TEST;
126
127
128 static Suite *
129 mpegaudioparse_suite (void)
130 {
131   Suite *s = suite_create ("mpegaudioparse");
132   TCase *tc_chain = tcase_create ("general");
133
134   suite_add_tcase (s, tc_chain);
135   tcase_add_test (tc_chain, test_parse_normal);
136   tcase_add_test (tc_chain, test_parse_drain_single);
137   tcase_add_test (tc_chain, test_parse_drain_garbage);
138   tcase_add_test (tc_chain, test_parse_split);
139   tcase_add_test (tc_chain, test_parse_skip_garbage);
140   tcase_add_test (tc_chain, test_parse_detect_stream);
141
142   return s;
143 }
144
145
146 /*
147  * TODO:
148  *   - Both push- and pull-modes need to be tested
149  *      * Pull-mode & EOS
150  */
151
152 int
153 main (int argc, char **argv)
154 {
155   int nf;
156
157   Suite *s = mpegaudioparse_suite ();
158   SRunner *sr = srunner_create (s);
159
160   gst_check_init (&argc, &argv);
161
162   /* init test context */
163   ctx_factory = "mpegaudioparse";
164   ctx_sink_template = &sinktemplate;
165   ctx_src_template = &srctemplate;
166
167   srunner_run_all (sr, CK_NORMAL);
168   nf = srunner_ntests_failed (sr);
169   srunner_free (sr);
170
171   return nf;
172 }