From ddf23f6d28ab24965c00b62e28f4457f5c13f77b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se> Date: Sat, 28 Sep 2002 15:56:36 +0200 Subject: [PATCH] * 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 --- testsuite/.cvsignore | 1 + testsuite/.gitignore | 1 + testsuite/Makefile.am | 1 + testsuite/sexp-test.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 testsuite/sexp-test.c diff --git a/testsuite/.cvsignore b/testsuite/.cvsignore index 5e269efb..0d066cd7 100644 --- a/testsuite/.cvsignore +++ b/testsuite/.cvsignore @@ -18,6 +18,7 @@ md5-test rsa-keygen-test rsa-test serpent-test +sexp-test sha1-test sha256-test twofish-test diff --git a/testsuite/.gitignore b/testsuite/.gitignore index b20bae51..6a3f61ba 100644 --- a/testsuite/.gitignore +++ b/testsuite/.gitignore @@ -18,6 +18,7 @@ /rsa-keygen-test /rsa-test /serpent-test +/sexp-test /sha1-test /sha256-test /twofish-test diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index af607e3e..cf111469 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -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 diff --git a/testsuite/sexp-test.c b/testsuite/sexp-test.c new file mode 100644 index 00000000..dc8c2693 --- /dev/null +++ b/testsuite/sexp-test.c @@ -0,0 +1,61 @@ +#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(); +} -- GitLab