LCOV - code coverage report
Current view: top level - src/interfaces/ecpg/test/compat_informix - rfmtdate.pgc (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 92.3 % 91 84
Test Date: 2026-07-25 22:15:46 Functions: 100.0 % 5 5
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 64.7 % 17 11

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

Generated by: LCOV version 2.0-1