|
Packit |
133782 |
/* Farstream unit tests for FsCodec
|
|
Packit |
133782 |
*
|
|
Packit |
133782 |
* Copyright (C) 2007 Collabora, Nokia
|
|
Packit |
133782 |
* @author: Olivier Crete <olivier.crete@collabora.co.uk>
|
|
Packit |
133782 |
*
|
|
Packit |
133782 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
133782 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
133782 |
* License as published by the Free Software Foundation; either
|
|
Packit |
133782 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
133782 |
*
|
|
Packit |
133782 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
133782 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
133782 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
133782 |
* Lesser General Public License for more details.
|
|
Packit |
133782 |
*
|
|
Packit |
133782 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
133782 |
* License along with this library; if not, write to the Free Software
|
|
Packit |
133782 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
133782 |
*/
|
|
Packit |
133782 |
|
|
Packit |
133782 |
|
|
Packit |
133782 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
133782 |
# include <config.h>
|
|
Packit |
133782 |
#endif
|
|
Packit |
133782 |
|
|
Packit |
133782 |
#include <gst/check/gstcheck.h>
|
|
Packit |
133782 |
#include <farstream/fs-element-added-notifier.h>
|
|
Packit |
133782 |
|
|
Packit |
133782 |
#include "testutils.h"
|
|
Packit |
133782 |
|
|
Packit |
133782 |
gboolean called = FALSE;
|
|
Packit |
133782 |
gpointer last_added = NULL;
|
|
Packit |
133782 |
gpointer last_bin = NULL;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
static void
|
|
Packit |
133782 |
_added_cb (FsElementAddedNotifier *notifier, GstBin *bin, GstElement *element,
|
|
Packit |
133782 |
gpointer user_data)
|
|
Packit |
133782 |
{
|
|
Packit |
133782 |
GstObject *parent = NULL;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_unless (user_data == &last_added, "Pass user_data is incorrect");
|
|
Packit |
133782 |
called = TRUE;
|
|
Packit |
133782 |
last_added = element;
|
|
Packit |
133782 |
last_bin = bin;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
if (bin)
|
|
Packit |
133782 |
{
|
|
Packit |
133782 |
parent = gst_object_get_parent (GST_OBJECT (element));
|
|
Packit |
133782 |
fail_if (GST_OBJECT_CAST (bin) != parent,
|
|
Packit |
133782 |
"The bin passed to use is not the right parent");
|
|
Packit |
133782 |
gst_object_unref (parent);
|
|
Packit |
133782 |
}
|
|
Packit |
133782 |
}
|
|
Packit |
133782 |
|
|
Packit |
133782 |
|
|
Packit |
133782 |
GST_START_TEST (test_bin_added_simple)
|
|
Packit |
133782 |
{
|
|
Packit |
133782 |
GstElement *pipeline = NULL;
|
|
Packit |
133782 |
GstElement *identity = NULL;
|
|
Packit |
133782 |
FsElementAddedNotifier *notifier = NULL;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
pipeline = gst_pipeline_new (NULL);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
identity = gst_element_factory_make ("identity", NULL);
|
|
Packit |
133782 |
gst_object_ref (identity);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
notifier = fs_element_added_notifier_new ();
|
|
Packit |
133782 |
|
|
Packit |
133782 |
g_signal_connect (notifier, "element-added",
|
|
Packit |
133782 |
G_CALLBACK (_added_cb), &last_added);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fs_element_added_notifier_add (notifier, GST_BIN (pipeline));
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_unless (gst_bin_add (GST_BIN (pipeline), identity),
|
|
Packit |
133782 |
"Could not add identity to pipeline");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_if (called == FALSE, "AddedCallback not called");
|
|
Packit |
133782 |
fail_unless (last_added == identity,
|
|
Packit |
133782 |
"The element passed to the callback was wrong"
|
|
Packit |
133782 |
" (it was %p, should have been %p",
|
|
Packit |
133782 |
last_added, identity);
|
|
Packit |
133782 |
fail_unless (last_bin == pipeline,
|
|
Packit |
133782 |
"The bin passed to the callback was wrong"
|
|
Packit |
133782 |
" (it was %p, should have been %p",
|
|
Packit |
133782 |
last_bin, pipeline);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_unless (gst_bin_remove (GST_BIN (pipeline), identity),
|
|
Packit |
133782 |
"Could not remove identity from pipeline");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
called = FALSE;
|
|
Packit |
133782 |
last_added = last_bin = NULL;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_unless (
|
|
Packit |
133782 |
fs_element_added_notifier_remove (notifier, GST_BIN (pipeline)),
|
|
Packit |
133782 |
"Could not remove notification");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_unless (gst_bin_add (GST_BIN (pipeline), identity),
|
|
Packit |
133782 |
"Could not add identity to pipeline");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_if (called == TRUE, "AddedCallback was removed, but was still called");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
called = FALSE;
|
|
Packit |
133782 |
last_added = last_bin = NULL;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
g_object_unref (notifier);
|
|
Packit |
133782 |
gst_object_unref (identity);
|
|
Packit |
133782 |
gst_object_unref (pipeline);
|
|
Packit |
133782 |
}
|
|
Packit |
133782 |
GST_END_TEST;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
|
|
Packit |
133782 |
GST_START_TEST (test_bin_added_recursive)
|
|
Packit |
133782 |
{
|
|
Packit |
133782 |
GstElement *pipeline = NULL;
|
|
Packit |
133782 |
GstElement *bin = NULL;
|
|
Packit |
133782 |
GstElement *identity = NULL;
|
|
Packit |
133782 |
FsElementAddedNotifier *notifier = NULL;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
pipeline = gst_pipeline_new (NULL);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
bin = gst_bin_new (NULL);
|
|
Packit |
133782 |
gst_object_ref (bin);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
gst_bin_add (GST_BIN (pipeline), bin);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
identity = gst_element_factory_make ("identity", NULL);
|
|
Packit |
133782 |
gst_object_ref (identity);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
notifier = fs_element_added_notifier_new ();
|
|
Packit |
133782 |
|
|
Packit |
133782 |
g_signal_connect (notifier, "element-added",
|
|
Packit |
133782 |
G_CALLBACK (_added_cb), &last_added);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fs_element_added_notifier_add (notifier, GST_BIN (pipeline));
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_unless (gst_bin_add (GST_BIN (bin), identity),
|
|
Packit |
133782 |
"Could not add identity to bin");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_if (called == FALSE, "AddedCallback not called");
|
|
Packit |
133782 |
fail_unless (last_added == identity,
|
|
Packit |
133782 |
"The element passed to the callback was wrong"
|
|
Packit |
133782 |
" (it was %p, should have been %p",
|
|
Packit |
133782 |
last_added, identity);
|
|
Packit |
133782 |
fail_unless (last_bin == bin,
|
|
Packit |
133782 |
"The bin passed to the callback was wrong"
|
|
Packit |
133782 |
" (it was %p, should have been %p",
|
|
Packit |
133782 |
last_bin, bin);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_unless (gst_bin_remove (GST_BIN (bin), identity),
|
|
Packit |
133782 |
"Could not remove identity from bin");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
called = FALSE;
|
|
Packit |
133782 |
last_added = last_bin = NULL;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_unless (
|
|
Packit |
133782 |
fs_element_added_notifier_remove (notifier, GST_BIN (pipeline)),
|
|
Packit |
133782 |
"Could not remove notification");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_unless (gst_bin_add (GST_BIN (bin), identity),
|
|
Packit |
133782 |
"Could not add identity to bin");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_if (called == TRUE, "AddedCallback was removed, but was still called");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_unless (gst_bin_remove (GST_BIN (bin), identity),
|
|
Packit |
133782 |
"Could not remove identity from bin");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fs_element_added_notifier_add (notifier, GST_BIN (pipeline));
|
|
Packit |
133782 |
|
|
Packit |
133782 |
called = FALSE;
|
|
Packit |
133782 |
last_added = last_bin = NULL;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
gst_bin_remove (GST_BIN (pipeline), bin);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_unless (gst_bin_add (GST_BIN (bin), identity),
|
|
Packit |
133782 |
"Could not add identity to bin");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_if (called == TRUE, "The bin was removed from the pipeline,"
|
|
Packit |
133782 |
" but the callback was still called");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
|
|
Packit |
133782 |
g_object_unref (notifier);
|
|
Packit |
133782 |
gst_object_unref (identity);
|
|
Packit |
133782 |
gst_object_unref (bin);
|
|
Packit |
133782 |
gst_object_unref (pipeline);
|
|
Packit |
133782 |
}
|
|
Packit |
133782 |
GST_END_TEST;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
static void
|
|
Packit |
133782 |
test_keyfile (FsElementAddedNotifier *notifier)
|
|
Packit |
133782 |
{
|
|
Packit |
133782 |
GstElement *pipeline;
|
|
Packit |
133782 |
GstElement *identity = NULL;
|
|
Packit |
133782 |
gboolean sync;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
pipeline = gst_pipeline_new (NULL);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
identity = gst_element_factory_make ("identity", NULL);
|
|
Packit |
133782 |
gst_object_ref (identity);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
g_object_get (identity, "sync", &sync, NULL);
|
|
Packit |
133782 |
fail_unless (sync == FALSE, "sync prop on identity does not start at FALSE");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fs_element_added_notifier_add (notifier, GST_BIN (pipeline));
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_unless (gst_bin_add (GST_BIN (pipeline), identity),
|
|
Packit |
133782 |
"Could not add identity to pipeline");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
g_object_get (identity, "sync", &sync, NULL);
|
|
Packit |
133782 |
fail_unless (sync == TRUE, "sync prop on identity is not changed to TRUE");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_unless (gst_bin_remove (GST_BIN (pipeline), identity),
|
|
Packit |
133782 |
"Could not remove identity from pipeline");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
g_object_set (identity, "sync", FALSE, NULL);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
g_object_get (identity, "sync", &sync, NULL);
|
|
Packit |
133782 |
fail_unless (sync == FALSE, "sync prop on identity not reset to FALSE");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_unless (
|
|
Packit |
133782 |
fs_element_added_notifier_remove (notifier, GST_BIN (pipeline)),
|
|
Packit |
133782 |
"Could not remove notification");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_unless (gst_bin_add (GST_BIN (pipeline), identity),
|
|
Packit |
133782 |
"Could not add identity to bin");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
g_object_get (identity, "sync", &sync, NULL);
|
|
Packit |
133782 |
fail_if (sync == TRUE, "sync prop on identity changed to TRUE");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fs_element_added_notifier_add (notifier, GST_BIN (pipeline));
|
|
Packit |
133782 |
|
|
Packit |
133782 |
g_object_get (identity, "sync", &sync, NULL);
|
|
Packit |
133782 |
fail_unless (sync == TRUE, "sync prop on identity is not changed to TRUE");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
gst_object_unref (identity);
|
|
Packit |
133782 |
gst_object_unref (pipeline);
|
|
Packit |
133782 |
}
|
|
Packit |
133782 |
|
|
Packit |
133782 |
|
|
Packit |
133782 |
GST_START_TEST (test_bin_keyfile)
|
|
Packit |
133782 |
{
|
|
Packit |
133782 |
GKeyFile *keyfile = g_key_file_new ();
|
|
Packit |
133782 |
FsElementAddedNotifier *notifier = NULL;
|
|
Packit |
133782 |
gulong ret;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
g_key_file_set_boolean (keyfile, "identity", "sync", TRUE);
|
|
Packit |
133782 |
g_key_file_set_boolean (keyfile, "identity", "invalid-property", TRUE);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
notifier = fs_element_added_notifier_new ();
|
|
Packit |
133782 |
|
|
Packit |
133782 |
ret = fs_element_added_notifier_set_properties_from_keyfile (notifier,
|
|
Packit |
133782 |
keyfile);
|
|
Packit |
133782 |
fail_if (ret == 0);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
test_keyfile (notifier);
|
|
Packit |
133782 |
}
|
|
Packit |
133782 |
GST_END_TEST;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
GST_START_TEST (test_bin_file)
|
|
Packit |
133782 |
{
|
|
Packit |
133782 |
FsElementAddedNotifier *notifier = NULL;
|
|
Packit |
133782 |
GError *error = NULL;
|
|
Packit |
133782 |
gchar *filename = NULL;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
notifier = fs_element_added_notifier_new ();
|
|
Packit |
133782 |
|
|
Packit |
133782 |
fail_if (fs_element_added_notifier_set_properties_from_file (notifier,
|
|
Packit |
133782 |
"invalid-filename", &error));
|
|
Packit |
133782 |
fail_if (error == NULL);
|
|
Packit |
133782 |
fail_unless (error->domain == G_FILE_ERROR);
|
|
Packit |
133782 |
g_clear_error (&error);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
filename = get_fullpath ("utils/gstelements.conf");
|
|
Packit |
133782 |
fail_unless (fs_element_added_notifier_set_properties_from_file (notifier,
|
|
Packit |
133782 |
filename, &error));
|
|
Packit |
133782 |
g_free (filename);
|
|
Packit |
133782 |
fail_if (error != NULL);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
test_keyfile (notifier);
|
|
Packit |
133782 |
}
|
|
Packit |
133782 |
GST_END_TEST;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
GST_START_TEST (test_bin_errors)
|
|
Packit |
133782 |
{
|
|
Packit |
133782 |
FsElementAddedNotifier *notifier = NULL;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
g_log_set_always_fatal (0);
|
|
Packit |
133782 |
g_log_set_fatal_mask (NULL, 0);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
ASSERT_CRITICAL (fs_element_added_notifier_add (NULL, NULL));
|
|
Packit |
133782 |
ASSERT_CRITICAL (fs_element_added_notifier_remove (NULL, NULL));
|
|
Packit |
133782 |
ASSERT_CRITICAL (fs_element_added_notifier_set_properties_from_keyfile (
|
|
Packit |
133782 |
NULL, NULL));
|
|
Packit |
133782 |
|
|
Packit |
133782 |
notifier = fs_element_added_notifier_new ();
|
|
Packit |
133782 |
|
|
Packit |
133782 |
ASSERT_CRITICAL (fs_element_added_notifier_add (notifier, NULL));
|
|
Packit |
133782 |
ASSERT_CRITICAL (fs_element_added_notifier_remove (notifier, NULL));
|
|
Packit |
133782 |
ASSERT_CRITICAL (fs_element_added_notifier_set_properties_from_keyfile (
|
|
Packit |
133782 |
notifier, NULL));
|
|
Packit |
133782 |
|
|
Packit |
133782 |
g_object_unref (notifier);
|
|
Packit |
133782 |
}
|
|
Packit |
133782 |
GST_END_TEST;
|
|
Packit |
133782 |
|
|
Packit |
133782 |
|
|
Packit |
133782 |
static Suite *
|
|
Packit |
133782 |
binadded_suite (void)
|
|
Packit |
133782 |
{
|
|
Packit |
133782 |
Suite *s = suite_create ("binadded");
|
|
Packit |
133782 |
TCase *tc_chain = tcase_create ("binadded");
|
|
Packit |
133782 |
|
|
Packit |
133782 |
suite_add_tcase (s, tc_chain);
|
|
Packit |
133782 |
tcase_add_test (tc_chain, test_bin_added_simple);
|
|
Packit |
133782 |
tcase_add_test (tc_chain, test_bin_added_recursive);
|
|
Packit |
133782 |
tcase_add_test (tc_chain, test_bin_keyfile);
|
|
Packit |
133782 |
tcase_add_test (tc_chain, test_bin_file);
|
|
Packit |
133782 |
tcase_add_test (tc_chain, test_bin_errors);
|
|
Packit |
133782 |
|
|
Packit |
133782 |
return s;
|
|
Packit |
133782 |
}
|
|
Packit |
133782 |
|
|
Packit |
133782 |
GST_CHECK_MAIN (binadded);
|