Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.git] / tests / check / elements / ac3parse.c
1 /*
2  * GStreamer
3  *
4  * unit test for ac3parse
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/x-ac3, framed=(boolean)false"
30 #define SINK_CAPS_TMPL  "audio/x-ac3, framed=(boolean)true"
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
46 static guint8 ac3_frame[512] = {
47   0x0b, 0x77, 0xb6, 0xa8, 0x10, 0x40, 0x2f, 0x84,
48   0x29, 0xcb, 0xfe, 0x75, 0x7c, 0xf9, 0xf3, 0xe7,
49   0xcf, 0x9f, 0x3e, 0x7c, 0xf9, 0xf3, 0xe7, 0xcf,
50   0x9f, 0x3e, 0x7c, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f,
51   0x3e, 0x7c, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 0x3e,
52   0x7c, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 0x3e, 0x7c,
53   0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 0x3e, 0x7c, 0xf9,
54   0xf3, 0xe7, 0xcf, 0x9f, 0x3e, 0x7c, 0xf9, 0xf3,
55   0xe7, 0xcf, 0x9f, 0x3e, 0x7c, 0xf9, 0xf3, 0xe7,
56   0xcf, 0x9f, 0x3e, 0x32, 0xd3, 0xff, 0xc0, 0x06,
57   0xe9, 0x40, 0x00, 0x6e, 0x94, 0x00, 0x06, 0xe9,
58   0x40, 0x00, 0x6e, 0x94, 0x00, 0x06, 0xe9, 0x40,
59   0x00, 0x6e, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00,
60   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61 };
62
63 static guint8 garbage_frame[] = {
64   0xff, 0xff, 0xff, 0xff, 0xff
65 };
66
67
68 GST_START_TEST (test_parse_normal)
69 {
70   gst_parser_test_normal (ac3_frame, sizeof (ac3_frame));
71 }
72
73 GST_END_TEST;
74
75
76 GST_START_TEST (test_parse_drain_single)
77 {
78   gst_parser_test_drain_single (ac3_frame, sizeof (ac3_frame));
79 }
80
81 GST_END_TEST;
82
83
84 GST_START_TEST (test_parse_drain_garbage)
85 {
86   gst_parser_test_drain_garbage (ac3_frame, sizeof (ac3_frame),
87       garbage_frame, sizeof (garbage_frame));
88 }
89
90 GST_END_TEST;
91
92
93 GST_START_TEST (test_parse_split)
94 {
95   gst_parser_test_split (ac3_frame, sizeof (ac3_frame));
96 }
97
98 GST_END_TEST;
99
100
101 GST_START_TEST (test_parse_skip_garbage)
102 {
103   gst_parser_test_skip_garbage (ac3_frame, sizeof (ac3_frame),
104       garbage_frame, sizeof (garbage_frame));
105 }
106
107 GST_END_TEST;
108
109
110 GST_START_TEST (test_parse_detect_stream)
111 {
112   gst_parser_test_output_caps (ac3_frame, sizeof (ac3_frame),
113       NULL, SINK_CAPS_TMPL ",channels=1,rate=48000,alignment=frame");
114 }
115
116 GST_END_TEST;
117
118
119 static Suite *
120 ac3parse_suite (void)
121 {
122   Suite *s = suite_create ("ac3parse");
123   TCase *tc_chain = tcase_create ("general");
124
125   suite_add_tcase (s, tc_chain);
126   tcase_add_test (tc_chain, test_parse_normal);
127   tcase_add_test (tc_chain, test_parse_drain_single);
128   tcase_add_test (tc_chain, test_parse_drain_garbage);
129   tcase_add_test (tc_chain, test_parse_split);
130   tcase_add_test (tc_chain, test_parse_skip_garbage);
131   tcase_add_test (tc_chain, test_parse_detect_stream);
132
133   return s;
134 }
135
136
137 /*
138  * TODO:
139  *   - Both push- and pull-modes need to be tested
140  *      * Pull-mode & EOS
141  */
142
143 int
144 main (int argc, char **argv)
145 {
146   int nf;
147
148   Suite *s = ac3parse_suite ();
149   SRunner *sr = srunner_create (s);
150
151   gst_check_init (&argc, &argv);
152
153   /* init test context */
154   ctx_factory = "ac3parse";
155   ctx_sink_template = &sinktemplate;
156   ctx_src_template = &srctemplate;
157
158   srunner_run_all (sr, CK_NORMAL);
159   nf = srunner_ntests_failed (sr);
160   srunner_free (sr);
161
162   return nf;
163 }