LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_config.c (source / functions) Hit Total Coverage
Test: GNU Taler coverage report Lines: 0 27 0.0 %
Date: 2020-08-15 06:12:35 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2020 Taler Systems SA
       4             : 
       5             :   TALER is free software; you can redistribute it and/or modify
       6             :   it under the terms of the GNU General Public License as
       7             :   published by the Free Software Foundation; either version 3, or
       8             :   (at your option) any later version.
       9             : 
      10             :   TALER is distributed in the hope that it will be useful, but
      11             :   WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             :   GNU General Public License for more details.
      14             : 
      15             :   You should have received a copy of the GNU General Public
      16             :   License along with TALER; see the file COPYING.  If not, see
      17             :   <http://www.gnu.org/licenses/>
      18             : */
      19             : 
      20             : /**
      21             :  * @file lib/testing_api_cmd_config.c
      22             :  * @brief command to test config request
      23             :  * @author Christian Grothoff
      24             :  */
      25             : 
      26             : #include "platform.h"
      27             : #include <taler/taler_exchange_service.h>
      28             : #include <taler/taler_testing_lib.h>
      29             : #include "taler_merchant_service.h"
      30             : #include "taler_merchant_testing_lib.h"
      31             : 
      32             : 
      33             : /**
      34             :  * State for a "config" CMD.
      35             :  */
      36             : struct ConfigState
      37             : {
      38             :   /**
      39             :    * Operation handle for a GET /public/config request.
      40             :    */
      41             :   struct TALER_MERCHANT_ConfigGetHandle *vgh;
      42             : 
      43             :   /**
      44             :    * Base URL of the merchant serving the request.
      45             :    */
      46             :   const char *merchant_url;
      47             : 
      48             :   /**
      49             :    * Expected HTTP response code.
      50             :    */
      51             :   unsigned int http_code;
      52             : 
      53             :   /**
      54             :    * Interpreter state.
      55             :    */
      56             :   struct TALER_TESTING_Interpreter *is;
      57             : 
      58             : };
      59             : 
      60             : 
      61             : /**
      62             :  * Free the state of a "config" CMD, and
      63             :  * possibly cancel a pending "config" operation.
      64             :  *
      65             :  * @param cls closure with the `struct ConfigState`
      66             :  * @param cmd command currently being freed.
      67             :  */
      68             : static void
      69           0 : config_cleanup (void *cls,
      70             :                 const struct TALER_TESTING_Command *cmd)
      71             : {
      72           0 :   struct ConfigState *cs = cls;
      73             : 
      74           0 :   if (NULL != cs->vgh)
      75             :   {
      76           0 :     TALER_LOG_WARNING ("config operation did not complete\n");
      77           0 :     TALER_MERCHANT_config_get_cancel (cs->vgh);
      78             :   }
      79           0 :   GNUNET_free (cs);
      80           0 : }
      81             : 
      82             : 
      83             : /**
      84             :  * Process "GET /public/config" (lookup) response.
      85             :  *
      86             :  * @param cls closure
      87             :  * @param hr HTTP response we got
      88             :  * @param ci basic information about the merchant
      89             :  * @param compat protocol compatibility information
      90             :  */
      91             : static void
      92           0 : config_cb (void *cls,
      93             :            const struct TALER_MERCHANT_HttpResponse *hr,
      94             :            const struct TALER_MERCHANT_ConfigInformation *ci,
      95             :            enum TALER_MERCHANT_VersionCompatibility compat)
      96             : {
      97           0 :   struct ConfigState *cs = cls;
      98             : 
      99             :   (void) ci;
     100           0 :   cs->vgh = NULL;
     101           0 :   if (cs->http_code != hr->http_status)
     102           0 :     TALER_TESTING_FAIL (cs->is);
     103           0 :   if (TALER_MERCHANT_VC_MATCH != compat)
     104           0 :     TALER_TESTING_FAIL (cs->is);
     105           0 :   TALER_TESTING_interpreter_next (cs->is);
     106             : }
     107             : 
     108             : 
     109             : /**
     110             :  * Run the "config" CMD.
     111             :  *
     112             :  * @param cls closure.
     113             :  * @param cmd command being currently run.
     114             :  * @param is interpreter state.
     115             :  */
     116             : static void
     117           0 : config_run (void *cls,
     118             :             const struct TALER_TESTING_Command *cmd,
     119             :             struct TALER_TESTING_Interpreter *is)
     120             : {
     121           0 :   struct ConfigState *cs = cls;
     122             : 
     123           0 :   cs->is = is;
     124           0 :   cs->vgh = TALER_MERCHANT_config_get (is->ctx,
     125             :                                        cs->merchant_url,
     126             :                                        &config_cb,
     127             :                                        cs);
     128           0 :   GNUNET_assert (NULL != cs->vgh);
     129           0 : }
     130             : 
     131             : 
     132             : /**
     133             :  * Define a "config" CMD.
     134             :  *
     135             :  * @param label command label.
     136             :  * @param merchant_url base URL of the merchant serving the
     137             :  *        "config" request.
     138             :  * @param http_code expected HTTP response code.
     139             :  * @return the command.
     140             :  */
     141             : struct TALER_TESTING_Command
     142           0 : TALER_TESTING_cmd_config (const char *label,
     143             :                           const char *merchant_url,
     144             :                           unsigned int http_code)
     145             : {
     146             :   struct ConfigState *cs;
     147             : 
     148           0 :   cs = GNUNET_new (struct ConfigState);
     149           0 :   cs->merchant_url = merchant_url;
     150           0 :   cs->http_code = http_code;
     151             :   {
     152           0 :     struct TALER_TESTING_Command cmd = {
     153             :       .cls = cs,
     154             :       .label = label,
     155             :       .run = &config_run,
     156             :       .cleanup = &config_cleanup
     157             :     };
     158             : 
     159           0 :     return cmd;
     160             :   }
     161             : }
     162             : 
     163             : 
     164             : /* end of testing_api_cmd_config.c */

Generated by: LCOV version 1.14