#include <errno.h>
#include "glib.h"
-#include "gstdio.h"
+#include <glib/gstdio.h>
#include <stdlib.h>
gchar *string;
gchar c[2] = "_";
- c[0] = ((gchar) ((long) (node->data)));
+ c[0] = ((gchar) ((gintptr) (node->data)));
string = g_strconcat (*p ? *p : "", c, NULL);
g_free (*p);
gnode_test (void)
{
#define C2P(c) ((gpointer) ((long) (c)))
-#define P2C(p) ((gchar) ((long) (p)))
+#define P2C(p) ((gchar) ((gintptr) (p)))
GNode *root;
GNode *node;
GNode *node_B;
return (*v == *test);
}
-
-static void
-test_g_mkdir_with_parents_1 (const gchar *base)
-{
- char *p0 = g_build_filename (base, "fum", NULL);
- char *p1 = g_build_filename (p0, "tem", NULL);
- char *p2 = g_build_filename (p1, "zap", NULL);
- FILE *f;
-
- g_remove (p2);
- g_remove (p1);
- g_remove (p0);
-
- if (g_file_test (p0, G_FILE_TEST_EXISTS))
- g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p0);
-
- if (g_file_test (p1, G_FILE_TEST_EXISTS))
- g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p1);
-
- if (g_file_test (p2, G_FILE_TEST_EXISTS))
- g_error ("failed, %s exists, cannot test g_mkdir_with_parents\n", p2);
-
- if (g_mkdir_with_parents (p2, 0777) == -1)
- g_error ("failed, g_mkdir_with_parents(%s) failed: %s\n", p2, g_strerror (errno));
-
- if (!g_file_test (p2, G_FILE_TEST_IS_DIR))
- g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p2);
-
- if (!g_file_test (p1, G_FILE_TEST_IS_DIR))
- g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p1);
-
- if (!g_file_test (p0, G_FILE_TEST_IS_DIR))
- g_error ("failed, g_mkdir_with_parents(%s) succeeded, but %s is not a directory\n", p2, p0);
-
- g_rmdir (p2);
- if (g_file_test (p2, G_FILE_TEST_EXISTS))
- g_error ("failed, did g_rmdir(%s), but %s is still there\n", p2, p2);
-
- g_rmdir (p1);
- if (g_file_test (p1, G_FILE_TEST_EXISTS))
- g_error ("failed, did g_rmdir(%s), but %s is still there\n", p1, p1);
-
- f = g_fopen (p1, "w");
- if (f == NULL)
- g_error ("failed, couldn't create file %s\n", p1);
- fclose (f);
-
- if (g_mkdir_with_parents (p1, 0666) == 0)
- g_error ("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p1, p1);
-
- if (g_mkdir_with_parents (p2, 0666) == 0)
- g_error("failed, g_mkdir_with_parents(%s) succeeded, even if %s is a file\n", p2, p1);
-
- g_remove (p2);
- g_remove (p1);
- g_remove (p0);
-}
-
-static void
-test_g_mkdir_with_parents (void)
-{
- gchar *cwd;
- if (g_test_verbose())
- g_print ("checking g_mkdir_with_parents() in subdir ./hum/");
- test_g_mkdir_with_parents_1 ("hum");
- g_remove ("hum");
- if (g_test_verbose())
- g_print ("checking g_mkdir_with_parents() in subdir ./hii///haa/hee/");
- test_g_mkdir_with_parents_1 ("hii///haa/hee");
- g_remove ("hii/haa/hee");
- g_remove ("hii/haa");
- g_remove ("hii");
- cwd = g_get_current_dir ();
- if (g_test_verbose())
- g_print ("checking g_mkdir_with_parents() in cwd: %s", cwd);
- test_g_mkdir_with_parents_1 (cwd);
- g_free (cwd);
-}
-
static void
test_g_parse_debug_string (void)
{
uddesktop = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
g_assert (uddesktop != NULL);
udddocs = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS);
- g_assert (udddocs != NULL);
uddpubshare = g_get_user_special_dir (G_USER_DIRECTORY_PUBLIC_SHARE);
- g_assert (uddpubshare != NULL);
sv = (gchar **) g_get_system_data_dirs ();
sdatadirs = g_strjoinv (G_SEARCHPATH_SEPARATOR_S, sv);
g_print ("current charset is not UTF-8: %s\n", charset);
#ifdef G_PLATFORM_WIN32
-#ifdef G_OS_WIN32
- /* Can't calculate GLib DLL name at runtime. */
- gchar *glib_dll = "libglib-2.0-0.dll";
-#endif
-#ifdef G_WITH_CYGWIN
- gchar *glib_dll = "cygglib-2.0-0.dll";
-#endif
-
g_print ("current locale: %s\n", g_win32_getlocale ());
- g_print ("GLib DLL name tested for: %s\n", glib_dll);
-
- g_print ("GLib installation directory, from Registry entry for %s if available: %s\n",
- GETTEXT_PACKAGE,
- g_win32_get_package_installation_directory (GETTEXT_PACKAGE, NULL));
- g_print ("Ditto, or from GLib DLL name: %s\n",
- g_win32_get_package_installation_directory (GETTEXT_PACKAGE, glib_dll));
- g_print ("Ditto, only from GLib DLL name: %s\n",
- g_win32_get_package_installation_directory (NULL, glib_dll));
- g_print ("locale subdirectory of GLib installation directory: %s\n",
- g_win32_get_package_installation_subdirectory (NULL, glib_dll, "lib\\locale"));
- g_print ("GTK+ 2.0 installation directory, if available: %s\n",
- g_win32_get_package_installation_directory ("gtk20", NULL));
g_print ("found more.com as %s\n", g_find_program_in_path ("more.com"));
g_print ("found regedit as %s\n", g_find_program_in_path ("regedit"));
GTimeVal ref_date, date;
gchar *tmp_string = NULL, *tmp_string_2, *string, *date_str;
guint i;
+ gchar *tz;
if (g_test_verbose())
g_print ("checking string chunks...");
g_free (tmp_string);
g_free (string);
-#define REF_SEC_UTC 320063760
-#define REF_STR_UTC "1980-02-22T10:36:00Z"
-#define REF_STR_CEST "1980-02-22T12:36:00+02:00"
-#define REF_STR_EST "1980-02-22T05:36:00-05:00"
+#define REF_INVALID1 "Wed Dec 19 17:20:20 GMT 2007"
+#define REF_INVALID2 "1980-02-22T10:36:00Zulu"
+#define REF_SEC_UTC 320063760
+#define REF_STR_UTC "1980-02-22T10:36:00Z"
+#define REF_STR_LOCAL "1980-02-22T13:36:00"
+#define REF_STR_CEST "1980-02-22T12:36:00+02:00"
+#define REF_STR_EST "19800222T053600-0500"
+#define REF_STR_NST "1980-02-22T07:06:00-03:30"
+#define REF_USEC_UTC 50000
+#define REF_STR_USEC_UTC "1980-02-22T10:36:00.050000Z"
+#define REF_STR_USEC_CEST "19800222T123600.050000000+0200"
+#define REF_STR_USEC_EST "1980-02-22T05:36:00,05-05:00"
+#define REF_STR_USEC_NST "19800222T070600,0500-0330"
if (g_test_verbose())
g_print ("checking g_time_val_from_iso8601...\n");
ref_date.tv_sec = REF_SEC_UTC;
ref_date.tv_usec = 0;
+ g_assert (g_time_val_from_iso8601 (REF_INVALID1, &date) == FALSE);
+ g_assert (g_time_val_from_iso8601 (REF_INVALID2, &date) == FALSE);
g_assert (g_time_val_from_iso8601 (REF_STR_UTC, &date) != FALSE);
if (g_test_verbose())
- g_print ("\t=> UTC stamp = %ld (should be: %ld) (%ld off)\n", date.tv_sec, ref_date.tv_sec, date.tv_sec - ref_date.tv_sec);
- g_assert (date.tv_sec == ref_date.tv_sec);
+ g_print ("\t=> UTC stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
+ date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
+ date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
+ g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
+
+ /* predefine time zone */
+ tz = g_getenv("TZ");
+ g_setenv("TZ", "UTC-03:00", 1);
+ tzset();
+
+ g_assert (g_time_val_from_iso8601 (REF_STR_LOCAL, &date) != FALSE);
+ if (g_test_verbose())
+ g_print ("\t=> LOCAL stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
+ date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
+ date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
+ g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
+
+ /* revert back user defined time zone */
+ if (tz)
+ g_setenv("TZ", tz, TRUE);
+ else
+ g_unsetenv("TZ");
+ tzset();
g_assert (g_time_val_from_iso8601 (REF_STR_CEST, &date) != FALSE);
if (g_test_verbose())
- g_print ("\t=> CEST stamp = %ld (should be: %ld) (%ld off)\n", date.tv_sec, ref_date.tv_sec, date.tv_sec - ref_date.tv_sec);
- g_assert (date.tv_sec == ref_date.tv_sec);
+ g_print ("\t=> CEST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
+ date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
+ date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
+ g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
g_assert (g_time_val_from_iso8601 (REF_STR_EST, &date) != FALSE);
if (g_test_verbose())
- g_print ("\t=> EST stamp = %ld (should be: %ld) (%ld off)\n", date.tv_sec, ref_date.tv_sec, date.tv_sec - ref_date.tv_sec);
- g_assert (date.tv_sec == ref_date.tv_sec);
+ g_print ("\t=> EST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
+ date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
+ date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
+ g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
+
+ g_assert (g_time_val_from_iso8601 (REF_STR_NST, &date) != FALSE);
+ if (g_test_verbose())
+ g_print ("\t=> NST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
+ date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
+ date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
+ g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
+
+ ref_date.tv_usec = REF_USEC_UTC;
+ g_assert (g_time_val_from_iso8601 (REF_STR_USEC_UTC, &date) != FALSE);
+ if (g_test_verbose())
+ g_print ("\t=> UTC stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
+ date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
+ date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
+ g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
+
+ g_assert (g_time_val_from_iso8601 (REF_STR_USEC_CEST, &date) != FALSE);
+ if (g_test_verbose())
+ g_print ("\t=> CEST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
+ date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
+ date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
+ g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
+
+ g_assert (g_time_val_from_iso8601 (REF_STR_USEC_EST, &date) != FALSE);
+ if (g_test_verbose())
+ g_print ("\t=> EST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
+ date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
+ date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
+ g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
+
+ g_assert (g_time_val_from_iso8601 (REF_STR_USEC_NST, &date) != FALSE);
+ if (g_test_verbose())
+ g_print ("\t=> NST stamp = %ld.%06ld (should be: %ld.%06ld) (%ld.%06ld off)\n",
+ date.tv_sec, date.tv_usec, ref_date.tv_sec, ref_date.tv_usec,
+ date.tv_sec - ref_date.tv_sec, date.tv_usec - ref_date.tv_usec);
+ g_assert (date.tv_sec == ref_date.tv_sec && date.tv_usec == ref_date.tv_usec);
if (g_test_verbose())
g_print ("checking g_time_val_to_iso8601...\n");
ref_date.tv_sec = REF_SEC_UTC;
- ref_date.tv_usec = 1;
+ ref_date.tv_usec = 0;
date_str = g_time_val_to_iso8601 (&ref_date);
g_assert (date_str != NULL);
if (g_test_verbose())
g_assert (strcmp (date_str, REF_STR_UTC) == 0);
g_free (date_str);
+ ref_date.tv_usec = REF_USEC_UTC;
+ date_str = g_time_val_to_iso8601 (&ref_date);
+ g_assert (date_str != NULL);
+ if (g_test_verbose())
+ g_print ("\t=> date string = %s (should be: %s)\n", date_str, REF_STR_USEC_UTC);
+ g_assert (strcmp (date_str, REF_STR_USEC_UTC) == 0);
+ g_free (date_str);
+
if (g_test_verbose())
g_print ("checking g_ascii_strcasecmp...");
g_assert (g_ascii_strcasecmp ("FroboZZ", "frobozz") == 0);
/* g_debug (argv[0]); */
}
+#ifndef G_DISABLE_DEPRECATED
static void
test_mem_chunks (void)
{
for (i = 0; i < 10000; i++)
g_mem_chunk_free (mem_chunk, mem[i]);
}
+#endif
int
main (int argc,
g_test_add_func ("/testglib/Relation", relation_test);
g_test_add_func ("/testglib/File Paths", test_paths);
g_test_add_func ("/testglib/File Functions", test_file_functions);
- g_test_add_func ("/testglib/Mkdir", test_g_mkdir_with_parents);
g_test_add_func ("/testglib/Parse Debug Strings", test_g_parse_debug_string);
+#ifndef G_DISABLE_DEPRECATED
g_test_add_func ("/testglib/GMemChunk (deprecated)", test_mem_chunks);
+#endif
g_test_add_func ("/testglib/Warnings & Errors", log_warning_error_tests);
g_test_add_func ("/testglib/Timers (slow)", timer_tests);