sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. sl@0: * sl@0: * This library is free software; you can redistribute it and/or sl@0: * modify it under the terms of the GNU Lesser General Public sl@0: * License as published by the Free Software Foundation; either sl@0: * version 2 of the License, or (at your option) any later version. sl@0: * sl@0: * This library is distributed in the hope that it will be useful, sl@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of sl@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU sl@0: * Lesser General Public License for more details. sl@0: * sl@0: * You should have received a copy of the GNU Lesser General Public sl@0: * License along with this library; if not, write to the sl@0: * Free Software Foundation, Inc., 59 Temple Place - Suite 330, sl@0: * Boston, MA 02111-1307, USA. sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #undef G_DISABLE_ASSERT sl@0: #undef G_LOG_DOMAIN sl@0: sl@0: #include sl@0: #include sl@0: #include "glib.h" sl@0: sl@0: #ifdef SYMBIAN sl@0: #include "mrt2_glib2_test.h" sl@0: #endif /*SYMBIAN*/ sl@0: sl@0: int sort_func(gconstpointer _a,gconstpointer _b,gpointer _user_data) sl@0: { sl@0: const guint8 *a = _a; sl@0: const guint8 *b = _b; sl@0: sl@0: gint *user_data = _user_data; sl@0: sl@0: if(*user_data == 1) sl@0: { sl@0: if((*a) > (*b)) sl@0: return -1; sl@0: else if((*a) == (*b)) sl@0: return 0; sl@0: else sl@0: return 1; sl@0: } sl@0: else sl@0: { sl@0: if((*a) < (*b)) sl@0: return -1; sl@0: else if(*a == *b) sl@0: return 0; sl@0: else sl@0: return 1; sl@0: } sl@0: } sl@0: sl@0: int ascending(gconstpointer _a,gconstpointer _b) sl@0: { sl@0: const guint8 *a = _a; sl@0: const guint8 *b = _b; sl@0: sl@0: if((*a) < (*b)) sl@0: return -1; sl@0: else if(*a == *b) sl@0: return 0; sl@0: else sl@0: return 1; sl@0: sl@0: } sl@0: sl@0: int main (int argc, sl@0: char *argv[]) sl@0: { sl@0: GByteArray *gbarray; sl@0: gint i; sl@0: int user_data = 1; sl@0: sl@0: #ifdef SYMBIAN sl@0: 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: #endif /*SYMBIAN*/ sl@0: sl@0: gbarray = g_byte_array_new (); sl@0: sl@0: g_byte_array_prepend(gbarray,(guint8 *)"c",1); sl@0: g_byte_array_prepend(gbarray,(guint8 *)"b",1); sl@0: g_byte_array_prepend(gbarray,(guint8 *)"a",1); sl@0: sl@0: g_assert(gbarray->data[0] == 'a'); sl@0: g_assert(gbarray->data[1] == 'b'); sl@0: g_assert(gbarray->data[2] == 'c'); sl@0: sl@0: g_byte_array_remove_index(gbarray,1); sl@0: sl@0: g_assert(gbarray->data[0] == 'a'); sl@0: g_assert(gbarray->data[1] == 'c'); sl@0: sl@0: g_byte_array_append(gbarray,(guint8 *)"b",1); sl@0: sl@0: g_byte_array_remove_index_fast(gbarray,1); sl@0: sl@0: g_assert(gbarray->data[1] == 'b'); sl@0: sl@0: g_byte_array_append(gbarray,(guint8 *)"c",1); sl@0: sl@0: g_byte_array_append(gbarray,(guint8 *)"d",1); sl@0: sl@0: g_byte_array_append(gbarray,(guint8 *)"e",1); sl@0: sl@0: g_byte_array_remove_range(gbarray,0,3); sl@0: sl@0: g_assert(gbarray->data[0] == 'd'); sl@0: g_assert(gbarray->data[1] == 'e'); sl@0: sl@0: g_byte_array_set_size(gbarray,10); sl@0: sl@0: g_assert(gbarray->len == 10); sl@0: sl@0: g_byte_array_free(gbarray,TRUE); sl@0: sl@0: gbarray = g_byte_array_sized_new (10); sl@0: sl@0: g_assert(gbarray->len == 0); sl@0: sl@0: g_byte_array_append(gbarray,(guint8 *)"c",1); sl@0: g_byte_array_append(gbarray,(guint8 *)"b",1); sl@0: g_byte_array_append(gbarray,(guint8 *)"a",1); sl@0: sl@0: g_byte_array_sort(gbarray,ascending); sl@0: sl@0: g_assert(gbarray->data[0] == 'a'); sl@0: g_assert(gbarray->data[1] == 'b'); sl@0: g_assert(gbarray->data[2] == 'c'); sl@0: sl@0: g_byte_array_sort_with_data(gbarray,sort_func,&user_data); sl@0: sl@0: g_assert(gbarray->data[0] == 'c'); sl@0: g_assert(gbarray->data[1] == 'b'); sl@0: g_assert(gbarray->data[2] == 'a'); sl@0: sl@0: g_byte_array_free(gbarray,TRUE); sl@0: sl@0: #if SYMBIAN sl@0: testResultXml("byte_array_test"); sl@0: #endif /* EMULATOR */ sl@0: sl@0: return 0; sl@0: }