LCOV - differential code coverage report
Current view: top level - src/interfaces/libpq/test - libpq_uri_regress.c (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage 16@8cea358b128 vs 17@8cea358b128 Lines: 88.0 % 25 22 3 22
Current Date: 2024-04-14 14:21:10 Functions: 100.0 % 1 1 1
Baseline: 16@8cea358b128 Branches: 87.5 % 24 21 3 21
Baseline Date: 2024-04-14 14:21:09 Line coverage date bins:
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed (240..) days: 88.0 % 25 22 3 22
Function coverage date bins:
(240..) days: 100.0 % 1 1 1
Branch coverage date bins:
(240..) days: 87.5 % 24 21 3 21

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*
                                  2                 :                :  * libpq_uri_regress.c
                                  3                 :                :  *      A test program for libpq URI format
                                  4                 :                :  *
                                  5                 :                :  * This is a helper for libpq conninfo regression testing.  It takes a single
                                  6                 :                :  * conninfo string as a parameter, parses it using PQconninfoParse, and then
                                  7                 :                :  * prints out the values from the parsed PQconninfoOption struct that differ
                                  8                 :                :  * from the defaults (obtained from PQconndefaults).
                                  9                 :                :  *
                                 10                 :                :  * Portions Copyright (c) 2012-2024, PostgreSQL Global Development Group
                                 11                 :                :  *
                                 12                 :                :  * IDENTIFICATION
                                 13                 :                :  *      src/interfaces/libpq/test/libpq_uri_regress.c
                                 14                 :                :  */
                                 15                 :                : 
                                 16                 :                : #include "postgres_fe.h"
                                 17                 :                : 
                                 18                 :                : #include "libpq-fe.h"
                                 19                 :                : 
                                 20                 :                : int
 4386 alvherre@alvh.no-ip.       21                 :CBC          60 : main(int argc, char *argv[])
                                 22                 :                : {
                                 23                 :                :     PQconninfoOption *opts;
                                 24                 :                :     PQconninfoOption *defs;
                                 25                 :                :     PQconninfoOption *opt;
                                 26                 :                :     PQconninfoOption *def;
                                 27                 :             60 :     char       *errmsg = NULL;
                                 28                 :             60 :     bool        local = true;
                                 29                 :                : 
                                 30         [ -  + ]:             60 :     if (argc != 2)
 4386 alvherre@alvh.no-ip.       31                 :UBC           0 :         return 1;
                                 32                 :                : 
 4386 alvherre@alvh.no-ip.       33                 :CBC          60 :     opts = PQconninfoParse(argv[1], &errmsg);
                                 34         [ +  + ]:             60 :     if (opts == NULL)
                                 35                 :                :     {
  711 dgustafsson@postgres       36                 :             14 :         fprintf(stderr, "libpq_uri_regress: %s", errmsg);
 4386 alvherre@alvh.no-ip.       37                 :             14 :         return 1;
                                 38                 :                :     }
                                 39                 :                : 
                                 40                 :             46 :     defs = PQconndefaults();
                                 41         [ -  + ]:             46 :     if (defs == NULL)
                                 42                 :                :     {
  711 dgustafsson@postgres       43                 :UBC           0 :         fprintf(stderr, "libpq_uri_regress: cannot fetch default options\n");
 4386 alvherre@alvh.no-ip.       44                 :              0 :         return 1;
                                 45                 :                :     }
                                 46                 :                : 
                                 47                 :                :     /*
                                 48                 :                :      * Loop on the options, and print the value of each if not the default.
                                 49                 :                :      *
                                 50                 :                :      * XXX this coding assumes that PQconninfoOption structs always have the
                                 51                 :                :      * keywords in the same order.
                                 52                 :                :      */
 4386 alvherre@alvh.no-ip.       53         [ +  + ]:CBC        1932 :     for (opt = opts, def = defs; opt->keyword; ++opt, ++def)
                                 54                 :                :     {
                                 55         [ +  + ]:           1886 :         if (opt->val != NULL)
                                 56                 :                :         {
                                 57   [ +  +  +  + ]:             91 :             if (def->val == NULL || strcmp(opt->val, def->val) != 0)
                                 58                 :             90 :                 printf("%s='%s' ", opt->keyword, opt->val);
                                 59                 :                : 
                                 60                 :                :             /*
                                 61                 :                :              * Try to detect if this is a Unix-domain socket or inet.  This is
                                 62                 :                :              * a bit grotty but it's the same thing that libpq itself does.
                                 63                 :                :              *
                                 64                 :                :              * Note that we directly test for '/' instead of using
                                 65                 :                :              * is_absolute_path, as that would be considerably more messy.
                                 66                 :                :              * This would fail on Windows, but that platform doesn't have
                                 67                 :                :              * Unix-domain sockets anyway.
                                 68                 :                :              */
                                 69         [ +  - ]:             91 :             if (*opt->val &&
                                 70         [ +  + ]:             91 :                 (strcmp(opt->keyword, "hostaddr") == 0 ||
                                 71   [ +  +  +  + ]:             89 :                  (strcmp(opt->keyword, "host") == 0 && *opt->val != '/')))
                                 72                 :                :             {
                                 73                 :             32 :                 local = false;
                                 74                 :                :             }
                                 75                 :                :         }
                                 76                 :                :     }
                                 77                 :                : 
                                 78         [ +  + ]:             46 :     if (local)
                                 79                 :             15 :         printf("(local)\n");
                                 80                 :                :     else
                                 81                 :             31 :         printf("(inet)\n");
                                 82                 :                : 
                                 83                 :             46 :     return 0;
                                 84                 :                : }
        

Generated by: LCOV version 2.1-beta2-3-g6141622