check/Makefile.am: add a .check target for running the check

Original commit message from CVS:

* check/Makefile.am:
add a .check target for running the check
* check/gst-libs/controller.c: (GST_START_TEST):
cosmetic fixups
* check/gst/gstbuffer.c: (GST_START_TEST), (gst_test_suite):
complete checks for gstbuffer; would be nice if I could get the
gcov stuff to work so I can see if I actually completed gstbuffer.c
* check/gstcheck.h:
add ASSERT_BUFFER_REFCOUNT
This commit is contained in:
Thomas Vander Stichele 2005-08-14 22:29:07 +00:00
parent f8a767a3e0
commit 5dee6ba2e8
8 changed files with 292 additions and 27 deletions

View file

@ -1,3 +1,15 @@
2005-08-15 Thomas Vander Stichele <thomas at apestaart dot org>
* check/Makefile.am:
add a .check target for running the check
* check/gst-libs/controller.c: (GST_START_TEST):
cosmetic fixups
* check/gst/gstbuffer.c: (GST_START_TEST), (gst_test_suite):
complete checks for gstbuffer; would be nice if I could get the
gcov stuff to work so I can see if I actually completed gstbuffer.c
* check/gstcheck.h:
add ASSERT_BUFFER_REFCOUNT
2005-08-13 Tim-Philipp Müller <tim at centricular dot net>
* docs/gst/gstreamer-sections.txt:
@ -21,10 +33,10 @@
* docs/gst/gstreamer-docs.sgml:
* docs/libs/gstreamer-libs-docs.sgml:
added deprecation and since indexes
added deprecation and since indexes
* libs/gst/controller/gst-controller.c:
* libs/gst/controller/gst-helper.c:
added since tags
added since tags
2005-08-11 Wim Taymans <wim@fluendo.com>

View file

@ -105,6 +105,12 @@ check-local-disabled:
@true
endif
# run any given test by running make test.check
%.check: % $(CHECK_REGISTRY)
@$(TESTS_ENVIRONMENT) \
$*
# valgrind any given test by running make test.valgrind
%.valgrind: % $(CHECK_REGISTRY)
@$(TESTS_ENVIRONMENT) \

View file

@ -22,30 +22,68 @@
#include "../gstcheck.h"
GST_START_TEST (test_caps)
{
GstBuffer *buffer;
GstCaps *caps, *caps2;
buffer = gst_buffer_new_and_alloc (4);
caps = gst_caps_from_string ("audio/x-raw-int");
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
fail_unless (gst_buffer_get_caps (buffer) == NULL);
gst_buffer_set_caps (buffer, caps);
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
fail_unless (gst_buffer_get_caps (buffer) == caps);
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
caps2 = gst_caps_from_string ("audio/x-raw-float");
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 1);
gst_buffer_set_caps (buffer, caps2);
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 2);
gst_buffer_set_caps (buffer, NULL);
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 1);
/* clean up, with caps2 still set as caps */
gst_buffer_set_caps (buffer, caps2);
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 2);
gst_buffer_unref (buffer);
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 1);
gst_caps_unref (caps);
gst_caps_unref (caps2);
}
GST_END_TEST;
GST_START_TEST (test_subbuffer)
{
GstBuffer *buffer, *sub;
int rc;
buffer = gst_buffer_new_and_alloc (4);
memset (GST_BUFFER_DATA (buffer), 0, 4);
sub = gst_buffer_create_sub (buffer, 1, 2);
fail_if (sub == NULL, "create_sub of buffer returned NULL");
fail_unless (GST_BUFFER_SIZE (sub) == 2, "subbuffer has wrong size");
fail_unless (memcmp (GST_BUFFER_DATA (buffer) + 1, GST_BUFFER_DATA (sub),
2) == 0, "subbuffer contains the wrong data");
rc = GST_MINI_OBJECT_REFCOUNT_VALUE (buffer);
fail_unless (rc == 2, "parent refcount is %d instead of 3", rc);
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 2);
ASSERT_BUFFER_REFCOUNT (sub, "subbuffer", 1);
/* clean up */
gst_buffer_unref (sub);
gst_buffer_unref (buffer);
}
GST_END_TEST
GST_END_TEST;
GST_START_TEST (test_is_span_fast)
{
GstBuffer *buffer, *sub1, *sub2;
@ -72,18 +110,98 @@ GST_START_TEST (test_is_span_fast)
gst_buffer_unref (sub2);
gst_buffer_unref (buffer);
}
GST_END_TEST Suite *
GST_END_TEST;
GST_START_TEST (test_span)
{
GstBuffer *buffer, *sub1, *sub2, *span;
buffer = gst_buffer_new_and_alloc (4);
memcpy (GST_BUFFER_DATA (buffer), "data", 4);
ASSERT_CRITICAL (gst_buffer_span (NULL, 1, NULL, 2));
ASSERT_CRITICAL (gst_buffer_span (buffer, 1, NULL, 2));
ASSERT_CRITICAL (gst_buffer_span (NULL, 1, buffer, 2));
ASSERT_CRITICAL (gst_buffer_span (buffer, 0, buffer, 10));
sub1 = gst_buffer_create_sub (buffer, 0, 2);
fail_if (sub1 == NULL, "create_sub of buffer returned NULL");
sub2 = gst_buffer_create_sub (buffer, 2, 2);
fail_if (sub2 == NULL, "create_sub of buffer returned NULL");
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
/* span will create a new subbuffer from the parent */
span = gst_buffer_span (sub1, 0, sub2, 4);
fail_unless (GST_BUFFER_SIZE (span) == 4, "spanned buffer is wrong size");
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 4);
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
ASSERT_BUFFER_REFCOUNT (span, "span", 1);
fail_unless (memcmp (GST_BUFFER_DATA (span), "data", 4) == 0,
"spanned buffer contains the wrong data");
gst_buffer_unref (span);
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
/* span from non-contiguous buffers will create new buffers */
span = gst_buffer_span (sub2, 0, sub1, 4);
fail_unless (GST_BUFFER_SIZE (span) == 4, "spanned buffer is wrong size");
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
ASSERT_BUFFER_REFCOUNT (span, "span", 1);
fail_unless (memcmp (GST_BUFFER_DATA (span), "tada", 4) == 0,
"spanned buffer contains the wrong data");
gst_buffer_unref (span);
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
/* span with different sizes */
span = gst_buffer_span (sub1, 1, sub2, 3);
fail_unless (GST_BUFFER_SIZE (span) == 3, "spanned buffer is wrong size");
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 4);
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
ASSERT_BUFFER_REFCOUNT (span, "span", 1);
fail_unless (memcmp (GST_BUFFER_DATA (span), "ata", 3) == 0,
"spanned buffer contains the wrong data");
gst_buffer_unref (span);
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
span = gst_buffer_span (sub2, 0, sub1, 3);
fail_unless (GST_BUFFER_SIZE (span) == 3, "spanned buffer is wrong size");
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
ASSERT_BUFFER_REFCOUNT (span, "span", 1);
fail_unless (memcmp (GST_BUFFER_DATA (span), "tad", 3) == 0,
"spanned buffer contains the wrong data");
gst_buffer_unref (span);
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
/* clean up */
gst_buffer_unref (sub1);
gst_buffer_unref (sub2);
gst_buffer_unref (buffer);
}
GST_END_TEST;
Suite *
gst_test_suite (void)
{
Suite *s = suite_create ("GstBuffer");
TCase *tc_chain = tcase_create ("general");
/* turn off timeout */
tcase_set_timeout (tc_chain, 60);
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_caps);
tcase_add_test (tc_chain, test_subbuffer);
tcase_add_test (tc_chain, test_is_span_fast);
tcase_add_test (tc_chain, test_span);
return s;
}

View file

@ -170,6 +170,9 @@ G_STMT_START { \
#define ASSERT_CAPS_REFCOUNT(caps, name, value) \
ASSERT_MINI_OBJECT_REFCOUNT(caps, name, value)
#define ASSERT_BUFFER_REFCOUNT(buffer, name, value) \
ASSERT_MINI_OBJECT_REFCOUNT(buffer, name, value)
#define ASSERT_MINI_OBJECT_REFCOUNT(caps, name, value) \
G_STMT_START { \
int rc; \

View file

@ -197,7 +197,6 @@ gst_buffer_new_and_alloc (guint size)
return newbuf;
}
/**
* gst_buffer_get_caps:
* @buffer: a #GstBuffer to get the caps of.
@ -328,12 +327,12 @@ gst_subbuffer_init (GTypeInstance * instance, gpointer g_class)
*
* Creates a sub-buffer from the parent at a given offset.
* This sub-buffer uses the actual memory space of the parent buffer.
* This function will copy the offset and timestamp field when the
* This function will copy the offset and timestamp field when the
* offset is 0, else they are set to _NONE.
* The duration field of the new buffer are set to GST_CLOCK_TIME_NONE.
*
* Returns: the new #GstBuffer, or NULL if there was an error.
*
*
* MT safe.
*/
GstBuffer *
@ -426,11 +425,11 @@ gst_buffer_is_span_fast (GstBuffer * buf1, GstBuffer * buf2)
*
* If the two source buffers are children of the same larger buffer,
* and are contiguous, the new buffer will be a child of the shared
* parent, and thus no copying is necessary. you can use
* parent, and thus no copying is necessary. you can use
* gst_buffer_is_span_fast() to determine if a memcpy will be needed.
*
* Returns: the new #GstBuffer that spans the two source buffers.
*
*
* MT safe.
*/
GstBuffer *

View file

@ -105,6 +105,12 @@ check-local-disabled:
@true
endif
# run any given test by running make test.check
%.check: % $(CHECK_REGISTRY)
@$(TESTS_ENVIRONMENT) \
$*
# valgrind any given test by running make test.valgrind
%.valgrind: % $(CHECK_REGISTRY)
@$(TESTS_ENVIRONMENT) \

View file

@ -22,30 +22,68 @@
#include "../gstcheck.h"
GST_START_TEST (test_caps)
{
GstBuffer *buffer;
GstCaps *caps, *caps2;
buffer = gst_buffer_new_and_alloc (4);
caps = gst_caps_from_string ("audio/x-raw-int");
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
fail_unless (gst_buffer_get_caps (buffer) == NULL);
gst_buffer_set_caps (buffer, caps);
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
fail_unless (gst_buffer_get_caps (buffer) == caps);
ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
caps2 = gst_caps_from_string ("audio/x-raw-float");
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 1);
gst_buffer_set_caps (buffer, caps2);
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 2);
gst_buffer_set_caps (buffer, NULL);
ASSERT_CAPS_REFCOUNT (caps, "caps", 1);
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 1);
/* clean up, with caps2 still set as caps */
gst_buffer_set_caps (buffer, caps2);
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 2);
gst_buffer_unref (buffer);
ASSERT_CAPS_REFCOUNT (caps2, "caps2", 1);
gst_caps_unref (caps);
gst_caps_unref (caps2);
}
GST_END_TEST;
GST_START_TEST (test_subbuffer)
{
GstBuffer *buffer, *sub;
int rc;
buffer = gst_buffer_new_and_alloc (4);
memset (GST_BUFFER_DATA (buffer), 0, 4);
sub = gst_buffer_create_sub (buffer, 1, 2);
fail_if (sub == NULL, "create_sub of buffer returned NULL");
fail_unless (GST_BUFFER_SIZE (sub) == 2, "subbuffer has wrong size");
fail_unless (memcmp (GST_BUFFER_DATA (buffer) + 1, GST_BUFFER_DATA (sub),
2) == 0, "subbuffer contains the wrong data");
rc = GST_MINI_OBJECT_REFCOUNT_VALUE (buffer);
fail_unless (rc == 2, "parent refcount is %d instead of 3", rc);
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 2);
ASSERT_BUFFER_REFCOUNT (sub, "subbuffer", 1);
/* clean up */
gst_buffer_unref (sub);
gst_buffer_unref (buffer);
}
GST_END_TEST
GST_END_TEST;
GST_START_TEST (test_is_span_fast)
{
GstBuffer *buffer, *sub1, *sub2;
@ -72,18 +110,98 @@ GST_START_TEST (test_is_span_fast)
gst_buffer_unref (sub2);
gst_buffer_unref (buffer);
}
GST_END_TEST Suite *
GST_END_TEST;
GST_START_TEST (test_span)
{
GstBuffer *buffer, *sub1, *sub2, *span;
buffer = gst_buffer_new_and_alloc (4);
memcpy (GST_BUFFER_DATA (buffer), "data", 4);
ASSERT_CRITICAL (gst_buffer_span (NULL, 1, NULL, 2));
ASSERT_CRITICAL (gst_buffer_span (buffer, 1, NULL, 2));
ASSERT_CRITICAL (gst_buffer_span (NULL, 1, buffer, 2));
ASSERT_CRITICAL (gst_buffer_span (buffer, 0, buffer, 10));
sub1 = gst_buffer_create_sub (buffer, 0, 2);
fail_if (sub1 == NULL, "create_sub of buffer returned NULL");
sub2 = gst_buffer_create_sub (buffer, 2, 2);
fail_if (sub2 == NULL, "create_sub of buffer returned NULL");
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
/* span will create a new subbuffer from the parent */
span = gst_buffer_span (sub1, 0, sub2, 4);
fail_unless (GST_BUFFER_SIZE (span) == 4, "spanned buffer is wrong size");
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 4);
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
ASSERT_BUFFER_REFCOUNT (span, "span", 1);
fail_unless (memcmp (GST_BUFFER_DATA (span), "data", 4) == 0,
"spanned buffer contains the wrong data");
gst_buffer_unref (span);
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
/* span from non-contiguous buffers will create new buffers */
span = gst_buffer_span (sub2, 0, sub1, 4);
fail_unless (GST_BUFFER_SIZE (span) == 4, "spanned buffer is wrong size");
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
ASSERT_BUFFER_REFCOUNT (span, "span", 1);
fail_unless (memcmp (GST_BUFFER_DATA (span), "tada", 4) == 0,
"spanned buffer contains the wrong data");
gst_buffer_unref (span);
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
/* span with different sizes */
span = gst_buffer_span (sub1, 1, sub2, 3);
fail_unless (GST_BUFFER_SIZE (span) == 3, "spanned buffer is wrong size");
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 4);
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
ASSERT_BUFFER_REFCOUNT (span, "span", 1);
fail_unless (memcmp (GST_BUFFER_DATA (span), "ata", 3) == 0,
"spanned buffer contains the wrong data");
gst_buffer_unref (span);
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
span = gst_buffer_span (sub2, 0, sub1, 3);
fail_unless (GST_BUFFER_SIZE (span) == 3, "spanned buffer is wrong size");
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
ASSERT_BUFFER_REFCOUNT (span, "span", 1);
fail_unless (memcmp (GST_BUFFER_DATA (span), "tad", 3) == 0,
"spanned buffer contains the wrong data");
gst_buffer_unref (span);
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 3);
/* clean up */
gst_buffer_unref (sub1);
gst_buffer_unref (sub2);
gst_buffer_unref (buffer);
}
GST_END_TEST;
Suite *
gst_test_suite (void)
{
Suite *s = suite_create ("GstBuffer");
TCase *tc_chain = tcase_create ("general");
/* turn off timeout */
tcase_set_timeout (tc_chain, 60);
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_caps);
tcase_add_test (tc_chain, test_subbuffer);
tcase_add_test (tc_chain, test_is_span_fast);
tcase_add_test (tc_chain, test_span);
return s;
}

View file

@ -170,6 +170,9 @@ G_STMT_START { \
#define ASSERT_CAPS_REFCOUNT(caps, name, value) \
ASSERT_MINI_OBJECT_REFCOUNT(caps, name, value)
#define ASSERT_BUFFER_REFCOUNT(buffer, name, value) \
ASSERT_MINI_OBJECT_REFCOUNT(buffer, name, value)
#define ASSERT_MINI_OBJECT_REFCOUNT(caps, name, value) \
G_STMT_START { \
int rc; \