mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
added first hack at testing suite design
Original commit message from CVS: added first hack at testing suite design
This commit is contained in:
parent
5c27fa2ac4
commit
cfb7276682
3 changed files with 400 additions and 0 deletions
3
docs/random/omega/testing/Makefile
Normal file
3
docs/random/omega/testing/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
|||
gstobject: gstobject.c
|
||||
libtool gcc -o gstobject gstobject.c -I../../../.. ../../../../gst/libgst.la \
|
||||
`gtk-config --cflags --libs` `xml-config --cflags --libs`
|
302
docs/random/omega/testing/gstobject.c
Normal file
302
docs/random/omega/testing/gstobject.c
Normal file
|
@ -0,0 +1,302 @@
|
|||
#include <gst/gst.h>
|
||||
|
||||
static gchar *_subject, *_category;
|
||||
static gint _testnum = 0;
|
||||
static gboolean _passed;
|
||||
static gint _total_tests = 0,_passed_tests = 0;
|
||||
static gint _random_size;
|
||||
|
||||
void tabpad(gchar *str,gint width) {
|
||||
int i;
|
||||
for (i=0;i<width-strlen(str);i++)
|
||||
fprintf(stderr," ");
|
||||
}
|
||||
|
||||
#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
|
||||
#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"); \
|
||||
} \
|
||||
}G_STMT_END;
|
||||
#define ENDTEST() G_STMT_START{ \
|
||||
_testnum++; \
|
||||
if (_passed) { \
|
||||
fprintf(stderr,"\tpassed.\n"); \
|
||||
_passed_tests++; \
|
||||
} else { \
|
||||
fprintf(stderr,"\tFAILED.\n"); \
|
||||
} \
|
||||
_total_tests++; \
|
||||
}G_STMT_END;
|
||||
|
||||
void SETUP_RANDOM_SIZE(void *random,gint size) {
|
||||
int i;
|
||||
if (random) g_free(random);
|
||||
_random_size = size;
|
||||
random = g_malloc(_random_size);
|
||||
for (i=0;i<_random_size;i++)
|
||||
((unsigned char *)random)[i] = i;
|
||||
}
|
||||
|
||||
#define SETUP_RANDOM(random,type) SETUP_RANDOM_SIZE(random,sizeof(type))
|
||||
|
||||
gboolean RANDOM_OK(void *random) {
|
||||
int i;
|
||||
for (i=0;i<_random_size;i++) {
|
||||
if (((unsigned char *)random)[i] != i) {
|
||||
SETUP_RANDOM_SIZE(random,_random_size);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[]) {
|
||||
GstObject *object;
|
||||
GstObject *parent;
|
||||
GstObject *newparent;
|
||||
GtkObject *gtkobject;
|
||||
GstObject *curparent;
|
||||
|
||||
gst_init(&argc,&argv);
|
||||
|
||||
TEST_SUBJECT("GstObject");
|
||||
|
||||
|
||||
TEST_CATEGORY("Creation");
|
||||
|
||||
TEST("create object");
|
||||
// setup
|
||||
// action
|
||||
object = gst_object_new();
|
||||
// assertions
|
||||
ASSERT(object != NULL);
|
||||
ASSERT(GST_IS_OBJECT(object));
|
||||
// cleanup
|
||||
g_free(object);
|
||||
ENDTEST();
|
||||
|
||||
|
||||
// new category
|
||||
TEST_CATEGORY("Refcounting");
|
||||
// category setup
|
||||
object = gst_object_new();
|
||||
|
||||
TEST("new object");
|
||||
// setup
|
||||
// action
|
||||
// assertions
|
||||
ASSERT(object->refcount == 1);
|
||||
ASSERT(GTK_OBJECT_FLOATING(object) == TRUE);
|
||||
// cleanup
|
||||
ENDTEST();
|
||||
|
||||
TEST("increment refcount");
|
||||
// setup
|
||||
// action
|
||||
gst_object_ref(object);
|
||||
// assertions
|
||||
ASSERT(object->refcount == 2);
|
||||
ASSERT(GTK_OBJECT_FLOATING(object) == TRUE);
|
||||
// cleanup
|
||||
ENDTEST();
|
||||
|
||||
TEST("sink object");
|
||||
// setup
|
||||
// action
|
||||
gst_object_sink(object);
|
||||
// assertions
|
||||
ASSERT(object->refcount == 1);
|
||||
ASSERT(GTK_OBJECT_FLOATING(object) == FALSE);
|
||||
// cleanup
|
||||
ENDTEST();
|
||||
|
||||
TEST("increment refcount after sink");
|
||||
// setup
|
||||
// action
|
||||
gst_object_ref(object);
|
||||
// assertions
|
||||
ASSERT(object->refcount == 2);
|
||||
ASSERT(GTK_OBJECT_FLOATING(object) == FALSE);
|
||||
// cleanup
|
||||
ENDTEST();
|
||||
|
||||
TEST("decrement refcount after sink");
|
||||
// setup
|
||||
// action
|
||||
gst_object_unref(object);
|
||||
// assertions
|
||||
ASSERT(object->refcount == 1);
|
||||
ASSERT(GTK_OBJECT_FLOATING(object) == FALSE);
|
||||
// cleanup
|
||||
ENDTEST();
|
||||
|
||||
// category cleanup
|
||||
g_free(object);
|
||||
|
||||
|
||||
|
||||
// new category
|
||||
TEST_CATEGORY("Parentage");
|
||||
// category setup
|
||||
object = gst_object_new();
|
||||
parent = gst_object_new();
|
||||
newparent = gst_object_new();
|
||||
gtkobject = gtk_type_new(gtk_object_get_type());
|
||||
// category assertions
|
||||
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");
|
||||
// setup
|
||||
// action
|
||||
gst_object_set_parent(NULL,NULL);
|
||||
// assertions
|
||||
ASSERT(object->parent == NULL);
|
||||
// cleanup
|
||||
ENDTEST();
|
||||
|
||||
TEST("gst_object_set_parent: invalid object");
|
||||
// setup
|
||||
// action
|
||||
gst_object_set_parent((GstObject*)gtkobject,NULL);
|
||||
// assertions
|
||||
ASSERT(object->parent == NULL);
|
||||
// cleanup
|
||||
ENDTEST();
|
||||
|
||||
TEST("gst_object_set_parent: null parent");
|
||||
// setup
|
||||
// action
|
||||
gst_object_set_parent(object,NULL);
|
||||
// assertions
|
||||
ASSERT(object->parent == NULL);
|
||||
// cleanup
|
||||
ENDTEST();
|
||||
|
||||
TEST("gst_object_set_parent: invalid parent");
|
||||
// setup
|
||||
// action
|
||||
gst_object_set_parent(object,(GstObject*)gtkobject);
|
||||
// assertions
|
||||
ASSERT(object->parent == NULL);
|
||||
// cleanup
|
||||
ENDTEST();
|
||||
|
||||
TEST("gst_object_set_parent: valid object, parent is object");
|
||||
// setup
|
||||
// action
|
||||
gst_object_set_parent(object,object);
|
||||
// assertions
|
||||
ASSERT(object->parent == NULL);
|
||||
// cleanup
|
||||
ENDTEST();
|
||||
|
||||
TEST("gst_object_set_parent: valid object and parent");
|
||||
// setup
|
||||
// action
|
||||
gst_object_set_parent(object,parent);
|
||||
// assertions
|
||||
ASSERT(object->parent == parent);
|
||||
// cleanup
|
||||
ENDTEST();
|
||||
|
||||
TEST("gst_object_set_parent: parent already set");
|
||||
// setup
|
||||
// action
|
||||
gst_object_set_parent(object,newparent);
|
||||
// assertions
|
||||
ASSERT(object->parent != newparent);
|
||||
ASSERT(object->parent == parent);
|
||||
// cleanup
|
||||
g_free(object);
|
||||
ENDTEST();
|
||||
|
||||
|
||||
TEST("gst_object_get_parent: null object");
|
||||
// setup
|
||||
// action
|
||||
curparent = gst_object_get_parent(NULL);
|
||||
// assertions
|
||||
ASSERT(curparent == NULL);
|
||||
// cleanup
|
||||
ENDTEST();
|
||||
|
||||
TEST("gst_object_get_parent: invalid object");
|
||||
// setup
|
||||
// action
|
||||
curparent = gst_object_get_parent((GstObject*)gtkobject);
|
||||
// assertions
|
||||
ASSERT(curparent == NULL);
|
||||
// cleanup
|
||||
ENDTEST();
|
||||
|
||||
TEST("gst_object_get_parent: no parent");
|
||||
// setup
|
||||
object = gst_object_new();
|
||||
// action
|
||||
curparent = gst_object_get_parent(object);
|
||||
// assertions
|
||||
ASSERT(curparent == NULL);
|
||||
// cleanup
|
||||
ENDTEST();
|
||||
|
||||
TEST("gst_object_get_parent: valid parent");
|
||||
// setup
|
||||
gst_object_set_parent(object,parent);
|
||||
// action
|
||||
curparent = gst_object_get_parent(object);
|
||||
// assertions
|
||||
ASSERT(curparent == parent);
|
||||
// cleanup
|
||||
g_free(object);
|
||||
ENDTEST();
|
||||
|
||||
|
||||
TEST("gst_object_unparent: null object");
|
||||
// setup
|
||||
// action
|
||||
gst_object_unparent(NULL);
|
||||
// assertions
|
||||
// NONE - FIXME!
|
||||
// cleanup
|
||||
ENDTEST();
|
||||
|
||||
TEST("gst_object_unparent: invalid object");
|
||||
// setup
|
||||
// action
|
||||
gst_object_unparent((GstObject*)gtkobject);
|
||||
// assertions
|
||||
// NONE - FIXME!
|
||||
// cleanup
|
||||
ENDTEST();
|
||||
|
||||
TEST("gst_object_unparent: no parent");
|
||||
// setup
|
||||
object = gst_object_new();
|
||||
|
||||
|
||||
// category cleanup
|
||||
g_free(object);
|
||||
g_free(parent);
|
||||
g_free(newparent);
|
||||
g_free(gtkobject);
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
95
docs/random/omega/testing/gstobject.txt
Normal file
95
docs/random/omega/testing/gstobject.txt
Normal file
|
@ -0,0 +1,95 @@
|
|||
Subject: GstObject
|
||||
|
||||
Areas to test
|
||||
=============
|
||||
|
||||
Creation
|
||||
Refcounting
|
||||
Destruction
|
||||
Flags
|
||||
Locking
|
||||
Parentage
|
||||
Path string
|
||||
|
||||
|
||||
Tests
|
||||
=====
|
||||
|
||||
Creation
|
||||
--------
|
||||
Create an object
|
||||
Does it return !NULL
|
||||
GST_IS_OBJECT() ?
|
||||
|
||||
Refcounting
|
||||
-----------
|
||||
Create new object
|
||||
object->refcount == 1, GTK_OBJECT_FLOATING(object) == TRUE
|
||||
Increment refcount
|
||||
object->refcount == 2
|
||||
Sink object
|
||||
object->refcount == 1, GTK_OBJECT_FLOATING(object) == FALSE
|
||||
Increment refcount
|
||||
object->refcount == 2
|
||||
Decrement refcount
|
||||
object->refcount == 1
|
||||
|
||||
Destruction
|
||||
-----------
|
||||
???
|
||||
|
||||
Flags (start with new object)
|
||||
-----
|
||||
Create new object
|
||||
Verify that all flags are unset
|
||||
Set a flag
|
||||
Verify it's set
|
||||
Unset a flag
|
||||
Verify it's not set
|
||||
|
||||
Locking (start with new object)
|
||||
-------
|
||||
Lock an object
|
||||
Try to lock, get false
|
||||
|
||||
Parentage (start with new object, check refcount == 1)
|
||||
---------
|
||||
gst_object_set_parent: (start with new parent object)
|
||||
Pass NULL...
|
||||
Pass !NULL, but not Object...
|
||||
Pass NULL parent...
|
||||
Pass !NULL parent, but not Object...
|
||||
Pass valid Object, and parent == object
|
||||
object->refcount == 1
|
||||
GTK_OBJECT_FLOATING(object) == TRUE
|
||||
object->parent == NULL
|
||||
Pass valid Object
|
||||
object->refcount == 1
|
||||
GTK_OBJECT_FLOATING(object) == FALSE
|
||||
object->parent == parent
|
||||
The "parent_set" signal should fire with the object and parent as args
|
||||
Pass Object with parent already set
|
||||
object->parent should not equal new parent
|
||||
object->refcount == 1
|
||||
gst_object_get_parent:
|
||||
Pass NULL...
|
||||
Pass !NULL, not Object...
|
||||
Pass valid object with no parent
|
||||
Get NULL
|
||||
Pass valid object with parent
|
||||
Get parent pointer
|
||||
gst_object_unparent:
|
||||
Pass NULL, with no parent
|
||||
no effect
|
||||
Pass !NULL, not Object, NULL parent
|
||||
pointer not mangled
|
||||
Pass valid object, with no parent
|
||||
object->parent == NULL
|
||||
object->refcount = 1
|
||||
Pass NULL, with valid parent
|
||||
no effect
|
||||
Pass !NULL, not Object, with valid object as parent
|
||||
pointer not mangled
|
||||
Pass valid object, with valid parent
|
||||
object->parent == NULL
|
||||
object->refcount == 0
|
Loading…
Reference in a new issue