Commit 71ad50ae authored by Brendan Long's avatar Brendan Long

Merge pull request #134 from gdesmott/tests

Add tests infrastructure
parents 2eecaf5b e8dda01c
......@@ -32,4 +32,7 @@ test/*.log
test/*.out
test/tmp
bug
test-driver
tests/*.log
tests/*.trs
tests/test-util
SUBDIRS = src tests
EXTRA_DIST = autogen.sh
# Note: plugindir is set in configure
# src folder
##############################################################################
# TODO: change libgstplugin.la to something else, e.g. libmysomething.la #
##############################################################################
plugin_LTLIBRARIES = src/libgstdlnasrc.la
##############################################################################
# TODO: for the next set of variables, name the prefix if you named the .la, #
# e.g. libmysomething.la => libmysomething_la_SOURCES #
# libmysomething_la_CFLAGS #
# libmysomething_la_LIBADD #
# libmysomething_la_LDFLAGS #
##############################################################################
# sources used to compile this plug-in
src_libgstdlnasrc_la_SOURCES = src/gstdlnasrc.c src/gstdlnasrc.h
# compiler and linker flags used to compile this plugin, set in configure.ac
src_libgstdlnasrc_la_CFLAGS = $(GST_CFLAGS) $(SOUP_CFLAGS)
src_libgstdlnasrc_la_CXXFLAGS = $(GST_CFLAGS)
src_libgstdlnasrc_la_LIBADD = $(GST_LIBS) $(SOUP_LIBS)
src_libgstdlnasrc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
src_libgstdlnasrc_la_LIBTOOLFLAGS = --tag=disable-static
# headers we need but don't want installed
noinst_HEADERS = src/gstdlnasrc.h
\ No newline at end of file
......@@ -97,6 +97,9 @@ dnl set proper LDFLAGS for plugins
GST_PLUGIN_LDFLAGS='-module -avoid-version -export-symbols-regex [_]*\(gst_\|Gst\|GST_\).*'
AC_SUBST(GST_PLUGIN_LDFLAGS)
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([
Makefile \
src/Makefile \
tests/Makefile])
AC_OUTPUT
# Note: plugindir is set in configure
##############################################################################
# TODO: change libgstplugin.la to something else, e.g. libmysomething.la #
##############################################################################
plugin_LTLIBRARIES = libgstdlnasrc.la
##############################################################################
# TODO: for the next set of variables, name the prefix if you named the .la, #
# e.g. libmysomething.la => libmysomething_la_SOURCES #
# libmysomething_la_CFLAGS #
# libmysomething_la_LIBADD #
# libmysomething_la_LDFLAGS #
##############################################################################
# sources used to compile this plug-in
sources = \
gstdlnasrc.c \
gstdlnasrc.h \
util.c \
util.h
AM_CFLAGS = $(GST_CFLAGS) $(SOUP_CFLAGS)
# compiler and linker flags used to compile this plugin, set in configure.ac
libgstdlnasrc_la_SOURCES = $(sources)
libgstdlnasrc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstdlnasrc_la_LIBADD = $(GST_LIBS) $(SOUP_LIBS)
libgstdlnasrc_la_LIBTOOLFLAGS = --tag=disable-static
# convenient internal lib used for tests
libdlnasrc_internal_la_SOURCES = $(sources)
noinst_LTLIBRARIES = libdlnasrc-internal.la
# headers we need but don't want installed
noinst_HEADERS = \
gstdlnasrc.h \
util.h
......@@ -35,9 +35,9 @@
#include <stdio.h>
#include <gst/gst.h>
#include <glib-object.h>
#include <libsoup/soup.h>
#include "gstdlnasrc.h"
#include "util.h"
enum
{
......@@ -325,11 +325,6 @@ static gboolean dlna_src_parse_byte_range (GstDlnaSrc * dlna_src,
const gchar * field_str, gint header_idx, guint64 * start_byte,
guint64 * end_byte, guint64 * total_bytes);
static gboolean
dlna_src_parse_npt_range (GstDlnaSrc * dlna_src, const gchar * npt_str,
gchar ** start_str, gchar ** stop_str, gchar ** total_str,
guint64 * start, guint64 * stop, guint64 * total);
static gboolean dlna_src_is_change_valid (GstDlnaSrc * dlna_src, gfloat rate,
GstFormat format, guint64 start,
GstSeekType start_type, guint64 stop, GstSeekType stop_type);
......@@ -340,9 +335,6 @@ static gboolean dlna_src_adjust_http_src_headers (GstDlnaSrc * dlna_src,
gfloat rate, GstFormat format, guint64 start, guint64 stop,
guint32 new_seqnum);
static gboolean dlna_src_npt_to_nanos (GstDlnaSrc * dlna_src, gchar * string,
guint64 * media_time_nanos);
static gboolean
dlna_src_convert_bytes_to_npt_nanos (GstDlnaSrc * dlna_src, guint64 bytes,
guint64 * npt_nanos);
......@@ -2688,91 +2680,6 @@ dlna_src_parse_byte_range (GstDlnaSrc * dlna_src,
return TRUE;
}
/**
* Parse the npt (normal play time) range which may be contained in the following headers:
*
* TimeSeekRange.dlna.org : npt=335.1-336.1/40445.4 bytes=1539686400-1540210688/304857907200
*
* availableSeekRange.dlna.org: 0 npt=0:00:00.000-0:00:48.716 bytes=0-5219255 cleartextbytes=0-5219255
*
* @param dlna_src this element instance
* @param field_str string containing HEAD response field header and value
* @param start_str starting time in string form read from header response field
* @param stop_str end time in string form read from header response field
* @param total_str total time in string form read from header response field
* @param start starting time in nanoseconds converted from string representation
* @param stop end time in nanoseconds converted from string representation
* @param total total time in nanoseconds converted from string representation
*
* @return returns TRUE
*/
static gboolean
dlna_src_parse_npt_range (GstDlnaSrc * dlna_src, const gchar * field_str,
gchar ** start_str, gchar ** stop_str, gchar ** total_str,
guint64 * start, guint64 * stop, guint64 * total)
{
gchar *header = NULL;
gchar *header_value = NULL;
gint ret_code = 0;
gchar tmp1[32] = { 0 };
gchar tmp2[32] = { 0 };
gchar tmp3[32] = { 0 };
/* Extract NPT portion of header value */
header =
strstr (g_ascii_strup (field_str, strlen (field_str)),
RANGE_HEADERS[HEADER_INDEX_NPT]);
if (header)
header_value = strstr (header, "=");
if (header_value)
header_value++;
else {
GST_WARNING_OBJECT (dlna_src,
"Problems parsing npt from HEAD response field header value: %s",
field_str);
return FALSE;
}
/* Determine if npt string includes total */
if (strstr (header_value, "/")) {
/* Extract start and end and total NPT */
if ((ret_code =
sscanf (header_value, "%31[^-]-%31[^/]/%31s %*s", tmp1, tmp2,
tmp3)) != 3) {
GST_WARNING_OBJECT (dlna_src,
"Problems parsing NPT from HEAD response field header %s, value: %s, retcode: %d, tmp: %s, %s, %s",
field_str, header_value, ret_code, tmp1, tmp2, tmp3);
return FALSE;
}
g_free (*total_str);
*total_str = g_strdup (tmp3);
if (strcmp (*total_str, "*") != 0)
if (!dlna_src_npt_to_nanos (dlna_src, *total_str, total))
return FALSE;
} else {
/* Extract start and end (there is no total) NPT */
if ((ret_code = sscanf (header_value, "%31[^-]-%31s %*s", tmp1, tmp2)) != 2) {
GST_WARNING_OBJECT (dlna_src,
"Problems parsing NPT from HEAD response field header %s, value: %s, retcode: %d, tmp: %s, %s",
field_str, header_value, ret_code, tmp1, tmp2);
return FALSE;
}
}
g_free (*start_str);
*start_str = g_strdup (tmp1);
if (!dlna_src_npt_to_nanos (dlna_src, *start_str, start))
return FALSE;
g_free (*stop_str);
*stop_str = g_strdup (tmp2);
if (!dlna_src_npt_to_nanos (dlna_src, *stop_str, stop))
return FALSE;
return TRUE;
}
/**
* Extract values from content features header in HEAD Response
*
......@@ -3751,59 +3658,6 @@ overflow:
return FALSE;
}
/**
* Convert supplied string which represents normal play time (npt) into
* nanoseconds. The format of NPT is as follows:
*
* npt time = npt sec | npt hhmmss
*
* npt sec = 1*DIGIT [ "." 1*3DIGIT ]
* npthhmmss = npthh":"nptmm":"nptss["."1*3DIGIT]
* npthh = 1*DIGIT ; any positive number
* nptmm = 1*2DIGIT ; 0-59
* nptss = 1*2DIGIT ; 0-59
*
* @param dlna_src this element, needed for logging
* @param string normal play time string to convert
* @param media_time_nanos npt string value converted into nanoseconds
*
* @return true if no problems encountered, false otherwise
*/
static gboolean
dlna_src_npt_to_nanos (GstDlnaSrc * dlna_src, gchar * string,
guint64 * media_time_nanos)
{
gboolean ret = FALSE;
guint hours = 0;
guint mins = 0;
float secs = 0.;
if (sscanf (string, "%u:%u:%f", &hours, &mins, &secs) == 3) {
/* Long form */
*media_time_nanos =
((hours * 60 * 60 * 1000) + (mins * 60 * 1000) +
(secs * 1000)) * 1000000L;
ret = TRUE;
GST_LOG_OBJECT (dlna_src,
"Convert npt str %s hr=%d:mn=%d:s=%f into nanosecs: %"
G_GUINT64_FORMAT, string, hours, mins, secs, *media_time_nanos);
} else if (sscanf (string, "%f", &secs) == 1) {
/* Short form */
*media_time_nanos = (secs * 1000) * 1000000L;
ret = TRUE;
GST_LOG_OBJECT (dlna_src,
"Convert npt str %s secs=%f into nanosecs: %"
G_GUINT64_FORMAT, string, secs, *media_time_nanos);
} else {
GST_ERROR_OBJECT (dlna_src,
"Problems converting npt str into nanosecs: %s", string);
}
return ret;
}
/**
* Formats given nanoseconds into string which represents normal play time (npt).
* The format of NPT is as follows:
......@@ -3832,7 +3686,6 @@ dlna_src_nanos_to_npt (GstDlnaSrc * dlna_src, guint64 media_time_nanos,
g_string_append_printf (npt_str, "%d:%02d:%02.3f", hours, minutes, seconds);
}
/* entry point to initialize the plug-in
* initialize the plug-in itself
* register the element factories and other features
......
......@@ -28,6 +28,7 @@
#include <gst/gst.h>
#include <gst/base/gstbasesrc.h>
#include <libsoup/soup.h>
G_BEGIN_DECLS
......
/* Copyright (C) 2013 Cable Television Laboratories, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CABLE TELEVISION LABS INC. OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include <stdio.h>
#include <string.h>
#include "util.h"
/**
* Convert supplied string which represents normal play time (npt) into
* nanoseconds. The format of NPT is as follows:
*
* npt time = npt sec | npt hhmmss
*
* npt sec = 1*DIGIT [ "." 1*3DIGIT ]
* npthhmmss = npthh":"nptmm":"nptss["."1*3DIGIT]
* npthh = 1*DIGIT ; any positive number
* nptmm = 1*2DIGIT ; 0-59
* nptss = 1*2DIGIT ; 0-59
*
* @param dlna_src this element, needed for logging
* @param string normal play time string to convert
* @param media_time_nanos npt string value converted into nanoseconds
*
* @return true if no problems encountered, false otherwise
*/
static gboolean
dlna_src_npt_to_nanos (GstDlnaSrc * dlna_src, gchar * string,
guint64 * media_time_nanos)
{
gboolean ret = FALSE;
guint hours = 0;
guint mins = 0;
float secs = 0.;
if (sscanf (string, "%u:%u:%f", &hours, &mins, &secs) == 3) {
/* Long form */
*media_time_nanos =
((hours * 60 * 60 * 1000) + (mins * 60 * 1000) +
(secs * 1000)) * 1000000L;
ret = TRUE;
GST_LOG_OBJECT (dlna_src,
"Convert npt str %s hr=%d:mn=%d:s=%f into nanosecs: %"
G_GUINT64_FORMAT, string, hours, mins, secs, *media_time_nanos);
} else if (sscanf (string, "%f", &secs) == 1) {
/* Short form */
*media_time_nanos = (secs * 1000) * 1000000L;
ret = TRUE;
GST_LOG_OBJECT (dlna_src,
"Convert npt str %s secs=%f into nanosecs: %"
G_GUINT64_FORMAT, string, secs, *media_time_nanos);
} else {
GST_ERROR_OBJECT (dlna_src,
"Problems converting npt str into nanosecs: %s", string);
}
return ret;
}
/**
* Parse the npt (normal play time) range which may be contained in the following headers:
*
* TimeSeekRange.dlna.org : npt=335.1-336.1/40445.4 bytes=1539686400-1540210688/304857907200
*
* availableSeekRange.dlna.org: 0 npt=0:00:00.000-0:00:48.716 bytes=0-5219255 cleartextbytes=0-5219255
*
* @param dlna_src this element instance
* @param field_str string containing HEAD response field header and value
* @param start_str starting time in string form read from header response field
* @param stop_str end time in string form read from header response field
* @param total_str total time in string form read from header response field
* @param start starting time in nanoseconds converted from string representation
* @param stop end time in nanoseconds converted from string representation
* @param total total time in nanoseconds converted from string representation
*
* @return returns TRUE
*/
gboolean
dlna_src_parse_npt_range (GstDlnaSrc * dlna_src, const gchar * field_str,
gchar ** start_str, gchar ** stop_str, gchar ** total_str,
guint64 * start, guint64 * stop, guint64 * total)
{
gchar *header = NULL;
gchar *header_value = NULL;
gint ret_code = 0;
gchar tmp1[32] = { 0 };
gchar tmp2[32] = { 0 };
gchar tmp3[32] = { 0 };
/* Init output variables */
g_free (*start_str);
g_free (*stop_str);
g_free (*total_str);
*start_str = NULL;
*stop_str = NULL;
*total_str = NULL;
*start = 0;
*stop = 0;
*total = 0;
/* Extract NPT portion of header value */
header =
strstr (g_ascii_strup (field_str, strlen (field_str)), "NPT");
if (header)
header_value = strstr (header, "=");
if (header_value)
header_value++;
else {
GST_WARNING_OBJECT (dlna_src,
"Problems parsing npt from HEAD response field header value: %s",
field_str);
return FALSE;
}
/* Determine if npt string includes total */
if (strstr (header_value, "/")) {
/* Extract start and end and total NPT */
if ((ret_code =
sscanf (header_value, "%31[^-]-%31[^/]/%31s %*s", tmp1, tmp2,
tmp3)) != 3) {
GST_WARNING_OBJECT (dlna_src,
"Problems parsing NPT from HEAD response field header %s, value: %s, retcode: %d, tmp: %s, %s, %s",
field_str, header_value, ret_code, tmp1, tmp2, tmp3);
return FALSE;
}
*total_str = g_strdup (tmp3);
if (strcmp (*total_str, "*") != 0)
if (!dlna_src_npt_to_nanos (dlna_src, *total_str, total))
return FALSE;
} else {
/* Extract start and end (there is no total) NPT */
if ((ret_code = sscanf (header_value, "%31[^-]-%31s %*s", tmp1, tmp2)) != 2) {
GST_WARNING_OBJECT (dlna_src,
"Problems parsing NPT from HEAD response field header %s, value: %s, retcode: %d, tmp: %s, %s",
field_str, header_value, ret_code, tmp1, tmp2);
return FALSE;
}
}
*start_str = g_strdup (tmp1);
if (!dlna_src_npt_to_nanos (dlna_src, *start_str, start))
return FALSE;
*stop_str = g_strdup (tmp2);
if (!dlna_src_npt_to_nanos (dlna_src, *stop_str, stop))
return FALSE;
return TRUE;
}
/* Copyright (C) 2013 Cable Television Laboratories, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CABLE TELEVISION LABS INC. OR ITS
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __GST_DLNA_SRC_UTIL_H__
#define __GST_DLNA_SRC_UTIL_H__
#include "gstdlnasrc.h"
gboolean dlna_src_parse_npt_range (GstDlnaSrc * dlna_src,
const gchar * field_str, gchar ** start_str, gchar ** stop_str,
gchar ** total_str, guint64 * start, guint64 * stop, guint64 * total);
#endif /* __GST_DLNA_SRC_UTIL_H__ */
programs_list = \
test-util
AM_CFLAGS = \
-I${top_srcdir}/src -I${top_builddir}/src \
$(GST_CFLAGS) $(SOUP_CFLAGS)
AM_LDFLAGS = \
$(GST_LIBS) \
$(SOUP_LIBS) \
$(GST_PLUGIN_LDFLAGS)
LDADD = \
$(top_builddir)/src/libdlnasrc-internal.la
noinst_PROGRAMS = $(programs_list)
TESTS = $(programs_list)
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <glib.h>
#include "util.h"
static void
do_test_parse_ntp_range (const gchar *field, const gchar *expected_start_str,
const gchar *expected_stop_str, const gchar *expected_total_str,
gint64 expected_start, gint64 expected_stop, gint64 expected_total)
{
gchar *start_str = NULL, *stop_str = NULL, *total_str = NULL;
guint64 start, stop, total;
g_assert (dlna_src_parse_npt_range (NULL, field,
&start_str, &stop_str, &total_str, &start, &stop, &total));
g_assert_cmpstr (start_str, ==, expected_start_str);
g_assert_cmpstr (stop_str, ==, expected_stop_str);
g_assert_cmpstr (total_str, ==, expected_total_str);
g_assert_cmpuint (start, ==, expected_start);
g_assert_cmpuint (stop, ==, expected_stop);
g_assert_cmpuint (total, ==, expected_total);
g_free (start_str);
g_free (stop_str);
g_free (total_str);
}
static void
test_parse_ntp_range (void)
{
do_test_parse_ntp_range ("TimeSeekRange.dlna.org : npt=335.1-336.1/40445.4 bytes=1539686400-1540210688/304857907200",
"335.1", "336.1", "40445.4", 335099985920, 336099999744, 40445400842240);
do_test_parse_ntp_range ("availableSeekRange.dlna.org: 0 npt=0:00:00.000-0:00:48.716 bytes=0-5219255 cleartextbytes=0-5219255",
"0:00:00.000", "0:00:48.716", NULL, 0, 48716001280, 0);
}
int
main (int argc,
char **argv)
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/util/parse-ntp-range", test_parse_ntp_range);
return g_test_run ();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment