"Fossies" - the Fresh Open Source Software Archive

Member "gstreamer-1.16.1/tests/check/gst/gstpreset.c" (19 Apr 2019, 8110 Bytes) of package /linux/misc/gstreamer-1.16.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "gstpreset.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.14.4_vs_1.16.0.

    1 /* GStreamer
    2  * Copyright (C) 2008 Nokia Corporation and its subsidiary(-ies)
    3  *               contact: <stefan.kost@nokia.com>
    4  *
    5  * gstpreset.c: Unit test for GstPreset
    6  *
    7  * This library is free software; you can redistribute it and/or
    8  * modify it under the terms of the GNU Library General Public
    9  * License as published by the Free Software Foundation; either
   10  * version 2 of the License, or (at your option) any later version.
   11  *
   12  * This library is distributed in the hope that it will be useful,
   13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15  * Library General Public License for more details.
   16  *
   17  * You should have received a copy of the GNU Library General Public
   18  * License along with this library; if not, write to the
   19  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
   20  * Boston, MA 02110-1301, USA.
   21  */
   22 
   23 #ifdef HAVE_CONFIG_H
   24 #  include "config.h"
   25 #endif
   26 
   27 #include <glib.h>
   28 #include <glib/gstdio.h>
   29 #include <gst/check/gstcheck.h>
   30 
   31 #ifdef HAVE_UNISTD_H
   32 #include <unistd.h>
   33 #endif
   34 
   35 static GType gst_preset_test_get_type (void);
   36 
   37 #define GST_TYPE_PRESET_TEST            (gst_preset_test_get_type ())
   38 #define GST_PRESET_TEST(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PRESET_TEST, GstPresetTest))
   39 #define GST_PRESET_TEST_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_PRESET_TEST, GstPresetTestClass))
   40 #define GST_IS_PRESET_TEST(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PRESET_TEST))
   41 #define GST_IS_PRESET_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PRESET_TEST))
   42 #define GST_PRESET_TEST_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PRESET_TEST, GstPresetTestClass))
   43 #define GST_PRESET_TEST_NAME            "preset-test"
   44 
   45 enum
   46 {
   47   PROP_TEST = 1,
   48 };
   49 
   50 typedef struct _GstPresetTest
   51 {
   52   GstElement parent;
   53 
   54   gint test;
   55 } GstPresetTest;
   56 
   57 typedef struct _GstPresetTestClass
   58 {
   59   GstElementClass parent_class;
   60 } GstPresetTestClass;
   61 
   62 static void
   63 gst_preset_test_get_property (GObject * object, guint property_id,
   64     GValue * value, GParamSpec * pspec)
   65 {
   66   GstPresetTest *self = GST_PRESET_TEST (object);
   67 
   68   switch (property_id) {
   69     case PROP_TEST:
   70       g_value_set_int (value, self->test);
   71       break;
   72     default:
   73       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
   74       break;
   75   }
   76 }
   77 
   78 static void
   79 gst_preset_test_set_property (GObject * object, guint property_id,
   80     const GValue * value, GParamSpec * pspec)
   81 {
   82   GstPresetTest *self = GST_PRESET_TEST (object);
   83 
   84   switch (property_id) {
   85     case PROP_TEST:
   86       self->test = g_value_get_int (value);
   87       break;
   88   }
   89 }
   90 
   91 static void
   92 gst_preset_test_class_init (GObjectClass * klass)
   93 {
   94   klass->set_property = gst_preset_test_set_property;
   95   klass->get_property = gst_preset_test_get_property;
   96 
   97   g_object_class_install_property (klass, PROP_TEST,
   98       g_param_spec_int ("test",
   99           "test prop",
  100           "test parameter for preset test",
  101           G_MININT, G_MAXINT, 0, G_PARAM_READWRITE));
  102 }
  103 
  104 static void
  105 gst_preset_test_base_init (GstPresetTestClass * klass)
  106 {
  107   GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
  108 
  109   gst_element_class_set_metadata (element_class,
  110       "Element for unit tests",
  111       "Testing", "Use in unit tests", "Stefan Kost <stefan.kost@nokia.com>");
  112 }
  113 
  114 static GType
  115 gst_preset_test_get_type (void)
  116 {
  117   static volatile gsize preset_test_type = 0;
  118 
  119   if (g_once_init_enter (&preset_test_type)) {
  120     GType type;
  121     const GTypeInfo info = {
  122       sizeof (GstPresetTestClass),
  123       (GBaseInitFunc) gst_preset_test_base_init,        /* base_init */
  124       NULL,                     /* base_finalize */
  125       (GClassInitFunc) gst_preset_test_class_init,      /* class_init */
  126       NULL,                     /* class_finalize */
  127       NULL,                     /* class_data */
  128       sizeof (GstPresetTest),
  129       0,                        /* n_preallocs */
  130       NULL,                     /* instance_init */
  131       NULL                      /* value_table */
  132     };
  133     const GInterfaceInfo preset_interface_info = {
  134       NULL,                     /* interface_init */
  135       NULL,                     /* interface_finalize */
  136       NULL                      /* interface_data */
  137     };
  138     type = g_type_register_static (GST_TYPE_ELEMENT, "GstPresetTest", &info, 0);
  139     g_type_add_interface_static (type, GST_TYPE_PRESET, &preset_interface_info);
  140     g_once_init_leave (&preset_test_type, type);
  141   }
  142   return preset_test_type;
  143 }
  144 
  145 static gboolean
  146 gst_preset_test_plugin_init (GstPlugin * plugin)
  147 {
  148   gst_element_register (plugin, GST_PRESET_TEST_NAME, GST_RANK_NONE,
  149       GST_TYPE_PRESET_TEST);
  150   return TRUE;
  151 }
  152 
  153 
  154 GST_START_TEST (test_check)
  155 {
  156   GstElement *elem;
  157 
  158   elem = gst_element_factory_make (GST_PRESET_TEST_NAME, NULL);
  159   fail_unless (GST_IS_PRESET (elem));
  160 
  161   gst_object_unref (elem);
  162 }
  163 
  164 GST_END_TEST;
  165 
  166 GST_START_TEST (test_load)
  167 {
  168   GstElement *elem;
  169   gboolean res;
  170 
  171   elem = gst_element_factory_make (GST_PRESET_TEST_NAME, NULL);
  172   res = gst_preset_load_preset (GST_PRESET (elem), "does-not-exist");
  173   fail_unless (!res);
  174 
  175   gst_object_unref (elem);
  176 }
  177 
  178 GST_END_TEST;
  179 
  180 GST_START_TEST (test_add)
  181 {
  182   GstElement *elem;
  183   gboolean res;
  184   gint val;
  185 
  186   elem = gst_element_factory_make (GST_PRESET_TEST_NAME, NULL);
  187   g_object_set (elem, "test", 5, NULL);
  188 
  189   res = gst_preset_save_preset (GST_PRESET (elem), "test");
  190   fail_unless (res);
  191 
  192   res = gst_preset_load_preset (GST_PRESET (elem), "test");
  193   fail_unless (res);
  194   g_object_get (elem, "test", &val, NULL);
  195   fail_unless (val == 5);
  196 
  197   gst_object_unref (elem);
  198 }
  199 
  200 GST_END_TEST;
  201 
  202 
  203 GST_START_TEST (test_del)
  204 {
  205   GstElement *elem;
  206   gboolean res;
  207 
  208   elem = gst_element_factory_make (GST_PRESET_TEST_NAME, NULL);
  209   res = gst_preset_save_preset (GST_PRESET (elem), "test");
  210   fail_unless (res);
  211 
  212   res = gst_preset_delete_preset (GST_PRESET (elem), "test");
  213   fail_unless (res);
  214 
  215   res = gst_preset_load_preset (GST_PRESET (elem), "test");
  216   fail_unless (!res);
  217 
  218   gst_object_unref (elem);
  219 }
  220 
  221 GST_END_TEST;
  222 
  223 GST_START_TEST (test_two_instances)
  224 {
  225   GstElement *elem1, *elem2;
  226   gboolean res;
  227   gint val;
  228 
  229   elem1 = gst_element_factory_make (GST_PRESET_TEST_NAME, NULL);
  230   g_object_set (elem1, "test", 5, NULL);
  231 
  232   res = gst_preset_save_preset (GST_PRESET (elem1), "test");
  233   fail_unless (res);
  234 
  235   elem2 = gst_element_factory_make (GST_PRESET_TEST_NAME, NULL);
  236   res = gst_preset_load_preset (GST_PRESET (elem2), "test");
  237   fail_unless (res);
  238   g_object_get (elem2, "test", &val, NULL);
  239   fail_unless (val == 5);
  240 
  241   gst_object_unref (elem1);
  242   gst_object_unref (elem2);
  243 }
  244 
  245 GST_END_TEST;
  246 
  247 
  248 static void
  249 remove_preset_file (void)
  250 {
  251   gchar *preset_file_name;
  252 
  253   preset_file_name = g_build_filename (g_get_user_data_dir (),
  254       "gstreamer-" GST_API_VERSION, "presets", "GstPresetTest.prs", NULL);
  255   g_unlink (preset_file_name);
  256   g_free (preset_file_name);
  257 }
  258 
  259 static void
  260 test_setup (void)
  261 {
  262   remove_preset_file ();
  263   gst_plugin_register_static (GST_VERSION_MAJOR,
  264       GST_VERSION_MINOR,
  265       "gst-test",
  266       "preset test plugin",
  267       gst_preset_test_plugin_init,
  268       VERSION, GST_LICENSE, PACKAGE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
  269 }
  270 
  271 static void
  272 test_teardown (void)
  273 {
  274   remove_preset_file ();
  275 }
  276 
  277 
  278 static Suite *
  279 gst_preset_suite (void)
  280 {
  281   Suite *s = suite_create ("GstPreset");
  282   TCase *tc = tcase_create ("preset");
  283   gchar *gst_dir;
  284   gboolean can_write = FALSE;
  285 
  286   /* check if we can create presets */
  287   gst_dir = g_build_filename (g_get_user_data_dir (),
  288       "gstreamer-" GST_API_VERSION, NULL);
  289 
  290 #ifdef G_OS_WIN32
  291   can_write = FALSE;            /* FIXME: test properly using win32 API */
  292 #else
  293   can_write = (g_access (gst_dir, R_OK | W_OK | X_OK) == 0);
  294 #endif
  295 
  296   g_free (gst_dir);
  297 
  298   suite_add_tcase (s, tc);
  299   tcase_add_test (tc, test_check);
  300   tcase_add_test (tc, test_load);
  301   if (can_write) {
  302     tcase_add_test (tc, test_add);
  303     tcase_add_test (tc, test_del);
  304     tcase_add_test (tc, test_two_instances);
  305   }
  306   tcase_add_unchecked_fixture (tc, test_setup, test_teardown);
  307 
  308   return s;
  309 }
  310 
  311 GST_CHECK_MAIN (gst_preset);