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);
}
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);
}
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);
}
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);
}