gstreamer_core/tsrc/check/gst/gstparamspecs/src/gstparamspecs.c
changeset 0 0e761a78d257
child 8 4a7fac7dd34a
child 29 567bb019e3e3
equal deleted inserted replaced
-1:000000000000 0:0e761a78d257
       
     1 /* GStreamer GstParamSpec unit tests
       
     2  * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net>
       
     3  *
       
     4  * This library is free software; you can redistribute it and/or
       
     5  * modify it under the terms of the GNU Library General Public
       
     6  * License as published by the Free Software Foundation; either
       
     7  * version 2 of the License, or (at your option) any later version.
       
     8  *
       
     9  * This library is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    12  * Library General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU Library General Public
       
    15  * License along with this library; if not, write to the
       
    16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
       
    17  * Boston, MA 02111-1307, USA.
       
    18  */
       
    19 
       
    20 
       
    21 #define LOG_FILE "c:\\logs\\gstparamspecs_logs.txt" 
       
    22 
       
    23 #include <gst/gst_global.h>
       
    24 #include "std_log_result.h" 
       
    25 #define LOG_FILENAME_LINE __FILE__, __LINE__
       
    26 
       
    27 void create_xml(int result)
       
    28 {
       
    29     if(result)
       
    30         assert_failed = 1;
       
    31     
       
    32     testResultXml(xmlfile);
       
    33     close_log_file();
       
    34 }
       
    35 
       
    36 
       
    37 #include <gst/check/gstcheck.h>
       
    38 #include <gst/gst.h>
       
    39 #include <string.h>
       
    40 
       
    41 #if EMULATOR
       
    42 static GET_GLOBAL_VAR_FROM_TLS(raised_critical,gstcheck,gboolean)
       
    43 #define _gst_check_raised_critical (*GET_GSTREAMER_WSD_VAR_NAME(raised_critical,gstcheck,g)())
       
    44 #else 
       
    45 extern gboolean _gst_check_raised_critical;
       
    46 #endif
       
    47 
       
    48 #if EMULATOR
       
    49 static GET_GLOBAL_VAR_FROM_TLS(expecting_log,gstcheck,gboolean)
       
    50 #define _gst_check_expecting_log (*GET_GSTREAMER_WSD_VAR_NAME(expecting_log,gstcheck,g)())
       
    51 #else 
       
    52 extern gboolean _gst_check_expecting_log;
       
    53 #endif
       
    54 
       
    55 /* some minimal dummy object */
       
    56 #define GST_TYPE_DUMMY_OBJ gst_dummy_obj_get_type()
       
    57 
       
    58 typedef struct
       
    59 {
       
    60   GstElement parent;
       
    61   guint num, denom;
       
    62 } GstDummyObj;
       
    63 
       
    64 typedef GstElementClass GstDummyObjClass;
       
    65 
       
    66 GST_BOILERPLATE (GstDummyObj, gst_dummy_obj, GstElement, GST_TYPE_ELEMENT);
       
    67 
       
    68 static void
       
    69 gst_dummy_obj_get_property (GObject * obj, guint prop_id, GValue * val,
       
    70     GParamSpec * pspec);
       
    71 static void
       
    72 gst_dummy_obj_set_property (GObject * obj, guint prop_id, const GValue * val,
       
    73     GParamSpec * pspec);
       
    74 
       
    75 static void
       
    76 gst_dummy_obj_base_init (gpointer g_class)
       
    77 {
       
    78 }
       
    79 
       
    80 static void
       
    81 gst_dummy_obj_class_init (GstDummyObjClass * klass)
       
    82 {
       
    83   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
       
    84 
       
    85   gobject_class->get_property = gst_dummy_obj_get_property;
       
    86   gobject_class->set_property = gst_dummy_obj_set_property;
       
    87 
       
    88   ASSERT_CRITICAL (
       
    89       /* default value is out of bounds, should print a warning */
       
    90       g_object_class_install_property (gobject_class, 1,
       
    91           gst_param_spec_fraction ("ratio", "ratio", "ratio", 0, 1, 2, 1,
       
    92               16, 4, G_PARAM_READWRITE)););
       
    93 
       
    94   /* should be within bounds */
       
    95   g_object_class_install_property (gobject_class, 2,
       
    96       gst_param_spec_fraction ("other-ratio", "other ratio", "other ratio",
       
    97           0, 1, 2, 1, 16, 9, G_PARAM_READWRITE));
       
    98 
       
    99   g_object_class_install_property (gobject_class, 3,
       
   100       g_param_spec_boolean ("foo", "foo", "foo", TRUE, G_PARAM_READWRITE));
       
   101 }
       
   102 
       
   103 static void
       
   104 gst_dummy_obj_init (GstDummyObj * obj, GstDummyObjClass * klass)
       
   105 {
       
   106   /* nothing to do there */
       
   107 }
       
   108 
       
   109 static void
       
   110 gst_dummy_obj_set_property (GObject * obj, guint prop_id, const GValue * val,
       
   111     GParamSpec * pspec)
       
   112 {
       
   113   GstDummyObj *dobj = (GstDummyObj *) obj;
       
   114 
       
   115   fail_unless_equals_int (prop_id, 2);
       
   116   dobj->num = gst_value_get_fraction_numerator (val);
       
   117   dobj->denom = gst_value_get_fraction_denominator (val);
       
   118 }
       
   119 
       
   120 static void
       
   121 gst_dummy_obj_get_property (GObject * obj, guint prop_id, GValue * val,
       
   122     GParamSpec * pspec)
       
   123 {
       
   124   GstDummyObj *dobj = (GstDummyObj *) obj;
       
   125 
       
   126   fail_unless_equals_int (prop_id, 2);
       
   127   gst_value_set_fraction (val, dobj->num, dobj->denom);
       
   128 }
       
   129 
       
   130 void test_param_spec_fraction()
       
   131 {
       
   132   GObject *obj;
       
   133   GValue val = { 0, };
       
   134   gint n = 0, d = 0;
       
   135   
       
   136   std_log(LOG_FILENAME_LINE, "Test Started test_param_spec_fraction");
       
   137 
       
   138   obj = g_object_new (GST_TYPE_DUMMY_OBJ, "other-ratio", 15, 8, NULL);
       
   139 
       
   140   g_value_init (&val, GST_TYPE_FRACTION);
       
   141   g_object_get_property (G_OBJECT (obj), "other-ratio", &val);
       
   142   fail_unless_equals_int (gst_value_get_fraction_numerator (&val), 15);
       
   143   fail_unless_equals_int (gst_value_get_fraction_denominator (&val), 8);
       
   144   g_value_unset (&val);
       
   145 
       
   146   g_object_get (obj, "other-ratio", &n, &d, NULL);
       
   147   fail_unless_equals_int (n, 15);
       
   148   fail_unless_equals_int (d, 8);
       
   149 
       
   150   g_object_unref (obj);
       
   151   
       
   152   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   153     create_xml(0);
       
   154 }
       
   155 
       
   156 
       
   157 void (*fn[]) (void) = {
       
   158 test_param_spec_fraction
       
   159 };
       
   160 
       
   161 char *args[] = {
       
   162 "test_param_spec_fraction"
       
   163 };
       
   164 
       
   165 GST_CHECK_MAIN (gst_param_spec);