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

* testsuite/sexp-test.c: Test sexp parser.

Rev: src/nettle/testsuite/.cvsignore:1.17
Rev: src/nettle/testsuite/Makefile.am:1.22
Rev: src/nettle/testsuite/sexp-test.c:1.1
parent aba7c120
......@@ -18,6 +18,7 @@ md5-test
rsa-keygen-test
rsa-test
serpent-test
sexp-test
sha1-test
sha256-test
twofish-test
......
......@@ -18,6 +18,7 @@
/rsa-keygen-test
/rsa-test
/serpent-test
/sexp-test
/sha1-test
/sha256-test
/twofish-test
......
......@@ -6,6 +6,7 @@ TS_PROGS = aes-test arcfour-test blowfish-test cast128-test \
des-test des3-test des-compat-test \
md5-test md5-compat-test sha1-test sha256-test \
serpent-test twofish-test \
sexp-test \
knuth-lfib-test \
cbc-test hmac-test bignum-test \
rsa-test rsa-keygen-test yarrow-test
......
#include "testutils.h"
#include "sexp.h"
int
test_main(void)
{
struct sexp_iterator i;
sexp_iterator_init(&i, LDATA(""));
ASSERT(sexp_iterator_next(&i) && i.type == SEXP_END);
sexp_iterator_init(&i, LDATA("()"));
ASSERT(sexp_iterator_next(&i) && i.type == SEXP_LIST
&& sexp_iterator_enter_list(&i)
&& sexp_iterator_next(&i) && i.type == SEXP_END
&& sexp_iterator_exit_list(&i)
&& sexp_iterator_next(&i) && i.type == SEXP_END);
sexp_iterator_init(&i, LDATA("("));
ASSERT(sexp_iterator_next(&i) && i.type == SEXP_LIST
&& sexp_iterator_enter_list(&i)
&& !sexp_iterator_next(&i));
sexp_iterator_init(&i, LDATA("3:foo0:[3:bar]1:x"));
ASSERT(sexp_iterator_next(&i) && i.type == SEXP_ATOM
&& !i.display_length && !i.display
&& i.atom_length == 3 && MEMEQ(3, "foo", i.atom)
&& sexp_iterator_next(&i) && i.type == SEXP_ATOM
&& !i.display_length && !i.display
&& !i.atom_length && i.atom
&& sexp_iterator_next(&i) && i.type == SEXP_ATOM
&& i.display_length == 3 && MEMEQ(3, "bar", i.display)
&& i.atom_length == 1 && MEMEQ(1, "x", i.atom));
{
struct sexp_assoc_key keys[2] =
{ { LDATA("n") }, { LDATA("e") } };
struct sexp_iterator v[2];
sexp_iterator_init(&i, LDATA("((1:n))"));
ASSERT(!sexp_iterator_assoc(&i, 2, keys, v));
sexp_iterator_init(&i, LDATA("((1:n)(1:n3:foo))"));
ASSERT(!sexp_iterator_assoc(&i, 2, keys, v));
sexp_iterator_init(&i, LDATA("((1:n2:xx3:foo)0:(1:y)(1:e))"));
ASSERT(sexp_iterator_assoc(&i, 2, keys, v));
ASSERT(sexp_iterator_next(&v[0]) && v[0].type == SEXP_ATOM
&& !v[0].display_length && !v[0].display
&& v[0].atom_length == 2 && MEMEQ(2, "xx", v[0].atom)
&& sexp_iterator_next(&v[0]) && v[0].type == SEXP_ATOM
&& !v[0].display_length && !v[0].display
&& v[0].atom_length == 3 && MEMEQ(3, "foo", v[0].atom)
&& sexp_iterator_next(&v[0]) && v[0].type == SEXP_END);
}
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