LCOV - differential code coverage report
Current view: top level - src/interfaces/ecpg/test/compat_informix - dec_test.pgc (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 86.9 % 130 113 17 113
Current Date: 2023-04-08 17:13:01 Functions: 100.0 % 2 2 2
Baseline: 15 Line coverage date bins:
Baseline Date: 2023-04-08 15:09:40 (240..) days: 86.9 % 130 113 17 113
Legend: Lines: hit not hit Function coverage date bins:
(240..) days: 100.0 % 2 2 2

 Age         Owner                  TLA  Line data    Source code
                                  1                 : #include <stdio.h>
                                  2                 : #include <stdlib.h>
                                  3                 : #include <pgtypes_numeric.h>
                                  4                 : #include <pgtypes_error.h>
                                  5                 : #include <decimal.h>
                                  6                 : #include <sqltypes.h>
                                  7                 : 
                                  8                 : exec sql include ../regression;
                                  9                 : 
                                 10                 : exec sql include ../printf_hack;
                                 11                 : 
                                 12                 : 
                                 13                 : /*
                                 14                 : TODO:
                                 15                 :     deccmp => DECUNKNOWN
                                 16                 :     decimal point: , and/or . ?
                                 17                 :     ECPG_INFORMIX_BAD_EXPONENT ?
                                 18                 : */
                                 19                 : 
                                 20                 : char* decs[] = { "2E394", "-2", ".794", "3.44", "592.49E21", "-32.84e4",
                                 21                 :                  "2E-394", ".1E-2", "+.0", "-592.49E-07", "+32.84e-4",
                                 22                 :                  ".500001", "-.5000001",
                                 23                 :                  "1234567890123456789012345678.91", /* 30 digits should fit
                                 24                 :                                                        into decimal */
                                 25                 :                  "1234567890123456789012345678.921", /* 31 digits should NOT
                                 26                 :                                                         fit into decimal */
                                 27                 :                  "not a number",
                                 28                 :                  NULL};
                                 29                 : 
                                 30                 : 
                                 31                 : static void
                                 32                 : check_errno(void);
                                 33                 : 
                                 34                 : #define BUFSIZE 200
                                 35                 : 
                                 36                 : int
 6081 meskes                     37 CBC           1 : main(void)
                                 38                 : {
                                 39                 :     decimal *dec, *din;
                                 40                 :     char buf[BUFSIZE];
                                 41                 :     long l;
                                 42               1 :     int i, j, k, q, r, count = 0;
                                 43                 :     double dbl;
                                 44               1 :     decimal **decarr = (decimal **) calloc(1, sizeof(decimal));
                                 45                 : 
                                 46               1 :     ECPGdebug(1, stderr);
                                 47                 : 
                                 48              17 :     for (i = 0; decs[i]; i++)
                                 49                 :     {
                                 50              16 :         dec = PGTYPESdecimal_new();
                                 51              16 :         r = deccvasc(decs[i], strlen(decs[i]), dec);
                                 52              16 :         if (r)
                                 53                 :         {
                                 54               2 :             check_errno();
                                 55               2 :             printf("dec[%d,0]: r: %d\n", i, r);
 4618                            56               2 :             PGTYPESdecimal_free(dec);
 6081                            57               2 :             continue;
                                 58                 :         }
                                 59              14 :         decarr = realloc(decarr, sizeof(decimal *) * (count + 1));
                                 60              14 :         decarr[count++] = dec;
                                 61                 : 
                                 62              14 :         r = dectoasc(dec, buf, BUFSIZE-1, -1);
                                 63              14 :         if (r < 0) check_errno();
                                 64              14 :         printf("dec[%d,1]: r: %d, %s\n", i, r, buf);
                                 65                 : 
                                 66              14 :         r = dectoasc(dec, buf, BUFSIZE-1, 0);
                                 67              14 :         if (r < 0) check_errno();
                                 68              14 :         printf("dec[%d,2]: r: %d, %s\n", i, r, buf);
                                 69              14 :         r = dectoasc(dec, buf, BUFSIZE-1, 1);
                                 70              14 :         if (r < 0) check_errno();
                                 71              14 :         printf("dec[%d,3]: r: %d, %s\n", i, r, buf);
                                 72              14 :         r = dectoasc(dec, buf, BUFSIZE-1, 2);
                                 73              14 :         if (r < 0) check_errno();
                                 74              14 :         printf("dec[%d,4]: r: %d, %s\n", i, r, buf);
                                 75                 : 
                                 76              14 :         din = PGTYPESdecimal_new();
                                 77              14 :         r = dectoasc(din, buf, BUFSIZE-1, 2);
                                 78              14 :         if (r < 0) check_errno();
                                 79              14 :         printf("dec[%d,5]: r: %d, %s\n", i, r, buf);
                                 80                 : 
                                 81              14 :         r = dectolong(dec, &l);
                                 82              14 :         if (r) check_errno();
                                 83              14 :         printf("dec[%d,6]: %ld (r: %d)\n", i, r?0L:l, r);
                                 84              14 :         if (r == 0)
                                 85                 :         {
                                 86              11 :             r = deccvlong(l, din);
                                 87              11 :             if (r) check_errno();
                                 88              11 :             dectoasc(din, buf, BUFSIZE-1, 2);
                                 89              11 :             q = deccmp(dec, din);
                                 90              11 :             printf("dec[%d,7]: %s (r: %d - cmp: %d)\n", i, buf, r, q);
                                 91                 :         }
                                 92                 : 
                                 93              14 :         r = dectoint(dec, &k);
                                 94              14 :         if (r) check_errno();
                                 95              14 :         printf("dec[%d,8]: %d (r: %d)\n", i, r?0:k, r);
                                 96              14 :         if (r == 0)
                                 97                 :         {
                                 98              11 :             r = deccvint(k, din);
                                 99              11 :             if (r) check_errno();
                                100              11 :             dectoasc(din, buf, BUFSIZE-1, 2);
                                101              11 :             q = deccmp(dec, din);
                                102              11 :             printf("dec[%d,9]: %s (r: %d - cmp: %d)\n", i, buf, r, q);
                                103                 :         }
                                104                 : 
 5918                           105              14 :         if (i != 6)
                                106                 :         {
                                107                 :             /* underflow does not work reliable on several archs, so not testing it here */
                                108                 :             /* this is a libc problem since we only call strtod() */
                                109              13 :             r = dectodbl(dec, &dbl);
                                110              13 :             if (r) check_errno();
 1640 tgl                       111              13 :             printf("dec[%d,10]: ", i);
                                112              13 :             print_double(r ? 0.0 : dbl);
                                113              13 :             printf(" (r: %d)\n", r);
                                114                 :         }
                                115                 : 
 6081 meskes                    116              14 :         PGTYPESdecimal_free(din);
                                117              14 :         printf("\n");
                                118                 :     }
                                119                 : 
                                120                 :     /* add a NULL value */
                                121               1 :     dec = PGTYPESdecimal_new();
                                122               1 :     decarr = realloc(decarr, sizeof(decimal *) * (count + 1));
                                123               1 :     decarr[count++] = dec;
                                124                 : 
                                125               1 :     rsetnull(CDECIMALTYPE, (char *) decarr[count-1]);
                                126               1 :     printf("dec[%d]: %sNULL\n", count-1,
                                127               1 :         risnull(CDECIMALTYPE, (char *) decarr[count-1]) ? "" : "NOT ");
                                128               1 :     printf("dec[0]: %sNULL\n",
                                129               1 :         risnull(CDECIMALTYPE, (char *) decarr[0]) ? "" : "NOT ");
                                130                 : 
                                131               1 :     r = dectoasc(decarr[3], buf, -1, -1);
                                132               1 :     check_errno(); printf("dectoasc with len == -1: r: %d\n", r);
                                133               1 :     r = dectoasc(decarr[3], buf, 0, -1);
                                134               1 :     check_errno(); printf("dectoasc with len == 0: r: %d\n", r);
                                135                 : 
                                136              16 :     for (i = 0; i < count; i++)
                                137                 :     {
                                138             240 :         for (j = 0; j < count; j++)
                                139                 :         {
                                140                 :             decimal a, s, m, d;
                                141                 :             int c;
                                142             225 :             c = deccmp(decarr[i], decarr[j]);
                                143             225 :             printf("dec[c,%d,%d]: %d\n", i, j, c);
                                144                 : 
                                145             225 :             r = decadd(decarr[i], decarr[j], &a);
                                146             225 :             if (r)
                                147                 :             {
                                148              62 :                 check_errno();
                                149              62 :                 printf("r: %d\n", r);
                                150                 :             }
                                151                 :             else
                                152                 :             {
                                153             163 :                 dectoasc(&a, buf, BUFSIZE-1, -1);
                                154             163 :                 printf("dec[a,%d,%d]: %s\n", i, j, buf);
                                155                 :             }
                                156                 : 
                                157             225 :             r = decsub(decarr[i], decarr[j], &s);
                                158             225 :             if (r)
                                159                 :             {
 6081 meskes                    160 UBC           0 :                 check_errno();
                                161               0 :                 printf("r: %d\n", r);
                                162                 :             }
                                163                 :             else
                                164                 :             {
 6081 meskes                    165 CBC         225 :                 dectoasc(&s, buf, BUFSIZE-1, -1);
                                166             225 :                 printf("dec[s,%d,%d]: %s\n", i, j, buf);
                                167                 :             }
                                168                 : 
                                169             225 :             r = decmul(decarr[i], decarr[j], &m);
                                170             225 :             if (r)
                                171                 :             {
 6081 meskes                    172 UBC           0 :                 check_errno();
                                173               0 :                 printf("r: %d\n", r);
                                174                 :             }
                                175                 :             else
                                176                 :             {
 6081 meskes                    177 CBC         225 :                 dectoasc(&m, buf, BUFSIZE-1, -1);
                                178             225 :                 printf("dec[m,%d,%d]: %s\n", i, j, buf);
                                179                 :             }
                                180                 : 
                                181             225 :             r = decdiv(decarr[i], decarr[j], &d);
                                182             225 :             if (r)
                                183                 :             {
                                184              14 :                 check_errno();
                                185              14 :                 printf("r: %d\n", r);
                                186                 :             }
                                187                 :             else
                                188                 :             {
                                189             211 :                 dectoasc(&d, buf, BUFSIZE-1, -1);
                                190             211 :                 printf("dec[d,%d,%d]: %s\n", i, j, buf);
                                191                 :             }
                                192                 :         }
                                193                 :     }
                                194                 : 
                                195              16 :     for (i = 0; i < count; i++)
                                196                 :     {
                                197              15 :         dectoasc(decarr[i], buf, BUFSIZE-1, -1);
                                198              15 :         printf("%d: %s\n", i, buf);
                                199                 : 
 4618                           200              15 :         PGTYPESdecimal_free(decarr[i]);
                                201                 :     }
                                202               1 :     free(decarr);
                                203                 : 
 2061 peter_e                   204               1 :     return 0;
                                205                 : }
                                206                 : 
                                207                 : static void
 6081 meskes                    208              92 : check_errno(void)
                                209                 : {
                                210              92 :     switch(errno)
                                211                 :     {
                                212               5 :         case 0:
                                213               5 :             printf("(no errno set) - ");
                                214               5 :             break;
 6081 meskes                    215 UBC           0 :         case ECPG_INFORMIX_NUM_OVERFLOW:
                                216               0 :             printf("(errno == ECPG_INFORMIX_NUM_OVERFLOW) - ");
                                217               0 :             break;
                                218               0 :         case ECPG_INFORMIX_NUM_UNDERFLOW:
                                219               0 :             printf("(errno == ECPG_INFORMIX_NUM_UNDERFLOW) - ");
                                220               0 :             break;
 6081 meskes                    221 CBC          70 :         case PGTYPES_NUM_OVERFLOW:
                                222              70 :             printf("(errno == PGTYPES_NUM_OVERFLOW) - ");
                                223              70 :             break;
 6081 meskes                    224 UBC           0 :         case PGTYPES_NUM_UNDERFLOW:
                                225               0 :             printf("(errno == PGTYPES_NUM_UNDERFLOW) - ");
                                226               0 :             break;
 6081 meskes                    227 CBC           3 :         case PGTYPES_NUM_BAD_NUMERIC:
                                228               3 :             printf("(errno == PGTYPES_NUM_BAD_NUMERIC) - ");
                                229               3 :             break;
                                230              14 :         case PGTYPES_NUM_DIVIDE_ZERO:
                                231              14 :             printf("(errno == PGTYPES_NUM_DIVIDE_ZERO) - ");
                                232              14 :             break;
 6081 meskes                    233 UBC           0 :         default:
                                234               0 :             printf("(unknown errno (%d))\n", errno);
                                235               0 :             printf("(libc: (%s)) ", strerror(errno));
                                236               0 :             break;
                                237                 :     }
 6081 meskes                    238 CBC          92 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a