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-05-16 06:16:58 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             : struct RewindIpState
      33             : {
      34             :   unsigned int new_ip;
      35             :   unsigned int *counter;
      36             : };
      37             : 
      38             : static void
      39           0 : rewind_ip_cleanup (void *cls,
      40             :                    const struct TALER_TESTING_Command *cmd)
      41           0 : {}
      42             : 
      43             : static void
      44           0 : rewind_ip_run (void *cls,
      45             :                const struct TALER_TESTING_Command *cmd,
      46             :                struct TALER_TESTING_Interpreter *is)
      47             : {
      48           0 :   struct RewindIpState *ris = cls;
      49             : 
      50           0 :   if (1 < *ris->counter)
      51             :   {
      52           0 :     is->ip = ris->new_ip;
      53           0 :     *ris->counter -= 1; 
      54             :   }
      55             : 
      56           0 :   TALER_TESTING_interpreter_next (is);
      57           0 : }
      58             : 
      59             : /**
      60             :  * Make the instruction pointer point to @a new_ip
      61             :  * only if @a counter is greater than zero.
      62             :  *
      63             :  * @param label command label
      64             :  * @param new_ip new instruction pointer's value.  Note that,
      65             :  * when the next instruction will be called, the interpreter
      66             :  * will increment the ip under the hood so this value must be
      67             :  * set to the index of the instruction we want to execute next
      68             :  * MINUS one.
      69             :  * @param counter counts how many times the rewinding has
      70             :  * to happen.
      71             :  */
      72             : struct TALER_TESTING_Command
      73           0 : TALER_TESTING_cmd_rewind_ip
      74             :   (const char *label,
      75             :    int new_ip,
      76             :    unsigned int *counter)
      77             : {
      78             :   struct RewindIpState *ris;
      79             :   struct TALER_TESTING_Command cmd;
      80             : 
      81           0 :   ris = GNUNET_new (struct RewindIpState);
      82           0 :   ris->new_ip = new_ip;
      83           0 :   ris->counter = counter;
      84             : 
      85           0 :   cmd.cls = ris;
      86           0 :   cmd.label = label;
      87           0 :   cmd.run = &rewind_ip_run;
      88           0 :   cmd.cleanup = &rewind_ip_cleanup;
      89             : 
      90           0 :   return cmd;
      91             : }
      92             : 

Generated by: LCOV version 1.13