LCOV - code coverage report
Current view: top level - testing - testing_api_trait_number.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 10 25 40.0 %
Date: 2021-08-30 06:43:37 Functions: 4 10 40.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2018-2020 Taler Systems SA
       4             : 
       5             :   TALER is free software; you can redistribute it and/or modify it
       6             :   under the terms of the GNU General Public License as published
       7             :   by the Free Software Foundation; either version 3, or (at your
       8             :   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 GNU
      13             :   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 testing/testing_api_trait_number.c
      21             :  * @brief traits to offer numbers
      22             :  * @author Marcello Stanisci
      23             :  */
      24             : #include "platform.h"
      25             : #include "taler_json_lib.h"
      26             : #include <gnunet/gnunet_curl_lib.h>
      27             : #include "taler_signatures.h"
      28             : #include "taler_testing_lib.h"
      29             : 
      30             : #define TALER_TESTING_TRAIT_UINT "uint"
      31             : #define TALER_TESTING_TRAIT_UINT32 "uint-32"
      32             : #define TALER_TESTING_TRAIT_UINT64 "uint-64"
      33             : #define TALER_TESTING_TRAIT_INT64 "int-64"
      34             : #define TALER_TESTING_TRAIT_BANK_ROW "bank-transaction-row"
      35             : 
      36             : 
      37             : /**
      38             :  * Obtain a number from @a cmd.
      39             :  *
      40             :  * @param cmd command to extract the number from.
      41             :  * @param index the number's index number.
      42             :  * @param[out] n set to the number coming from @a cmd.
      43             :  * @return #GNUNET_OK on success.
      44             :  */
      45             : int
      46           1 : TALER_TESTING_get_trait_uint (const struct TALER_TESTING_Command *cmd,
      47             :                               unsigned int index,
      48             :                               const unsigned int **n)
      49             : {
      50           1 :   return cmd->traits (cmd->cls,
      51             :                       (const void **) n,
      52             :                       TALER_TESTING_TRAIT_UINT,
      53             :                       index);
      54             : }
      55             : 
      56             : 
      57             : /**
      58             :  * Offer a number.
      59             :  *
      60             :  * @param index the number's index number.
      61             :  * @param n the number to offer.
      62             :  * @return #GNUNET_OK on success.
      63             :  */
      64             : struct TALER_TESTING_Trait
      65         305 : TALER_TESTING_make_trait_uint (unsigned int index,
      66             :                                const unsigned int *n)
      67             : {
      68         305 :   struct TALER_TESTING_Trait ret = {
      69             :     .index = index,
      70             :     .trait_name = TALER_TESTING_TRAIT_UINT,
      71             :     .ptr = (const void *) n
      72             :   };
      73         305 :   return ret;
      74             : }
      75             : 
      76             : 
      77             : /**
      78             :  * Obtain a "number" value from @a cmd, 32-bit version.
      79             :  *
      80             :  * @param cmd command to extract the number from.
      81             :  * @param index the number's index number.
      82             :  * @param[out] n set to the number coming from @a cmd.
      83             :  * @return #GNUNET_OK on success.
      84             :  */
      85             : int
      86           0 : TALER_TESTING_get_trait_uint32 (const struct TALER_TESTING_Command *cmd,
      87             :                                 unsigned int index,
      88             :                                 const uint32_t **n)
      89             : {
      90           0 :   return cmd->traits (cmd->cls,
      91             :                       (const void **) n,
      92             :                       TALER_TESTING_TRAIT_UINT32,
      93             :                       index);
      94             : }
      95             : 
      96             : 
      97             : /**
      98             :  * Offer number trait, 32-bit version.
      99             :  *
     100             :  * @param index the number's index number.
     101             :  * @param n number to offer.
     102             :  */
     103             : struct TALER_TESTING_Trait
     104           0 : TALER_TESTING_make_trait_uint32 (unsigned int index,
     105             :                                  const uint32_t *n)
     106             : {
     107           0 :   struct TALER_TESTING_Trait ret = {
     108             :     .index = index,
     109             :     .trait_name = TALER_TESTING_TRAIT_UINT32,
     110             :     .ptr = (const void *) n
     111             :   };
     112           0 :   return ret;
     113             : }
     114             : 
     115             : 
     116             : /**
     117             :  * Obtain a "number" value from @a cmd, 64-bit version.
     118             :  *
     119             :  * @param cmd command to extract the number from.
     120             :  * @param index the number's index number.
     121             :  * @param[out] n set to the number coming from @a cmd.
     122             :  * @return #GNUNET_OK on success.
     123             :  */
     124             : int
     125           0 : TALER_TESTING_get_trait_uint64 (const struct TALER_TESTING_Command *cmd,
     126             :                                 unsigned int index,
     127             :                                 const uint64_t **n)
     128             : {
     129           0 :   return cmd->traits (cmd->cls,
     130             :                       (const void **) n,
     131             :                       TALER_TESTING_TRAIT_UINT64,
     132             :                       index);
     133             : }
     134             : 
     135             : 
     136             : /**
     137             :  * Offer number trait, 64-bit version.
     138             :  *
     139             :  * @param index the number's index number.
     140             :  * @param n number to offer.
     141             :  */
     142             : struct TALER_TESTING_Trait
     143           0 : TALER_TESTING_make_trait_uint64 (unsigned int index,
     144             :                                  const uint64_t *n)
     145             : {
     146           0 :   struct TALER_TESTING_Trait ret = {
     147             :     .index = index,
     148             :     .trait_name = TALER_TESTING_TRAIT_UINT64,
     149             :     .ptr = (const void *) n
     150             :   };
     151           0 :   return ret;
     152             : }
     153             : 
     154             : 
     155             : /**
     156             :  * Obtain a "number" value from @a cmd, 64-bit signed version.
     157             :  *
     158             :  * @param cmd command to extract the number from.
     159             :  * @param index the number's index number.
     160             :  * @param[out] n set to the number coming from @a cmd.
     161             :  * @return #GNUNET_OK on success.
     162             :  */
     163             : int
     164           0 : TALER_TESTING_get_trait_int64 (const struct TALER_TESTING_Command *cmd,
     165             :                                unsigned int index,
     166             :                                const int64_t **n)
     167             : {
     168           0 :   return cmd->traits (cmd->cls,
     169             :                       (const void **) n,
     170             :                       TALER_TESTING_TRAIT_INT64,
     171             :                       index);
     172             : }
     173             : 
     174             : 
     175             : /**
     176             :  * Offer number trait, 64-bit signed version.
     177             :  *
     178             :  * @param index the number's index number.
     179             :  * @param n number to offer.
     180             :  */
     181             : struct TALER_TESTING_Trait
     182           0 : TALER_TESTING_make_trait_int64 (unsigned int index,
     183             :                                 const int64_t *n)
     184             : {
     185           0 :   struct TALER_TESTING_Trait ret = {
     186             :     .index = index,
     187             :     .trait_name = TALER_TESTING_TRAIT_INT64,
     188             :     .ptr = (const void *) n
     189             :   };
     190           0 :   return ret;
     191             : }
     192             : 
     193             : 
     194             : /**
     195             :  * Obtain a bank transaction row value from @a cmd.
     196             :  *
     197             :  * @param cmd command to extract the number from.
     198             :  * @param[out] row set to the number coming from @a cmd.
     199             :  * @return #GNUNET_OK on success.
     200             :  */
     201             : int
     202          36 : TALER_TESTING_get_trait_bank_row (const struct TALER_TESTING_Command *cmd,
     203             :                                   const uint64_t **row)
     204             : {
     205          36 :   return cmd->traits (cmd->cls,
     206             :                       (const void **) row,
     207             :                       TALER_TESTING_TRAIT_BANK_ROW,
     208             :                       0);
     209             : }
     210             : 
     211             : 
     212             : /**
     213             :  * Offer bank transaction row trait.
     214             :  *
     215             :  * @param row number to offer.
     216             :  */
     217             : struct TALER_TESTING_Trait
     218        1108 : TALER_TESTING_make_trait_bank_row (const uint64_t *row)
     219             : {
     220        1108 :   struct TALER_TESTING_Trait ret = {
     221             :     .index = 0,
     222             :     .trait_name = TALER_TESTING_TRAIT_BANK_ROW,
     223             :     .ptr = (const void *) row
     224             :   };
     225        1108 :   return ret;
     226             : }
     227             : 
     228             : 
     229             : /* end of testing_api_trait_number.c */

Generated by: LCOV version 1.14