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-05-16 06:16:58 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 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             :  * @return #GNUNET_OK on success
      45             :  */
      46             : int
      47           3 : TALER_TESTING_get_trait_proposal_reference
      48             :   (const struct TALER_TESTING_Command *cmd,
      49             :    unsigned int index,
      50             :    const char **proposal_reference)
      51             : {
      52           3 :   return cmd->traits (cmd->cls,
      53             :                       (void **) proposal_reference,
      54             :                       TALER_TESTING_TRAIT_PROPOSAL_REFERENCE,
      55             :                       index);
      56             : }
      57             : 
      58             : 
      59             : /**
      60             :  * Offer a proposal reference.
      61             :  *
      62             :  * @param index which reference to offer if there are
      63             :  *        multiple on offer
      64             :  * @param proposal_reference set to the offered reference.
      65             :  * @return the trait
      66             :  */
      67             : struct TALER_TESTING_Trait
      68          17 : TALER_TESTING_make_trait_proposal_reference
      69             :   (unsigned int index,
      70             :    const char *proposal_reference)
      71             : {
      72          17 :   struct TALER_TESTING_Trait ret = {
      73             :     .index = index,
      74             :     .trait_name = TALER_TESTING_TRAIT_PROPOSAL_REFERENCE,
      75             :     .ptr = (const void *) proposal_reference
      76             :   };
      77          17 :   return ret;
      78             : }
      79             : 
      80             : 
      81             : /**
      82             :  * Obtain a reference to any command that can provide coins as
      83             :  * traits.
      84             :  *
      85             :  * @param cmd command to extract trait from
      86             :  * @param index which reference to pick if @a cmd has multiple
      87             :  *        on offer
      88             :  * @param coin_reference[out] set to the wanted reference. NOTE:
      89             :  *        a _single_ reference can contain _multiple_ instances,
      90             :  *        using semi-colon as separator.  For example, a _single_
      91             :  *        reference can be this: "coin-ref-1", or even this:
      92             :  *        "coin-ref-1;coin-ref-2".  The "pay" command contains
      93             :  *        functions that can parse such format.
      94             :  * @return #GNUNET_OK on success
      95             :  */
      96             : int
      97           3 : TALER_TESTING_get_trait_coin_reference
      98             :   (const struct TALER_TESTING_Command *cmd,
      99             :    unsigned int index,
     100             :    const char **coin_reference)
     101             : {
     102           3 :   return cmd->traits (cmd->cls,
     103             :                       (void **) coin_reference,
     104             :                       TALER_TESTING_TRAIT_COIN_REFERENCE,
     105             :                       index);
     106             : }
     107             : 
     108             : 
     109             : /**
     110             :  * Offer a coin reference.
     111             :  *
     112             :  * @param index which reference to offer if there are
     113             :  *        multiple on offer
     114             :  * @param coin_reference set to the offered reference.
     115             :  * @return the trait
     116             :  */
     117             : struct TALER_TESTING_Trait
     118          17 : TALER_TESTING_make_trait_coin_reference
     119             :   (unsigned int index,
     120             :    const char *coin_reference)
     121             : {
     122          17 :   struct TALER_TESTING_Trait ret = {
     123             :     .index = index,
     124             :     .trait_name = TALER_TESTING_TRAIT_COIN_REFERENCE,
     125             :     .ptr = (const void *) coin_reference
     126             :   };
     127          17 :   return ret;
     128             : }
     129             : 
     130             : 
     131             : /* end of testing_api_trait_string.c */

Generated by: LCOV version 1.13