Blame tests/check/elements/ac3parse.c

Packit 1f69a5
/*
Packit 1f69a5
 * GStreamer
Packit 1f69a5
 *
Packit 1f69a5
 * unit test for ac3parse
Packit 1f69a5
 *
Packit 1f69a5
 * Copyright (C) 2008 Nokia Corporation. All rights reserved.
Packit 1f69a5
 *
Packit 1f69a5
 * Contact: Stefan Kost <stefan.kost@nokia.com>
Packit 1f69a5
 *
Packit 1f69a5
 * This library is free software; you can redistribute it and/or
Packit 1f69a5
 * modify it under the terms of the GNU Library General Public
Packit 1f69a5
 * License as published by the Free Software Foundation; either
Packit 1f69a5
 * version 2 of the License, or (at your option) any later version.
Packit 1f69a5
 *
Packit 1f69a5
 * This library is distributed in the hope that it will be useful,
Packit 1f69a5
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 1f69a5
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 1f69a5
 * Library General Public License for more details.
Packit 1f69a5
 *
Packit 1f69a5
 * You should have received a copy of the GNU Library General Public
Packit 1f69a5
 * License along with this library; if not, write to the
Packit 1f69a5
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 1f69a5
 * Boston, MA 02110-1301, USA.
Packit 1f69a5
 */
Packit 1f69a5
Packit 1f69a5
#include <gst/check/gstcheck.h>
Packit 1f69a5
#include "parser.h"
Packit 1f69a5
Packit 1f69a5
#define SRC_CAPS_TMPL   "audio/x-ac3, framed=(boolean)false"
Packit 1f69a5
#define SINK_CAPS_TMPL  "audio/x-ac3, framed=(boolean)true"
Packit 1f69a5
Packit 1f69a5
GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
Packit 1f69a5
    GST_PAD_SINK,
Packit 1f69a5
    GST_PAD_ALWAYS,
Packit 1f69a5
    GST_STATIC_CAPS (SINK_CAPS_TMPL)
Packit 1f69a5
    );
Packit 1f69a5
Packit 1f69a5
GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
Packit 1f69a5
    GST_PAD_SRC,
Packit 1f69a5
    GST_PAD_ALWAYS,
Packit 1f69a5
    GST_STATIC_CAPS (SRC_CAPS_TMPL)
Packit 1f69a5
    );
Packit 1f69a5
Packit 1f69a5
/* some data */
Packit 1f69a5
Packit 1f69a5
static guint8 ac3_frame[512] = {
Packit 1f69a5
  0x0b, 0x77, 0xb6, 0xa8, 0x10, 0x40, 0x2f, 0x84,
Packit 1f69a5
  0x29, 0xcb, 0xfe, 0x75, 0x7c, 0xf9, 0xf3, 0xe7,
Packit 1f69a5
  0xcf, 0x9f, 0x3e, 0x7c, 0xf9, 0xf3, 0xe7, 0xcf,
Packit 1f69a5
  0x9f, 0x3e, 0x7c, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f,
Packit 1f69a5
  0x3e, 0x7c, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 0x3e,
Packit 1f69a5
  0x7c, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 0x3e, 0x7c,
Packit 1f69a5
  0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 0x3e, 0x7c, 0xf9,
Packit 1f69a5
  0xf3, 0xe7, 0xcf, 0x9f, 0x3e, 0x7c, 0xf9, 0xf3,
Packit 1f69a5
  0xe7, 0xcf, 0x9f, 0x3e, 0x7c, 0xf9, 0xf3, 0xe7,
Packit 1f69a5
  0xcf, 0x9f, 0x3e, 0x32, 0xd3, 0xff, 0xc0, 0x06,
Packit 1f69a5
  0xe9, 0x40, 0x00, 0x6e, 0x94, 0x00, 0x06, 0xe9,
Packit 1f69a5
  0x40, 0x00, 0x6e, 0x94, 0x00, 0x06, 0xe9, 0x40,
Packit 1f69a5
  0x00, 0x6e, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00,
Packit 1f69a5
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Packit 1f69a5
};
Packit 1f69a5
Packit 1f69a5
static guint8 garbage_frame[] = {
Packit 1f69a5
  0xff, 0xff, 0xff, 0xff, 0xff
Packit 1f69a5
};
Packit 1f69a5
Packit 1f69a5
Packit 1f69a5
GST_START_TEST (test_parse_normal)
Packit 1f69a5
{
Packit 1f69a5
  gst_parser_test_normal (ac3_frame, sizeof (ac3_frame));
Packit 1f69a5
}
Packit 1f69a5
Packit 1f69a5
GST_END_TEST;
Packit 1f69a5
Packit 1f69a5
Packit 1f69a5
GST_START_TEST (test_parse_drain_single)
Packit 1f69a5
{
Packit 1f69a5
  gst_parser_test_drain_single (ac3_frame, sizeof (ac3_frame));
Packit 1f69a5
}
Packit 1f69a5
Packit 1f69a5
GST_END_TEST;
Packit 1f69a5
Packit 1f69a5
Packit 1f69a5
GST_START_TEST (test_parse_drain_garbage)
Packit 1f69a5
{
Packit 1f69a5
  gst_parser_test_drain_garbage (ac3_frame, sizeof (ac3_frame),
Packit 1f69a5
      garbage_frame, sizeof (garbage_frame));
Packit 1f69a5
}
Packit 1f69a5
Packit 1f69a5
GST_END_TEST;
Packit 1f69a5
Packit 1f69a5
Packit 1f69a5
GST_START_TEST (test_parse_split)
Packit 1f69a5
{
Packit 1f69a5
  gst_parser_test_split (ac3_frame, sizeof (ac3_frame));
Packit 1f69a5
}
Packit 1f69a5
Packit 1f69a5
GST_END_TEST;
Packit 1f69a5
Packit 1f69a5
Packit 1f69a5
GST_START_TEST (test_parse_skip_garbage)
Packit 1f69a5
{
Packit 1f69a5
  gst_parser_test_skip_garbage (ac3_frame, sizeof (ac3_frame),
Packit 1f69a5
      garbage_frame, sizeof (garbage_frame));
Packit 1f69a5
}
Packit 1f69a5
Packit 1f69a5
GST_END_TEST;
Packit 1f69a5
Packit 1f69a5
Packit 1f69a5
GST_START_TEST (test_parse_detect_stream)
Packit 1f69a5
{
Packit 1f69a5
  gst_parser_test_output_caps (ac3_frame, sizeof (ac3_frame),
Packit 1f69a5
      NULL, SINK_CAPS_TMPL ",channels=1,rate=48000,alignment=frame");
Packit 1f69a5
}
Packit 1f69a5
Packit 1f69a5
GST_END_TEST;
Packit 1f69a5
Packit 1f69a5
Packit 1f69a5
static Suite *
Packit 1f69a5
ac3parse_suite (void)
Packit 1f69a5
{
Packit 1f69a5
  Suite *s = suite_create ("ac3parse");
Packit 1f69a5
  TCase *tc_chain = tcase_create ("general");
Packit 1f69a5
Packit 1f69a5
  /* init test context */
Packit 1f69a5
  ctx_factory = "ac3parse";
Packit 1f69a5
  ctx_sink_template = &sinktemplate;
Packit 1f69a5
  ctx_src_template = &srctemplate;
Packit 1f69a5
Packit 1f69a5
  suite_add_tcase (s, tc_chain);
Packit 1f69a5
  tcase_add_test (tc_chain, test_parse_normal);
Packit 1f69a5
  tcase_add_test (tc_chain, test_parse_drain_single);
Packit 1f69a5
  tcase_add_test (tc_chain, test_parse_drain_garbage);
Packit 1f69a5
  tcase_add_test (tc_chain, test_parse_split);
Packit 1f69a5
  tcase_add_test (tc_chain, test_parse_skip_garbage);
Packit 1f69a5
  tcase_add_test (tc_chain, test_parse_detect_stream);
Packit 1f69a5
Packit 1f69a5
  return s;
Packit 1f69a5
}
Packit 1f69a5
Packit 1f69a5
Packit 1f69a5
/*
Packit 1f69a5
 * TODO:
Packit 1f69a5
 *   - Both push- and pull-modes need to be tested
Packit 1f69a5
 *      * Pull-mode & EOS
Packit 1f69a5
 */
Packit 1f69a5
GST_CHECK_MAIN (ac3parse);