Back to index

glibc  2.9
Defines | Functions | Variables
bug-getdate1.c File Reference
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include "../test-skeleton.c"

Go to the source code of this file.

Defines

#define PREPARE(argc, argv)
#define TEST_FUNCTION   do_test (argc, argv)

Functions

static void output_to_template_file (const char *str)
static int process_getdate_on (const char *str)
static int do_test (int argc, char *argv[])

Variables

static char * templ_filename

Define Documentation

#define PREPARE (   argc,
  argv 
)
Value:
if (argc < 2)                                                  \
    {                                                          \
      puts ("Command line: progname template_filename_full_path");    \
      exit (1);                                                       \
    }                                                          \
  add_temp_file (argv[1])

Definition at line 137 of file bug-getdate1.c.

#define TEST_FUNCTION   do_test (argc, argv)

Definition at line 145 of file bug-getdate1.c.


Function Documentation

static int do_test ( int  argc,
char *  argv[] 
) [static]

Definition at line 69 of file bug-getdate1.c.

{

  templ_filename = argv[1];

  setenv ("DATEMSK", templ_filename, 1);

  /*
   * The following 4 testcases reproduce the problem:
   * 1. Templates "%S" and "%M" are not processed,
   *    when used without "%H" template
   */
  int res = 0;
  output_to_template_file ("%M");
  res |= process_getdate_on ("1");

  output_to_template_file ("%M %H");
  res |= process_getdate_on ("1 2");

  output_to_template_file ("%S");
  res |= process_getdate_on ("1");

  output_to_template_file ("%S %H");
  res |= process_getdate_on ("1 2");

  /*
   * The following 9 testcases reproduce the problem:
   * 2. Templates "%Y", "%y", "%d", "%C", "%C %y"
   *    are not processed separately
   */
  output_to_template_file ("%Y");
  process_getdate_on ("2001");

  output_to_template_file ("%Y %m");
  res |= process_getdate_on ("2001 3");

  output_to_template_file ("%y");
  res |= process_getdate_on ("70");

  output_to_template_file ("%y %m");
  res |= process_getdate_on ("70 3");

  output_to_template_file ("%d");
  res |= process_getdate_on ("06");

  output_to_template_file ("%d %m");
  res |= process_getdate_on ("25 3");

  output_to_template_file ("%C");
  res |= process_getdate_on ("20");

  output_to_template_file ("%C %y %m");
  res |= process_getdate_on ("20 3 2");

  output_to_template_file ("%C %y");
  res |= process_getdate_on ("20 5");

  /*
   * The following testcase reproduces the problem:
   * 3. When template is "%Y %m", day of month is not set
   *    to 1 as standard requires
   */
  output_to_template_file ("%Y %m");
  res |= process_getdate_on ("2008 3");

  return res;
}

Here is the call graph for this function:

static void output_to_template_file ( const char *  str) [static]

Definition at line 11 of file bug-getdate1.c.

{
  FILE *fd = fopen (templ_filename, "w");
  if (fd == NULL)
    {
      printf ("Can not open file for writing\n");
      exit (1);
    }

  fprintf (fd, "%s\n", str);
  fclose (fd);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int process_getdate_on ( const char *  str) [static]

Definition at line 28 of file bug-getdate1.c.

{
  struct tm *res;
  char templ[1000];
  FILE *fd = fopen (templ_filename, "r");

  if (fd == NULL)
    {
      printf ("Can not open file for reading\n");
      exit (1);
    }

  if (fgets (templ, 1000, fd) == NULL)
    {
      printf ("Can not read file\n");
      exit (1);
    }
  fclose (fd);

  res = getdate (str);
  if (res == NULL)
    {
      printf ("Failed on getdate(\"%s\"), template is: %s", str, templ);
      printf ("Error number: %d\n\n", getdate_err);
      return 1;
    }
  printf ("Success on getdate(\"%s\"), template is: %s\n", str, templ);
  printf ("Result is\n");
  printf ("Seconds: %d\n", res->tm_sec);
  printf ("Minutes: %d\n", res->tm_min);
  printf ("Hour: %d\n", res->tm_hour);
  printf ("Day of month: %d\n", res->tm_mday);
  printf ("Month of year: %d\n", res->tm_mon);
  printf ("Years since 1900: %d\n", res->tm_year);
  printf ("Day of week: %d\n", res->tm_wday);
  printf ("Day of year: %d\n", res->tm_yday);
  printf ("Daylight Savings flag: %d\n\n", res->tm_isdst);
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char* templ_filename [static]

Definition at line 6 of file bug-getdate1.c.