From 34ca4f8c24625023f627f7654472bc39058f21fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Thu, 7 Nov 2002 09:08:05 +0100 Subject: [PATCH] (test_main): Added tests for %i and %l. Rev: src/nettle/testsuite/sexp-format-test.c:1.2 --- testsuite/sexp-format-test.c | 79 +++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 14 deletions(-) diff --git a/testsuite/sexp-format-test.c b/testsuite/sexp-format-test.c index 0f0ffd2e..65039859 100644 --- a/testsuite/sexp-format-test.c +++ b/testsuite/sexp-format-test.c @@ -8,30 +8,81 @@ int test_main(void) { struct nettle_buffer buffer; - const uint8_t e1[] = "(3:foo(3:bar17:xxxxxxxxxxxxxxxxx))"; - - nettle_buffer_init(&buffer); - ASSERT(sexp_format(&buffer, "(%s(%s%s))", - "foo", "bar", "xxxxxxxxxxxxxxxxx")); - ASSERT(buffer.size == strlen(e1)); - ASSERT(MEMEQ(buffer.size, buffer.contents, e1)); + { + const uint8_t e[] = "(3:foo(3:bar17:xxxxxxxxxxxxxxxxx))"; - nettle_buffer_clear(&buffer); - + nettle_buffer_init(&buffer); + ASSERT(sexp_format(&buffer, "(%z(%z%z))", + "foo", "bar", "xxxxxxxxxxxxxxxxx") + == strlen(e)); + + ASSERT(sexp_format(NULL, "(%z(%z%z))", + "foo", "bar", "xxxxxxxxxxxxxxxxx") + == strlen(e)); + + ASSERT(buffer.size == strlen(e)); + ASSERT(MEMEQ(buffer.size, buffer.contents, e)); + } + { + const uint8_t e[] = "{KDM6Zm9vKDM6YmFyMTc6eHh4eHh4eHh4eHh4eHh4eHgpKQ==}"; + + nettle_buffer_init(&buffer); + ASSERT(sexp_transport_format(&buffer, "(%z(%z%z))", + "foo", "bar", "xxxxxxxxxxxxxxxxx") + == strlen(e)); + + ASSERT(sexp_transport_format(NULL, "(%z(%z%z))", + "foo", "bar", "xxxxxxxxxxxxxxxxx") + == strlen(e)); + + ASSERT(buffer.size == strlen(e)); + ASSERT(MEMEQ(buffer.size, buffer.contents, e)); + } + { + const uint8_t e[] = "1:a2:bc3:def4:ghij"; + + nettle_buffer_init(&buffer); + ASSERT(sexp_format(&buffer, "%i%i%i%i", + 0x61, 0x6263, 0x646566, 0x6768696a) + == strlen(e)); + + ASSERT(buffer.size == strlen(e)); + ASSERT(MEMEQ(buffer.size, buffer.contents, e)); + } + + { + const uint8_t e[] = "(3:foo(4:bar))"; + + nettle_buffer_init(&buffer); + ASSERT(sexp_format(&buffer, "(%z%l)", + "foo", 7, "(4:bar)") + == strlen(e)); + + ASSERT(buffer.size == strlen(e)); + ASSERT(MEMEQ(buffer.size, buffer.contents, e)); + } + #if HAVE_LIBGMP { mpz_t x; - const uint8_t e2[] = "(3:foo(3:bar11:abcdefghijk))"; + const uint8_t e[] = "(3:foo(3:bar11:abcdefghijk))"; + + nettle_buffer_clear(&buffer); nettle_mpz_init_set_str_256(x, 11, "abcdefghijk"); nettle_buffer_init(&buffer); - ASSERT(sexp_format(&buffer, "(%s(%s%b))", - "foo", "bar", x)); + ASSERT(sexp_format(&buffer, "(%z(%z%b))", + "foo", "bar", x) + == strlen(e)); - ASSERT(buffer.size == strlen(e2)); - ASSERT(MEMEQ(buffer.size, buffer.contents, e2)); + ASSERT(sexp_format(NULL, "(%z(%z%b))", + "foo", "bar", x) + == strlen(e)); + + ASSERT(buffer.size == strlen(e)); + ASSERT(MEMEQ(buffer.size, buffer.contents, e)); nettle_buffer_clear(&buffer); mpz_clear(x); -- GitLab