diff options
author | Stef Walter <stefw@gnome.org> | 2013-05-21 16:41:09 +0200 |
---|---|---|
committer | Stef Walter <stefw@gnome.org> | 2013-05-27 10:46:11 +0200 |
commit | cb8f2e3a04d9365121ffea0d76d8b3d47e2cc1ec (patch) | |
tree | 0f1b8a6d70ef15f4e3154def0f4a316fb717cce6 /common/tests | |
parent | 4fd057258177f4f14bbe78c2d02d5a65eaf3f3dc (diff) |
url: Encode directly to a buffer
Diffstat (limited to 'common/tests')
-rw-r--r-- | common/tests/test-url.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/common/tests/test-url.c b/common/tests/test-url.c index 4c62594..892bf3c 100644 --- a/common/tests/test-url.c +++ b/common/tests/test-url.c @@ -120,28 +120,34 @@ static void test_encode (void) { const unsigned char *input = (unsigned char *)"TEST"; - char *encoded; - size_t length; + p11_buffer buf; + + if (!p11_buffer_init_null (&buf, 5)) + assert_not_reached (); - encoded = p11_url_encode (input, input + 5, "", &length); - assert_str_eq ("%54%45%53%54%00", (char *)encoded); - assert_num_eq (15, length); + p11_url_encode (input, input + 5, "", &buf); + assert (p11_buffer_ok (&buf)); + assert_str_eq ("%54%45%53%54%00", (char *)buf.data); + assert_num_eq (15, buf.len); - free (encoded); + p11_buffer_uninit (&buf); } static void test_encode_verbatim (void) { const unsigned char *input = (unsigned char *)"TEST"; - char *encoded; - size_t length; + p11_buffer buf; + + if (!p11_buffer_init_null (&buf, 5)) + assert_not_reached (); - encoded = p11_url_encode (input, input + 5, "ES", &length); - assert_str_eq ("%54ES%54%00", (char *)encoded); - assert_num_eq (11, length); + p11_url_encode (input, input + 5, "ES", &buf); + assert (p11_buffer_ok (&buf)); + assert_str_eq ("%54ES%54%00", (char *)buf.data); + assert_num_eq (11, buf.len); - free (encoded); + p11_buffer_uninit (&buf); } int |