diff options
| author | Christian Grothoff <christian@grothoff.org> | 2015-05-18 18:53:12 +0200 | 
|---|---|---|
| committer | Christian Grothoff <christian@grothoff.org> | 2015-05-18 18:53:12 +0200 | 
| commit | 7b4623706c3a87b444362ca27027d9bfb1aa25ae (patch) | |
| tree | e546a3407f4465be9110fffeaab3ae38c5f8c3b2 /src/util/test_wireformats.c | |
| parent | cb68cc7e5b03a03f335e121def044034978adf17 (diff) | |
| parent | 17985453c560300dba044617bafdb8f682d29e4c (diff) | |
Merge branch 'master' of git+ssh://taler.net/var/git/mint
Diffstat (limited to 'src/util/test_wireformats.c')
| -rw-r--r-- | src/util/test_wireformats.c | 55 | 
1 files changed, 47 insertions, 8 deletions
| diff --git a/src/util/test_wireformats.c b/src/util/test_wireformats.c index 26ec4b79..ebb96604 100644 --- a/src/util/test_wireformats.c +++ b/src/util/test_wireformats.c @@ -24,7 +24,8 @@  #include "taler_util.h"  #include "taler_json_lib.h" -static const char * const json_wire_str = +/* Valid SEPA data */ +static const char * const valid_wire_str =      "{ \"type\":\"SEPA\", \  \"IBAN\":\"DE67830654080004822650\",                 \  \"name\":\"GNUnet e.V.\",                               \ @@ -33,7 +34,40 @@ static const char * const json_wire_str =  \"r\":123456789,                                     \  \"address\": \"foobar\"}"; -int main(int argc, const char *const argv[]) +/* IBAN has wrong country code */ +static const char * const invalid_wire_str = +    "{ \"type\":\"SEPA\", \ +\"IBAN\":\"XX67830654080004822650\",                 \ +\"name\":\"GNUnet e.V.\",                               \ +\"bic\":\"GENODEF1SLR\",                                 \ +\"edate\":\"1449930207000\",                                \ +\"r\":123456789,                                     \ +\"address\": \"foobar\"}"; + +/* IBAN has wrong checksum */ +static const char * const invalid_wire_str2 = +    "{ \"type\":\"SEPA\", \ +\"IBAN\":\"DE67830654080004822651\",                 \ +\"name\":\"GNUnet e.V.\",                               \ +\"bic\":\"GENODEF1SLR\",                                 \ +\"edate\":\"1449930207000\",                                \ +\"r\":123456789,                                     \ +\"address\": \"foobar\"}"; + +/* Unsupported wireformat type */ +static const char * const unsupported_wire_str = +    "{ \"type\":\"unsupported\", \ +\"IBAN\":\"DE67830654080004822650\",                 \ +\"name\":\"GNUnet e.V.\",                               \ +\"bic\":\"GENODEF1SLR\",                                 \ +\"edate\":\"1449930207000\",                                \ +\"r\":123456789,                                     \ +\"address\": \"foobar\"}"; + + +int  +main(int argc,  +     const char *const argv[])  {    json_t *wire;    json_error_t error; @@ -41,13 +75,18 @@ int main(int argc, const char *const argv[])    GNUNET_log_setup ("test-json-validations", "WARNING", NULL);    (void) memset(&error, 0, sizeof(error)); -  wire = json_loads (json_wire_str, 0, &error); -  if (NULL == wire) -  { -    TALER_json_warn (error); -    return 2; -  } +  GNUNET_assert (NULL != (wire = json_loads (unsupported_wire_str, 0, NULL))); +  GNUNET_assert (1 != TALER_json_validate_wireformat ("unsupported", wire)); +  json_decref (wire); +  GNUNET_assert (NULL != (wire = json_loads (invalid_wire_str, 0, NULL))); +  GNUNET_assert (1 != TALER_json_validate_wireformat ("SEPA", wire)); +  json_decref (wire); +  GNUNET_assert (NULL != (wire = json_loads (invalid_wire_str2, 0, NULL))); +  GNUNET_assert (1 != TALER_json_validate_wireformat ("SEPA", wire)); +  json_decref (wire); +  GNUNET_assert (NULL != (wire = json_loads (valid_wire_str, 0, &error)));    ret = TALER_json_validate_wireformat ("SEPA", wire); +  json_decref (wire);    if (1 == ret)      return 0;    return 1; | 
