From c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 5 Oct 2019 15:09:28 +0200 Subject: global reindent, now with uncrustify hook enabled --- src/json/test_json.c | 184 ++++++++++++++++++++++++++------------------------- 1 file changed, 94 insertions(+), 90 deletions(-) (limited to 'src/json/test_json.c') diff --git a/src/json/test_json.c b/src/json/test_json.c index 4b9fbc710..f77d9add9 100644 --- a/src/json/test_json.c +++ b/src/json/test_json.c @@ -34,32 +34,34 @@ * @return 0 on success */ static int -test_abs_time() +test_abs_time () { json_t *j; struct GNUNET_TIME_Absolute a1; struct GNUNET_TIME_Absolute a2; - struct GNUNET_JSON_Specification s1[] = { GNUNET_JSON_spec_absolute_time(NULL, - &a2), - GNUNET_JSON_spec_end() }; - struct GNUNET_JSON_Specification s2[] = { GNUNET_JSON_spec_absolute_time(NULL, - &a2), - GNUNET_JSON_spec_end() }; - - a1 = GNUNET_TIME_absolute_get(); - GNUNET_TIME_round_abs(&a1); - j = GNUNET_JSON_from_time_abs(a1); - GNUNET_assert(NULL != j); - GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(j, s1, NULL, NULL)); - GNUNET_assert(a1.abs_value_us == a2.abs_value_us); - json_decref(j); + struct GNUNET_JSON_Specification s1[] = { GNUNET_JSON_spec_absolute_time ( + NULL, + &a2), + GNUNET_JSON_spec_end () }; + struct GNUNET_JSON_Specification s2[] = { GNUNET_JSON_spec_absolute_time ( + NULL, + &a2), + GNUNET_JSON_spec_end () }; + + a1 = GNUNET_TIME_absolute_get (); + GNUNET_TIME_round_abs (&a1); + j = GNUNET_JSON_from_time_abs (a1); + GNUNET_assert (NULL != j); + GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (j, s1, NULL, NULL)); + GNUNET_assert (a1.abs_value_us == a2.abs_value_us); + json_decref (j); a1 = GNUNET_TIME_UNIT_FOREVER_ABS; - j = GNUNET_JSON_from_time_abs(a1); - GNUNET_assert(NULL != j); - GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(j, s2, NULL, NULL)); - GNUNET_assert(a1.abs_value_us == a2.abs_value_us); - json_decref(j); + j = GNUNET_JSON_from_time_abs (a1); + GNUNET_assert (NULL != j); + GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (j, s2, NULL, NULL)); + GNUNET_assert (a1.abs_value_us == a2.abs_value_us); + json_decref (j); return 0; } @@ -70,31 +72,33 @@ test_abs_time() * @return 0 on success */ static int -test_rel_time() +test_rel_time () { json_t *j; struct GNUNET_TIME_Relative r1; struct GNUNET_TIME_Relative r2; - struct GNUNET_JSON_Specification s1[] = { GNUNET_JSON_spec_relative_time(NULL, - &r2), - GNUNET_JSON_spec_end() }; - struct GNUNET_JSON_Specification s2[] = { GNUNET_JSON_spec_relative_time(NULL, - &r2), - GNUNET_JSON_spec_end() }; + struct GNUNET_JSON_Specification s1[] = { GNUNET_JSON_spec_relative_time ( + NULL, + &r2), + GNUNET_JSON_spec_end () }; + struct GNUNET_JSON_Specification s2[] = { GNUNET_JSON_spec_relative_time ( + NULL, + &r2), + GNUNET_JSON_spec_end () }; r1 = GNUNET_TIME_UNIT_SECONDS; - j = GNUNET_JSON_from_time_rel(r1); - GNUNET_assert(NULL != j); - GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(j, s1, NULL, NULL)); - GNUNET_assert(r1.rel_value_us == r2.rel_value_us); - json_decref(j); + j = GNUNET_JSON_from_time_rel (r1); + GNUNET_assert (NULL != j); + GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (j, s1, NULL, NULL)); + GNUNET_assert (r1.rel_value_us == r2.rel_value_us); + json_decref (j); r1 = GNUNET_TIME_UNIT_FOREVER_REL; - j = GNUNET_JSON_from_time_rel(r1); - GNUNET_assert(NULL != j); - GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(j, s2, NULL, NULL)); - GNUNET_assert(r1.rel_value_us == r2.rel_value_us); - json_decref(j); + j = GNUNET_JSON_from_time_rel (r1); + GNUNET_assert (NULL != j); + GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (j, s2, NULL, NULL)); + GNUNET_assert (r1.rel_value_us == r2.rel_value_us); + json_decref (j); return 0; } @@ -105,26 +109,26 @@ test_rel_time() * @return 0 on success */ static int -test_raw() +test_raw () { char blob[256]; unsigned int i; json_t *j; for (i = 0; i <= 256; i++) - { - char blob2[256]; - struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_fixed(NULL, - blob2, - i), - GNUNET_JSON_spec_end() }; - - memset(blob, i, i); - j = GNUNET_JSON_from_data(blob, i); - GNUNET_assert(NULL != j); - GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(j, spec, NULL, NULL)); - GNUNET_assert(0 == memcmp(blob, blob2, i)); - } + { + char blob2[256]; + struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_fixed (NULL, + blob2, + i), + GNUNET_JSON_spec_end () }; + + memset (blob, i, i); + j = GNUNET_JSON_from_data (blob, i); + GNUNET_assert (NULL != j); + GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (j, spec, NULL, NULL)); + GNUNET_assert (0 == memcmp (blob, blob2, i)); + } return 0; } @@ -135,36 +139,36 @@ test_raw() * @return 0 on success */ static int -test_rsa() +test_rsa () { struct GNUNET_CRYPTO_RsaPublicKey *pub; struct GNUNET_CRYPTO_RsaPublicKey *pub2; struct GNUNET_JSON_Specification pspec[] = - { GNUNET_JSON_spec_rsa_public_key(NULL, &pub2), GNUNET_JSON_spec_end() }; + { GNUNET_JSON_spec_rsa_public_key (NULL, &pub2), GNUNET_JSON_spec_end () }; struct GNUNET_CRYPTO_RsaSignature *sig; struct GNUNET_CRYPTO_RsaSignature *sig2; struct GNUNET_JSON_Specification sspec[] = - { GNUNET_JSON_spec_rsa_signature(NULL, &sig2), GNUNET_JSON_spec_end() }; + { GNUNET_JSON_spec_rsa_signature (NULL, &sig2), GNUNET_JSON_spec_end () }; struct GNUNET_CRYPTO_RsaPrivateKey *priv; struct GNUNET_HashCode msg; json_t *jp; json_t *js; - priv = GNUNET_CRYPTO_rsa_private_key_create(1024); - pub = GNUNET_CRYPTO_rsa_private_key_get_public(priv); - memset(&msg, 42, sizeof(msg)); - sig = GNUNET_CRYPTO_rsa_sign_fdh(priv, &msg); - GNUNET_assert(NULL != (jp = GNUNET_JSON_from_rsa_public_key(pub))); - GNUNET_assert(NULL != (js = GNUNET_JSON_from_rsa_signature(sig))); - GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(jp, pspec, NULL, NULL)); - GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(js, sspec, NULL, NULL)); - GNUNET_break(0 == GNUNET_CRYPTO_rsa_signature_cmp(sig, sig2)); - GNUNET_break(0 == GNUNET_CRYPTO_rsa_public_key_cmp(pub, pub2)); - GNUNET_CRYPTO_rsa_signature_free(sig); - GNUNET_CRYPTO_rsa_signature_free(sig2); - GNUNET_CRYPTO_rsa_private_key_free(priv); - GNUNET_CRYPTO_rsa_public_key_free(pub); - GNUNET_CRYPTO_rsa_public_key_free(pub2); + priv = GNUNET_CRYPTO_rsa_private_key_create (1024); + pub = GNUNET_CRYPTO_rsa_private_key_get_public (priv); + memset (&msg, 42, sizeof(msg)); + sig = GNUNET_CRYPTO_rsa_sign_fdh (priv, &msg); + GNUNET_assert (NULL != (jp = GNUNET_JSON_from_rsa_public_key (pub))); + GNUNET_assert (NULL != (js = GNUNET_JSON_from_rsa_signature (sig))); + GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (jp, pspec, NULL, NULL)); + GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (js, sspec, NULL, NULL)); + GNUNET_break (0 == GNUNET_CRYPTO_rsa_signature_cmp (sig, sig2)); + GNUNET_break (0 == GNUNET_CRYPTO_rsa_public_key_cmp (pub, pub2)); + GNUNET_CRYPTO_rsa_signature_free (sig); + GNUNET_CRYPTO_rsa_signature_free (sig2); + GNUNET_CRYPTO_rsa_private_key_free (priv); + GNUNET_CRYPTO_rsa_public_key_free (pub); + GNUNET_CRYPTO_rsa_public_key_free (pub2); return 0; } @@ -175,47 +179,47 @@ test_rsa() * @return 0 on success */ static int -test_boolean() +test_boolean () { int b1; int b2; json_t *json; - struct GNUNET_JSON_Specification pspec[] = { GNUNET_JSON_spec_boolean("b1", - &b1), - GNUNET_JSON_spec_boolean("b2", - &b2), - GNUNET_JSON_spec_end() }; + struct GNUNET_JSON_Specification pspec[] = { GNUNET_JSON_spec_boolean ("b1", + &b1), + GNUNET_JSON_spec_boolean ("b2", + &b2), + GNUNET_JSON_spec_end () }; - json = json_object(); - json_object_set_new(json, "b1", json_true()); - json_object_set_new(json, "b2", json_false()); + json = json_object (); + json_object_set_new (json, "b1", json_true ()); + json_object_set_new (json, "b2", json_false ()); - GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(json, pspec, NULL, NULL)); + GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (json, pspec, NULL, NULL)); - GNUNET_assert(GNUNET_YES == b1); - GNUNET_assert(GNUNET_NO == b2); + GNUNET_assert (GNUNET_YES == b1); + GNUNET_assert (GNUNET_NO == b2); - json_object_set_new(json, "b1", json_integer(42)); + json_object_set_new (json, "b1", json_integer (42)); - GNUNET_assert(GNUNET_OK != GNUNET_JSON_parse(json, pspec, NULL, NULL)); + GNUNET_assert (GNUNET_OK != GNUNET_JSON_parse (json, pspec, NULL, NULL)); return 0; } int -main(int argc, const char *const argv[]) +main (int argc, const char *const argv[]) { - GNUNET_log_setup("test-json", "WARNING", NULL); - if (0 != test_abs_time()) + GNUNET_log_setup ("test-json", "WARNING", NULL); + if (0 != test_abs_time ()) return 1; - if (0 != test_rel_time()) + if (0 != test_rel_time ()) return 1; - if (0 != test_raw()) + if (0 != test_raw ()) return 1; - if (0 != test_rsa()) + if (0 != test_rsa ()) return 1; - if (0 != test_boolean()) + if (0 != test_boolean ()) return 1; /* FIXME: test EdDSA signature conversion... */ return 0; -- cgit v1.2.3