LCOV - code coverage report
Current view: top level - lib - testing_api_cmd_rewind.c (source / functions) Hit Total Coverage
Test: rcoverage.info Lines: 0 18 0.0 %
Date: 2018-09-19 06:18:31 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2014-2018 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_rewind.c
      22             :  * @brief command to rewind the instruction pointer.
      23             :  * @author Marcello Stanisci
      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 "rewind" CMD.
      35             :  */
      36             : struct RewindIpState
      37             : {
      38             :   /**
      39             :    * Instruction pointer to set into the interpreter.
      40             :    */
      41             :   unsigned int new_ip;
      42             : 
      43             :   /**
      44             :    * How many times this set should take place.
      45             :    * However, this value lives at the calling process,
      46             :    * and this CMD is only in charge of checking and
      47             :    * decremeting it.
      48             :    */
      49             :   unsigned int *counter;
      50             : };
      51             : 
      52             : 
      53             : /**
      54             :  * Only defined to respect the API.
      55             :  */
      56             : static void
      57           0 : rewind_ip_cleanup (void *cls,
      58             :                    const struct TALER_TESTING_Command *cmd)
      59           0 : {}
      60             : 
      61             : 
      62             : /**
      63             :  * Run the "rewind" CMD.
      64             :  *
      65             :  * @param cls closure.
      66             :  * @param cmd command being executed now.
      67             :  * @param is the interpreter state.
      68             :  */
      69             : static void
      70           0 : rewind_ip_run (void *cls,
      71             :                const struct TALER_TESTING_Command *cmd,
      72             :                struct TALER_TESTING_Interpreter *is)
      73             : {
      74           0 :   struct RewindIpState *ris = cls;
      75             : 
      76           0 :   if (1 < *ris->counter)
      77             :   {
      78           0 :     is->ip = ris->new_ip;
      79           0 :     *ris->counter -= 1; 
      80             :   }
      81             : 
      82           0 :   TALER_TESTING_interpreter_next (is);
      83           0 : }
      84             : 
      85             : /**
      86             :  * Make the instruction pointer point to @a new_ip
      87             :  * only if @a counter is greater than zero.
      88             :  *
      89             :  * @param label command label
      90             :  * @param new_ip new instruction pointer's value.  Note that,
      91             :  * when the next instruction will be called, the interpreter
      92             :  * will increment the ip _anyway_ so this value must be
      93             :  * set to the index of the instruction we want to execute next
      94             :  * MINUS one.
      95             :  * @param counter counts how many times the rewinding has
      96             :  * to happen.
      97             :  */
      98             : struct TALER_TESTING_Command
      99           0 : TALER_TESTING_cmd_rewind_ip
     100             :   (const char *label,
     101             :    int new_ip,
     102             :    unsigned int *counter)
     103             : {
     104             :   struct RewindIpState *ris;
     105             :   struct TALER_TESTING_Command cmd;
     106             : 
     107           0 :   ris = GNUNET_new (struct RewindIpState);
     108           0 :   ris->new_ip = new_ip;
     109           0 :   ris->counter = counter;
     110             : 
     111           0 :   cmd.cls = ris;
     112           0 :   cmd.label = label;
     113           0 :   cmd.run = &rewind_ip_run;
     114           0 :   cmd.cleanup = &rewind_ip_cleanup;
     115             : 
     116           0 :   return cmd;
     117             : }

Generated by: LCOV version 1.13