1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/glib/tsrc/BC/src/dataset_test.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,114 @@
1.4 +/*
1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
1.6 +*
1.7 +* This library is free software; you can redistribute it and/or
1.8 +* modify it under the terms of the GNU Lesser General Public
1.9 +* License as published by the Free Software Foundation; either
1.10 +* version 2 of the License, or (at your option) any later version.
1.11 +*
1.12 +* This library is distributed in the hope that it will be useful,
1.13 +* but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.15 +* Lesser General Public License for more details.
1.16 +*
1.17 +* You should have received a copy of the GNU Lesser General Public
1.18 +* License along with this library; if not, write to the
1.19 +* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1.20 +* Boston, MA 02111-1307, USA.
1.21 +*
1.22 +* Description:
1.23 +*
1.24 +*/
1.25 +
1.26 +
1.27 +
1.28 +#undef G_DISABLE_ASSERT
1.29 +#undef G_LOG_DOMAIN
1.30 +
1.31 +#include <stdio.h>
1.32 +#include <string.h>
1.33 +#include "glib.h"
1.34 +
1.35 +#ifdef SYMBIAN
1.36 +#include "mrt2_glib2_test.h"
1.37 +#endif /*SYMBIAN*/
1.38 +
1.39 +struct data
1.40 +{
1.41 + char a[50],b[50],c[50];
1.42 +};
1.43 +
1.44 +void function(GQuark key_id,gpointer data,gpointer user_data)
1.45 +{
1.46 + int *i = (int *)user_data;
1.47 + (*i)++;
1.48 +}
1.49 +
1.50 +void dataset_test()
1.51 +{
1.52 + struct data *d = g_malloc(sizeof(struct data));
1.53 + gchar *str1,*str2,*str3,*str4,*str5,*str6;
1.54 + int user_data = 0;
1.55 +
1.56 + GQuark q1,q2,q3;
1.57 +
1.58 + strcpy(d->a,"test1");
1.59 + strcpy(d->b,"test2");
1.60 + strcpy(d->c,"test3");
1.61 +
1.62 + q1 = g_quark_from_string(d->a);
1.63 + q2 = g_quark_from_string(d->b);
1.64 + q3 = g_quark_from_string(d->c);
1.65 +
1.66 + g_dataset_id_set_data_full(d,q1,d->a,NULL);
1.67 + g_dataset_id_set_data_full(d,q2,d->b,NULL);
1.68 + g_dataset_id_set_data_full(d,q3,d->c,NULL);
1.69 +
1.70 + str1 = g_dataset_id_get_data(d,q1);
1.71 + str2 = g_dataset_id_get_data(d,q2);
1.72 + str3 = g_dataset_id_get_data(d,q3);
1.73 +
1.74 + // These assertions will check whether g_dataset_id_set_data_full &
1.75 + // g_dataset_id_get_data is sucessful or not
1.76 + g_assert(!strcmp(str1,d->a));
1.77 + g_assert(!strcmp(str2,d->b));
1.78 + g_assert(!strcmp(str3,d->c));
1.79 +
1.80 + str4 = g_dataset_id_remove_no_notify(d,q1);
1.81 + str5 = g_dataset_id_get_data(d,q1);
1.82 +
1.83 + //This assertion will check if g_dataset_id_remove_no_notify is sucessful or not
1.84 + g_assert(!strcmp(str4,d->a));
1.85 + g_assert(str5 == NULL);
1.86 +
1.87 + g_dataset_foreach(d,function,&user_data);
1.88 +
1.89 +
1.90 + //This assertion will check if g_dataset_foreach is sucessful or not
1.91 + g_assert(user_data == 2);
1.92 +
1.93 + g_dataset_destroy(d);
1.94 +
1.95 + str6 = g_dataset_id_get_data(d,q2);
1.96 +
1.97 + //This assertion will check if g_dataset_destroy is successful or not
1.98 + g_assert(str5 == NULL);
1.99 +
1.100 +}
1.101 +
1.102 +
1.103 +int main (int argc,
1.104 + char *argv[])
1.105 +{
1.106 + #ifdef SYMBIAN
1.107 + 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);
1.108 + #endif /*SYMBIAN*/
1.109 +
1.110 + dataset_test();
1.111 +
1.112 + #if SYMBIAN
1.113 + testResultXml("dataset_test");
1.114 + #endif /* EMULATOR */
1.115 +
1.116 + return 0;
1.117 +}
1.118 \ No newline at end of file