First public contribution.
2 * Copyright (c) 2009 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.
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.
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.
24 #undef G_DISABLE_ASSERT
32 #include "mrt2_glib2_test.h"
35 int sort_func(gconstpointer _a,gconstpointer _b,gpointer _user_data)
40 gint *user_data = _user_data;
62 int ascending(gconstpointer _a,gconstpointer _b)
84 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);
87 gbarray = g_byte_array_new ();
89 g_byte_array_prepend(gbarray,(guint8 *)"c",1);
90 g_byte_array_prepend(gbarray,(guint8 *)"b",1);
91 g_byte_array_prepend(gbarray,(guint8 *)"a",1);
93 g_assert(gbarray->data[0] == 'a');
94 g_assert(gbarray->data[1] == 'b');
95 g_assert(gbarray->data[2] == 'c');
97 g_byte_array_remove_index(gbarray,1);
99 g_assert(gbarray->data[0] == 'a');
100 g_assert(gbarray->data[1] == 'c');
102 g_byte_array_append(gbarray,(guint8 *)"b",1);
104 g_byte_array_remove_index_fast(gbarray,1);
106 g_assert(gbarray->data[1] == 'b');
108 g_byte_array_append(gbarray,(guint8 *)"c",1);
110 g_byte_array_append(gbarray,(guint8 *)"d",1);
112 g_byte_array_append(gbarray,(guint8 *)"e",1);
114 g_byte_array_remove_range(gbarray,0,3);
116 g_assert(gbarray->data[0] == 'd');
117 g_assert(gbarray->data[1] == 'e');
119 g_byte_array_set_size(gbarray,10);
121 g_assert(gbarray->len == 10);
123 g_byte_array_free(gbarray,TRUE);
125 gbarray = g_byte_array_sized_new (10);
127 g_assert(gbarray->len == 0);
129 g_byte_array_append(gbarray,(guint8 *)"c",1);
130 g_byte_array_append(gbarray,(guint8 *)"b",1);
131 g_byte_array_append(gbarray,(guint8 *)"a",1);
133 g_byte_array_sort(gbarray,ascending);
135 g_assert(gbarray->data[0] == 'a');
136 g_assert(gbarray->data[1] == 'b');
137 g_assert(gbarray->data[2] == 'c');
139 g_byte_array_sort_with_data(gbarray,sort_func,&user_data);
141 g_assert(gbarray->data[0] == 'c');
142 g_assert(gbarray->data[1] == 'b');
143 g_assert(gbarray->data[2] == 'a');
145 g_byte_array_free(gbarray,TRUE);
148 testResultXml("byte_array_test");
149 #endif /* EMULATOR */