LCOV - code coverage report
Current view: top level - lib - testing_api_trait_hash.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_hash.c
      21             :  * @brief offer any trait that is passed over as a hash code.
      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_TIP_ID "tip-id"
      30             : #define TALER_TESTING_TRAIT_H_CONTRACT_TERMS "h-contract-terms"
      31             : 
      32             : /**
      33             :  * Obtain tip id from a @a cmd.
      34             :  *
      35             :  * @param cmd command to extract trait from
      36             :  * @param index which signature to pick if @a cmd has multiple
      37             :  *        on offer
      38             :  * @param tip_id[out] set to the wanted data.
      39             :  * @return #GNUNET_OK on success
      40             :  */
      41             : int
      42           3 : TALER_TESTING_get_trait_tip_id
      43             :   (const struct TALER_TESTING_Command *cmd,
      44             :    unsigned int index,
      45             :    struct GNUNET_HashCode **tip_id)
      46             : {
      47           3 :   return cmd->traits (cmd->cls,
      48             :                       (void **) tip_id,
      49             :                       TALER_TESTING_TRAIT_TIP_ID,
      50             :                       index);
      51             : }
      52             : 
      53             : 
      54             : /**
      55             :  * Offer tip id.
      56             :  *
      57             :  * @param index which tip id to offer if there are
      58             :  *        multiple on offer
      59             :  * @param planchet_secrets set to the offered secrets.
      60             :  * @return the trait
      61             :  */
      62             : struct TALER_TESTING_Trait
      63           3 : TALER_TESTING_make_trait_tip_id
      64             :   (unsigned int index,
      65             :    const struct GNUNET_HashCode *tip_id)
      66             : {
      67           3 :   struct TALER_TESTING_Trait ret = {
      68             :     .index = index,
      69             :     .trait_name = TALER_TESTING_TRAIT_TIP_ID,
      70             :     .ptr = (const void *) tip_id
      71             :   };
      72           3 :   return ret;
      73             : }
      74             : 
      75             : 
      76             : /**
      77             :  * Obtain contract terms hash from a @a cmd.
      78             :  *
      79             :  * @param cmd command to extract trait from
      80             :  * @param index which hash code to pick if @a cmd has multiple
      81             :  *        on offer
      82             :  * @param h_contract_terms[out] set to the wanted data.
      83             :  * @return #GNUNET_OK on success
      84             :  */
      85             : int
      86          11 : TALER_TESTING_get_trait_h_contract_terms
      87             :   (const struct TALER_TESTING_Command *cmd,
      88             :    unsigned int index,
      89             :    const struct GNUNET_HashCode **h_contract_terms)
      90             : {
      91          11 :   return cmd->traits (cmd->cls,
      92             :                       (void **) h_contract_terms,
      93             :                       TALER_TESTING_TRAIT_H_CONTRACT_TERMS,
      94             :                       index);
      95             : }
      96             : 
      97             : 
      98             : /**
      99             :  * Offer contract terms hash code.
     100             :  *
     101             :  * @param index which hash code to offer if there are
     102             :  *        multiple on offer
     103             :  * @param h_contract_terms set to the offered hash code.
     104             :  * @return the trait
     105             :  */
     106             : struct TALER_TESTING_Trait
     107          76 : TALER_TESTING_make_trait_h_contract_terms
     108             :   (unsigned int index,
     109             :    const struct GNUNET_HashCode *h_contract_terms)
     110             : {
     111          76 :   struct TALER_TESTING_Trait ret = {
     112             :     .index = index,
     113             :     .trait_name = TALER_TESTING_TRAIT_H_CONTRACT_TERMS,
     114             :     .ptr = (const void *) h_contract_terms
     115             :   };
     116          76 :   return ret;
     117             : }

Generated by: LCOV version 1.13