Sat, 12 Nov 2022 20:50:45 +0100
refactor send_cgi into non-blocking SAF (wip)
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"); |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
354 | 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
|
355 | UCX_TEST_ASSERT(expr->left, "missing left expression"); |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
356 | UCX_TEST_ASSERT(expr->right, "missing right expression"); |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
357 | 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
|
358 | 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
|
359 | UCX_TEST_ASSERT(expr->left->left, "mul: missing left"); |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
360 | UCX_TEST_ASSERT(expr->left->right, "mul: missing right"); |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
361 | 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
|
362 | 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
|
363 | 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
|
364 | |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
365 | UCX_TEST_END; |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
366 | |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
367 | pool_destroy(pool); |
bb7cff720dd0
add obj.conf expression parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
368 | } |