glib/tsrc/BC/tests/gobject/paramspec-test.c
changeset 31 ce057bb09d0b
child 45 4b03adbd26ca
equal deleted inserted replaced
30:e20de85af2ee 31:ce057bb09d0b
       
     1 /* GLIB - Library of useful routines for C programming
       
     2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
       
     3  * Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
       
     4  * This library is free software; you can redistribute it and/or
       
     5  * modify it under the terms of the GNU Lesser 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  * Lesser General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU Lesser 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  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
       
    22  * file for a list of people on the GLib Team.  See the ChangeLog
       
    23  * files for a list of changes.  These files are distributed with
       
    24  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
       
    25  */
       
    26 
       
    27 #undef G_DISABLE_ASSERT
       
    28 #undef G_LOG_DOMAIN
       
    29 
       
    30 #include <string.h>
       
    31 
       
    32 #include <glib.h>
       
    33 #include <glib-object.h>
       
    34 
       
    35 #ifdef SYMBIAN
       
    36 #include "mrt2_glib2_test.h"
       
    37 #include <gobject_global.h>
       
    38 #endif //SYMBIAN
       
    39 
       
    40 static void
       
    41 test_param_spec_char (void)
       
    42 {
       
    43   GParamSpec *pspec;
       
    44   GValue value = { 0, };
       
    45   gboolean modified;
       
    46  
       
    47   pspec = g_param_spec_char ("char", "nick", "blurb",
       
    48 			     20, 40, 30, G_PARAM_READWRITE);
       
    49 
       
    50   //g_param_spec_ref_force_floating(pspec);			     
       
    51   //g_assert(g_param_spec_is_floating(pspec)); 			     
       
    52   g_param_spec_ref_sink(pspec);
       
    53 
       
    54   g_assert (strcmp (g_param_spec_get_name (pspec), "char") == 0);
       
    55   g_assert (strcmp (g_param_spec_get_nick (pspec), "nick") == 0);
       
    56   g_assert (strcmp (g_param_spec_get_blurb (pspec), "blurb") == 0);
       
    57 
       
    58   g_value_init (&value, G_TYPE_CHAR);
       
    59   g_value_set_char (&value, 30);
       
    60 
       
    61   g_assert (g_param_value_defaults (pspec, &value));
       
    62   
       
    63   g_value_set_char (&value, 0);
       
    64   modified = g_param_value_validate (pspec, &value);
       
    65   g_assert (modified && g_value_get_char (&value) == 20);
       
    66 
       
    67   g_value_set_char (&value, 20);
       
    68   modified = g_param_value_validate (pspec, &value);
       
    69   g_assert (!modified && g_value_get_char (&value) == 20);
       
    70 
       
    71   g_value_set_char (&value, 40);
       
    72   modified = g_param_value_validate (pspec, &value);
       
    73   g_assert (!modified && g_value_get_char (&value) == 40);
       
    74 
       
    75   g_value_set_char (&value, 60);
       
    76   modified = g_param_value_validate (pspec, &value);
       
    77   g_assert (modified && g_value_get_char (&value) == 40);
       
    78 
       
    79   g_param_spec_unref (pspec);
       
    80 }
       
    81 
       
    82 static void
       
    83 test_param_spec_override (void)
       
    84 {
       
    85   GParamSpec *ospec, *pspec;
       
    86   GValue value = { 0, };
       
    87   gboolean modified;
       
    88  
       
    89   ospec = g_param_spec_char ("char", "nick", "blurb",
       
    90 			     20, 40, 30, G_PARAM_READWRITE);
       
    91 
       
    92   pspec = g_param_spec_override ("override", ospec);
       
    93 
       
    94   g_assert (strcmp (g_param_spec_get_name (pspec), "override") == 0);
       
    95   g_assert (strcmp (g_param_spec_get_nick (pspec), "nick") == 0);
       
    96   g_assert (strcmp (g_param_spec_get_blurb (pspec), "blurb") == 0);
       
    97 
       
    98   g_value_init (&value, G_TYPE_CHAR);
       
    99   g_value_set_char (&value, 30);
       
   100 
       
   101   g_assert (g_param_value_defaults (pspec, &value));
       
   102   
       
   103   g_value_set_char (&value, 0);
       
   104   modified = g_param_value_validate (pspec, &value);
       
   105   g_assert (modified && g_value_get_char (&value) == 20);
       
   106 
       
   107   g_value_set_char (&value, 20);
       
   108   modified = g_param_value_validate (pspec, &value);
       
   109   g_assert (!modified && g_value_get_char (&value) == 20);
       
   110 
       
   111   g_value_set_char (&value, 40);
       
   112   modified = g_param_value_validate (pspec, &value);
       
   113   g_assert (!modified && g_value_get_char (&value) == 40);
       
   114 
       
   115   g_value_set_char (&value, 60);
       
   116   modified = g_param_value_validate (pspec, &value);
       
   117   g_assert (modified && g_value_get_char (&value) == 40);
       
   118 
       
   119   g_param_spec_unref (pspec);
       
   120 }
       
   121 
       
   122 static void
       
   123 test_param_spec_gtype (void)
       
   124 {
       
   125   GParamSpec *pspec;
       
   126   GValue value = { 0, };
       
   127   gboolean modified;
       
   128   
       
   129   pspec = g_param_spec_gtype ("gtype", "nick", "blurb",
       
   130 			      G_TYPE_PARAM, G_PARAM_READWRITE);
       
   131   
       
   132   g_value_init (&value, G_TYPE_GTYPE);
       
   133   g_value_set_gtype (&value, G_TYPE_PARAM);
       
   134 
       
   135   g_assert (g_param_value_defaults (pspec, &value));
       
   136   
       
   137   g_value_set_gtype (&value, G_TYPE_INT);
       
   138   modified = g_param_value_validate (pspec, &value);
       
   139   g_assert (modified && g_value_get_gtype (&value) == G_TYPE_PARAM);
       
   140 
       
   141   g_value_set_gtype (&value, G_TYPE_PARAM_INT);
       
   142   modified = g_param_value_validate (pspec, &value);
       
   143   g_assert (!modified && g_value_get_gtype (&value) == G_TYPE_PARAM_INT);
       
   144 }
       
   145 
       
   146 int
       
   147 main (int argc, char *argv[])
       
   148 {
       
   149 #ifdef SYMBIAN
       
   150   g_log_set_handler (NULL,  G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
       
   151   g_set_print_handler(mrtPrintHandler);
       
   152   #endif /*SYMBIAN*/
       
   153   g_type_init (); 
       
   154   
       
   155   test_param_spec_char ();
       
   156   test_param_spec_override ();
       
   157   test_param_spec_gtype ();
       
   158   
       
   159 #ifdef SYMBIAN
       
   160 testResultXml("paramspec-test");
       
   161 #endif /*SYMBIAN*/
       
   162   return 0;
       
   163 }