tests: transform1: make test work with CK_FORK=no

We need to clear some global state and register a new test
basetransform subclass for each test because we do things
in class_init base on global state.

https://bugzilla.gnome.org/show_bug.cgi?id=623469
This commit is contained in:
Tim-Philipp Müller 2016-04-11 10:27:56 +01:00
parent f9eb3b98f1
commit 1fa64722d0
3 changed files with 55 additions and 21 deletions

View file

@ -28,18 +28,7 @@ GST_STATIC_PAD_TEMPLATE ("sink",
typedef struct _GstTestTrans GstTestTrans; typedef struct _GstTestTrans GstTestTrans;
typedef struct _GstTestTransClass GstTestTransClass; typedef struct _GstTestTransClass GstTestTransClass;
#define GST_TYPE_TEST_TRANS \ #define GST_TEST_TRANS(obj) ((GstTestTrans *)(obj))
(gst_test_trans_get_type())
#define GST_TEST_TRANS(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_TEST_TRANS,GstTestTrans))
#define GST_TEST_TRANS_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_TEST_TRANS,GstTestTransClass))
#define GST_TEST_TRANS_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), GST_TYPE_TEST_TRANS, GstTestTransClass))
#define GST_IS_TEST_TRANS(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_TEST_TRANS))
#define GST_IS_TEST_TRANS_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_TEST_TRANS))
struct _GstTestTrans struct _GstTestTrans
{ {
@ -53,10 +42,6 @@ struct _GstTestTransClass
GstBaseTransformClass parent_class; GstBaseTransformClass parent_class;
}; };
GType gst_test_trans_get_type (void);
G_DEFINE_TYPE (GstTestTrans, gst_test_trans, GST_TYPE_BASE_TRANSFORM);
static GstFlowReturn (*klass_transform) (GstBaseTransform * trans, static GstFlowReturn (*klass_transform) (GstBaseTransform * trans,
GstBuffer * inbuf, GstBuffer * outbuf) = NULL; GstBuffer * inbuf, GstBuffer * outbuf) = NULL;
static GstFlowReturn (*klass_transform_ip) (GstBaseTransform * trans, static GstFlowReturn (*klass_transform_ip) (GstBaseTransform * trans,
@ -92,6 +77,8 @@ gst_test_trans_class_init (GstTestTransClass * klass)
gst_element_class_add_static_pad_template (element_class, sink_template); gst_element_class_add_static_pad_template (element_class, sink_template);
gst_element_class_add_static_pad_template (element_class, src_template); gst_element_class_add_static_pad_template (element_class, src_template);
GST_INFO ("setting up %s", g_type_name (((GTypeClass *) klass)->g_type));
trans_class->passthrough_on_same_caps = klass_passthrough_on_same_caps; trans_class->passthrough_on_same_caps = klass_passthrough_on_same_caps;
if (klass_transform_ip != NULL) if (klass_transform_ip != NULL)
trans_class->transform_ip = klass_transform_ip; trans_class->transform_ip = klass_transform_ip;
@ -156,9 +143,24 @@ gst_test_trans_new (void)
TestTransData *res; TestTransData *res;
GstPad *tmp; GstPad *tmp;
GstPadTemplate *templ; GstPadTemplate *templ;
GType type;
/* we register a new sub-class for every test-run, so the class init
* function is called for every test run and can be set up properly
* even with CK_FORK=no */
{
static gint counter = 0;
gchar name[100];
g_snprintf (name, sizeof (name), "GstTestTrans%d", ++counter);
type = g_type_register_static_simple (GST_TYPE_BASE_TRANSFORM, name,
sizeof (GstTestTransClass), (GClassInitFunc) gst_test_trans_class_init,
sizeof (GstTestTrans), (GInstanceInitFunc) gst_test_trans_init, 0);
}
res = g_new0 (TestTransData, 1); res = g_new0 (TestTransData, 1);
res->trans = g_object_new (GST_TYPE_TEST_TRANS, NULL); res->trans = g_object_new (type, NULL);
templ = gst_static_pad_template_get (sink_template); templ = gst_static_pad_template_get (sink_template);
templ->direction = GST_PAD_SRC; templ->direction = GST_PAD_SRC;

View file

@ -96,6 +96,14 @@ GST_START_TEST (basetransform_chain_pt1)
gst_test_trans_push_segment (trans); gst_test_trans_push_segment (trans);
gst_test_trans_free (trans); gst_test_trans_free (trans);
klass_transform_ip = NULL;
klass_transform = NULL;
klass_transform_caps = NULL;
klass_transform_size = NULL;
klass_set_caps = NULL;
klass_submit_input_buffer = NULL;
klass_generate_output = NULL;
} }
GST_END_TEST; GST_END_TEST;
@ -879,6 +887,25 @@ GST_START_TEST (basetransform_chain_ct3)
GST_END_TEST; GST_END_TEST;
static void
transform1_setup (void)
{
sink_template = &gst_test_trans_sink_template;
src_template = &gst_test_trans_src_template;
}
static void
transform1_teardown (void)
{
/* reset global state */
klass_transform_ip = NULL;
klass_transform = NULL;
klass_transform_caps = NULL;
klass_transform_size = NULL;
klass_set_caps = NULL;
klass_submit_input_buffer = NULL;
klass_generate_output = NULL;
}
static Suite * static Suite *
gst_basetransform_suite (void) gst_basetransform_suite (void)
@ -887,6 +914,8 @@ gst_basetransform_suite (void)
TCase *tc = tcase_create ("general"); TCase *tc = tcase_create ("general");
suite_add_tcase (s, tc); suite_add_tcase (s, tc);
tcase_add_checked_fixture (tc, transform1_setup, transform1_teardown);
/* pass through */ /* pass through */
tcase_add_test (tc, basetransform_chain_pt1); tcase_add_test (tc, basetransform_chain_pt1);
tcase_add_test (tc, basetransform_chain_pt2); tcase_add_test (tc, basetransform_chain_pt2);

View file

@ -49,10 +49,13 @@ static GstFlowReturn
collate_submit_input_buffer (GstBaseTransform * trans, collate_submit_input_buffer (GstBaseTransform * trans,
gboolean is_discont, GstBuffer * input) gboolean is_discont, GstBuffer * input)
{ {
GstFlowReturn ret = GstBaseTransformClass *tt_parent_class;
GST_BASE_TRANSFORM_CLASS GstFlowReturn ret;
(gst_test_trans_parent_class)->submit_input_buffer (trans, is_discont,
input); tt_parent_class =
g_type_class_peek_parent (GST_BASE_TRANSFORM_GET_CLASS (trans));
ret = tt_parent_class->submit_input_buffer (trans, is_discont, input);
if (ret != GST_FLOW_OK) if (ret != GST_FLOW_OK)
return ret; return ret;