#include <stdio.h>#include <string.h>#include "glib.h"Go to the source code of this file.
Classes | |
| struct | GlibTestInfo |
Defines | |
| #define | TEST(m, cond) |
| #define | C2P(c) ((gpointer) ((long) (c))) |
| #define | P2C(p) ((gchar) ((long) (p))) |
| #define | GLIB_TEST_STRING "el dorado " |
| #define | GLIB_TEST_STRING_5 "el do" |
Functions | |
| int | main (int argc, char *argv[]) |
Variables | |
| int | array [10000] |
| gboolean | failed = FALSE |
|
|
Definition at line 47 of file array-test.c. |
|
|
Definition at line 50 of file array-test.c. |
|
|
Definition at line 51 of file array-test.c. |
|
|
Definition at line 48 of file array-test.c. |
|
|
Value: G_STMT_START { failed = !(cond); \ if (failed) \ { if (!m) \ g_print ("\n(%s:%d) failed for: %s\n", __FILE__, __LINE__, ( # cond )); \ else \ g_print ("\n(%s:%d) failed for: %s: (%s)\n", __FILE__, __LINE__, ( # cond ), (gchar*)m); \ } \ else \ g_print ("."); fflush (stdout); \ } G_STMT_END Definition at line 36 of file array-test.c. |
|
||||||||||||
|
Definition at line 60 of file array-test.c. References _GByteArray::data, FALSE, g_array_append_val, g_array_free(), g_array_index, g_array_new(), g_array_prepend_val, g_assert, g_byte_array_append(), g_byte_array_free(), g_byte_array_new(), g_print(), g_ptr_array_add(), g_ptr_array_free(), g_ptr_array_index, g_ptr_array_new(), and TRUE. 00062 { 00063 gint i; 00064 GArray *garray; 00065 GPtrArray *gparray; 00066 GByteArray *gbarray; 00067 00068 /* array tests */ 00069 garray = g_array_new (FALSE, FALSE, sizeof (gint)); 00070 for (i = 0; i < 10000; i++) 00071 g_array_append_val (garray, i); 00072 00073 for (i = 0; i < 10000; i++) 00074 g_assert (g_array_index (garray, gint, i) == i); 00075 00076 g_array_free (garray, TRUE); 00077 00078 garray = g_array_new (FALSE, FALSE, sizeof (gint)); 00079 for (i = 0; i < 100; i++) 00080 g_array_prepend_val (garray, i); 00081 00082 for (i = 0; i < 100; i++) 00083 g_assert (g_array_index (garray, gint, i) == (100 - i - 1)); 00084 00085 g_array_free (garray, TRUE); 00086 00087 /* pointer arrays */ 00088 gparray = g_ptr_array_new (); 00089 for (i = 0; i < 10000; i++) 00090 g_ptr_array_add (gparray, GINT_TO_POINTER (i)); 00091 00092 for (i = 0; i < 10000; i++) 00093 if (g_ptr_array_index (gparray, i) != GINT_TO_POINTER (i)) 00094 g_print ("array fails: %p ( %p )\n", g_ptr_array_index (gparray, i), GINT_TO_POINTER (i)); 00095 00096 g_ptr_array_free (gparray, TRUE); 00097 00098 /* byte arrays */ 00099 gbarray = g_byte_array_new (); 00100 for (i = 0; i < 10000; i++) 00101 g_byte_array_append (gbarray, (guint8*) "abcd", 4); 00102 00103 for (i = 0; i < 10000; i++) 00104 { 00105 g_assert (gbarray->data[4*i] == 'a'); 00106 g_assert (gbarray->data[4*i+1] == 'b'); 00107 g_assert (gbarray->data[4*i+2] == 'c'); 00108 g_assert (gbarray->data[4*i+3] == 'd'); 00109 } 00110 00111 g_byte_array_free (gbarray, TRUE); 00112 00113 return 0; 00114 }
|
|
|
Definition at line 33 of file array-test.c. |
|
|
Definition at line 34 of file array-test.c. |