tizen 2.0 init
[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 /* some data */
45 static guint8 mp3_frame[384] = {
46   0xff, 0xfb, 0x94, 0xc4, 0xff, 0x83, 0xc0, 0x00,
47   0x01, 0xa4, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
48   0x34, 0x80, 0x00, 0x00, 0x04, 0x00,
49 };
50
51 static guint8 garbage_frame[] = {
52   0xff, 0xff, 0xff, 0xff, 0xff
53 };
54
55
56 GST_START_TEST (test_parse_normal)
57 {
58   gst_parser_test_normal (mp3_frame, sizeof (mp3_frame));
59 }
60
61 GST_END_TEST;
62
63
64 GST_START_TEST (test_parse_drain_single)
65 {
66   gst_parser_test_drain_single (mp3_frame, sizeof (mp3_frame));
67 }
68
69 GST_END_TEST;
70
71
72 GST_START_TEST (test_parse_drain_garbage)
73 {
74   gst_parser_test_drain_garbage (mp3_frame, sizeof (mp3_frame),
75       garbage_frame, sizeof (garbage_frame));
76 }
77
78 GST_END_TEST;
79
80
81 GST_START_TEST (test_parse_split)
82 {
83   gst_parser_test_split (mp3_frame, sizeof (mp3_frame));
84 }
85
86 GST_END_TEST;
87
88
89 GST_START_TEST (test_parse_skip_garbage)
90 {
91   gst_parser_test_skip_garbage (mp3_frame, sizeof (mp3_frame),
92       garbage_frame, sizeof (garbage_frame));
93 }
94
95 GST_END_TEST;
96
97
98 #define structure_get_int(s,f) \
99     (g_value_get_int(gst_structure_get_value(s,f)))
100 #define fail_unless_structure_field_int_equals(s,field,num) \
101     fail_unless_equals_int (structure_get_int(s,field), num)
102
103 GST_START_TEST (test_parse_detect_stream)
104 {
105   GstStructure *s;
106   GstCaps *caps;
107
108   caps = gst_parser_test_get_output_caps (mp3_frame, sizeof (mp3_frame), NULL);
109
110   fail_unless (caps != NULL);
111
112   GST_LOG ("mpegaudio output caps: %" GST_PTR_FORMAT, caps);
113   s = gst_caps_get_structure (caps, 0);
114   fail_unless (gst_structure_has_name (s, "audio/mpeg"));
115   fail_unless_structure_field_int_equals (s, "mpegversion", 1);
116   fail_unless_structure_field_int_equals (s, "layer", 3);
117   fail_unless_structure_field_int_equals (s, "channels", 1);
118   fail_unless_structure_field_int_equals (s, "rate", 48000);
119
120   gst_caps_unref (caps);
121 }
122
123 GST_END_TEST;
124
125
126 static Suite *
127 mpegaudioparse_suite (void)
128 {
129   Suite *s = suite_create ("mpegaudioparse");
130   TCase *tc_chain = tcase_create ("general");
131
132   suite_add_tcase (s, tc_chain);
133   tcase_add_test (tc_chain, test_parse_normal);
134   tcase_add_test (tc_chain, test_parse_drain_single);
135   tcase_add_test (tc_chain, test_parse_drain_garbage);
136   tcase_add_test (tc_chain, test_parse_split);
137   tcase_add_test (tc_chain, test_parse_skip_garbage);
138   tcase_add_test (tc_chain, test_parse_detect_stream);
139
140   return s;
141 }
142
143
144 /*
145  * TODO:
146  *   - Both push- and pull-modes need to be tested
147  *      * Pull-mode & EOS
148  */
149
150 int
151 main (int argc, char **argv)
152 {
153   int nf;
154
155   Suite *s = mpegaudioparse_suite ();
156   SRunner *sr = srunner_create (s);
157
158   gst_check_init (&argc, &argv);
159
160   /* init test context */
161   ctx_factory = "mpegaudioparse";
162   ctx_sink_template = &sinktemplate;
163   ctx_src_template = &srctemplate;
164
165   srunner_run_all (sr, CK_NORMAL);
166   nf = srunner_ntests_failed (sr);
167   srunner_free (sr);
168
169   return nf;
170 }