2001-01-20 19:20:13 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
static gchar *_subject, *_category;
|
|
|
|
static gint _testnum = 0;
|
|
|
|
static gboolean _passed;
|
2004-03-13 15:27:01 +00:00
|
|
|
static gint _total_tests = 0, _passed_tests = 0;
|
2001-01-20 19:20:13 +00:00
|
|
|
static gint _random_size;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
void
|
|
|
|
tabpad (gchar * str, gint width)
|
|
|
|
{
|
2001-01-20 19:20:13 +00:00
|
|
|
int i;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
for (i = 0; i < width - strlen (str); i++)
|
|
|
|
fprintf (stderr, " ");
|
2001-01-20 19:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define TEST_SUBJECT(subject) fprintf(stderr,"Subject: %s\n",subject),_subject = subject
|
|
|
|
#define TEST_CATEGORY(category) fprintf(stderr,"\n\nCategory: %s\n",category)
|
|
|
|
|
|
|
|
#define TEST(test) fprintf(stderr,"Test %d: %s...\n",_testnum,test),_passed = TRUE
|
2005-12-06 19:29:15 +00:00
|
|
|
#define ASSERT(expr) G_STMT_START{ \
|
|
|
|
fprintf(stderr,"\t%s:",#expr);tabpad(#expr,50); \
|
|
|
|
if (!(expr)) { \
|
|
|
|
fprintf(stderr,"FAILED\n"); \
|
|
|
|
_passed = FALSE; \
|
|
|
|
} else { \
|
|
|
|
fprintf(stderr,"passed\n"); \
|
|
|
|
} \
|
2001-01-20 19:20:13 +00:00
|
|
|
}G_STMT_END;
|
2005-12-06 19:29:15 +00:00
|
|
|
#define ENDTEST() G_STMT_START{ \
|
|
|
|
_testnum++; \
|
|
|
|
if (_passed) { \
|
|
|
|
fprintf(stderr,"\tpassed.\n"); \
|
|
|
|
_passed_tests++; \
|
|
|
|
} else { \
|
|
|
|
fprintf(stderr,"\tFAILED.\n"); \
|
|
|
|
} \
|
|
|
|
_total_tests++; \
|
2001-01-20 19:20:13 +00:00
|
|
|
}G_STMT_END;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
void
|
|
|
|
SETUP_RANDOM_SIZE (void *random, gint size)
|
|
|
|
{
|
2001-01-20 19:20:13 +00:00
|
|
|
int i;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
if (random)
|
|
|
|
g_free (random);
|
2001-01-20 19:20:13 +00:00
|
|
|
_random_size = size;
|
2004-03-13 15:27:01 +00:00
|
|
|
random = g_malloc (_random_size);
|
|
|
|
for (i = 0; i < _random_size; i++)
|
|
|
|
((unsigned char *) random)[i] = i;
|
2001-01-20 19:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define SETUP_RANDOM(random,type) SETUP_RANDOM_SIZE(random,sizeof(type))
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gboolean
|
|
|
|
RANDOM_OK (void *random)
|
|
|
|
{
|
2001-01-20 19:20:13 +00:00
|
|
|
int i;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
for (i = 0; i < _random_size; i++) {
|
|
|
|
if (((unsigned char *) random)[i] != i) {
|
|
|
|
SETUP_RANDOM_SIZE (random, _random_size);
|
2001-01-20 19:20:13 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2001-01-20 19:20:13 +00:00
|
|
|
GstObject *object;
|
|
|
|
GstObject *parent;
|
|
|
|
GstObject *newparent;
|
|
|
|
GtkObject *gtkobject;
|
|
|
|
GstObject *curparent;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_init (&argc, &argv);
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST_SUBJECT ("GstObject");
|
2001-01-20 19:20:13 +00:00
|
|
|
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST_CATEGORY ("Creation");
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("create object");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
object = gst_object_new ();
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (object != NULL);
|
|
|
|
ASSERT (GST_IS_OBJECT (object));
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
g_free (object);
|
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
|
|
|
|
2002-03-19 04:10:13 +00:00
|
|
|
/* new category */
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST_CATEGORY ("Refcounting");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* category setup */
|
2004-03-13 15:27:01 +00:00
|
|
|
object = gst_object_new ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("new object");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (object->refcount == 1);
|
|
|
|
ASSERT (GTK_OBJECT_FLOATING (object) == TRUE);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("increment refcount");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_object_ref (object);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (object->refcount == 2);
|
|
|
|
ASSERT (GTK_OBJECT_FLOATING (object) == TRUE);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("sink object");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_object_sink (object);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (object->refcount == 1);
|
|
|
|
ASSERT (GTK_OBJECT_FLOATING (object) == FALSE);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("increment refcount after sink");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_object_ref (object);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (object->refcount == 2);
|
|
|
|
ASSERT (GTK_OBJECT_FLOATING (object) == FALSE);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("decrement refcount after sink");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_object_unref (object);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (object->refcount == 1);
|
|
|
|
ASSERT (GTK_OBJECT_FLOATING (object) == FALSE);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2002-03-19 04:10:13 +00:00
|
|
|
/* category cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
g_free (object);
|
2001-01-20 19:20:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-03-19 04:10:13 +00:00
|
|
|
/* new category */
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST_CATEGORY ("Parentage");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* category setup */
|
2004-03-13 15:27:01 +00:00
|
|
|
object = gst_object_new ();
|
|
|
|
parent = gst_object_new ();
|
|
|
|
newparent = gst_object_new ();
|
|
|
|
gtkobject = gtk_type_new (gtk_object_get_type ());
|
2002-03-19 04:10:13 +00:00
|
|
|
/* category assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (object != NULL);
|
|
|
|
ASSERT (object->refcount == 1);
|
|
|
|
ASSERT (object->parent == NULL);
|
|
|
|
ASSERT (parent != NULL);
|
|
|
|
ASSERT (newparent != NULL);
|
|
|
|
ASSERT (gtkobject != NULL);
|
|
|
|
ASSERT (!GST_IS_OBJECT (gtkobject));
|
|
|
|
|
|
|
|
TEST ("gst_object_set_parent: null object");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_object_set_parent (NULL, NULL);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (object->parent == NULL);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("gst_object_set_parent: invalid object");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_object_set_parent ((GstObject *) gtkobject, NULL);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (object->parent == NULL);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("gst_object_set_parent: null parent");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_object_set_parent (object, NULL);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (object->parent == NULL);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("gst_object_set_parent: invalid parent");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_object_set_parent (object, (GstObject *) gtkobject);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (object->parent == NULL);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("gst_object_set_parent: valid object, parent is object");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_object_set_parent (object, object);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (object->parent == NULL);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("gst_object_set_parent: valid object and parent");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_object_set_parent (object, parent);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (object->parent == parent);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("gst_object_set_parent: parent already set");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_object_set_parent (object, newparent);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (object->parent != newparent);
|
|
|
|
ASSERT (object->parent == parent);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
g_free (object);
|
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("gst_object_get_parent: null object");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
curparent = gst_object_get_parent (NULL);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (curparent == NULL);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("gst_object_get_parent: invalid object");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
curparent = gst_object_get_parent ((GstObject *) gtkobject);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (curparent == NULL);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("gst_object_get_parent: no parent");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
2004-03-13 15:27:01 +00:00
|
|
|
object = gst_object_new ();
|
2002-03-19 04:10:13 +00:00
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
curparent = gst_object_get_parent (object);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (curparent == NULL);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("gst_object_get_parent: valid parent");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_object_set_parent (object, parent);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
curparent = gst_object_get_parent (object);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
2004-03-13 15:27:01 +00:00
|
|
|
ASSERT (curparent == parent);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
g_free (object);
|
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("gst_object_unparent: null object");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_object_unparent (NULL);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
|
|
|
/* NONE - FIXME! */
|
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("gst_object_unparent: invalid object");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
|
|
|
/* action */
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_object_unparent ((GstObject *) gtkobject);
|
2002-03-19 04:10:13 +00:00
|
|
|
/* assertions */
|
|
|
|
/* NONE - FIXME! */
|
|
|
|
/* cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
ENDTEST ();
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
TEST ("gst_object_unparent: no parent");
|
2002-03-19 04:10:13 +00:00
|
|
|
/* setup */
|
2004-03-13 15:27:01 +00:00
|
|
|
object = gst_object_new ();
|
|
|
|
|
2001-01-20 19:20:13 +00:00
|
|
|
|
2002-03-19 04:10:13 +00:00
|
|
|
/* category cleanup */
|
2004-03-13 15:27:01 +00:00
|
|
|
g_free (object);
|
|
|
|
g_free (parent);
|
|
|
|
g_free (newparent);
|
|
|
|
g_free (gtkobject);
|
2001-01-20 19:20:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
fprintf (stderr, "\n\nTotal tests:\t%d\n", _total_tests);
|
|
|
|
fprintf (stderr, "Total passed:\t%d\n", _passed_tests);
|
|
|
|
fprintf (stderr, "Total FAILED:\t%d\n", _total_tests - _passed_tests);
|
2001-01-20 19:20:13 +00:00
|
|
|
}
|