LCOV - differential code coverage report
Current view: top level - src/interfaces/ecpg/test/pgtypeslib - dt_test2.pgc (source / functions) Coverage Total Hit UBC CBC
Current: c70b6db34ffeab48beef1fb4ce61bcad3772b8dd vs 06473f5a344df8c9594ead90a609b86f6724cff8 Lines: 96.5 % 57 55 2 55
Current Date: 2025-09-06 07:49:51 +0900 Functions: 100.0 % 1 1 1
Baseline: lcov-20250907-010129-baseline Branches: 78.6 % 28 22 6 22
Baseline Date: 2025-09-05 08:21:35 +0100 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(360..) days: 96.5 % 57 55 2 55
Function coverage date bins:
(360..) days: 100.0 % 1 1 1
Branch coverage date bins:
(360..) days: 78.6 % 28 22 6 22

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : #include <stdio.h>
                                  2                 :                : #include <string.h>
                                  3                 :                : #include <stdlib.h>
                                  4                 :                : #include <limits.h>
                                  5                 :                : #include <pgtypes_date.h>
                                  6                 :                : #include <pgtypes_timestamp.h>
                                  7                 :                : 
                                  8                 :                : exec sql include ../regression;
                                  9                 :                : 
                                 10                 :                : char *dates[] = { "19990108foobar",
                                 11                 :                :                   "19990108 foobar",
                                 12                 :                :                   "1999-01-08 foobar",
                                 13                 :                :                   "January 8, 1999",
                                 14                 :                :                   "1999-01-08",
                                 15                 :                :                   "1/8/1999",
                                 16                 :                :                   "1/18/1999",
                                 17                 :                :                   "01/02/03",
                                 18                 :                :                   "1999-Jan-08",
                                 19                 :                :                   "Jan-08-1999",
                                 20                 :                :                   "08-Jan-1999",
                                 21                 :                :                   "99-Jan-08",
                                 22                 :                :                   "08-Jan-99",
                                 23                 :                :                   "08-Jan-06",
                                 24                 :                :                   "Jan-08-99",
                                 25                 :                :                   "19990108",
                                 26                 :                :                   "990108",
                                 27                 :                :                   "1999.008",
                                 28                 :                :                   "J2451187",
                                 29                 :                :                   "January 8, 99 BC",
                                 30                 :                :                   /*
                                 31                 :                :                    * Maximize space usage in ParseDateTime() with 25
                                 32                 :                :                    * (MAXDATEFIELDS) fields and 128 (MAXDATELEN) total length.
                                 33                 :                :                    */
                                 34                 :                :                   "........................Xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
                                 35                 :                :                   "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                                 36                 :                :                   /* 26 fields */
                                 37                 :                :                   ".........................aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
                                 38                 :                :                   "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                                 39                 :                :                   NULL };
                                 40                 :                : 
                                 41                 :                : /* do not conflict with libc "times" symbol */
                                 42                 :                : static char *times[] = { "0:04",
                                 43                 :                :                   "1:59 PDT",
                                 44                 :                :                   "13:24:40 -8:00",
                                 45                 :                :                   "13:24:40.495+3",
                                 46                 :                :                   "13:24:40.123456123+3",
                                 47                 :                :                   NULL };
                                 48                 :                : 
                                 49                 :                : char *intervals[] = { "1 minute",
                                 50                 :                :                       "1 12:59:10",
                                 51                 :                :                       "2 day 12 hour 59 minute 10 second",
                                 52                 :                :                       "1 days 12 hrs 59 mins 10 secs",
                                 53                 :                :                       "1 days 1 hours 1 minutes 1 seconds",
                                 54                 :                :                       "1 year 59 mins",
                                 55                 :                :                       "1 year 59 mins foobar",
                                 56                 :                :                       NULL };
                                 57                 :                : 
                                 58                 :                : int
 6976 meskes@postgresql.or       59                 :CBC           1 : main(void)
                                 60                 :                : {
                                 61                 :                :     exec sql begin declare section;
                                 62                 :                :         date date1;
                                 63                 :                :         timestamp ts1, ts2;
                                 64                 :                :         char *text;
                                 65                 :                :         interval *i1;
                                 66                 :                :         date *dc;
                                 67                 :                :     exec sql end declare section;
                                 68                 :                : 
                                 69                 :                :     int i, j;
                                 70                 :                :     char *endptr;
                                 71                 :                : 
                                 72                 :              1 :     ECPGdebug(1, stderr);
                                 73                 :                : 
                                 74                 :              1 :     ts1 = PGTYPEStimestamp_from_asc("2003-12-04 17:34:29", NULL);
                                 75                 :              1 :     text = PGTYPEStimestamp_to_asc(ts1);
                                 76                 :                : 
                                 77                 :              1 :     printf("timestamp: %s\n", text);
 2638 tmunro@postgresql.or       78                 :              1 :     PGTYPESchar_free(text);
                                 79                 :                : 
 6976 meskes@postgresql.or       80                 :              1 :     date1 = PGTYPESdate_from_timestamp(ts1);
 6933                            81                 :              1 :     dc = PGTYPESdate_new();
                                 82                 :              1 :     *dc = date1;
                                 83                 :              1 :     text = PGTYPESdate_to_asc(*dc);
 6976                            84                 :              1 :     printf("Date of timestamp: %s\n", text);
 2638 tmunro@postgresql.or       85                 :              1 :     PGTYPESchar_free(text);
 6933 meskes@postgresql.or       86                 :              1 :     PGTYPESdate_free(dc);
                                 87                 :                : 
 6942                            88         [ +  + ]:             23 :     for (i = 0; dates[i]; i++)
                                 89                 :                :     {
                                 90                 :             22 :         bool err = false;
                                 91                 :             22 :         date1 = PGTYPESdate_from_asc(dates[i], &endptr);
                                 92         [ +  + ]:             22 :         if (date1 == INT_MIN) {
                                 93                 :              5 :             err = true;
                                 94                 :                :         }
                                 95                 :             22 :         text = PGTYPESdate_to_asc(date1);
                                 96   [ +  +  +  + ]:             44 :         printf("Date[%d]: %s (%c - %c)\n",
                                 97                 :                :                     i, err ? "-" : text,
                                 98         [ +  - ]:             22 :                     endptr ? 'N' : 'Y',
                                 99                 :                :                     err ? 'T' : 'F');
 2638 tmunro@postgresql.or      100                 :             22 :         PGTYPESchar_free(text);
 6942 meskes@postgresql.or      101         [ +  + ]:             22 :         if (!err)
                                102                 :                :         {
                                103         [ +  + ]:            102 :             for (j = 0; times[j]; j++)
                                104                 :                :             {
 4338 tgl@sss.pgh.pa.us         105                 :             85 :                 int length = strlen(dates[i])
                                106                 :                :                         + 1
                                107                 :             85 :                         + strlen(times[j])
                                108                 :             85 :                         + 1;
                                109                 :             85 :                 char* t = malloc(length);
                                110                 :             85 :                 sprintf(t, "%s %s", dates[i], times[j]);
 6942 meskes@postgresql.or      111                 :             85 :                 ts1 = PGTYPEStimestamp_from_asc(t, NULL);
                                112                 :             85 :                 text = PGTYPEStimestamp_to_asc(ts1);
 3118 tgl@sss.pgh.pa.us         113                 :             85 :                 printf("TS[%d,%d]: %s\n",
                                114         [ +  - ]:             85 :                        i, j, errno ? "-" : text);
 2638 tmunro@postgresql.or      115                 :             85 :                 PGTYPESchar_free(text);
 5500 meskes@postgresql.or      116                 :             85 :                 free(t);
                                117                 :                :             }
                                118                 :                :         }
                                119                 :                :     }
                                120                 :                : 
 6942                           121                 :              1 :     ts1 = PGTYPEStimestamp_from_asc("2004-04-04 23:23:23", NULL);
                                122                 :                : 
                                123         [ +  + ]:              8 :     for (i = 0; intervals[i]; i++)
                                124                 :                :     {
                                125                 :                :         interval *ic;
                                126                 :              7 :         i1 = PGTYPESinterval_from_asc(intervals[i], &endptr);
                                127         [ -  + ]:              7 :         if (*endptr)
 6942 meskes@postgresql.or      128                 :UBC           0 :             printf("endptr set to %s\n", endptr);
 6942 meskes@postgresql.or      129         [ +  + ]:CBC           7 :         if (!i1)
                                130                 :                :         {
                                131                 :              1 :             printf("Error parsing interval %d\n", i);
                                132                 :              1 :             continue;
                                133                 :                :         }
                                134                 :              6 :         j = PGTYPEStimestamp_add_interval(&ts1, i1, &ts2);
                                135         [ -  + ]:              6 :         if (j < 0)
 6942 meskes@postgresql.or      136                 :UBC           0 :             continue;
 6942 meskes@postgresql.or      137                 :CBC           6 :         text = PGTYPESinterval_to_asc(i1);
                                138         [ +  - ]:              6 :         printf("interval[%d]: %s\n", i, text ? text : "-");
 2638 tmunro@postgresql.or      139                 :              6 :         PGTYPESchar_free(text);
                                140                 :                : 
 6933 meskes@postgresql.or      141                 :              6 :         ic = PGTYPESinterval_new();
                                142                 :              6 :         PGTYPESinterval_copy(i1, ic);
                                143                 :              6 :         text = PGTYPESinterval_to_asc(i1);
                                144         [ +  - ]:              6 :         printf("interval_copy[%d]: %s\n", i, text ? text : "-");
 2638 tmunro@postgresql.or      145                 :              6 :         PGTYPESchar_free(text);
 6933 meskes@postgresql.or      146                 :              6 :         PGTYPESinterval_free(ic);
 5500                           147                 :              6 :         PGTYPESinterval_free(i1);
                                148                 :                :     }
                                149                 :                : 
 2943 peter_e@gmx.net           150                 :              1 :     return 0;
                                151                 :                : }
        

Generated by: LCOV version 2.4-beta