src/server/test/object.c

Sat, 26 Nov 2022 19:14:29 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 26 Nov 2022 19:14:29 +0100
changeset 439
255e316db762
parent 435
713ec3da79ec
child 452
ce359a2b51fe
permissions
-rw-r--r--

fix srvctrl thread stacksize

423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2022 Olaf Wintermann. All rights reserved.
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "object.h"
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include "../util/object.h"
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <cx/linked_list.h>
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include <cx/compare.h>
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "object.h"
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 UCX_TEST(test_expr_parse_expr_value) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 cxstring token = cx_str("123");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 UCX_TEST_ASSERT(pos == 1, "wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 UCX_TEST_ASSERT(expr, "expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_INT, "wrong type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
424
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
60 UCX_TEST(test_expr_parse_expr_neg_value) {
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
61 pool_handle_t *pool = pool_create();
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
62
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
63 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
64 cxstring token = cx_str("-123");
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
65 cxListAdd(tokens, &token);
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
66
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
67 UCX_TEST_BEGIN;
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
68
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
69 size_t pos = 0;
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
70 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
71
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
72 UCX_TEST_ASSERT(pos == 1, "wrong token pos");
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
73 UCX_TEST_ASSERT(expr, "expression is null");
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
74 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_INT, "wrong type");
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
75 UCX_TEST_ASSERT(expr->value.i == -123, "wrong value");
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
76
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
77 UCX_TEST_END;
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
78
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
79 pool_destroy(pool);
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
80 }
3df9258cd3cc allow '-' in tokens, add support for negative integers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 423
diff changeset
81
423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 UCX_TEST(test_expr_parse_expr_value_str) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 cxstring token = cx_str("\"hello world\"");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 UCX_TEST_ASSERT(pos == 1, "wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 UCX_TEST_ASSERT(expr, "expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_STRING, "wrong type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 UCX_TEST_ASSERT(!cx_strcmp(expr->value.str, cx_str("hello world")), "wrong value");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 UCX_TEST(test_expr_parse_expr_value_bool) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 cxstring token = cx_str("true");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 UCX_TEST_ASSERT(pos == 1, "wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 UCX_TEST_ASSERT(expr, "expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_BOOL, "wrong type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 UCX_TEST_ASSERT(expr->value.b == 1, "wrong value");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 UCX_TEST(test_expr_parse_expr_value_var) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 cxstring token = cx_str("$test");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 UCX_TEST_ASSERT(pos == 1, "wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 UCX_TEST_ASSERT(expr, "expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_VARIABLE, "wrong type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 UCX_TEST_ASSERT(!cx_strcmp(expr->value.var, cx_str("test")), "wrong var name");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 UCX_TEST(test_expr_parse_expr_not_value) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 cxstring token = cx_str("not");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 token = cx_str("true");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 UCX_TEST_ASSERT(pos == 2, "wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 UCX_TEST_ASSERT(expr, "expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_UNARY, "wrong root expression type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 UCX_TEST_ASSERT(expr->left, "missing left expression");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 UCX_TEST_ASSERT(!expr->right, "right expression should be null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 UCX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_BOOL, "left expression has wrong type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 UCX_TEST_ASSERT(expr->left->value.b == 1, "left expression has wrong value");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 UCX_TEST(test_expr_parse_expr_sign_value) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 CxList *tokens1 = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 cxstring token = cx_str("+");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 cxListAdd(tokens1, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 token = cx_str("123");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 cxListAdd(tokens1, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 CxList *tokens2 = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 token = cx_str("-");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 cxListAdd(tokens2, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 token = cx_str("123");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 cxListAdd(tokens2, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens1, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 UCX_TEST_ASSERT(pos == 2, "test1: wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 UCX_TEST_ASSERT(expr, "test1: expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 expr = expr_parse_logical_expr(pool, tokens2, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 UCX_TEST_ASSERT(pos == 2, "test2: wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 UCX_TEST_ASSERT(expr, "test2: expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_UNARY, "wrong expression type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_SUB, "wrong expression operator");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 UCX_TEST_ASSERT(expr->left, "missing left expresion");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 UCX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_INT, "left expression has wrong type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 UCX_TEST_ASSERT(expr->left->value.i == 123, "left expression has wrong value");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 UCX_TEST(test_expr_parse_expr_compare2values) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 cxstring token = cx_str("2");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 token = cx_str("==");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 token = cx_str("2");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 UCX_TEST_ASSERT(pos == 3, "wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 UCX_TEST_ASSERT(expr, "expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_BINARY, "wrong expression type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 UCX_TEST_ASSERT(expr->left, "left expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 UCX_TEST_ASSERT(expr->right, "right expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 UCX_TEST_ASSERT(expr->left->operator == NSAPI_EXPRESSION_NOOP, "left should be a literal with no operator");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 UCX_TEST_ASSERT(expr->right->operator == NSAPI_EXPRESSION_NOOP, "right should be a literal with no operator");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 UCX_TEST(test_expr_parse_expr_compare2value_expr) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 cxstring token = cx_str("2");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 token = cx_str("==");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 token = cx_str("1");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 token = cx_str("+");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 token = cx_str("1");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 UCX_TEST_ASSERT(pos == 5, "wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 UCX_TEST_ASSERT(expr, "expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_BINARY, "wrong expression type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 UCX_TEST_ASSERT(expr->left, "left expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274 UCX_TEST_ASSERT(expr->right, "right expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276 UCX_TEST_ASSERT(expr->left->operator == NSAPI_EXPRESSION_NOOP, "left should be a literal with no operator");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 UCX_TEST_ASSERT(expr->right->operator == NSAPI_EXPRESSION_ADD, "right should be a binary expression");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 UCX_TEST(test_expr_parse_expr_compare2expr_value) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 cxstring token = cx_str("1");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290 token = cx_str("+");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 token = cx_str("1");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 token = cx_str("==");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 token = cx_str("2");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 UCX_TEST_ASSERT(pos == 5, "wrong token pos");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 UCX_TEST_ASSERT(expr, "expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_BINARY, "wrong expression type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 UCX_TEST_ASSERT(expr->left, "left expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309 UCX_TEST_ASSERT(expr->right, "right expression is null");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310 UCX_TEST_ASSERT(expr->right->value.i == 2, "right wrong value");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
312 UCX_TEST_ASSERT(expr->left->operator == NSAPI_EXPRESSION_ADD, "left should be a binary operation");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313 UCX_TEST_ASSERT(expr->right->operator == NSAPI_EXPRESSION_NOOP, "right should be NOOP");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 UCX_TEST_ASSERT(expr->left->left, "ADD-op missing left");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315 UCX_TEST_ASSERT(expr->left->right, "ADD-op missing right");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
316 UCX_TEST_ASSERT(expr->left->left->value.i == 1, "ADD-op: wrong left value");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
317 UCX_TEST_ASSERT(expr->left->right->value.i == 1, "ADD-op: wrong right value");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
322 }
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
324 UCX_TEST(test_expr_parse_expr_bracket) {
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
325 pool_handle_t *pool = pool_create();
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 // expression: 2 * (1 + 2) == 6
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 cxstring token = cx_str("2");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331 token = cx_str("*");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333 token = cx_str("(");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 token = cx_str("1");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 token = cx_str("+");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 token = cx_str("2");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341 token = cx_str(")");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 token = cx_str("==");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 token = cx_str("6");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 cxListAdd(tokens, &token);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348 UCX_TEST_BEGIN;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
350 size_t pos = 0;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
351 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
352
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
353 UCX_TEST_ASSERT(pos == 9, "wrong token pos");
435
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
354 UCX_TEST_ASSERT(expr, "expression is null");
423
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
355 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_EQ, "root: wrong operator");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
356 UCX_TEST_ASSERT(expr->left, "missing left expression");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
357 UCX_TEST_ASSERT(expr->right, "missing right expression");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
358 UCX_TEST_ASSERT(expr->right->type == NSAPI_EXPRESSION_INT, "right expression has wrong type");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
359 UCX_TEST_ASSERT(expr->left->operator == NSAPI_EXPRESSION_MUL, "left expression has wrong operator");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
360 UCX_TEST_ASSERT(expr->left->left, "mul: missing left");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
361 UCX_TEST_ASSERT(expr->left->right, "mul: missing right");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
362 UCX_TEST_ASSERT(expr->left->right->operator == NSAPI_EXPRESSION_ADD, "missing add operator");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
363 UCX_TEST_ASSERT(expr->left->right->left, "add: missing left");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
364 UCX_TEST_ASSERT(expr->left->right->left, "add: missing right");
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
365
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
366 UCX_TEST_END;
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
367
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368 pool_destroy(pool);
bb7cff720dd0 add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
369 }
435
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
370
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
371 UCX_TEST(test_expr_parse_expr_func_arg0) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
372 pool_handle_t *pool = pool_create();
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
373
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
374 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
375 cxstring token = cx_str("test");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
376 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
377 token = cx_str("(");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
378 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
379 token = cx_str(")");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
380 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
381
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
382 UCX_TEST_BEGIN;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
383
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
384 size_t pos = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
385 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
386
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
387 UCX_TEST_ASSERT(pos == 3, "wrong token pos");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
388 UCX_TEST_ASSERT(expr, "expression is null");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
389 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER, "wrong expression type");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
390 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL, "wrong expression operator");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
391 UCX_TEST_ASSERT(!expr->left, "left is not null");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
392 UCX_TEST_ASSERT(!expr->right, "right is not null");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
393
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
394 UCX_TEST_END;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
395
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
396 pool_destroy(pool);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
397 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
398
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
399
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
400 int test_get_args(NSAPIExpression *arglist, size_t maxArgs, size_t *numArgs, NSAPIExpression *arg) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
401 if(!arg) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
402 return 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
403 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
404 if(arg->operator == NSAPI_EXPRESSION_ARG) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
405 if(arg->left) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
406 if(test_get_args(arglist, maxArgs, numArgs, arg->left)) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
407 return 1;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
408 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
409 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
410 if(arg->right) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
411 if(test_get_args(arglist, maxArgs, numArgs, arg->right)) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
412 return 1;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
413 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
414 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
415 } else {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
416 if(*numArgs >= maxArgs) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
417 return 1;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
418 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
419 arglist[*numArgs] = *arg;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
420 (*numArgs)++;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
421 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
422
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
423 return 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
424 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
425
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
426
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
427 UCX_TEST(test_expr_parse_expr_func_arg1) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
428 pool_handle_t *pool = pool_create();
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
429
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
430 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
431 cxstring token = cx_str("test");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
432 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
433 token = cx_str("(");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
434 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
435 token = cx_str("1");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
436 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
437 token = cx_str(")");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
438 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
439
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
440 UCX_TEST_BEGIN;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
441
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
442 size_t pos = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
443 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
444
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
445 UCX_TEST_ASSERT(pos == tokens->size, "wrong token pos");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
446 UCX_TEST_ASSERT(expr, "expression is null");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
447 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER, "wrong expression type");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
448 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL, "wrong expression operator");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
449
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
450 size_t numArgs = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
451 NSAPIExpression args[8];
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
452 int err = test_get_args(args, 8, &numArgs, expr->left);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
453 UCX_TEST_ASSERT(err == 0, "too much args");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
454 UCX_TEST_ASSERT(numArgs == 1, "wrong arg count");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
455 UCX_TEST_ASSERT(args[0].value.i == 1, "wrong arg value");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
456
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
457 UCX_TEST_END;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
458
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
459 pool_destroy(pool);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
460 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
461
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
462 UCX_TEST(test_expr_parse_expr_func_arg3) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
463 pool_handle_t *pool = pool_create();
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
464
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
465 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
466 cxstring token = cx_str("test");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
467 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
468 token = cx_str("(");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
469 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
470 token = cx_str("1");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
471 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
472 token = cx_str(",");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
473 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
474 token = cx_str("2");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
475 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
476 token = cx_str(",");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
477 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
478 token = cx_str("3");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
479 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
480 token = cx_str(")");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
481 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
482
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
483 UCX_TEST_BEGIN;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
484
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
485 size_t pos = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
486 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
487
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
488 UCX_TEST_ASSERT(pos == tokens->size, "wrong token pos");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
489 UCX_TEST_ASSERT(expr, "expression is null");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
490 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER, "wrong expression type");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
491 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL, "wrong expression operator");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
492
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
493 size_t numArgs = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
494 NSAPIExpression args[8];
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
495 int err = test_get_args(args, 8, &numArgs, expr->left);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
496 UCX_TEST_ASSERT(err == 0, "too much args");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
497 UCX_TEST_ASSERT(numArgs == 3, "wrong arg count");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
498 UCX_TEST_ASSERT(args[0].value.i == 1, "arg0: wrong value");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
499 UCX_TEST_ASSERT(args[1].value.i == 2, "arg1: wrong value");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
500 UCX_TEST_ASSERT(args[2].value.i == 3, "arg2: wrong value");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
501
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
502 UCX_TEST_END;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
503
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
504 pool_destroy(pool);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
505 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
506
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
507 UCX_TEST(test_expr_parse_expr_func_expr1) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
508 pool_handle_t *pool = pool_create();
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
509
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
510 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
511 cxstring token = cx_str("test");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
512 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
513 token = cx_str("(");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
514 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
515 token = cx_str("1");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
516 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
517 token = cx_str(",");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
518 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
519 token = cx_str("2");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
520 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
521 token = cx_str("+");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
522 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
523 token = cx_str("3");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
524 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
525 token = cx_str(")");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
526 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
527
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
528 UCX_TEST_BEGIN;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
529
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
530 size_t pos = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
531 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
532
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
533 UCX_TEST_ASSERT(pos == tokens->size, "wrong token pos");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
534 UCX_TEST_ASSERT(expr, "expression is null");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
535 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER, "wrong expression type");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
536 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL, "wrong expression operator");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
537
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
538 size_t numArgs = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
539 NSAPIExpression args[8];
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
540 int err = test_get_args(args, 8, &numArgs, expr->left);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
541 UCX_TEST_ASSERT(err == 0, "too much args");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
542 UCX_TEST_ASSERT(numArgs == 2, "wrong arg count");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
543 UCX_TEST_ASSERT(args[0].value.i == 1, "arg0: wrong value");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
544 UCX_TEST_ASSERT(args[1].operator == NSAPI_EXPRESSION_ADD, "arg1: wrong operator");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
545 UCX_TEST_ASSERT(args[1].left && args[1].right, "arg1: missing operator values");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
546 UCX_TEST_ASSERT(args[1].left->value.i == 2 && args[1].right->value.i == 3, "arg1: wrong operator values");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
547
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
548 UCX_TEST_END;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
549
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
550 pool_destroy(pool);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
551 }
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
552
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
553 UCX_TEST(test_expr_parse_expr_func_expr2) {
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
554 pool_handle_t *pool = pool_create();
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
555
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
556 CxList *tokens = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(cxstring));
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
557 cxstring token = cx_str("test");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
558 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
559 token = cx_str("(");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
560 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
561 token = cx_str("2");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
562 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
563 token = cx_str("+");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
564 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
565 token = cx_str("3");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
566 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
567 token = cx_str(",");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
568 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
569 token = cx_str("sub");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
570 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
571 token = cx_str("(");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
572 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
573 token = cx_str("4");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
574 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
575 token = cx_str(")");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
576 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
577 token = cx_str(",");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
578 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
579 token = cx_str("6");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
580 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
581 token = cx_str(")");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
582 cxListAdd(tokens, &token);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
583
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
584 UCX_TEST_BEGIN;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
585
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
586 size_t pos = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
587 NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
588
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
589 UCX_TEST_ASSERT(pos == tokens->size, "wrong token pos");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
590 UCX_TEST_ASSERT(expr, "expression is null");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
591 UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER, "wrong expression type");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
592 UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL, "wrong expression operator");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
593
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
594 size_t numArgs = 0;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
595 NSAPIExpression args[8];
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
596 int err = test_get_args(args, 8, &numArgs, expr->left);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
597 UCX_TEST_ASSERT(err == 0, "too much args");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
598 UCX_TEST_ASSERT(numArgs == 3, "wrong arg count");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
599 UCX_TEST_ASSERT(args[0].operator == NSAPI_EXPRESSION_ADD, "arg0: wrong operator");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
600 UCX_TEST_ASSERT(args[0].left && args[0].right, "arg0: missing operator values");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
601 UCX_TEST_ASSERT(args[1].operator == NSAPI_EXPRESSION_CALL, "arg1: wrong operator");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
602 UCX_TEST_ASSERT(args[1].left, "arg1: missing args");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
603 UCX_TEST_ASSERT(args[2].type == NSAPI_EXPRESSION_INT, "arg2: wrong type");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
604 UCX_TEST_ASSERT(args[2].value.i == 6, "arg2: wrong value");
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
605
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
606 UCX_TEST_END;
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
607
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
608 pool_destroy(pool);
713ec3da79ec expression parser: add support for functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 424
diff changeset
609 }

mercurial