LCOV - code coverage report
Current view: top level - tests - run-swdb.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 61 0.0 %
Date: 2016-12-01 18:45:36 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /* run-swdb.c  - Test tool for SWDB function
       2             :  * Copyright (C) 2016 g10 Code GmbH
       3             :  *
       4             :  * This file is part of GPGME.
       5             :  *
       6             :  * GPGME is free software; you can redistribute it and/or modify it
       7             :  * under the terms of the GNU Lesser General Public License as
       8             :  * published by the Free Software Foundation; either version 2.1 of
       9             :  * the License, or (at your option) any later version.
      10             :  *
      11             :  * GPGME is distributed in the hope that it will be useful, but
      12             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14             :  * Lesser General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU Lesser General Public
      17             :  * License along with this program; if not, see <https://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : /* We need to include config.h so that we know whether we are building
      21             :    with large file system (LFS) support. */
      22             : #ifdef HAVE_CONFIG_H
      23             : #include <config.h>
      24             : #endif
      25             : 
      26             : #include <stdlib.h>
      27             : #include <stdio.h>
      28             : #include <string.h>
      29             : #include <assert.h>
      30             : 
      31             : #include <gpgme.h>
      32             : 
      33             : #define PGM "run-swdb"
      34             : 
      35             : #include "run-support.h"
      36             : 
      37             : 
      38             : static int verbose;
      39             : 
      40             : 
      41             : static const char *
      42           0 : isotimestr (unsigned long value)
      43             : {
      44             :   time_t t;
      45             :   static char buffer[25+5];
      46             :   struct tm *tp;
      47             : 
      48           0 :   if (!value)
      49           0 :     return "none";
      50           0 :   t = value;
      51             : 
      52           0 :   tp = gmtime (&t);
      53           0 :   snprintf (buffer, sizeof buffer, "%04d-%02d-%02d %02d:%02d:%02d",
      54           0 :             1900+tp->tm_year, tp->tm_mon+1, tp->tm_mday,
      55             :             tp->tm_hour, tp->tm_min, tp->tm_sec);
      56           0 :   return buffer;
      57             : }
      58             : 
      59             : 
      60             : static int
      61           0 : show_usage (int ex)
      62             : {
      63           0 :   fputs ("usage: " PGM " [options] NAME [VERSION]\n\n"
      64             :          "Options:\n"
      65             :          "  --verbose        run in verbose mode\n"
      66             :          "  --status         print status lines from the backend\n"
      67             :          , stderr);
      68           0 :   exit (ex);
      69             : }
      70             : 
      71             : 
      72             : int
      73           0 : main (int argc, char **argv)
      74             : {
      75           0 :   int last_argc = -1;
      76             :   gpgme_error_t err;
      77             :   gpgme_ctx_t ctx;
      78           0 :   gpgme_protocol_t protocol = GPGME_PROTOCOL_GPGCONF;
      79             :   const char *name;
      80             :   const char *iversion;
      81             :   gpgme_query_swdb_result_t result;
      82             : 
      83           0 :   if (argc)
      84           0 :     { argc--; argv++; }
      85             : 
      86           0 :   while (argc && last_argc != argc )
      87             :     {
      88           0 :       last_argc = argc;
      89           0 :       if (!strcmp (*argv, "--"))
      90             :         {
      91           0 :           argc--; argv++;
      92           0 :           break;
      93             :         }
      94           0 :       else if (!strcmp (*argv, "--help"))
      95           0 :         show_usage (0);
      96           0 :       else if (!strcmp (*argv, "--verbose"))
      97             :         {
      98           0 :           verbose = 1;
      99           0 :           argc--; argv++;
     100             :         }
     101           0 :       else if (!strncmp (*argv, "--", 2))
     102           0 :         show_usage (1);
     103             :     }
     104             : 
     105           0 :   if (argc < 1 || argc > 2)
     106           0 :     show_usage (1);
     107           0 :   name = argv[0];
     108           0 :   iversion = argc > 1? argv[1] : NULL;
     109             : 
     110           0 :   init_gpgme (protocol);
     111             : 
     112           0 :   err = gpgme_new (&ctx);
     113           0 :   fail_if_err (err);
     114           0 :   gpgme_set_protocol (ctx, protocol);
     115             : 
     116           0 :   err = gpgme_op_query_swdb (ctx, name, iversion, 0);
     117           0 :   if (err)
     118             :     {
     119           0 :       fprintf (stderr, PGM ": error querying swdb: %s\n", gpg_strerror (err));
     120           0 :       exit (1);
     121             :     }
     122             : 
     123           0 :   result = gpgme_op_query_swdb_result (ctx);
     124           0 :   if (!result)
     125             :     {
     126           0 :       fprintf (stderr, PGM ": error querying swdb: %s\n", "no result");
     127           0 :       exit (1);
     128             :     }
     129             : 
     130           0 :   printf ("package ...: %s\n"
     131             :           "iversion ..: %s\n"
     132             :           "version ...: %s\n",
     133           0 :           nonnull (result->name),
     134           0 :           nonnull (result->iversion),
     135           0 :           nonnull (result->version));
     136           0 :   printf ("reldate ...: %s\n", isotimestr (result->reldate));
     137           0 :   printf ("created ...: %s\n", isotimestr (result->created));
     138           0 :   printf ("retrieved .: %s\n", isotimestr (result->retrieved));
     139           0 :   printf ("flags .....:%s%s%s%s%s%s%s\n",
     140           0 :           result->warning? " warning" : "",
     141           0 :           result->update?  " update"  : "",
     142           0 :           result->urgent?  " urgent"  : "",
     143           0 :           result->unknown? " unknown" : "",
     144           0 :           result->tooold?  " tooold"  : "",
     145           0 :           result->noinfo?  " noinfo"  : "",
     146           0 :           result->error?   " error"   : "" );
     147             : 
     148             : 
     149           0 :   gpgme_release (ctx);
     150           0 :   return 0;
     151             : }

Generated by: LCOV version 1.11