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-09-21 06:18:36 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             : /**
      30             :  * TODO: have _one_ pair of getter/setter for hash-coded
      31             :  * traits and define the getters/setters for tip id and hashed
      32             :  * contract terms as _macros_.
      33             :  */
      34             : 
      35             : #define TALER_TESTING_TRAIT_TIP_ID "tip-id"
      36             : #define TALER_TESTING_TRAIT_H_CONTRACT_TERMS "h-contract-terms"
      37             : 
      38             : /**
      39             :  * Obtain tip id from a @a cmd.
      40             :  *
      41             :  * @param cmd command to extract the trait from.
      42             :  * @param index which tip id to pick if @a
      43             :  *        cmd has multiple on offer
      44             :  * @param tip_id[out] set to the wanted data.
      45             :  *
      46             :  * @return #GNUNET_OK on success
      47             :  */
      48             : int
      49           4 : TALER_TESTING_get_trait_tip_id
      50             :   (const struct TALER_TESTING_Command *cmd,
      51             :    unsigned int index,
      52             :    struct GNUNET_HashCode **tip_id)
      53             : {
      54           4 :   return cmd->traits (cmd->cls,
      55             :                       (void **) tip_id,
      56             :                       TALER_TESTING_TRAIT_TIP_ID,
      57             :                       index);
      58             : }
      59             : 
      60             : 
      61             : /**
      62             :  * Offer tip id.
      63             :  *
      64             :  * @param index which tip id to offer if there are
      65             :  *        multiple on offer.
      66             :  * @param tip_id set to the offered tip id.
      67             :  * @return the trait
      68             :  */
      69             : struct TALER_TESTING_Trait
      70           4 : TALER_TESTING_make_trait_tip_id
      71             :   (unsigned int index,
      72             :    const struct GNUNET_HashCode *tip_id)
      73             : {
      74           4 :   struct TALER_TESTING_Trait ret = {
      75             :     .index = index,
      76             :     .trait_name = TALER_TESTING_TRAIT_TIP_ID,
      77             :     .ptr = (const void *) tip_id
      78             :   };
      79           4 :   return ret;
      80             : }
      81             : 
      82             : 
      83             : /**
      84             :  * Obtain contract terms hash from a @a cmd.
      85             :  *
      86             :  * @param cmd command to extract the trait from.
      87             :  * @param index index number of the trait to fetch.
      88             :  * @param h_contract_terms[out] set to the wanted data.
      89             :  *
      90             :  * @return #GNUNET_OK on success
      91             :  */
      92             : int
      93          24 : TALER_TESTING_get_trait_h_contract_terms
      94             :   (const struct TALER_TESTING_Command *cmd,
      95             :    unsigned int index,
      96             :    const struct GNUNET_HashCode **h_contract_terms)
      97             : {
      98          24 :   return cmd->traits (cmd->cls,
      99             :                       (void **) h_contract_terms,
     100             :                       TALER_TESTING_TRAIT_H_CONTRACT_TERMS,
     101             :                       index);
     102             : }
     103             : 
     104             : 
     105             : /**
     106             :  * Offer contract terms hash code.
     107             :  *
     108             :  * @param index which hashed contract terms to
     109             :  *        offer if there are multiple on offer
     110             :  * @param h_contract_terms set to the offered hashed
     111             :  *        contract terms.
     112             :  *
     113             :  * @return the trait
     114             :  */
     115             : struct TALER_TESTING_Trait
     116         181 : TALER_TESTING_make_trait_h_contract_terms
     117             :   (unsigned int index,
     118             :    const struct GNUNET_HashCode *h_contract_terms)
     119             : {
     120         181 :   struct TALER_TESTING_Trait ret = {
     121             :     .index = index,
     122             :     .trait_name = TALER_TESTING_TRAIT_H_CONTRACT_TERMS,
     123             :     .ptr = (const void *) h_contract_terms
     124             :   };
     125         181 :   return ret;
     126             : }

Generated by: LCOV version 1.13