LCOV - code coverage report
Current view: top level - testing - testing_api_trait_string.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 12 22 54.5 %
Date: 2021-08-30 06:43:37 Functions: 4 8 50.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_string.c
      21             :  * @brief offers strings traits.
      22             :  * @author Marcello Stanisci
      23             :  * @author Christian Grothoff
      24             :  */
      25             : #include "platform.h"
      26             : #include "taler_json_lib.h"
      27             : #include <gnunet/gnunet_curl_lib.h>
      28             : #include "taler_signatures.h"
      29             : #include "taler_testing_lib.h"
      30             : 
      31             : /**
      32             :  * Some string. Avoid, use something more precise!
      33             :  */
      34             : #define TALER_TESTING_TRAIT_STRING "string"
      35             : 
      36             : /**
      37             :  * An HTTP-URL.
      38             :  */
      39             : #define TALER_TESTING_TRAIT_URL "url"
      40             : 
      41             : /**
      42             :  * A PAYTO-URL.
      43             :  */
      44             : #define TALER_TESTING_TRAIT_PAYTO "payto"
      45             : 
      46             : /**
      47             :  * String identifying an order.
      48             :  */
      49             : #define TALER_TESTING_TRAIT_ORDER_ID "order-id"
      50             : 
      51             : 
      52             : /**
      53             :  * Obtain a string from @a cmd.
      54             :  *
      55             :  * @param cmd command to extract the subject from.
      56             :  * @param index index number associated with the transfer
      57             :  *        subject to offer.
      58             :  * @param[out] s where to write the offered
      59             :  *        string
      60             :  * @return #GNUNET_OK on success.
      61             :  */
      62             : int
      63           0 : TALER_TESTING_get_trait_string (const struct TALER_TESTING_Command *cmd,
      64             :                                 unsigned int index,
      65             :                                 const char **s)
      66             : {
      67           0 :   return cmd->traits (cmd->cls,
      68             :                       (const void **) s,
      69             :                       TALER_TESTING_TRAIT_STRING,
      70             :                       index);
      71             : }
      72             : 
      73             : 
      74             : /**
      75             :  * Offer string.
      76             :  *
      77             :  * @param index index number associated with the transfer
      78             :  *        subject being offered.
      79             :  * @param s transfer subject to offer.
      80             :  * @return the trait.
      81             :  */
      82             : struct TALER_TESTING_Trait
      83           0 : TALER_TESTING_make_trait_string (unsigned int index,
      84             :                                  const char *s)
      85             : {
      86           0 :   struct TALER_TESTING_Trait ret = {
      87             :     .index = index,
      88             :     .trait_name = TALER_TESTING_TRAIT_STRING,
      89             :     .ptr = (const void *) s
      90             :   };
      91           0 :   return ret;
      92             : }
      93             : 
      94             : 
      95             : /**
      96             :  * Obtain a HTTP url from @a cmd.
      97             :  *
      98             :  * @param cmd command to extract the url from.
      99             :  * @param index which url is to be picked, in case
     100             :  *        multiple are offered.
     101             :  * @param[out] url where to write the url.
     102             :  * @return #GNUNET_OK on success.
     103             :  */
     104             : int
     105           5 : TALER_TESTING_get_trait_url (const struct TALER_TESTING_Command *cmd,
     106             :                              unsigned int index,
     107             :                              const char **url)
     108             : {
     109           5 :   return cmd->traits (cmd->cls,
     110             :                       (const void **) url,
     111             :                       TALER_TESTING_TRAIT_URL,
     112             :                       index);
     113             : }
     114             : 
     115             : 
     116             : /**
     117             :  * Offer HTTP url in a trait.
     118             :  *
     119             :  * @param index which url is to be picked,
     120             :  *        in case multiple are offered.
     121             :  * @param url the url to offer.
     122             :  *
     123             :  * @return the trait.
     124             :  */
     125             : struct TALER_TESTING_Trait
     126        1609 : TALER_TESTING_make_trait_url (unsigned int index,
     127             :                               const char *url)
     128             : {
     129        1609 :   struct TALER_TESTING_Trait ret = {
     130             :     .index = index,
     131             :     .trait_name = TALER_TESTING_TRAIT_URL,
     132             :     .ptr = (const void *) url
     133             :   };
     134             : 
     135        1609 :   GNUNET_assert ( (NULL == url) ||
     136             :                   (0 != strncasecmp (url,
     137             :                                      "payto://",
     138             :                                      strlen ("payto://"))) );
     139        1609 :   return ret;
     140             : }
     141             : 
     142             : 
     143             : /**
     144             :  * Obtain a order id from @a cmd.
     145             :  *
     146             :  * @param cmd command to extract the order id from.
     147             :  * @param index which order id is to be picked, in case
     148             :  *        multiple are offered.
     149             :  * @param[out] order_id where to write the order id.
     150             :  * @return #GNUNET_OK on success.
     151             :  */
     152             : int
     153           0 : TALER_TESTING_get_trait_order_id (const struct TALER_TESTING_Command *cmd,
     154             :                                   unsigned int index,
     155             :                                   const char **order_id)
     156             : {
     157           0 :   return cmd->traits (cmd->cls,
     158             :                       (const void **) order_id,
     159             :                       TALER_TESTING_TRAIT_ORDER_ID,
     160             :                       index);
     161             : }
     162             : 
     163             : 
     164             : /**
     165             :  * Offer order id in a trait.
     166             :  *
     167             :  * @param index which order id is to be offered,
     168             :  *        in case multiple are offered.
     169             :  * @param order_id the order id to offer.
     170             :  * @return the trait.
     171             :  */
     172             : struct TALER_TESTING_Trait
     173           0 : TALER_TESTING_make_trait_order_id (unsigned int index,
     174             :                                    const char *order_id)
     175             : {
     176           0 :   struct TALER_TESTING_Trait ret = {
     177             :     .index = index,
     178             :     .trait_name = TALER_TESTING_TRAIT_ORDER_ID,
     179             :     .ptr = (const void *) order_id
     180             :   };
     181           0 :   return ret;
     182             : }
     183             : 
     184             : 
     185             : /**
     186             :  * Obtain a PAYTO-url from @a cmd.
     187             :  *
     188             :  * @param cmd command to extract the url from.
     189             :  * @param pt which url is to be picked, in case
     190             :  *        multiple are offered.
     191             :  * @param[out] url where to write the url.
     192             :  * @return #GNUNET_OK on success.
     193             :  */
     194             : int
     195          20 : TALER_TESTING_get_trait_payto (const struct TALER_TESTING_Command *cmd,
     196             :                                enum TALER_TESTING_PaytoType pt,
     197             :                                const char **url)
     198             : {
     199          20 :   return cmd->traits (cmd->cls,
     200             :                       (const void **) url,
     201             :                       TALER_TESTING_TRAIT_PAYTO,
     202             :                       (unsigned int) pt);
     203             : }
     204             : 
     205             : 
     206             : /**
     207             :  * Offer a "payto" URL reference.
     208             :  *
     209             :  * @param pt which reference is to be offered,
     210             :  *        in case multiple are offered.
     211             :  * @param payto_uri the payto URI
     212             :  * @return the trait.
     213             :  */
     214             : struct TALER_TESTING_Trait
     215        2216 : TALER_TESTING_make_trait_payto (enum TALER_TESTING_PaytoType pt,
     216             :                                 const char *payto_uri)
     217             : {
     218        2216 :   struct TALER_TESTING_Trait ret = {
     219             :     .index = (unsigned int) pt,
     220             :     .trait_name = TALER_TESTING_TRAIT_PAYTO,
     221             :     .ptr = (const void *) payto_uri,
     222             :   };
     223             : 
     224        2216 :   GNUNET_assert (0 == strncasecmp (payto_uri,
     225             :                                    "payto://",
     226             :                                    strlen ("payto://")));
     227        2216 :   return ret;
     228             : }
     229             : 
     230             : 
     231             : /* end of testing_api_trait_string.c */

Generated by: LCOV version 1.14