From 1c9569392fc00de4e135271fabccac0b3d02953e Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 8 Mar 2005 15:57:15 +0000 Subject: [PATCH] Added parentage check. Original commit message from CVS: * check/gst/gstobject.c: (START_TEST), (gst_object_suite): * gst/gstthread.c: (gst_thread_release_children_locks): Added parentage check. Fix build og GstThread again. --- ChangeLog | 7 +++ check/gst/gstobject.c | 107 ++++++++++++++++++++++++++++++++++++++++++++ gst/gstthread.c | 1 + tests/check/gst/gstobject.c | 107 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 222 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5f39427..189edca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2005-03-08 Wim Taymans + * check/gst/gstobject.c: (START_TEST), (gst_object_suite): + * gst/gstthread.c: (gst_thread_release_children_locks): + Added parentage check. + Fix build og GstThread again. + +2005-03-08 Wim Taymans + * docs/design/part-MT-refcounting.txt: * docs/design/part-conventions.txt: * docs/design/part-gstobject.txt: diff --git a/check/gst/gstobject.c b/check/gst/gstobject.c index 52f92e9..4789cf6 100644 --- a/check/gst/gstobject.c +++ b/check/gst/gstobject.c @@ -327,6 +327,111 @@ START_TEST (test_fake_object_name_threaded_unique) } END_TEST +/* parentage test on GstFakeObject */ +START_TEST (test_fake_object_parentage) +{ + GstObject *object1, *object2; + GstObject *parent; + gboolean result; + + /* create new object */ + object1 = g_object_new (gst_fake_object_get_type (), NULL); + fail_if (object1 == NULL, "Failed to create instance of GstFakeObject"); + fail_unless (GST_IS_OBJECT (object1), + "GstFakeObject instance is not a GstObject"); + fail_unless (GST_OBJECT_IS_FLOATING (object1), + "GstFakeObject instance is not floating"); + + /* check the parent */ + parent = gst_object_get_parent (object1); + fail_if (parent != NULL, "GstFakeObject has parent"); + /* try to set a NULL parent, this should give a warning */ + ASSERT_CRITICAL (result = gst_object_set_parent (object1, NULL)); + fail_if (result == TRUE, "GstFakeObject accepted NULL parent"); + /* try to set itself as parent, we expect a warning here */ + ASSERT_CRITICAL (result = gst_object_set_parent (object1, object1)); + fail_if (result == TRUE, "GstFakeObject accepted itself as parent"); + + /* should still be floating */ + fail_unless (GST_OBJECT_IS_FLOATING (object1), + "GstFakeObject instance is not floating"); + + /* create another object */ + object2 = g_object_new (gst_fake_object_get_type (), NULL); + fail_if (object2 == NULL, + "Failed to create another instance of GstFakeObject"); + fail_unless (GST_IS_OBJECT (object2), + "second GstFakeObject instance is not a GstObject"); + fail_unless (GST_OBJECT_IS_FLOATING (object1), + "GstFakeObject instance is not floating"); + + /* try to set other object as parent */ + result = gst_object_set_parent (object1, object2); + fail_if (result == FALSE, + "GstFakeObject could not accept other object as parent"); + + /* should not be floating anymore */ + fail_if (GST_OBJECT_IS_FLOATING (object1), + "GstFakeObject instance is still floating"); + /* parent should still be floating */ + fail_unless (GST_OBJECT_IS_FLOATING (object2), + "GstFakeObject instance is not floating"); + + /* check the parent */ + parent = gst_object_get_parent (object1); + fail_if (parent != object2, "GstFakeObject has wrong parent"); + gst_object_unref (parent); + /* try to set other object as parent again */ + result = gst_object_set_parent (object1, object2); + fail_if (result == TRUE, "GstFakeObject could set parent twice"); + + /* ref before unparenting */ + gst_object_ref (object1); + /* clear parent of object */ + gst_object_unparent (object1); + + /* check the parent */ + parent = gst_object_get_parent (object1); + fail_if (parent != NULL, "GstFakeObject has parent"); + + /* object should not be floating */ + fail_if (GST_OBJECT_IS_FLOATING (object1), + "GstFakeObject instance is floating again"); + + gst_object_unref (object1); + gst_object_unref (object2); +} + +END_TEST +/* parentage test dispose on GstFakeObject, since our testcase + * does not handle the parent relation completely, the parent does + * not hold a ref to the child, we cannot dispose the parent to + * dipose the child as well. This test needs to be run with DEBUG + * info to check if the finalize methods are called correctly. */ +START_TEST (test_fake_object_parentage_dispose) +{ + GstObject *object1, *object2; + gboolean result; + + object1 = g_object_new (gst_fake_object_get_type (), NULL); + fail_if (object1 == NULL, "Failed to create instance of GstFakeObject"); + + object2 = g_object_new (gst_fake_object_get_type (), NULL); + fail_if (object2 == NULL, "Failed to create instance of GstFakeObject"); + + /* try to set other object as parent */ + result = gst_object_set_parent (object1, object2); + fail_if (result == FALSE, + "GstFakeObject could not accept other object as parent"); + + /* clear parent of object */ + gst_object_unparent (object1); + + /* now dispose parent */ + gst_object_unref (object2); +} + +END_TEST /* test: try renaming a parented object, make sure it fails */ Suite * gst_object_suite (void) { @@ -339,6 +444,8 @@ END_TEST tcase_add_test (tc_chain, test_fake_object_name_threaded_wrong); tcase_add_test (tc_chain, test_fake_object_name_threaded_right); tcase_add_test (tc_chain, test_fake_object_name_threaded_unique); + tcase_add_test (tc_chain, test_fake_object_parentage); + tcase_add_test (tc_chain, test_fake_object_parentage_dispose); //tcase_add_checked_fixture (tc_chain, setup, teardown); /* SEGV tests go last so we can debug the others */ diff --git a/gst/gstthread.c b/gst/gstthread.c index 04f910a..cd9ba51 100644 --- a/gst/gstthread.c +++ b/gst/gstthread.c @@ -26,6 +26,7 @@ #include "gstthread.h" #include "gstmarshal.h" #include "gstscheduler.h" +#include "gstutils.h" #include "gstinfo.h" #define GST_CAT_DEFAULT GST_CAT_THREAD diff --git a/tests/check/gst/gstobject.c b/tests/check/gst/gstobject.c index 52f92e9..4789cf6 100644 --- a/tests/check/gst/gstobject.c +++ b/tests/check/gst/gstobject.c @@ -327,6 +327,111 @@ START_TEST (test_fake_object_name_threaded_unique) } END_TEST +/* parentage test on GstFakeObject */ +START_TEST (test_fake_object_parentage) +{ + GstObject *object1, *object2; + GstObject *parent; + gboolean result; + + /* create new object */ + object1 = g_object_new (gst_fake_object_get_type (), NULL); + fail_if (object1 == NULL, "Failed to create instance of GstFakeObject"); + fail_unless (GST_IS_OBJECT (object1), + "GstFakeObject instance is not a GstObject"); + fail_unless (GST_OBJECT_IS_FLOATING (object1), + "GstFakeObject instance is not floating"); + + /* check the parent */ + parent = gst_object_get_parent (object1); + fail_if (parent != NULL, "GstFakeObject has parent"); + /* try to set a NULL parent, this should give a warning */ + ASSERT_CRITICAL (result = gst_object_set_parent (object1, NULL)); + fail_if (result == TRUE, "GstFakeObject accepted NULL parent"); + /* try to set itself as parent, we expect a warning here */ + ASSERT_CRITICAL (result = gst_object_set_parent (object1, object1)); + fail_if (result == TRUE, "GstFakeObject accepted itself as parent"); + + /* should still be floating */ + fail_unless (GST_OBJECT_IS_FLOATING (object1), + "GstFakeObject instance is not floating"); + + /* create another object */ + object2 = g_object_new (gst_fake_object_get_type (), NULL); + fail_if (object2 == NULL, + "Failed to create another instance of GstFakeObject"); + fail_unless (GST_IS_OBJECT (object2), + "second GstFakeObject instance is not a GstObject"); + fail_unless (GST_OBJECT_IS_FLOATING (object1), + "GstFakeObject instance is not floating"); + + /* try to set other object as parent */ + result = gst_object_set_parent (object1, object2); + fail_if (result == FALSE, + "GstFakeObject could not accept other object as parent"); + + /* should not be floating anymore */ + fail_if (GST_OBJECT_IS_FLOATING (object1), + "GstFakeObject instance is still floating"); + /* parent should still be floating */ + fail_unless (GST_OBJECT_IS_FLOATING (object2), + "GstFakeObject instance is not floating"); + + /* check the parent */ + parent = gst_object_get_parent (object1); + fail_if (parent != object2, "GstFakeObject has wrong parent"); + gst_object_unref (parent); + /* try to set other object as parent again */ + result = gst_object_set_parent (object1, object2); + fail_if (result == TRUE, "GstFakeObject could set parent twice"); + + /* ref before unparenting */ + gst_object_ref (object1); + /* clear parent of object */ + gst_object_unparent (object1); + + /* check the parent */ + parent = gst_object_get_parent (object1); + fail_if (parent != NULL, "GstFakeObject has parent"); + + /* object should not be floating */ + fail_if (GST_OBJECT_IS_FLOATING (object1), + "GstFakeObject instance is floating again"); + + gst_object_unref (object1); + gst_object_unref (object2); +} + +END_TEST +/* parentage test dispose on GstFakeObject, since our testcase + * does not handle the parent relation completely, the parent does + * not hold a ref to the child, we cannot dispose the parent to + * dipose the child as well. This test needs to be run with DEBUG + * info to check if the finalize methods are called correctly. */ +START_TEST (test_fake_object_parentage_dispose) +{ + GstObject *object1, *object2; + gboolean result; + + object1 = g_object_new (gst_fake_object_get_type (), NULL); + fail_if (object1 == NULL, "Failed to create instance of GstFakeObject"); + + object2 = g_object_new (gst_fake_object_get_type (), NULL); + fail_if (object2 == NULL, "Failed to create instance of GstFakeObject"); + + /* try to set other object as parent */ + result = gst_object_set_parent (object1, object2); + fail_if (result == FALSE, + "GstFakeObject could not accept other object as parent"); + + /* clear parent of object */ + gst_object_unparent (object1); + + /* now dispose parent */ + gst_object_unref (object2); +} + +END_TEST /* test: try renaming a parented object, make sure it fails */ Suite * gst_object_suite (void) { @@ -339,6 +444,8 @@ END_TEST tcase_add_test (tc_chain, test_fake_object_name_threaded_wrong); tcase_add_test (tc_chain, test_fake_object_name_threaded_right); tcase_add_test (tc_chain, test_fake_object_name_threaded_unique); + tcase_add_test (tc_chain, test_fake_object_parentage); + tcase_add_test (tc_chain, test_fake_object_parentage_dispose); //tcase_add_checked_fixture (tc_chain, setup, teardown); /* SEGV tests go last so we can debug the others */ -- 2.7.4