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., 51 Franklin St, Fifth Floor,
23  * Boston, MA 02110-1301, 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 
GST_START_TEST(test_parse_normal)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 
GST_START_TEST(test_parse_drain_single)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 
GST_START_TEST(test_parse_drain_garbage)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 
GST_START_TEST(test_parse_split)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 
GST_START_TEST(test_parse_skip_garbage)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 
GST_START_TEST(test_parse_detect_stream)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 *
ac3parse_suite(void)120 ac3parse_suite (void)
121 {
122   Suite *s = suite_create ("ac3parse");
123   TCase *tc_chain = tcase_create ("general");
124 
125   /* init test context */
126   ctx_factory = "ac3parse";
127   ctx_sink_template = &sinktemplate;
128   ctx_src_template = &srctemplate;
129 
130   suite_add_tcase (s, tc_chain);
131   tcase_add_test (tc_chain, test_parse_normal);
132   tcase_add_test (tc_chain, test_parse_drain_single);
133   tcase_add_test (tc_chain, test_parse_drain_garbage);
134   tcase_add_test (tc_chain, test_parse_split);
135   tcase_add_test (tc_chain, test_parse_skip_garbage);
136   tcase_add_test (tc_chain, test_parse_detect_stream);
137 
138   return s;
139 }
140 
141 
142 /*
143  * TODO:
144  *   - Both push- and pull-modes need to be tested
145  *      * Pull-mode & EOS
146  */
147 GST_CHECK_MAIN (ac3parse);
148