Commit 5d9a12f7 authored by Daniel Salzman's avatar Daniel Salzman

dname: fix typo in knot_dname_storage_t, add a simple test

parent 542273f0
......@@ -36,7 +36,7 @@ typedef uint8_t knot_dname_t;
/*! \brief Local domain name storage. */
typedef union {
knot_dname_t *dname;
knot_dname_t dname;
uint8_t data[KNOT_DNAME_MAXLEN];
} knot_dname_storage_t;
......@@ -348,9 +348,9 @@ size_t knot_dname_labels(const uint8_t *name, const uint8_t *pkt);
* Lookup: \\x00
*
* \param src Source domain name.
* \param storage Memory to store converted name into.
* \param storage Memory to store converted name into. Don't use directly!
*
* \retval Lookup format if successful.
* \retval Lookup format if successful (pointer into the storage).
* \retval NULL on invalid parameters.
*/
uint8_t *knot_dname_lf(const knot_dname_t *src, knot_dname_storage_t *storage);
......
......@@ -138,6 +138,22 @@ static void test_dname_lf(void)
ok(out != NULL && out[0] == '\x00', "knot_dname_lf: zero-label DNAME converted");
}
static void test_dname_storage(void)
{
const knot_dname_t *dname = (uint8_t *)"\x04""test";
size_t dname_len = knot_dname_size(dname);
knot_dname_storage_t storage;
size_t store_len = knot_dname_store(&storage, dname);
size_t storage_len = knot_dname_size(&storage.dname);
ok(store_len == dname_len && storage_len == dname_len &&
memcmp(&storage, dname, dname_len) == 0 &&
memcmp(&storage.data, dname, dname_len) == 0 &&
memcmp(&storage.dname, dname, dname_len) == 0,
"knot_dname_storage: valid name");
}
int main(int argc, char *argv[])
{
plan_lazy();
......@@ -563,9 +579,11 @@ int main(int argc, char *argv[])
knot_dname_free(d, NULL);
/* DNAME CONVERSION TO LOOK-UP FORMAT CHECK */
/* OTHER CHECKS */
test_dname_lf();
test_dname_storage();
return 0;
}
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