Blame tests/check/elements/audiotestsrc.c

Packit 971217
/* GStreamer
Packit 971217
 *
Packit 971217
 * unit test for audiotestsrc
Packit 971217
 *
Packit 971217
 * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
Packit 971217
 *
Packit 971217
 * This library is free software; you can redistribute it and/or
Packit 971217
 * modify it under the terms of the GNU Library General Public
Packit 971217
 * License as published by the Free Software Foundation; either
Packit 971217
 * version 2 of the License, or (at your option) any later version.
Packit 971217
 *
Packit 971217
 * This library is distributed in the hope that it will be useful,
Packit 971217
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 971217
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 971217
 * Library General Public License for more details.
Packit 971217
 *
Packit 971217
 * You should have received a copy of the GNU Library General Public
Packit 971217
 * License along with this library; if not, write to the
Packit 971217
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 971217
 * Boston, MA 02110-1301, USA.
Packit 971217
 */
Packit 971217
Packit 971217
#ifdef HAVE_CONFIG_H
Packit 971217
#include "config.h"
Packit 971217
#endif
Packit 971217
Packit 971217
#include <gst/check/gstcheck.h>
Packit 971217
#include <gst/audio/audio.h>
Packit 971217
Packit 971217
/* For ease of programming we use globals to keep refs for our floating
Packit 971217
 * src and sink pads we create; otherwise we always have to do get_pad,
Packit 971217
 * get_peer, and then remove references in every test function */
Packit 971217
static GstPad *mysinkpad;
Packit 971217
Packit 971217
Packit 971217
#define CAPS_TEMPLATE_STRING            \
Packit 971217
    "audio/x-raw, "                     \
Packit 971217
    "format = (string) "GST_AUDIO_NE(S16)", "   \
Packit 971217
    "channels = (int) 1, "              \
Packit 971217
    "rate = (int) [ 1,  MAX ]"
Packit 971217
Packit 971217
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
Packit 971217
    GST_PAD_SINK,
Packit 971217
    GST_PAD_ALWAYS,
Packit 971217
    GST_STATIC_CAPS (CAPS_TEMPLATE_STRING)
Packit 971217
    );
Packit 971217
Packit 971217
static GstElement *
Packit 971217
setup_audiotestsrc (void)
Packit 971217
{
Packit 971217
  GstElement *audiotestsrc;
Packit 971217
Packit 971217
  GST_DEBUG ("setup_audiotestsrc");
Packit 971217
  audiotestsrc = gst_check_setup_element ("audiotestsrc");
Packit 971217
  mysinkpad = gst_check_setup_sink_pad (audiotestsrc, &sinktemplate);
Packit 971217
  gst_pad_set_active (mysinkpad, TRUE);
Packit 971217
Packit 971217
  return audiotestsrc;
Packit 971217
}
Packit 971217
Packit 971217
static void
Packit 971217
cleanup_audiotestsrc (GstElement * audiotestsrc)
Packit 971217
{
Packit 971217
  GST_DEBUG ("cleanup_audiotestsrc");
Packit 971217
Packit 971217
  g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
Packit 971217
  g_list_free (buffers);
Packit 971217
  buffers = NULL;
Packit 971217
Packit 971217
  gst_pad_set_active (mysinkpad, FALSE);
Packit 971217
  gst_check_teardown_sink_pad (audiotestsrc);
Packit 971217
  gst_check_teardown_element (audiotestsrc);
Packit 971217
}
Packit 971217
Packit 971217
GST_START_TEST (test_all_waves)
Packit 971217
{
Packit 971217
  GstElement *audiotestsrc;
Packit 971217
  GObjectClass *oclass;
Packit 971217
  GParamSpec *property;
Packit 971217
  GEnumValue *values;
Packit 971217
  guint j = 0;
Packit 971217
Packit 971217
  audiotestsrc = setup_audiotestsrc ();
Packit 971217
  oclass = G_OBJECT_GET_CLASS (audiotestsrc);
Packit 971217
  property = g_object_class_find_property (oclass, "wave");
Packit 971217
  fail_unless (G_IS_PARAM_SPEC_ENUM (property));
Packit 971217
  values = G_ENUM_CLASS (g_type_class_ref (property->value_type))->values;
Packit 971217
Packit 971217
Packit 971217
  while (values[j].value_name) {
Packit 971217
    GST_DEBUG_OBJECT (audiotestsrc, "testing wave %s", values[j].value_name);
Packit 971217
    g_object_set (audiotestsrc, "wave", values[j].value, NULL);
Packit 971217
Packit 971217
    fail_unless (gst_element_set_state (audiotestsrc,
Packit 971217
            GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
Packit 971217
        "could not set to playing");
Packit 971217
Packit 971217
    g_mutex_lock (&check_mutex);
Packit 971217
    while (g_list_length (buffers) < 10)
Packit 971217
      g_cond_wait (&check_cond, &check_mutex);
Packit 971217
    g_mutex_unlock (&check_mutex);
Packit 971217
Packit 971217
    gst_element_set_state (audiotestsrc, GST_STATE_READY);
Packit 971217
Packit 971217
    g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
Packit 971217
    g_list_free (buffers);
Packit 971217
    buffers = NULL;
Packit 971217
    ++j;
Packit 971217
  }
Packit 971217
Packit 971217
  /* cleanup */
Packit 971217
  cleanup_audiotestsrc (audiotestsrc);
Packit 971217
}
Packit 971217
Packit 971217
GST_END_TEST;
Packit 971217
Packit 971217
static Suite *
Packit 971217
audiotestsrc_suite (void)
Packit 971217
{
Packit 971217
  Suite *s = suite_create ("audiotestsrc");
Packit 971217
  TCase *tc_chain = tcase_create ("general");
Packit 971217
Packit 971217
  suite_add_tcase (s, tc_chain);
Packit 971217
  tcase_add_test (tc_chain, test_all_waves);
Packit 971217
Packit 971217
  return s;
Packit 971217
}
Packit 971217
Packit 971217
GST_CHECK_MAIN (audiotestsrc);