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