Commit eb26bf0b authored by Niels Möller's avatar Niels Möller

(test_main): Check that %i and %b

generate leading zeroes when needed. Check that %b handles
negative numbers.

Rev: src/nettle/testsuite/sexp-format-test.c:1.3
parent a8001c2b
......@@ -40,14 +40,14 @@ test_main(void)
ASSERT(MEMEQ(buffer.size, buffer.contents, e));
}
{
const uint8_t e[] = "1:a2:bc3:def4:ghij";
const uint8_t e[] = "1:\0""1:a2:bc3:def4:ghij5:\x00\xDE\xAD\xBE\xEF";
nettle_buffer_init(&buffer);
ASSERT(sexp_format(&buffer, "%i%i%i%i",
0x61, 0x6263, 0x646566, 0x6768696a)
== strlen(e));
ASSERT(sexp_format(&buffer, "%i%i%i%i%i%i",
0, 0x61, 0x6263, 0x646566, 0x6768696a, 0xDEADBEEF)
== LLENGTH(e));
ASSERT(buffer.size == strlen(e));
ASSERT(buffer.size == LLENGTH(e));
ASSERT(MEMEQ(buffer.size, buffer.contents, e));
}
......@@ -66,22 +66,28 @@ test_main(void)
#if HAVE_LIBGMP
{
mpz_t x;
const uint8_t e[] = "(3:foo(3:bar11:abcdefghijk))";
mpz_t y;
mpz_t z;
const uint8_t e[] =
"(3:foo(3:bar1:\xff""11:abcdefghijk13:\0\x81""abcdefghijk))";
nettle_buffer_clear(&buffer);
nettle_mpz_init_set_str_256(x, 11, "abcdefghijk");
mpz_init_set_si(x, -1);
nettle_mpz_init_set_str_256_u(y, 11, "abcdefghijk");
nettle_mpz_init_set_str_256_u(z, 12, "\x81""abcdefghijk");
nettle_buffer_init(&buffer);
ASSERT(sexp_format(&buffer, "(%z(%z%b))",
"foo", "bar", x)
== strlen(e));
ASSERT(sexp_format(&buffer, "(%z(%z%b%b%b))",
"foo", "bar", x, y, z)
== LLENGTH(e));
ASSERT(sexp_format(NULL, "(%z(%z%b))",
"foo", "bar", x)
== strlen(e));
ASSERT(sexp_format(NULL, "(%z(%z%b%b%b))",
"foo", "bar", x, y, z)
== LLENGTH(e));
ASSERT(buffer.size == strlen(e));
ASSERT(buffer.size == LLENGTH(e));
ASSERT(MEMEQ(buffer.size, buffer.contents, e));
nettle_buffer_clear(&buffer);
......@@ -91,5 +97,3 @@ test_main(void)
SUCCESS();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment