LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/compat_informix - rfmtdate.pgc (source / functions) Hit Total Coverage
Test: PostgreSQL 17devel Lines: 84 91 92.3 %
Date: 2024-04-24 20:11:41 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #include <stdio.h>
       2             : #include <stdlib.h>
       3             : #include <pgtypes_error.h>
       4             : #include <sqltypes.h>
       5             : 
       6             : /*
       7             :  * This file tests various forms of date-input/output by means of
       8             :  * rfmtdate / rdefmtdate / rstrdate
       9             :  */
      10             : 
      11             : 
      12             : static void
      13             : check_return(int ret);
      14             : 
      15             : static void
      16           8 : date_test_strdate(const char *input)
      17             : {
      18             :     static int i;
      19             :     date d;
      20             :     int r, q;
      21             :     char dbuf[11];
      22             : 
      23           8 :     r = rstrdate(input, &d);
      24           8 :     printf("r: %d ", r);
      25           8 :     if (r == 0)
      26             :     {
      27           8 :         q = rdatestr(d, dbuf);
      28           8 :         printf("q: %d ", q);
      29           8 :         if (q == 0)
      30             :         {
      31           8 :             printf("date %d: %s\n", i++, dbuf);
      32             :         }
      33             :         else
      34           0 :             printf("\n");
      35             :     }
      36             :     else
      37           0 :         check_return(r);
      38           8 : }
      39             : 
      40             : static void
      41          80 : date_test_defmt(const char *fmt, const char *input)
      42             : {
      43             :     static int i;
      44             :     char dbuf[11];
      45             :     date d;
      46             :     int q, r;
      47             : 
      48          80 :     r = rdefmtdate(&d, fmt, input);
      49          80 :     printf("r: %d ", r);
      50          80 :     if (r == 0)
      51             :     {
      52          60 :         q = rdatestr(d, dbuf);
      53          60 :         printf("q: %d ", q);
      54          60 :         if (q == 0)
      55             :         {
      56          60 :             printf("date %d: %s\n", i++, dbuf);
      57             :         }
      58             :         else
      59           0 :             printf("\n");
      60             :     }
      61             :     else
      62          20 :         check_return(r);
      63          80 : }
      64             : 
      65             : static void
      66          48 : date_test_fmt(date d, const char *fmt)
      67             : {
      68             :     static int i;
      69             :     char buf[200];
      70             :     int r;
      71             : 
      72          48 :     r = rfmtdate(d, fmt, buf);
      73          48 :     printf("r: %d ", r);
      74          48 :     if (r != 0)
      75           0 :         check_return(r);
      76             :     else
      77          48 :         printf("date: %d: %s\n", i++, buf);
      78          48 : }
      79             : 
      80             : 
      81             : int
      82           4 : main(void)
      83             : {
      84           4 :     short mdy[3] = { 11, 23, 1959 };
      85             :     char dbuf[11];
      86             :     date d;
      87             :     int r;
      88             : 
      89           4 :     ECPGdebug(1, stderr);
      90             : 
      91           4 :     r = rmdyjul(mdy, &d);
      92           4 :     printf("create: r: %d\n", r);
      93           4 :     if (r == 0)
      94             :     {
      95           4 :         rdatestr(d, dbuf);
      96           4 :         printf("date: %s\n", dbuf);
      97             :     }
      98             : 
      99             :     /* input mask is mmddyyyy */
     100           4 :     date_test_strdate("12031994");
     101           4 :     date_test_strdate("9.6.1994");
     102             : 
     103           4 :     date_test_fmt(d, "mmddyy");
     104           4 :     date_test_fmt(d, "ddmmyy");
     105           4 :     date_test_fmt(d, "yymmdd");
     106           4 :     date_test_fmt(d, "yy/mm/dd");
     107           4 :     date_test_fmt(d, "yy mm dd");
     108           4 :     date_test_fmt(d, "yy.mm.dd");
     109           4 :     date_test_fmt(d, ".mm.yyyy.dd.");
     110           4 :     date_test_fmt(d, "mmm. dd, yyyy");
     111           4 :     date_test_fmt(d, "mmm dd yyyy");
     112           4 :     date_test_fmt(d, "yyyy dd mm");
     113           4 :     date_test_fmt(d, "ddd, mmm. dd, yyyy");
     114           4 :     date_test_fmt(d, "(ddd) mmm. dd, yyyy");
     115             : 
     116           4 :     date_test_defmt("ddmmyy", "21-2-54");
     117           4 :     date_test_defmt("ddmmyy", "2-12-54");
     118           4 :     date_test_defmt("ddmmyy", "20111954");
     119           4 :     date_test_defmt("ddmmyy", "130464");
     120           4 :     date_test_defmt("mmm.dd.yyyy", "MAR-12-1967");
     121           4 :     date_test_defmt("yy/mm/dd", "1954, February 3rd");
     122           4 :     date_test_defmt("mmm.dd.yyyy", "041269");
     123           4 :     date_test_defmt("yy/mm/dd", "In the year 2525, in the month of July, mankind will be alive on the 28th day");
     124           4 :     date_test_defmt("dd-mm-yy", "I said on the 28th of July in the year 2525");
     125           4 :     date_test_defmt("mmm.dd.yyyy", "9/14/58");
     126           4 :     date_test_defmt("yy/mm/dd", "47/03/29");
     127           4 :     date_test_defmt("mmm.dd.yyyy", "oct 28 1975");
     128           4 :     date_test_defmt("mmddyy", "Nov 14th, 1985");
     129             :     /* ok: still contains dd mm yy */
     130           4 :     date_test_defmt("bladdfoommbaryybong", "20/11/1954");
     131             :     /* 1994 is not a leap year, it accepts the date as 01-03-1994 */
     132           4 :     date_test_defmt("ddmmyy", "29-02-1994");
     133             : 
     134             :     /* ECPG_INFORMIX_ENOTDMY, need "dd", "mm" and "yy" */
     135           4 :     date_test_defmt("dmy", "20/11/1954");
     136             : 
     137             :     /* ECPG_INFORMIX_ENOSHORTDATE */
     138           4 :     date_test_defmt("ddmmyy", "21254");
     139           4 :     date_test_defmt("ddmmyy", "    21254    ");
     140             : 
     141             :     /* ECPG_INFORMIX_BAD_DAY */
     142           4 :     date_test_defmt("ddmmyy", "320494");
     143             : 
     144             :     /* ECPG_INFORMIX_BAD_MONTH */
     145           4 :     date_test_defmt("mm-yyyy-dd", "13-1993-21");
     146             : 
     147             :     /* ECPG_INFORMIX_BAD_YEAR */
     148             :     /* ??? */
     149             : 
     150           4 :     return 0;
     151             : }
     152             : 
     153             : static void
     154          20 : check_return(int ret)
     155             : {
     156          20 :     switch(ret)
     157             :     {
     158           4 :         case ECPG_INFORMIX_ENOTDMY:
     159           4 :             printf("(ECPG_INFORMIX_ENOTDMY)");
     160           4 :             break;
     161           8 :         case ECPG_INFORMIX_ENOSHORTDATE:
     162           8 :             printf("(ECPG_INFORMIX_ENOSHORTDATE)");
     163           8 :             break;
     164           4 :         case ECPG_INFORMIX_BAD_DAY:
     165           4 :             printf("(ECPG_INFORMIX_BAD_DAY)");
     166           4 :             break;
     167           4 :         case ECPG_INFORMIX_BAD_MONTH:
     168           4 :             printf("(ECPG_INFORMIX_BAD_MONTH)");
     169           4 :             break;
     170           0 :         default:
     171           0 :             printf("(unknown ret: %d)", ret);
     172           0 :             break;
     173             :     }
     174          20 :     printf("\n");
     175          20 : }

Generated by: LCOV version 1.14