1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/glib/tsrc/BC/src/byte_array_test.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,152 @@
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 +#undef G_DISABLE_ASSERT
1.28 +#undef G_LOG_DOMAIN
1.29 +
1.30 +#include <stdio.h>
1.31 +#include <string.h>
1.32 +#include "glib.h"
1.33 +
1.34 +#ifdef SYMBIAN
1.35 +#include "mrt2_glib2_test.h"
1.36 +#endif /*SYMBIAN*/
1.37 +
1.38 +int sort_func(gconstpointer _a,gconstpointer _b,gpointer _user_data)
1.39 +{
1.40 + const guint8 *a = _a;
1.41 + const guint8 *b = _b;
1.42 +
1.43 + gint *user_data = _user_data;
1.44 +
1.45 + if(*user_data == 1)
1.46 + {
1.47 + if((*a) > (*b))
1.48 + return -1;
1.49 + else if((*a) == (*b))
1.50 + return 0;
1.51 + else
1.52 + return 1;
1.53 + }
1.54 + else
1.55 + {
1.56 + if((*a) < (*b))
1.57 + return -1;
1.58 + else if(*a == *b)
1.59 + return 0;
1.60 + else
1.61 + return 1;
1.62 + }
1.63 +}
1.64 +
1.65 +int ascending(gconstpointer _a,gconstpointer _b)
1.66 +{
1.67 + const guint8 *a = _a;
1.68 + const guint8 *b = _b;
1.69 +
1.70 + if((*a) < (*b))
1.71 + return -1;
1.72 + else if(*a == *b)
1.73 + return 0;
1.74 + else
1.75 + return 1;
1.76 +
1.77 +}
1.78 +
1.79 +int main (int argc,
1.80 + char *argv[])
1.81 +{
1.82 + GByteArray *gbarray;
1.83 + gint i;
1.84 + int user_data = 1;
1.85 +
1.86 + #ifdef SYMBIAN
1.87 + 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.88 + #endif /*SYMBIAN*/
1.89 +
1.90 + gbarray = g_byte_array_new ();
1.91 +
1.92 + g_byte_array_prepend(gbarray,(guint8 *)"c",1);
1.93 + g_byte_array_prepend(gbarray,(guint8 *)"b",1);
1.94 + g_byte_array_prepend(gbarray,(guint8 *)"a",1);
1.95 +
1.96 + g_assert(gbarray->data[0] == 'a');
1.97 + g_assert(gbarray->data[1] == 'b');
1.98 + g_assert(gbarray->data[2] == 'c');
1.99 +
1.100 + g_byte_array_remove_index(gbarray,1);
1.101 +
1.102 + g_assert(gbarray->data[0] == 'a');
1.103 + g_assert(gbarray->data[1] == 'c');
1.104 +
1.105 + g_byte_array_append(gbarray,(guint8 *)"b",1);
1.106 +
1.107 + g_byte_array_remove_index_fast(gbarray,1);
1.108 +
1.109 + g_assert(gbarray->data[1] == 'b');
1.110 +
1.111 + g_byte_array_append(gbarray,(guint8 *)"c",1);
1.112 +
1.113 + g_byte_array_append(gbarray,(guint8 *)"d",1);
1.114 +
1.115 + g_byte_array_append(gbarray,(guint8 *)"e",1);
1.116 +
1.117 + g_byte_array_remove_range(gbarray,0,3);
1.118 +
1.119 + g_assert(gbarray->data[0] == 'd');
1.120 + g_assert(gbarray->data[1] == 'e');
1.121 +
1.122 + g_byte_array_set_size(gbarray,10);
1.123 +
1.124 + g_assert(gbarray->len == 10);
1.125 +
1.126 + g_byte_array_free(gbarray,TRUE);
1.127 +
1.128 + gbarray = g_byte_array_sized_new (10);
1.129 +
1.130 + g_assert(gbarray->len == 0);
1.131 +
1.132 + g_byte_array_append(gbarray,(guint8 *)"c",1);
1.133 + g_byte_array_append(gbarray,(guint8 *)"b",1);
1.134 + g_byte_array_append(gbarray,(guint8 *)"a",1);
1.135 +
1.136 + g_byte_array_sort(gbarray,ascending);
1.137 +
1.138 + g_assert(gbarray->data[0] == 'a');
1.139 + g_assert(gbarray->data[1] == 'b');
1.140 + g_assert(gbarray->data[2] == 'c');
1.141 +
1.142 + g_byte_array_sort_with_data(gbarray,sort_func,&user_data);
1.143 +
1.144 + g_assert(gbarray->data[0] == 'c');
1.145 + g_assert(gbarray->data[1] == 'b');
1.146 + g_assert(gbarray->data[2] == 'a');
1.147 +
1.148 + g_byte_array_free(gbarray,TRUE);
1.149 +
1.150 + #if SYMBIAN
1.151 + testResultXml("byte_array_test");
1.152 + #endif /* EMULATOR */
1.153 +
1.154 + return 0;
1.155 +}
1.156 \ No newline at end of file