From: Klas Lindfors Date: Fri, 9 Nov 2012 14:06:57 +0000 (+0100) Subject: add testing of ykp_ndef_as_text() X-Git-Tag: v1.10.0~30 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3199d5f9711a2ad77ac5c72a64199fe4a0db7d9d;p=yubikey-personalization add testing of ykp_ndef_as_text() --- diff --git a/tests/test_ndef_construction.c b/tests/test_ndef_construction.c index 9ce029c..47c0104 100644 --- a/tests/test_ndef_construction.c +++ b/tests/test_ndef_construction.c @@ -41,11 +41,15 @@ void _test_https_uri() YK_NDEF *ndef = ykp_alloc_ndef(); char uri[] = "https://example.com/foo"; int rc = ykp_construct_ndef_uri(ndef, uri); + char text[256]; assert(rc == 1); assert(ndef->type == 'U'); assert(ndef->data[0] == 0x04); assert(strncmp(ndef->data + 1, "example.com/foo", 15) == 0); assert(ndef->len == 16); + rc = ykp_ndef_as_text(ndef, text, 256); + assert(rc == 1); + assert(strncmp(uri, text, strlen(uri)) == 0); ykp_free_ndef(ndef); } @@ -65,11 +69,15 @@ void _test_exact_uri() YK_NDEF *ndef = ykp_alloc_ndef(); char uri[] = "https://www.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; int rc = ykp_construct_ndef_uri(ndef, uri); + char text[256]; assert(rc == 1); assert(ndef->type == 'U'); assert(ndef->data[0] == 0x02); assert(strncmp(ndef->data + 1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", NDEF_DATA_SIZE -1) == 0); assert(ndef->len == NDEF_DATA_SIZE); + rc = ykp_ndef_as_text(ndef, text, 256); + assert(rc == 1); + assert(strncmp(uri, text, strlen(uri)) == 0); ykp_free_ndef(ndef); } @@ -78,12 +86,16 @@ void _test_exact_text() YK_NDEF *ndef = ykp_alloc_ndef(); char text[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; int rc = ykp_construct_ndef_text(ndef, text, "en", false); + char text2[256]; assert(rc == 1); assert(ndef->type == 'T'); assert(ndef->data[0] == 2); assert(strncmp(ndef->data + 1, "en", 2) == 0); assert(strncmp(ndef->data + 3, text, NDEF_DATA_SIZE - 3) == 0); assert(ndef->len == NDEF_DATA_SIZE); + rc = ykp_ndef_as_text(ndef, text2, 256); + assert(rc == 1); + assert(strncmp(text, text2, strlen(text)) == 0); ykp_free_ndef(ndef); } @@ -93,12 +105,16 @@ void _test_other_lang_text() char text[] = "aaaaaaaaaaaaaaa"; size_t text_len = strlen(text); int rc = ykp_construct_ndef_text(ndef, text, "sv-SE", true); + char text2[256]; assert(rc == 1); assert(ndef->type == 'T'); assert(ndef->data[0] == (0x80 & 5)); assert(strncmp(ndef->data + 1, "sv-SE", 5) == 0); assert(strncmp(ndef->data + 6, text, text_len) == 0); assert(ndef->len == text_len + 6); + rc = ykp_ndef_as_text(ndef, text2, 256); + assert(rc == 1); + assert(strncmp(text, text2, strlen(text))); ykp_free_ndef(ndef); }