| 
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  | 
#include "glib.h"
  | 
| 
sl@0
 | 
     6  | 
  | 
| 
sl@0
 | 
     7  | 
#include <stdio.h>
  | 
| 
sl@0
 | 
     8  | 
#include <string.h>
  | 
| 
sl@0
 | 
     9  | 
#include <stdlib.h>
  | 
| 
sl@0
 | 
    10  | 
#include <locale.h>
  | 
| 
sl@0
 | 
    11  | 
#include <time.h>
  | 
| 
sl@0
 | 
    12  | 
  | 
| 
sl@0
 | 
    13  | 
#ifdef __SYMBIAN32__
  | 
| 
sl@0
 | 
    14  | 
#include "mrt2_glib2_test.h"
  | 
| 
sl@0
 | 
    15  | 
#endif /*__SYMBIAN32__*/
  | 
| 
sl@0
 | 
    16  | 
  | 
| 
sl@0
 | 
    17  | 
  | 
| 
sl@0
 | 
    18  | 
gboolean failed = FALSE;
  | 
| 
sl@0
 | 
    19  | 
guint32 passed = 0;
  | 
| 
sl@0
 | 
    20  | 
guint32 notpassed = 0;
  | 
| 
sl@0
 | 
    21  | 
  | 
| 
sl@0
 | 
    22  | 
#define	TEST(m,cond)	G_STMT_START { failed = !(cond); \
 | 
| 
sl@0
 | 
    23  | 
if (failed) \
  | 
| 
sl@0
 | 
    24  | 
  exit(1); \
  | 
| 
sl@0
 | 
    25  | 
} G_STMT_END
  | 
| 
sl@0
 | 
    26  | 
  | 
| 
sl@0
 | 
    27  | 
void g_date_debug_print(GDate* d)
  | 
| 
sl@0
 | 
    28  | 
{
 | 
| 
sl@0
 | 
    29  | 
}
  | 
| 
sl@0
 | 
    30  | 
  | 
| 
sl@0
 | 
    31  | 
void g_print_dummy(const char *format, ...)
  | 
| 
sl@0
 | 
    32  | 
{
 | 
| 
sl@0
 | 
    33  | 
}
  | 
| 
sl@0
 | 
    34  | 
  | 
| 
sl@0
 | 
    35  | 
void fflush_dummy (FILE *f)
  | 
| 
sl@0
 | 
    36  | 
{
 | 
| 
sl@0
 | 
    37  | 
}
  | 
| 
sl@0
 | 
    38  | 
  | 
| 
sl@0
 | 
    39  | 
  | 
| 
sl@0
 | 
    40  | 
#define g_print g_print_dummy
  | 
| 
sl@0
 | 
    41  | 
#define fflush fflush_dummy
  | 
| 
sl@0
 | 
    42  | 
  | 
| 
sl@0
 | 
    43  | 
int main(int argc, char** argv)
  | 
| 
sl@0
 | 
    44  | 
{
 | 
| 
sl@0
 | 
    45  | 
  GDate* d;
  | 
| 
sl@0
 | 
    46  | 
  guint32 j;
  | 
| 
sl@0
 | 
    47  | 
  GDateMonth m;
  | 
| 
sl@0
 | 
    48  | 
  GDateYear y, prev_y;
  | 
| 
sl@0
 | 
    49  | 
  GDateDay day;
  | 
| 
sl@0
 | 
    50  | 
  gchar buf[101];
  | 
| 
sl@0
 | 
    51  | 
  gchar* loc;
  | 
| 
sl@0
 | 
    52  | 
  | 
| 
sl@0
 | 
    53  | 
  /* Try to get all the leap year cases. */
  | 
| 
sl@0
 | 
    54  | 
  GDateYear check_years[] = { 
 | 
| 
sl@0
 | 
    55  | 
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  | 
| 
sl@0
 | 
    56  | 
    11, 12, 13, 14, 98, 99, 100, 101, 102, 103, 397, 
  | 
| 
sl@0
 | 
    57  | 
    398, 399, 400, 401, 402, 403, 404, 405, 406,
  | 
| 
sl@0
 | 
    58  | 
    1598, 1599, 1600, 1601, 1602, 1650, 1651,
  | 
| 
sl@0
 | 
    59  | 
    1897, 1898, 1899, 1900, 1901, 1902, 1903, 
  | 
| 
sl@0
 | 
    60  | 
    1961, 1962, 1963, 1964, 1965, 1967,
  | 
| 
sl@0
 | 
    61  | 
    1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 1976,
  | 
| 
sl@0
 | 
    62  | 
    1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 
  | 
| 
sl@0
 | 
    63  | 
    1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 
  | 
| 
sl@0
 | 
    64  | 
    1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 
  | 
| 
sl@0
 | 
    65  | 
    2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012,
  | 
| 
sl@0
 | 
    66  | 
    3000, 3001, 3002, 3998, 3999, 4000, 4001, 4002, 4003
  | 
| 
sl@0
 | 
    67  | 
  };
  | 
| 
sl@0
 | 
    68  | 
                           
  | 
| 
sl@0
 | 
    69  | 
  guint n_check_years = sizeof(check_years)/sizeof(GDateYear);
  | 
| 
sl@0
 | 
    70  | 
  | 
| 
sl@0
 | 
    71  | 
  guint i = 0;
  | 
| 
sl@0
 | 
    72  | 
  gboolean discontinuity = FALSE;
  | 
| 
sl@0
 | 
    73  | 
  | 
| 
sl@0
 | 
    74  | 
  #ifdef __SYMBIAN32__
  | 
| 
sl@0
 | 
    75  | 
  //GLIB_INIT();
  | 
| 
sl@0
 | 
    76  | 
  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
 | 
    77  | 
  g_set_print_handler(mrtPrintHandler);
  | 
| 
sl@0
 | 
    78  | 
  #endif /*__SYMBIAN32__*/
  | 
| 
sl@0
 | 
    79  | 
  
  | 
| 
sl@0
 | 
    80  | 
  //g_print("checking GDate...");
 | 
| 
sl@0
 | 
    81  | 
  
  | 
| 
sl@0
 | 
    82  | 
  TEST("sizeof(GDate) is not more than 8 bytes on this platform", sizeof(GDate) < 9);
 | 
| 
sl@0
 | 
    83  | 
  | 
| 
sl@0
 | 
    84  | 
  d = g_date_new();
  | 
| 
sl@0
 | 
    85  | 
  | 
| 
sl@0
 | 
    86  | 
  TEST("Empty constructor produces invalid date", !g_date_valid(d));
 | 
| 
sl@0
 | 
    87  | 
  | 
| 
sl@0
 | 
    88  | 
  g_date_free(d);
  | 
| 
sl@0
 | 
    89  | 
  | 
| 
sl@0
 | 
    90  | 
  d = g_date_new_dmy(1,1,1);
  | 
| 
sl@0
 | 
    91  | 
  | 
| 
sl@0
 | 
    92  | 
  TEST("January 1, Year 1 created and valid", g_date_valid(d));
 | 
| 
sl@0
 | 
    93  | 
  | 
| 
sl@0
 | 
    94  | 
  j = g_date_get_julian(d);
  | 
| 
sl@0
 | 
    95  | 
  
  | 
| 
sl@0
 | 
    96  | 
  TEST("January 1, Year 1 is Julian date 1", j == 1);
 | 
| 
sl@0
 | 
    97  | 
  | 
| 
sl@0
 | 
    98  | 
  TEST("Returned month is January", g_date_get_month(d) == G_DATE_JANUARY);
 | 
| 
sl@0
 | 
    99  | 
  TEST("Returned day is 1", g_date_get_day(d) == 1);
 | 
| 
sl@0
 | 
   100  | 
  TEST("Returned year is 1", g_date_get_year(d) == 1);
 | 
| 
sl@0
 | 
   101  | 
  | 
| 
sl@0
 | 
   102  | 
  TEST("Bad month is invalid", !g_date_valid_month(G_DATE_BAD_MONTH));
 | 
| 
sl@0
 | 
   103  | 
  TEST("Month 13 is invalid",  !g_date_valid_month(13));
 | 
| 
sl@0
 | 
   104  | 
  TEST("Bad day is invalid",   !g_date_valid_day(G_DATE_BAD_DAY));
 | 
| 
sl@0
 | 
   105  | 
  TEST("Day 32 is invalid",     !g_date_valid_day(32));
 | 
| 
sl@0
 | 
   106  | 
  TEST("Bad year is invalid",  !g_date_valid_year(G_DATE_BAD_YEAR));
 | 
| 
sl@0
 | 
   107  | 
  TEST("Bad julian is invalid", !g_date_valid_julian(G_DATE_BAD_JULIAN));
 | 
| 
sl@0
 | 
   108  | 
  TEST("Bad weekday is invalid", !g_date_valid_weekday(G_DATE_BAD_WEEKDAY));
 | 
| 
sl@0
 | 
   109  | 
  TEST("Year 2000 is a leap year", g_date_is_leap_year(2000));
 | 
| 
sl@0
 | 
   110  | 
  TEST("Year 1999 is not a leap year", !g_date_is_leap_year(1999));
 | 
| 
sl@0
 | 
   111  | 
  TEST("Year 1996 is a leap year", g_date_is_leap_year(1996));
 | 
| 
sl@0
 | 
   112  | 
  TEST("Year 1600 is a leap year", g_date_is_leap_year(1600));
 | 
| 
sl@0
 | 
   113  | 
  TEST("Year 2100 is not a leap year", !g_date_is_leap_year(2100));
 | 
| 
sl@0
 | 
   114  | 
  TEST("Year 1800 is not a leap year", !g_date_is_leap_year(1800));
 | 
| 
sl@0
 | 
   115  | 
  | 
| 
sl@0
 | 
   116  | 
  g_date_free(d);
  | 
| 
sl@0
 | 
   117  | 
  
  | 
| 
sl@0
 | 
   118  | 
  loc = setlocale(LC_ALL,"");
  | 
| 
sl@0
 | 
   119  | 
  if (loc) 
  | 
| 
sl@0
 | 
   120  | 
    g_print("\nLocale set to %s\n", loc);
 | 
| 
sl@0
 | 
   121  | 
  else 
  | 
| 
sl@0
 | 
   122  | 
    g_print("\nLocale unchanged\n");
 | 
| 
sl@0
 | 
   123  | 
  | 
| 
sl@0
 | 
   124  | 
  d = g_date_new();
  | 
| 
sl@0
 | 
   125  | 
  g_date_set_time(d, time(NULL));
  | 
| 
sl@0
 | 
   126  | 
  TEST("Today is valid", g_date_valid(d));
 | 
| 
sl@0
 | 
   127  | 
  | 
| 
sl@0
 | 
   128  | 
  g_date_strftime(buf,100,"Today is a %A, %x\n", d);
  | 
| 
sl@0
 | 
   129  | 
  g_print("%s", buf);
 | 
| 
sl@0
 | 
   130  | 
  | 
| 
sl@0
 | 
   131  | 
  g_date_set_time(d, 1);
  | 
| 
sl@0
 | 
   132  | 
  TEST("Beginning of Unix epoch is valid", g_date_valid(d));
 | 
| 
sl@0
 | 
   133  | 
  | 
| 
sl@0
 | 
   134  | 
  g_date_strftime(buf,100,"1 second into the Unix epoch it was a %A, in the month of %B, %x\n", d);
  | 
| 
sl@0
 | 
   135  | 
  g_print("%s", buf);
 | 
| 
sl@0
 | 
   136  | 
  | 
| 
sl@0
 | 
   137  | 
  g_date_set_julian(d, 1);
  | 
| 
sl@0
 | 
   138  | 
  TEST("GDate's \"Julian\" epoch's first day is valid", g_date_valid(d));
 | 
| 
sl@0
 | 
   139  | 
  | 
| 
sl@0
 | 
   140  | 
  g_date_strftime(buf,100,"Our \"Julian\" epoch begins on a %A, in the month of %B, %x\n",
  | 
| 
sl@0
 | 
   141  | 
		  d);
  | 
| 
sl@0
 | 
   142  | 
  g_print("%s", buf);
 | 
| 
sl@0
 | 
   143  | 
  | 
| 
sl@0
 | 
   144  | 
  g_date_set_dmy(d, 10, 1, 2000);
  | 
| 
sl@0
 | 
   145  | 
  | 
| 
sl@0
 | 
   146  | 
  g_date_strftime(buf,100,"%x", d);
  | 
| 
sl@0
 | 
   147  | 
  | 
| 
sl@0
 | 
   148  | 
  g_date_set_parse(d, buf);
  | 
| 
sl@0
 | 
   149  | 
  /* Note: this test will hopefully work, but no promises. */
  | 
| 
sl@0
 | 
   150  | 
  TEST("Successfully parsed a %x-formatted string", 
 | 
| 
sl@0
 | 
   151  | 
       g_date_valid(d) && 
  | 
| 
sl@0
 | 
   152  | 
       g_date_get_month(d) == 1 && 
  | 
| 
sl@0
 | 
   153  | 
       g_date_get_day(d) == 10 && 
  | 
| 
sl@0
 | 
   154  | 
       g_date_get_year(d) == 2000);
  | 
| 
sl@0
 | 
   155  | 
  if (failed)
  | 
| 
sl@0
 | 
   156  | 
    g_date_debug_print(d);
  | 
| 
sl@0
 | 
   157  | 
  
  | 
| 
sl@0
 | 
   158  | 
  g_date_free(d);
  | 
| 
sl@0
 | 
   159  | 
  | 
| 
sl@0
 | 
   160  | 
  j = G_DATE_BAD_JULIAN;
  | 
| 
sl@0
 | 
   161  | 
  | 
| 
sl@0
 | 
   162  | 
  i = 0;
  | 
| 
sl@0
 | 
   163  | 
  discontinuity = TRUE;
  | 
| 
sl@0
 | 
   164  | 
  y      = check_years[0];
  | 
| 
sl@0
 | 
   165  | 
  prev_y = G_DATE_BAD_YEAR;
  | 
| 
sl@0
 | 
   166  | 
  while (i < n_check_years) 
  | 
| 
sl@0
 | 
   167  | 
    {
 | 
| 
sl@0
 | 
   168  | 
      guint32 first_day_of_year = G_DATE_BAD_JULIAN;
  | 
| 
sl@0
 | 
   169  | 
      guint16 days_in_year = g_date_is_leap_year(y) ? 366 : 365;
  | 
| 
sl@0
 | 
   170  | 
      guint   sunday_week_of_year = 0;
  | 
| 
sl@0
 | 
   171  | 
      guint   sunday_weeks_in_year = g_date_get_sunday_weeks_in_year(y);
  | 
| 
sl@0
 | 
   172  | 
      guint   monday_week_of_year = 0;
  | 
| 
sl@0
 | 
   173  | 
      guint   monday_weeks_in_year = g_date_get_monday_weeks_in_year(y);
  | 
| 
sl@0
 | 
   174  | 
      guint   iso8601_week_of_year = 0;
  | 
| 
sl@0
 | 
   175  | 
  | 
| 
sl@0
 | 
   176  | 
      if (discontinuity)
  | 
| 
sl@0
 | 
   177  | 
        g_print(" (Break in sequence of requested years to check)\n");
 | 
| 
sl@0
 | 
   178  | 
  | 
| 
sl@0
 | 
   179  | 
      g_print("Checking year %u", y);
 | 
| 
sl@0
 | 
   180  | 
  | 
| 
sl@0
 | 
   181  | 
      TEST("Year is valid", g_date_valid_year(y));
 | 
| 
sl@0
 | 
   182  | 
  | 
| 
sl@0
 | 
   183  | 
      TEST("Number of Sunday weeks in year is 52 or 53", 
 | 
| 
sl@0
 | 
   184  | 
	   sunday_weeks_in_year == 52 || sunday_weeks_in_year == 53);
  | 
| 
sl@0
 | 
   185  | 
      
  | 
| 
sl@0
 | 
   186  | 
      TEST("Number of Monday weeks in year is 52 or 53", 
 | 
| 
sl@0
 | 
   187  | 
	   monday_weeks_in_year == 52 || monday_weeks_in_year == 53);
  | 
| 
sl@0
 | 
   188  | 
	   
  | 
| 
sl@0
 | 
   189  | 
      m = 1;
  | 
| 
sl@0
 | 
   190  | 
      while (m < 13) 
  | 
| 
sl@0
 | 
   191  | 
	{
 | 
| 
sl@0
 | 
   192  | 
	  guint8 dim = g_date_get_days_in_month(m,y);
  | 
| 
sl@0
 | 
   193  | 
	  GDate days[31];         /* This is the fast way, no allocation */
  | 
| 
sl@0
 | 
   194  | 
  | 
| 
sl@0
 | 
   195  | 
	  TEST("Sensible number of days in month", (dim > 0 && dim < 32));
 | 
| 
sl@0
 | 
   196  | 
  | 
| 
sl@0
 | 
   197  | 
	  TEST("Month between 1 and 12 is valid", g_date_valid_month(m));
 | 
| 
sl@0
 | 
   198  | 
  | 
| 
sl@0
 | 
   199  | 
	  day = 1;
  | 
| 
sl@0
 | 
   200  | 
  | 
| 
sl@0
 | 
   201  | 
	  g_date_clear(days, 31);
  | 
| 
sl@0
 | 
   202  | 
  | 
| 
sl@0
 | 
   203  | 
	  while (day <= dim) 
  | 
| 
sl@0
 | 
   204  | 
	    {
 | 
| 
sl@0
 | 
   205  | 
	      guint i;
  | 
| 
sl@0
 | 
   206  | 
              GDate tmp;
  | 
| 
sl@0
 | 
   207  | 
  | 
| 
sl@0
 | 
   208  | 
	      TEST("DMY triplet is valid", g_date_valid_dmy(day,m,y));
 | 
| 
sl@0
 | 
   209  | 
  | 
| 
sl@0
 | 
   210  | 
	      /* Create GDate with triplet */
  | 
| 
sl@0
 | 
   211  | 
	      
  | 
| 
sl@0
 | 
   212  | 
	      d = &days[day-1];
  | 
| 
sl@0
 | 
   213  | 
  | 
| 
sl@0
 | 
   214  | 
	      TEST("Cleared day is invalid", !g_date_valid(d));
 | 
| 
sl@0
 | 
   215  | 
  | 
| 
sl@0
 | 
   216  | 
	      g_date_set_dmy(d,day,m,y);
  | 
| 
sl@0
 | 
   217  | 
  | 
| 
sl@0
 | 
   218  | 
	      TEST("Set day is valid", g_date_valid(d));
 | 
| 
sl@0
 | 
   219  | 
  | 
| 
sl@0
 | 
   220  | 
	      if (m == G_DATE_JANUARY && day == 1) 
  | 
| 
sl@0
 | 
   221  | 
		{
 | 
| 
sl@0
 | 
   222  | 
		  first_day_of_year = g_date_get_julian(d);
  | 
| 
sl@0
 | 
   223  | 
		}
  | 
| 
sl@0
 | 
   224  | 
  | 
| 
sl@0
 | 
   225  | 
	      g_assert(first_day_of_year != G_DATE_BAD_JULIAN);
  | 
| 
sl@0
 | 
   226  | 
  | 
| 
sl@0
 | 
   227  | 
	      TEST("Date with DMY triplet is valid", g_date_valid(d));
 | 
| 
sl@0
 | 
   228  | 
	      TEST("Month accessor works", g_date_get_month(d) == m);
 | 
| 
sl@0
 | 
   229  | 
	      TEST("Year accessor works", g_date_get_year(d) == y);
 | 
| 
sl@0
 | 
   230  | 
	      TEST("Day of month accessor works", g_date_get_day(d) == day);
 | 
| 
sl@0
 | 
   231  | 
  | 
| 
sl@0
 | 
   232  | 
	      TEST("Day of year is consistent with Julian dates",
 | 
| 
sl@0
 | 
   233  | 
		   ((g_date_get_julian(d) + 1 - first_day_of_year) ==
  | 
| 
sl@0
 | 
   234  | 
		    (g_date_get_day_of_year(d))));
  | 
| 
sl@0
 | 
   235  | 
  | 
| 
sl@0
 | 
   236  | 
	      if (failed) 
  | 
| 
sl@0
 | 
   237  | 
		{
 | 
| 
sl@0
 | 
   238  | 
		  g_print("first day: %u this day: %u day of year: %u\n", 
 | 
| 
sl@0
 | 
   239  | 
			  first_day_of_year, 
  | 
| 
sl@0
 | 
   240  | 
			  g_date_get_julian(d),
  | 
| 
sl@0
 | 
   241  | 
			  g_date_get_day_of_year(d));
  | 
| 
sl@0
 | 
   242  | 
		}
  | 
| 
sl@0
 | 
   243  | 
	      
  | 
| 
sl@0
 | 
   244  | 
	      if (m == G_DATE_DECEMBER && day == 31) 
  | 
| 
sl@0
 | 
   245  | 
		{
 | 
| 
sl@0
 | 
   246  | 
		  TEST("Last day of year equals number of days in year", 
 | 
| 
sl@0
 | 
   247  | 
		       g_date_get_day_of_year(d) == days_in_year);
  | 
| 
sl@0
 | 
   248  | 
		  if (failed) 
  | 
| 
sl@0
 | 
   249  | 
		    {
 | 
| 
sl@0
 | 
   250  | 
		      g_print("last day: %u days in year: %u\n", 
 | 
| 
sl@0
 | 
   251  | 
			      g_date_get_day_of_year(d), days_in_year);
  | 
| 
sl@0
 | 
   252  | 
		    }
  | 
| 
sl@0
 | 
   253  | 
		}
  | 
| 
sl@0
 | 
   254  | 
  | 
| 
sl@0
 | 
   255  | 
	      TEST("Day of year is not more than number of days in the year",
 | 
| 
sl@0
 | 
   256  | 
		   g_date_get_day_of_year(d) <= days_in_year);
  | 
| 
sl@0
 | 
   257  | 
  | 
| 
sl@0
 | 
   258  | 
	      TEST("Monday week of year is not more than number of weeks in the year",
 | 
| 
sl@0
 | 
   259  | 
		   g_date_get_monday_week_of_year(d) <= monday_weeks_in_year);
  | 
| 
sl@0
 | 
   260  | 
	      if (failed)
  | 
| 
sl@0
 | 
   261  | 
		{
 | 
| 
sl@0
 | 
   262  | 
		  g_print("Weeks in year: %u\n", monday_weeks_in_year);
 | 
| 
sl@0
 | 
   263  | 
		  g_date_debug_print(d);
  | 
| 
sl@0
 | 
   264  | 
		}
  | 
| 
sl@0
 | 
   265  | 
	      TEST("Monday week of year is >= than last week of year",
 | 
| 
sl@0
 | 
   266  | 
		   g_date_get_monday_week_of_year(d) >= monday_week_of_year);
  | 
| 
sl@0
 | 
   267  | 
  | 
| 
sl@0
 | 
   268  | 
	      if (g_date_get_weekday(d) == G_DATE_MONDAY) 
  | 
| 
sl@0
 | 
   269  | 
		{
 | 
| 
sl@0
 | 
   270  | 
		  
  | 
| 
sl@0
 | 
   271  | 
		  TEST("Monday week of year on Monday 1 more than previous day's week of year",
 | 
| 
sl@0
 | 
   272  | 
		       (g_date_get_monday_week_of_year(d) - monday_week_of_year) == 1);
  | 
| 
sl@0
 | 
   273  | 
		  if ((m == G_DATE_JANUARY && day <= 4) ||
  | 
| 
sl@0
 | 
   274  | 
		      (m == G_DATE_DECEMBER && day >= 29)) {
 | 
| 
sl@0
 | 
   275  | 
		    TEST("ISO 8601 week of year on Monday Dec 29 - Jan 4 is 1",
 | 
| 
sl@0
 | 
   276  | 
			 (g_date_get_iso8601_week_of_year(d) == 1));
  | 
| 
sl@0
 | 
   277  | 
		  } else {
 | 
| 
sl@0
 | 
   278  | 
		    TEST("ISO 8601 week of year on Monday 1 more than previous day's week of year",
 | 
| 
sl@0
 | 
   279  | 
			 (g_date_get_iso8601_week_of_year(d) - iso8601_week_of_year) == 1);
  | 
| 
sl@0
 | 
   280  | 
		  }
  | 
| 
sl@0
 | 
   281  | 
		}
  | 
| 
sl@0
 | 
   282  | 
	      else 
  | 
| 
sl@0
 | 
   283  | 
		{
 | 
| 
sl@0
 | 
   284  | 
		  TEST("Monday week of year on non-Monday 0 more than previous day's week of year",
 | 
| 
sl@0
 | 
   285  | 
		       (g_date_get_monday_week_of_year(d) - monday_week_of_year) == 0);
  | 
| 
sl@0
 | 
   286  | 
		  if (!(day == 1 && m == G_DATE_JANUARY)) {
 | 
| 
sl@0
 | 
   287  | 
		    TEST("ISO 8601 week of year on non-Monday 0 more than previous day's week of year (",
 | 
| 
sl@0
 | 
   288  | 
			 (g_date_get_iso8601_week_of_year(d) - iso8601_week_of_year) == 0);
  | 
| 
sl@0
 | 
   289  | 
		  }
  | 
| 
sl@0
 | 
   290  | 
		}
  | 
| 
sl@0
 | 
   291  | 
  | 
| 
sl@0
 | 
   292  | 
  | 
| 
sl@0
 | 
   293  | 
	      monday_week_of_year = g_date_get_monday_week_of_year(d);
  | 
| 
sl@0
 | 
   294  | 
	      iso8601_week_of_year = g_date_get_iso8601_week_of_year(d);
  | 
| 
sl@0
 | 
   295  | 
  | 
| 
sl@0
 | 
   296  | 
  | 
| 
sl@0
 | 
   297  | 
	      TEST("Sunday week of year is not more than number of weeks in the year",
 | 
| 
sl@0
 | 
   298  | 
		   g_date_get_sunday_week_of_year(d) <= sunday_weeks_in_year);
  | 
| 
sl@0
 | 
   299  | 
	      if (failed)
  | 
| 
sl@0
 | 
   300  | 
		{
 | 
| 
sl@0
 | 
   301  | 
		  g_date_debug_print(d);
  | 
| 
sl@0
 | 
   302  | 
		}
  | 
| 
sl@0
 | 
   303  | 
	      TEST("Sunday week of year is >= than last week of year",
 | 
| 
sl@0
 | 
   304  | 
		   g_date_get_sunday_week_of_year(d) >= sunday_week_of_year);
  | 
| 
sl@0
 | 
   305  | 
  | 
| 
sl@0
 | 
   306  | 
	      if (g_date_get_weekday(d) == G_DATE_SUNDAY) 
  | 
| 
sl@0
 | 
   307  | 
		{
 | 
| 
sl@0
 | 
   308  | 
		  TEST("Sunday week of year on Sunday 1 more than previous day's week of year",
 | 
| 
sl@0
 | 
   309  | 
		       (g_date_get_sunday_week_of_year(d) - sunday_week_of_year) == 1);
  | 
| 
sl@0
 | 
   310  | 
		}
  | 
| 
sl@0
 | 
   311  | 
	      else 
  | 
| 
sl@0
 | 
   312  | 
		{
 | 
| 
sl@0
 | 
   313  | 
		  TEST("Sunday week of year on non-Sunday 0 more than previous day's week of year",
 | 
| 
sl@0
 | 
   314  | 
		       (g_date_get_sunday_week_of_year(d) - sunday_week_of_year) == 0);
  | 
| 
sl@0
 | 
   315  | 
		}
  | 
| 
sl@0
 | 
   316  | 
  | 
| 
sl@0
 | 
   317  | 
	      sunday_week_of_year = g_date_get_sunday_week_of_year(d);
  | 
| 
sl@0
 | 
   318  | 
  | 
| 
sl@0
 | 
   319  | 
	      TEST("Date is equal to itself",
 | 
| 
sl@0
 | 
   320  | 
		   g_date_compare(d,d) == 0);
  | 
| 
sl@0
 | 
   321  | 
  | 
| 
sl@0
 | 
   322  | 
  | 
| 
sl@0
 | 
   323  | 
	      /*************** Increments ***********/
  | 
| 
sl@0
 | 
   324  | 
  | 
| 
sl@0
 | 
   325  | 
              i = 1;
  | 
| 
sl@0
 | 
   326  | 
              while (i < 402) /* Need to get 400 year increments in */ 
  | 
| 
sl@0
 | 
   327  | 
                {
 | 
| 
sl@0
 | 
   328  | 
	      
  | 
| 
sl@0
 | 
   329  | 
                  /***** Days ******/
  | 
| 
sl@0
 | 
   330  | 
                  tmp = *d;
  | 
| 
sl@0
 | 
   331  | 
                  g_date_add_days(d, i);
  | 
| 
sl@0
 | 
   332  | 
  | 
| 
sl@0
 | 
   333  | 
                  TEST("Adding days gives a value greater than previous",
 | 
| 
sl@0
 | 
   334  | 
                       g_date_compare(d, &tmp) > 0);
  | 
| 
sl@0
 | 
   335  | 
  | 
| 
sl@0
 | 
   336  | 
                  g_date_subtract_days(d, i);
  | 
| 
sl@0
 | 
   337  | 
                  TEST("Forward days then backward days returns us to current day",
 | 
| 
sl@0
 | 
   338  | 
                       g_date_get_day(d) == day);
  | 
| 
sl@0
 | 
   339  | 
  | 
| 
sl@0
 | 
   340  | 
                  if (failed) 
  | 
| 
sl@0
 | 
   341  | 
                    {
 | 
| 
sl@0
 | 
   342  | 
                      g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
 | 
| 
sl@0
 | 
   343  | 
                      g_date_debug_print(d);
  | 
| 
sl@0
 | 
   344  | 
                    }
  | 
| 
sl@0
 | 
   345  | 
  | 
| 
sl@0
 | 
   346  | 
                  TEST("Forward days then backward days returns us to current month",
 | 
| 
sl@0
 | 
   347  | 
                       g_date_get_month(d) == m);
  | 
| 
sl@0
 | 
   348  | 
  | 
| 
sl@0
 | 
   349  | 
                  if (failed) 
  | 
| 
sl@0
 | 
   350  | 
                    {
 | 
| 
sl@0
 | 
   351  | 
                      g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
 | 
| 
sl@0
 | 
   352  | 
                      g_date_debug_print(d);
  | 
| 
sl@0
 | 
   353  | 
                    }
  | 
| 
sl@0
 | 
   354  | 
  | 
| 
sl@0
 | 
   355  | 
                  TEST("Forward days then backward days returns us to current year",
 | 
| 
sl@0
 | 
   356  | 
                       g_date_get_year(d) == y);
  | 
| 
sl@0
 | 
   357  | 
  | 
| 
sl@0
 | 
   358  | 
                  if (failed) 
  | 
| 
sl@0
 | 
   359  | 
                    {
 | 
| 
sl@0
 | 
   360  | 
                      g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
 | 
| 
sl@0
 | 
   361  | 
                      g_date_debug_print(d);
  | 
| 
sl@0
 | 
   362  | 
                    }
  | 
| 
sl@0
 | 
   363  | 
  | 
| 
sl@0
 | 
   364  | 
                  /******* Months ********/
  | 
| 
sl@0
 | 
   365  | 
  | 
| 
sl@0
 | 
   366  | 
                  tmp = *d;
  | 
| 
sl@0
 | 
   367  | 
                  g_date_add_months(d, i);
  | 
| 
sl@0
 | 
   368  | 
                  TEST("Adding months gives a larger value",
 | 
| 
sl@0
 | 
   369  | 
                       g_date_compare(d, &tmp) > 0);
  | 
| 
sl@0
 | 
   370  | 
                  g_date_subtract_months(d, i);
  | 
| 
sl@0
 | 
   371  | 
  | 
| 
sl@0
 | 
   372  | 
                  TEST("Forward months then backward months returns us to current month",
 | 
| 
sl@0
 | 
   373  | 
                       g_date_get_month(d) == m);
  | 
| 
sl@0
 | 
   374  | 
  | 
| 
sl@0
 | 
   375  | 
                  if (failed) 
  | 
| 
sl@0
 | 
   376  | 
                    {
 | 
| 
sl@0
 | 
   377  | 
                      g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
 | 
| 
sl@0
 | 
   378  | 
                      g_date_debug_print(d);
  | 
| 
sl@0
 | 
   379  | 
                    }
  | 
| 
sl@0
 | 
   380  | 
  | 
| 
sl@0
 | 
   381  | 
                  TEST("Forward months then backward months returns us to current year",
 | 
| 
sl@0
 | 
   382  | 
                       g_date_get_year(d) == y);
  | 
| 
sl@0
 | 
   383  | 
  | 
| 
sl@0
 | 
   384  | 
                  if (failed) 
  | 
| 
sl@0
 | 
   385  | 
                    {
 | 
| 
sl@0
 | 
   386  | 
                      g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
 | 
| 
sl@0
 | 
   387  | 
                      g_date_debug_print(d);
  | 
| 
sl@0
 | 
   388  | 
                    }
  | 
| 
sl@0
 | 
   389  | 
  | 
| 
sl@0
 | 
   390  | 
		  
  | 
| 
sl@0
 | 
   391  | 
                  if (day < 29) 
  | 
| 
sl@0
 | 
   392  | 
                    {
 | 
| 
sl@0
 | 
   393  | 
                      /* Day should be unchanged */
  | 
| 
sl@0
 | 
   394  | 
		      
  | 
| 
sl@0
 | 
   395  | 
                      TEST("Forward months then backward months returns us to current day",
 | 
| 
sl@0
 | 
   396  | 
                           g_date_get_day(d) == day);
  | 
| 
sl@0
 | 
   397  | 
		      
  | 
| 
sl@0
 | 
   398  | 
                      if (failed) 
  | 
| 
sl@0
 | 
   399  | 
                        {
 | 
| 
sl@0
 | 
   400  | 
                          g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
 | 
| 
sl@0
 | 
   401  | 
                          g_date_debug_print(d);
  | 
| 
sl@0
 | 
   402  | 
                        }
  | 
| 
sl@0
 | 
   403  | 
                    }
  | 
| 
sl@0
 | 
   404  | 
                  else 
  | 
| 
sl@0
 | 
   405  | 
                    {
 | 
| 
sl@0
 | 
   406  | 
                      /* reset the day for later tests */
  | 
| 
sl@0
 | 
   407  | 
                      g_date_set_day(d, day);
  | 
| 
sl@0
 | 
   408  | 
                    }
  | 
| 
sl@0
 | 
   409  | 
  | 
| 
sl@0
 | 
   410  | 
                  /******* Years ********/
  | 
| 
sl@0
 | 
   411  | 
  | 
| 
sl@0
 | 
   412  | 
                  tmp = *d;
  | 
| 
sl@0
 | 
   413  | 
                  g_date_add_years(d, i);
  | 
| 
sl@0
 | 
   414  | 
  | 
| 
sl@0
 | 
   415  | 
                  TEST("Adding years gives a larger value",
 | 
| 
sl@0
 | 
   416  | 
                       g_date_compare(d,&tmp) > 0);
  | 
| 
sl@0
 | 
   417  | 
		      
  | 
| 
sl@0
 | 
   418  | 
                  g_date_subtract_years(d, i);
  | 
| 
sl@0
 | 
   419  | 
  | 
| 
sl@0
 | 
   420  | 
                  TEST("Forward years then backward years returns us to current month",
 | 
| 
sl@0
 | 
   421  | 
                       g_date_get_month(d) == m);
  | 
| 
sl@0
 | 
   422  | 
  | 
| 
sl@0
 | 
   423  | 
                  if (failed) 
  | 
| 
sl@0
 | 
   424  | 
                    {
 | 
| 
sl@0
 | 
   425  | 
                      g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
 | 
| 
sl@0
 | 
   426  | 
                      g_date_debug_print(d);
  | 
| 
sl@0
 | 
   427  | 
                    }
  | 
| 
sl@0
 | 
   428  | 
  | 
| 
sl@0
 | 
   429  | 
                  TEST("Forward years then backward years returns us to current year",
 | 
| 
sl@0
 | 
   430  | 
                       g_date_get_year(d) == y);
  | 
| 
sl@0
 | 
   431  | 
  | 
| 
sl@0
 | 
   432  | 
                  if (failed) 
  | 
| 
sl@0
 | 
   433  | 
                    {
 | 
| 
sl@0
 | 
   434  | 
                      g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
 | 
| 
sl@0
 | 
   435  | 
                      g_date_debug_print(d);
  | 
| 
sl@0
 | 
   436  | 
                    }
  | 
| 
sl@0
 | 
   437  | 
  | 
| 
sl@0
 | 
   438  | 
                  if (m != 2 && day != 29) 
  | 
| 
sl@0
 | 
   439  | 
                    {
 | 
| 
sl@0
 | 
   440  | 
                      TEST("Forward years then backward years returns us to current day",
 | 
| 
sl@0
 | 
   441  | 
                           g_date_get_day(d) == day);
  | 
| 
sl@0
 | 
   442  | 
		      
  | 
| 
sl@0
 | 
   443  | 
                      if (failed) 
  | 
| 
sl@0
 | 
   444  | 
                        {
 | 
| 
sl@0
 | 
   445  | 
                          g_print("  (increment %u, dmy %u %u %u) ", i, day, m, y);
 | 
| 
sl@0
 | 
   446  | 
                          g_date_debug_print(d);
  | 
| 
sl@0
 | 
   447  | 
                        }
  | 
| 
sl@0
 | 
   448  | 
                    }
  | 
| 
sl@0
 | 
   449  | 
                  else 
  | 
| 
sl@0
 | 
   450  | 
                    {
 | 
| 
sl@0
 | 
   451  | 
                      g_date_set_day(d, day); /* reset */
  | 
| 
sl@0
 | 
   452  | 
                    }
  | 
| 
sl@0
 | 
   453  | 
  | 
| 
sl@0
 | 
   454  | 
                  i += 10;
  | 
| 
sl@0
 | 
   455  | 
                }
  | 
| 
sl@0
 | 
   456  | 
  | 
| 
sl@0
 | 
   457  | 
	      /*****  increment test relative to our local Julian count */
  | 
| 
sl@0
 | 
   458  | 
  | 
| 
sl@0
 | 
   459  | 
              if (!discontinuity) {
 | 
| 
sl@0
 | 
   460  | 
  | 
| 
sl@0
 | 
   461  | 
                /* We can only run sequence tests between sequential years */
  | 
| 
sl@0
 | 
   462  | 
                
  | 
| 
sl@0
 | 
   463  | 
                TEST("Julians are sequential with increment 1",
 | 
| 
sl@0
 | 
   464  | 
                     j+1 == g_date_get_julian(d));
  | 
| 
sl@0
 | 
   465  | 
                if (failed) 
  | 
| 
sl@0
 | 
   466  | 
                  {
 | 
| 
sl@0
 | 
   467  | 
                    g_print("Out of sequence, prev: %u expected: %u got: %u\n",
 | 
| 
sl@0
 | 
   468  | 
                            j, j+1, g_date_get_julian(d));
  | 
| 
sl@0
 | 
   469  | 
                  }
  | 
| 
sl@0
 | 
   470  | 
  | 
| 
sl@0
 | 
   471  | 
                g_date_add_days(d,1);
  | 
| 
sl@0
 | 
   472  | 
                TEST("Next day has julian 1 higher",
 | 
| 
sl@0
 | 
   473  | 
                     g_date_get_julian(d) == j + 2);
  | 
| 
sl@0
 | 
   474  | 
                g_date_subtract_days(d, 1);
  | 
| 
sl@0
 | 
   475  | 
                
  | 
| 
sl@0
 | 
   476  | 
                if (j != G_DATE_BAD_JULIAN) 
  | 
| 
sl@0
 | 
   477  | 
                  {
 | 
| 
sl@0
 | 
   478  | 
                    g_date_subtract_days(d, 1);
  | 
| 
sl@0
 | 
   479  | 
                    
  | 
| 
sl@0
 | 
   480  | 
                    TEST("Previous day has julian 1 lower",
 | 
| 
sl@0
 | 
   481  | 
                         g_date_get_julian(d) == j);
  | 
| 
sl@0
 | 
   482  | 
                    
  | 
| 
sl@0
 | 
   483  | 
                    g_date_add_days(d, 1); /* back to original */
  | 
| 
sl@0
 | 
   484  | 
                  }
  | 
| 
sl@0
 | 
   485  | 
              }    
  | 
| 
sl@0
 | 
   486  | 
              discontinuity = FALSE; /* goes away now */            
  | 
| 
sl@0
 | 
   487  | 
  | 
| 
sl@0
 | 
   488  | 
              fflush(stdout);
  | 
| 
sl@0
 | 
   489  | 
              fflush(stderr);
  | 
| 
sl@0
 | 
   490  | 
  | 
| 
sl@0
 | 
   491  | 
	      j = g_date_get_julian(d); /* inc current julian */
  | 
| 
sl@0
 | 
   492  | 
  | 
| 
sl@0
 | 
   493  | 
	      ++day;
  | 
| 
sl@0
 | 
   494  | 
	    } 
  | 
| 
sl@0
 | 
   495  | 
	  ++m;
  | 
| 
sl@0
 | 
   496  | 
	}
  | 
| 
sl@0
 | 
   497  | 
      g_print(" done\n");
 | 
| 
sl@0
 | 
   498  | 
      ++i;
  | 
| 
sl@0
 | 
   499  | 
      prev_y = y;
  | 
| 
sl@0
 | 
   500  | 
      y = check_years[i];
  | 
| 
sl@0
 | 
   501  | 
      if (prev_y == G_DATE_BAD_YEAR || 
  | 
| 
sl@0
 | 
   502  | 
          (prev_y + 1) != y) discontinuity = TRUE;
  | 
| 
sl@0
 | 
   503  | 
    }
  | 
| 
sl@0
 | 
   504  | 
  
  | 
| 
sl@0
 | 
   505  | 
  
  | 
| 
sl@0
 | 
   506  | 
  g_print("\n%u tests passed, %u failed\n",passed, notpassed);
 | 
| 
sl@0
 | 
   507  | 
  | 
| 
sl@0
 | 
   508  | 
  #ifdef __SYMBIAN32__
  | 
| 
sl@0
 | 
   509  | 
  testResultXml("date-test");
 | 
| 
sl@0
 | 
   510  | 
  #endif
  | 
| 
sl@0
 | 
   511  | 
  
  | 
| 
sl@0
 | 
   512  | 
  return 0;
  | 
| 
sl@0
 | 
   513  | 
}
  | 
| 
sl@0
 | 
   514  | 
  | 
| 
sl@0
 | 
   515  | 
  |