Interpret EINTR as G_IO_ERROR_AGAIN.
[platform/upstream/glib.git] / testglib.c
index 2a5ba73..940851b 100644 (file)
@@ -77,7 +77,7 @@ g_node_test (void)
   GNode *node_G;
   GNode *node_J;
   guint i;
-  gchar *tstring;
+  gchar *tstring, *cstring;
 
   g_print ("checking n-way trees: ");
   failed = FALSE;
@@ -165,7 +165,18 @@ g_node_test (void)
   g_node_traverse (root, G_LEVEL_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
   TEST (tstring, strcmp (tstring, "ABFEDCGKJIH") == 0);
   g_free (tstring); tstring = NULL;
-  
+
+  cstring = NULL;
+  node = g_node_copy (root);
+  TEST (NULL, g_node_n_nodes (root, G_TRAVERSE_ALL) == g_node_n_nodes (node, G_TRAVERSE_ALL));
+  TEST (NULL, g_node_max_height (root) == g_node_max_height (node));
+  g_node_traverse (root, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &tstring);
+  g_node_traverse (node, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_build_string, &cstring);
+  TEST (cstring, strcmp (tstring, cstring) == 0);
+  g_free (tstring); tstring = NULL;
+  g_free (cstring); cstring = NULL;
+  g_node_destroy (node);
+
   g_node_destroy (root);
 
   /* allocation tests */
@@ -726,6 +737,65 @@ main (int   argc,
   g_print ("and next 70:\n%s\n", string2->str+142);
   g_print ("last 70 chars:\n%s\n", string2->str+string2->len - 70);
 
+  g_string_free (string1, TRUE);
+  g_string_free (string2, TRUE);
+
+  /* append */
+  string1 = g_string_new ("firsthalf");
+  g_string_append (string1, "lasthalf");
+  g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
+  g_string_free (string1, TRUE);
+
+  /* append_len */
+
+  string1 = g_string_new ("firsthalf");
+  g_string_append_len (string1, "lasthalfjunkjunk", strlen ("lasthalf"));
+  g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
+  g_string_free (string1, TRUE);  
+  
+  /* prepend */
+  string1 = g_string_new ("lasthalf");
+  g_string_prepend (string1, "firsthalf");
+  g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
+  g_string_free (string1, TRUE);
+
+  /* prepend_len */
+  string1 = g_string_new ("lasthalf");
+  g_string_prepend_len (string1, "firsthalfjunkjunk", strlen ("firsthalf"));
+  g_assert (strcmp (string1->str, "firsthalflasthalf") == 0);
+  g_string_free (string1, TRUE);
+  
+  /* insert */
+  string1 = g_string_new ("firstlast");
+  g_string_insert (string1, 5, "middle");
+  g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
+  g_string_free (string1, TRUE);
+
+  /* insert with pos == end of the string */
+  string1 = g_string_new ("firstmiddle");
+  g_string_insert (string1, strlen ("firstmiddle"), "last");
+  g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
+  g_string_free (string1, TRUE);
+  
+  /* insert_len */
+
+  string1 = g_string_new ("firstlast");
+  g_string_insert_len (string1, 5, "middlejunkjunk", strlen ("middle"));
+  g_assert (strcmp (string1->str, "firstmiddlelast") == 0);
+  g_string_free (string1, TRUE);
+
+  /* insert_len with magic -1 pos for append */
+  string1 = g_string_new ("first");
+  g_string_insert_len (string1, -1, "lastjunkjunk", strlen ("last"));
+  g_assert (strcmp (string1->str, "firstlast") == 0);
+  g_string_free (string1, TRUE);
+  
+  /* insert_len with magic -1 len for strlen-the-string */
+  string1 = g_string_new ("first");
+  g_string_insert_len (string1, 5, "last", -1);
+  g_assert (strcmp (string1->str, "firstlast") == 0);
+  g_string_free (string1, TRUE);
+  
   g_print ("ok\n");
 
   g_print ("checking timers...\n");
@@ -914,8 +984,13 @@ main (int   argc,
 #ifdef G_HAVE_GINT64
   g_assert (GUINT64_SWAP_LE_BE (gu64t1) == gu64t2);  
 #endif
+
   g_print ("ok\n");
 
+#ifdef G_OS_WIN32
+  g_print ("current locale: %s\n", g_win32_getlocale ());
+#endif
+
   return 0;
 }