os/ossrv/glib/tsrc/BC/tests/gobject/paramspec-test.c
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/* GLIB - Library of useful routines for C programming
sl@0
     2
 * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
sl@0
     3
 * Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
sl@0
     4
 * This library is free software; you can redistribute it and/or
sl@0
     5
 * modify it under the terms of the GNU Lesser General Public
sl@0
     6
 * License as published by the Free Software Foundation; either
sl@0
     7
 * version 2 of the License, or (at your option) any later version.
sl@0
     8
 *
sl@0
     9
 * This library is distributed in the hope that it will be useful,
sl@0
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
sl@0
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
sl@0
    12
 * Lesser General Public License for more details.
sl@0
    13
 *
sl@0
    14
 * You should have received a copy of the GNU Lesser General Public
sl@0
    15
 * License along with this library; if not, write to the
sl@0
    16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
sl@0
    17
 * Boston, MA 02111-1307, USA.
sl@0
    18
 */
sl@0
    19
sl@0
    20
/*
sl@0
    21
 * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
sl@0
    22
 * file for a list of people on the GLib Team.  See the ChangeLog
sl@0
    23
 * files for a list of changes.  These files are distributed with
sl@0
    24
 * GLib at ftp://ftp.gtk.org/pub/gtk/. 
sl@0
    25
 */
sl@0
    26
sl@0
    27
#undef G_DISABLE_ASSERT
sl@0
    28
#undef G_LOG_DOMAIN
sl@0
    29
sl@0
    30
#include <string.h>
sl@0
    31
sl@0
    32
#include <glib.h>
sl@0
    33
#include <glib-object.h>
sl@0
    34
sl@0
    35
#ifdef SYMBIAN
sl@0
    36
#include "mrt2_glib2_test.h"
sl@0
    37
#include <gobject_global.h>
sl@0
    38
#endif //SYMBIAN
sl@0
    39
sl@0
    40
static void
sl@0
    41
test_param_spec_char (void)
sl@0
    42
{
sl@0
    43
  GParamSpec *pspec;
sl@0
    44
  GValue value = { 0, };
sl@0
    45
  gboolean modified;
sl@0
    46
 
sl@0
    47
  pspec = g_param_spec_char ("char", "nick", "blurb",
sl@0
    48
			     20, 40, 30, G_PARAM_READWRITE);
sl@0
    49
sl@0
    50
  //g_param_spec_ref_force_floating(pspec);			     
sl@0
    51
  //g_assert(g_param_spec_is_floating(pspec)); 			     
sl@0
    52
  g_param_spec_ref_sink(pspec);
sl@0
    53
sl@0
    54
  g_assert (strcmp (g_param_spec_get_name (pspec), "char") == 0);
sl@0
    55
  g_assert (strcmp (g_param_spec_get_nick (pspec), "nick") == 0);
sl@0
    56
  g_assert (strcmp (g_param_spec_get_blurb (pspec), "blurb") == 0);
sl@0
    57
sl@0
    58
  g_value_init (&value, G_TYPE_CHAR);
sl@0
    59
  g_value_set_char (&value, 30);
sl@0
    60
sl@0
    61
  g_assert (g_param_value_defaults (pspec, &value));
sl@0
    62
  
sl@0
    63
  g_value_set_char (&value, 0);
sl@0
    64
  modified = g_param_value_validate (pspec, &value);
sl@0
    65
  g_assert (modified && g_value_get_char (&value) == 20);
sl@0
    66
sl@0
    67
  g_value_set_char (&value, 20);
sl@0
    68
  modified = g_param_value_validate (pspec, &value);
sl@0
    69
  g_assert (!modified && g_value_get_char (&value) == 20);
sl@0
    70
sl@0
    71
  g_value_set_char (&value, 40);
sl@0
    72
  modified = g_param_value_validate (pspec, &value);
sl@0
    73
  g_assert (!modified && g_value_get_char (&value) == 40);
sl@0
    74
sl@0
    75
  g_value_set_char (&value, 60);
sl@0
    76
  modified = g_param_value_validate (pspec, &value);
sl@0
    77
  g_assert (modified && g_value_get_char (&value) == 40);
sl@0
    78
sl@0
    79
  g_param_spec_unref (pspec);
sl@0
    80
}
sl@0
    81
sl@0
    82
static void
sl@0
    83
test_param_spec_override (void)
sl@0
    84
{
sl@0
    85
  GParamSpec *ospec, *pspec;
sl@0
    86
  GValue value = { 0, };
sl@0
    87
  gboolean modified;
sl@0
    88
 
sl@0
    89
  ospec = g_param_spec_char ("char", "nick", "blurb",
sl@0
    90
			     20, 40, 30, G_PARAM_READWRITE);
sl@0
    91
sl@0
    92
  pspec = g_param_spec_override ("override", ospec);
sl@0
    93
sl@0
    94
  g_assert (strcmp (g_param_spec_get_name (pspec), "override") == 0);
sl@0
    95
  g_assert (strcmp (g_param_spec_get_nick (pspec), "nick") == 0);
sl@0
    96
  g_assert (strcmp (g_param_spec_get_blurb (pspec), "blurb") == 0);
sl@0
    97
sl@0
    98
  g_value_init (&value, G_TYPE_CHAR);
sl@0
    99
  g_value_set_char (&value, 30);
sl@0
   100
sl@0
   101
  g_assert (g_param_value_defaults (pspec, &value));
sl@0
   102
  
sl@0
   103
  g_value_set_char (&value, 0);
sl@0
   104
  modified = g_param_value_validate (pspec, &value);
sl@0
   105
  g_assert (modified && g_value_get_char (&value) == 20);
sl@0
   106
sl@0
   107
  g_value_set_char (&value, 20);
sl@0
   108
  modified = g_param_value_validate (pspec, &value);
sl@0
   109
  g_assert (!modified && g_value_get_char (&value) == 20);
sl@0
   110
sl@0
   111
  g_value_set_char (&value, 40);
sl@0
   112
  modified = g_param_value_validate (pspec, &value);
sl@0
   113
  g_assert (!modified && g_value_get_char (&value) == 40);
sl@0
   114
sl@0
   115
  g_value_set_char (&value, 60);
sl@0
   116
  modified = g_param_value_validate (pspec, &value);
sl@0
   117
  g_assert (modified && g_value_get_char (&value) == 40);
sl@0
   118
sl@0
   119
  g_param_spec_unref (pspec);
sl@0
   120
}
sl@0
   121
sl@0
   122
static void
sl@0
   123
test_param_spec_gtype (void)
sl@0
   124
{
sl@0
   125
  GParamSpec *pspec;
sl@0
   126
  GValue value = { 0, };
sl@0
   127
  gboolean modified;
sl@0
   128
  
sl@0
   129
  pspec = g_param_spec_gtype ("gtype", "nick", "blurb",
sl@0
   130
			      G_TYPE_PARAM, G_PARAM_READWRITE);
sl@0
   131
  
sl@0
   132
  g_value_init (&value, G_TYPE_GTYPE);
sl@0
   133
  g_value_set_gtype (&value, G_TYPE_PARAM);
sl@0
   134
sl@0
   135
  g_assert (g_param_value_defaults (pspec, &value));
sl@0
   136
  
sl@0
   137
  g_value_set_gtype (&value, G_TYPE_INT);
sl@0
   138
  modified = g_param_value_validate (pspec, &value);
sl@0
   139
  g_assert (modified && g_value_get_gtype (&value) == G_TYPE_PARAM);
sl@0
   140
sl@0
   141
  g_value_set_gtype (&value, G_TYPE_PARAM_INT);
sl@0
   142
  modified = g_param_value_validate (pspec, &value);
sl@0
   143
  g_assert (!modified && g_value_get_gtype (&value) == G_TYPE_PARAM_INT);
sl@0
   144
}
sl@0
   145
sl@0
   146
int
sl@0
   147
main (int argc, char *argv[])
sl@0
   148
{
sl@0
   149
#ifdef SYMBIAN
sl@0
   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);
sl@0
   151
  g_set_print_handler(mrtPrintHandler);
sl@0
   152
  #endif /*SYMBIAN*/
sl@0
   153
  g_type_init (); 
sl@0
   154
  
sl@0
   155
  test_param_spec_char ();
sl@0
   156
  test_param_spec_override ();
sl@0
   157
  test_param_spec_gtype ();
sl@0
   158
  
sl@0
   159
#ifdef SYMBIAN
sl@0
   160
testResultXml("paramspec-test");
sl@0
   161
#endif /*SYMBIAN*/
sl@0
   162
  return 0;
sl@0
   163
}