glib/tsrc/BC/tests/testgdateparser.c
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /* Portion Copyright © 2008-09 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/
       
     2 #undef G_DISABLE_ASSERT
       
     3 #undef G_LOG_DOMAIN
       
     4 
       
     5 #ifdef GLIB_COMPILATION
       
     6 #undef GLIB_COMPILATION
       
     7 #endif
       
     8 
       
     9 #include "glib.h"
       
    10 
       
    11 #include <stdio.h>
       
    12 #include <string.h>
       
    13 #include <locale.h>
       
    14 
       
    15 #ifdef SYMBIAN
       
    16 #include "mrt2_glib2_test.h"
       
    17 #endif /*SYMBIAN*/
       
    18 
       
    19 
       
    20 void g_date_debug_print(GDate* d)
       
    21 {
       
    22   if (!d) g_print("NULL!\n");
       
    23   else 
       
    24     g_print("julian: %u (%s) DMY: %u %u %u (%s)\n",
       
    25 	    d->julian_days, 
       
    26 	    d->julian ? "valid" : "invalid",
       
    27 	    d->day,
       
    28 	    d->month,
       
    29 	    d->year,
       
    30 	    d->dmy ? "valid" : "invalid");
       
    31   
       
    32   fflush(stdout);
       
    33 }
       
    34 
       
    35 /* These only work in the POSIX locale, maybe C too - 
       
    36  * type POSIX into the program to check them
       
    37  */
       
    38 char* posix_tests [] = {
       
    39   "19981024",
       
    40   "981024",
       
    41   "October 1998",
       
    42   "October 98",
       
    43   "oCT 98",
       
    44   "10/24/98",
       
    45   "10 -- 24 -- 98",
       
    46   "10/24/1998",
       
    47   "October 24, 1998",
       
    48   NULL
       
    49 };
       
    50 
       
    51 int main(int argc, char** argv)
       
    52 {
       
    53 	GDate* d;
       
    54 	gchar* loc;
       
    55 	char** s = posix_tests;
       
    56 
       
    57 	#ifdef SYMBIAN
       
    58 	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);
       
    59 	g_set_print_handler(mrtPrintHandler);
       
    60 	#endif /*SYMBIAN*/
       
    61 	  
       
    62 
       
    63 	loc = setlocale(LC_ALL,"");
       
    64 
       
    65 	d = g_date_new();
       
    66 	
       
    67 	while (*s) 
       
    68 	{
       
    69 		g_date_set_parse(d, *s);
       
    70 
       
    71 		if (!g_date_valid(d))
       
    72 		  {
       
    73 		    g_print(" failed.\n");
       
    74 		    g_assert(FALSE && "testgdateparser");
       
    75 		  }
       
    76 		else 
       
    77 		  {
       
    78 		    gchar buf[256];
       
    79 		    
       
    80 		    g_date_strftime(buf,100," parsed `%x' (%B %d %Y)\n",
       
    81 		                    d);
       
    82 		  }
       
    83 		++s;
       
    84 	}
       
    85 	
       
    86 	g_date_free(d);
       
    87 #ifdef SYMBIAN
       
    88   testResultXml("testgdateparser");
       
    89 #endif /* EMULATOR */
       
    90 	return 0;
       
    91 }
       
    92 
       
    93