Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / nettle / testsuite / sexp-test.c
blob324d61f0fc0568518fae68422d5928ae3a17de7b
1 #include "testutils.h"
2 #include "sexp.h"
4 void
5 test_main(void)
7 struct sexp_iterator i;
8 uint32_t x;
10 ASSERT(sexp_iterator_first(&i, LDATA("")));
11 ASSERT(i.type == SEXP_END);
13 ASSERT(sexp_iterator_first(&i, LDATA("()")));
14 ASSERT(i.type == SEXP_LIST
15 && sexp_iterator_enter_list(&i)
16 && i.type == SEXP_END
17 && sexp_iterator_exit_list(&i)
18 && i.type == SEXP_END);
20 ASSERT(sexp_iterator_first(&i, LDATA("(")));
21 ASSERT(i.type == SEXP_LIST
22 && !sexp_iterator_enter_list(&i));
24 /* Check integers. */
25 ASSERT(sexp_iterator_first(&i, LDATA("1:\0"
26 "1:\x11"
27 "2:\x00\x11"
28 "2:\x00\x80"
29 "5:\x00\xaa\xbb\xcc\xdd")));
30 ASSERT(sexp_iterator_get_uint32(&i, &x) && x == 0);
31 ASSERT(sexp_iterator_get_uint32(&i, &x) && x == 0x11);
32 ASSERT(sexp_iterator_get_uint32(&i, &x) && x == 0x11);
33 ASSERT(sexp_iterator_get_uint32(&i, &x) && x == 0x80);
34 ASSERT(sexp_iterator_get_uint32(&i, &x) && x == 0xaabbccdd);
36 ASSERT(sexp_iterator_first(&i, LDATA("3:foo0:[3:bar]12:xxxxxxxxxxxx")));
37 ASSERT(i.type == SEXP_ATOM
38 && !i.display_length && !i.display
39 && i.atom_length == 3 && MEMEQ(3, "foo", i.atom)
41 && sexp_iterator_next(&i) && i.type == SEXP_ATOM
42 && !i.display_length && !i.display
43 && !i.atom_length && i.atom
45 && sexp_iterator_next(&i) && i.type == SEXP_ATOM
46 && i.display_length == 3 && MEMEQ(3, "bar", i.display)
47 && i.atom_length == 12 && MEMEQ(12, "xxxxxxxxxxxx", i.atom)
49 && sexp_iterator_next(&i) && i.type == SEXP_END);
51 /* Same data, transport encoded. */
54 struct tstring *s
55 = tstring_data(LDATA("{Mzpmb28=} {MDo=} {WzM6YmFyXTEyOnh4eHh4eHh4eHh4eA==}"));
56 ASSERT(sexp_transport_iterator_first (&i, s->length, s->data));
57 ASSERT(i.type == SEXP_ATOM
58 && !i.display_length && !i.display
59 && i.atom_length == 3 && MEMEQ(3, "foo", i.atom)
61 && sexp_iterator_next(&i) && i.type == SEXP_ATOM
62 && !i.display_length && !i.display
63 && !i.atom_length && i.atom
65 && sexp_iterator_next(&i) && i.type == SEXP_ATOM
66 && i.display_length == 3 && MEMEQ(3, "bar", i.display)
67 && i.atom_length == 12 && MEMEQ(12, "xxxxxxxxxxxx", i.atom)
69 && sexp_iterator_next(&i) && i.type == SEXP_END);
73 static const uint8_t *keys[2] = { "n", "e" };
74 struct sexp_iterator v[2];
76 ASSERT(sexp_iterator_first(&i, LDATA("((1:n2:xx3:foo)0:(1:y)(1:e))")));
77 ASSERT(sexp_iterator_enter_list(&i)
78 && sexp_iterator_assoc(&i, 2, keys, v));
80 ASSERT(v[0].type == SEXP_ATOM
81 && !v[0].display_length && !v[0].display
82 && v[0].atom_length == 2 && MEMEQ(2, "xx", v[0].atom)
84 && sexp_iterator_next(&v[0]) && v[0].type == SEXP_ATOM
85 && !v[0].display_length && !v[0].display
86 && v[0].atom_length == 3 && MEMEQ(3, "foo", v[0].atom)
88 && sexp_iterator_next(&v[0]) && v[0].type == SEXP_END);
90 ASSERT(v[1].type == SEXP_END);
92 ASSERT(sexp_iterator_first(&i, LDATA("((1:n))")));
93 ASSERT(sexp_iterator_enter_list(&i)
94 && !sexp_iterator_assoc(&i, 2, keys, v));
96 ASSERT(sexp_iterator_first(&i, LDATA("((1:n)(1:n3:foo))")));
97 ASSERT(sexp_iterator_enter_list(&i)
98 && !sexp_iterator_assoc(&i, 2, keys, v));