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