LCOV - code coverage report
Current view: top level - lib - testing_api_trait_string.c (source / functions) Hit Total Coverage
Test: rcoverage.info Lines: 10 10 100.0 %
Date: 2018-07-14 06:17:23 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 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             :  * @file lib/testing_api_trait_string.c
      21             :  * @brief offer traits that come as strings.
      22             :  * @author Marcello Stanisci
      23             :  */
      24             : #include "platform.h"
      25             : #include <taler/taler_signatures.h>
      26             : #include <taler/taler_exchange_service.h>
      27             : #include <taler/taler_testing_lib.h>
      28             : 
      29             : #define TALER_TESTING_TRAIT_PROPOSAL_REFERENCE "proposal-reference"
      30             : #define TALER_TESTING_TRAIT_COIN_REFERENCE "coin-reference"
      31             : 
      32             : /**
      33             :  * Obtain a reference to a proposal command.  Any command that
      34             :  * works with proposals, might need to offer their reference to
      35             :  * it.  Notably, the "pay" command, offers its proposal reference
      36             :  * to the "pay abort" command as the latter needs to reconstruct
      37             :  * the same data needed by the former in order to use the "pay
      38             :  * abort" API.
      39             :  *
      40             :  * @param cmd command to extract the trait from.
      41             :  * @param index which reference to pick if @a cmd has multiple
      42             :  *        on offer.
      43             :  * @param proposal_reference[out] set to the wanted reference.
      44             :  *
      45             :  * @return #GNUNET_OK on success
      46             :  */
      47             : int
      48           3 : TALER_TESTING_get_trait_proposal_reference
      49             :   (const struct TALER_TESTING_Command *cmd,
      50             :    unsigned int index,
      51             :    const char **proposal_reference)
      52             : {
      53           3 :   return cmd->traits (cmd->cls,
      54             :                       (void **) proposal_reference,
      55             :                       TALER_TESTING_TRAIT_PROPOSAL_REFERENCE,
      56             :                       index);
      57             : }
      58             : 
      59             : 
      60             : /**
      61             :  * Offer a proposal reference.
      62             :  *
      63             :  * @param index which reference to offer if there are
      64             :  *        multiple on offer.
      65             :  * @param proposal_reference pointer to the reference to offer.
      66             :  *
      67             :  * @return the trait
      68             :  */
      69             : struct TALER_TESTING_Trait
      70          18 : TALER_TESTING_make_trait_proposal_reference
      71             :   (unsigned int index,
      72             :    const char *proposal_reference)
      73             : {
      74          18 :   struct TALER_TESTING_Trait ret = {
      75             :     .index = index,
      76             :     .trait_name = TALER_TESTING_TRAIT_PROPOSAL_REFERENCE,
      77             :     .ptr = (const void *) proposal_reference
      78             :   };
      79          18 :   return ret;
      80             : }
      81             : 
      82             : 
      83             : /**
      84             :  * Obtain a reference to any command that can provide coins as
      85             :  * traits.
      86             :  *
      87             :  * @param cmd command to extract trait from
      88             :  * @param index which reference to pick if @a cmd has multiple
      89             :  *        on offer
      90             :  * @param coin_reference[out] set to the wanted reference.
      91             :  *        NOTE: a _single_ reference can contain
      92             :  *        _multiple_ instances, using semi-colon as separator.
      93             :  *        For example, a _single_ reference can be this:
      94             :  *        "coin-ref-1", or even this: "coin-ref-1;coin-ref-2".
      95             :  *        The "pay" command contains functions that can parse
      96             :  *        such format.
      97             :  *
      98             :  * @return #GNUNET_OK on success
      99             :  */
     100             : int
     101           4 : TALER_TESTING_get_trait_coin_reference
     102             :   (const struct TALER_TESTING_Command *cmd,
     103             :    unsigned int index,
     104             :    const char **coin_reference)
     105             : {
     106           4 :   return cmd->traits (cmd->cls,
     107             :                       (void **) coin_reference,
     108             :                       TALER_TESTING_TRAIT_COIN_REFERENCE,
     109             :                       index);
     110             : }
     111             : 
     112             : 
     113             : /**
     114             :  * Offer a coin reference.
     115             :  *
     116             :  * @param index which reference to offer if there are
     117             :  *        multiple on offer.
     118             :  * @param coin_reference set to the offered reference.
     119             :  *
     120             :  * @return the trait
     121             :  */
     122             : struct TALER_TESTING_Trait
     123          18 : TALER_TESTING_make_trait_coin_reference
     124             :   (unsigned int index,
     125             :    const char *coin_reference)
     126             : {
     127          18 :   struct TALER_TESTING_Trait ret = {
     128             :     .index = index,
     129             :     .trait_name = TALER_TESTING_TRAIT_COIN_REFERENCE,
     130             :     .ptr = (const void *) coin_reference
     131             :   };
     132          18 :   return ret;
     133             : }
     134             : 
     135             : 
     136             : /* end of testing_api_trait_string.c */

Generated by: LCOV version 1.13