author | alanb |
Thu, 01 Dec 2016 15:54:39 +0000 | |
changeset 42309 | 21f9f3fbc302 |
parent 41671 | 9e0c6db4918a |
child 42624 | 91e01fe9f1e3 |
permissions | -rw-r--r-- |
41335 | 1 |
/* |
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#include "precompiled.hpp" |
|
26 |
#include "prims/jvm.h" |
|
27 |
#include "utilities/json.hpp" |
|
28 |
#include "unittest.hpp" |
|
29 |
||
30 |
class JSON_GTest : public JSON { |
|
31 |
public: |
|
32 |
static void test(const char* json, bool valid); |
|
33 |
||
34 |
private: |
|
35 |
JSON_GTest(const char* text); |
|
36 |
||
37 |
void log(uint level, const char* format, ...) ATTRIBUTE_PRINTF(3, 4); |
|
38 |
||
39 |
bool callback(JSON_TYPE t, JSON_VAL* v, uint level); |
|
40 |
JSON_TYPE prev; |
|
41 |
}; |
|
42 |
||
43 |
void JSON_GTest::test(const char* text, bool should_pass) { |
|
44 |
JSON_GTest json(text); |
|
45 |
if (should_pass) { |
|
46 |
ASSERT_TRUE(json.valid()) << "failed on a valid json string"; |
|
47 |
} else { |
|
48 |
ASSERT_FALSE(json.valid()) << "succeeded on an invalid json string"; |
|
49 |
} |
|
50 |
} |
|
51 |
||
52 |
JSON_GTest::JSON_GTest(const char* text) : JSON(text, false, tty) { |
|
53 |
prev = JSON_NONE; |
|
54 |
parse(); |
|
55 |
} |
|
56 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
57 |
TEST_VM(utilities, json_curly_braces) { |
41335 | 58 |
JSON_GTest::test("{}", true); |
59 |
} |
|
60 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
61 |
TEST_VM(utilities, json_brackets) { |
41335 | 62 |
JSON_GTest::test("[]", true); |
63 |
} |
|
64 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
65 |
TEST_VM(utilities, json_space_braces) { |
41335 | 66 |
JSON_GTest::test(" { } ", true); |
67 |
} |
|
68 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
69 |
TEST_VM(utilities, json_space_bracketes) { |
41335 | 70 |
JSON_GTest::test(" [ ] ", true); |
71 |
} |
|
72 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
73 |
TEST_VM(utilities, json_quoted_error) { |
41335 | 74 |
JSON_GTest::test("\"error\"", false); |
75 |
} |
|
76 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
77 |
TEST_VM(utilities, json_error_string) { |
41335 | 78 |
JSON_GTest::test("error", false); |
79 |
} |
|
80 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
81 |
TEST_VM(utilities, json_simple_integer) { |
41335 | 82 |
JSON_GTest::test("1", false); |
83 |
} |
|
84 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
85 |
TEST_VM(utilities, json_siple_float) { |
41335 | 86 |
JSON_GTest::test("1.2", false); |
87 |
} |
|
88 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
89 |
TEST_VM(utilities, json_simple_boolean_true) { |
41335 | 90 |
JSON_GTest::test("true", false); |
91 |
} |
|
92 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
93 |
TEST_VM(utilities, json_simple_boolean_false) { |
41335 | 94 |
JSON_GTest::test("false", false); |
95 |
} |
|
96 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
97 |
TEST_VM(utilities, json_simple_null) { |
41335 | 98 |
JSON_GTest::test("null", false); |
99 |
} |
|
100 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
101 |
TEST_VM(utilities, json_one_element_int_array) { |
41335 | 102 |
JSON_GTest::test("[ 1 ]", true); |
103 |
} |
|
104 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
105 |
TEST_VM(utilities, json_int_array) { |
41335 | 106 |
JSON_GTest::test("[ 1, ]", true); |
107 |
} |
|
108 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
109 |
TEST_VM(utilities, json_one_element_bool_array) { |
41335 | 110 |
JSON_GTest::test("[ true ]", true); |
111 |
} |
|
112 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
113 |
TEST_VM(utilities, json_bool_array) { |
41335 | 114 |
JSON_GTest::test("[ true, ]", true); |
115 |
} |
|
116 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
117 |
TEST_VM(utilities, json_one_element_false_array) { |
41335 | 118 |
JSON_GTest::test("[ false ]", true); |
119 |
} |
|
120 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
121 |
TEST_VM(utilities, json_false_bool_array) { |
41335 | 122 |
JSON_GTest::test("[ false, ]", true); |
123 |
} |
|
124 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
125 |
TEST_VM(utilities, json_one_null_array) { |
41335 | 126 |
JSON_GTest::test("[ null ]", true); |
127 |
} |
|
128 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
129 |
TEST_VM(utilities, json_null_array) { |
41335 | 130 |
JSON_GTest::test("[ null, ]", true); |
131 |
} |
|
132 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
133 |
TEST_VM(utilities, json_one_empty_string_array) { |
41335 | 134 |
JSON_GTest::test("[ \"\" ]", true); |
135 |
} |
|
136 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
137 |
TEST_VM(utilities, json_empty_string_array) { |
41335 | 138 |
JSON_GTest::test("[ \"\", ]", true); |
139 |
} |
|
140 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
141 |
TEST_VM(utilities, json_single_string_array) { |
41335 | 142 |
JSON_GTest::test("[ \"elem1\" ]", true); |
143 |
} |
|
144 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
145 |
TEST_VM(utilities, json_string_comma_arrray) { |
41335 | 146 |
JSON_GTest::test("[ \"elem1\", ]", true); |
147 |
} |
|
148 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
149 |
TEST_VM(utilities, json_two_strings_array) { |
41335 | 150 |
JSON_GTest::test("[ \"elem1\", \"elem2\" ]", true); |
151 |
} |
|
152 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
153 |
TEST_VM(utilities, json_two_strings_comma_array) { |
41335 | 154 |
JSON_GTest::test("[ \"elem1\", \"elem2\", ]", true); |
155 |
} |
|
156 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
157 |
TEST_VM(utilities, json_curly_braces_outside) { |
41335 | 158 |
JSON_GTest::test("[ \"elem1\" ] { }", false); |
159 |
} |
|
160 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
161 |
TEST_VM(utilities, json_element_in_array) { |
41335 | 162 |
JSON_GTest::test("[ elem1, \"elem2\" ]", false); |
163 |
} |
|
164 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
165 |
TEST_VM(utilities, json_incorrect_end_array) { |
41335 | 166 |
JSON_GTest::test("[ \"elem1\"", false); |
167 |
} |
|
168 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
169 |
TEST_VM(utilities, json_incorrect_string_end) { |
41335 | 170 |
JSON_GTest::test("[ \"elem1 ]", false); |
171 |
} |
|
172 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
173 |
TEST_VM(utilities, json_incorrect_end_of_two_elements_array) { |
41335 | 174 |
JSON_GTest::test("[ \"elem1\", \"elem2\"", false); |
175 |
} |
|
176 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
177 |
TEST_VM(utilities, json_incorrect_bool_true_array) { |
41335 | 178 |
JSON_GTest::test("[ truefoo ]", false); |
179 |
} |
|
180 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
181 |
TEST_VM(utilities, json_incorrect_bool_false_array) { |
41335 | 182 |
JSON_GTest::test("[ falsefoo ]", false); |
183 |
} |
|
184 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
185 |
TEST_VM(utilities, json_incorrect_null_array) { |
41335 | 186 |
JSON_GTest::test("[ nullfoo ]", false); |
187 |
} |
|
188 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
189 |
TEST_VM(utilities, json_key_pair) { |
41335 | 190 |
JSON_GTest::test("{ key : 1 }", true); |
191 |
} |
|
192 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
193 |
TEST_VM(utilities, json_key_pair_comma) { |
41335 | 194 |
JSON_GTest::test("{ key : 1, }", true); |
195 |
} |
|
196 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
197 |
TEST_VM(utilities, json_bool_true_key) { |
41335 | 198 |
JSON_GTest::test("{ key : true }", true); |
199 |
} |
|
200 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
201 |
TEST_VM(utilities, json_bool_true_key_comma) { |
41335 | 202 |
JSON_GTest::test("{ key : true, }", true); |
203 |
} |
|
204 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
205 |
TEST_VM(utilities, json_bool_false_key) { |
41335 | 206 |
JSON_GTest::test("{ key : false }", true); |
207 |
} |
|
208 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
209 |
TEST_VM(utilities, json_bool_false_key_comma) { |
41335 | 210 |
JSON_GTest::test("{ key : false, }", true); |
211 |
} |
|
212 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
213 |
TEST_VM(utilities, json_null_key) { |
41335 | 214 |
JSON_GTest::test("{ key : null }", true); |
215 |
} |
|
216 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
217 |
TEST_VM(utilities, json_null_key_comma) { |
41335 | 218 |
JSON_GTest::test("{ key : null, }", true); |
219 |
} |
|
220 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
221 |
TEST_VM(utilities, json_pair_of_empty_strings) { |
41335 | 222 |
JSON_GTest::test("{ \"\" : \"\" }", true); |
223 |
} |
|
224 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
225 |
TEST_VM(utilities, json_pair_of_empty_strings_comma) { |
41335 | 226 |
JSON_GTest::test("{ \"\" : \"\", }", true); |
227 |
} |
|
228 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
229 |
TEST_VM(utilities, json_pair_of_strings) { |
41335 | 230 |
JSON_GTest::test("{ \"key1\" : \"val1\" }", true); |
231 |
} |
|
232 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
233 |
TEST_VM(utilities, json_pair_of_strings_comma) { |
41335 | 234 |
JSON_GTest::test("{ \"key1\" : \"val1\", }", true); |
235 |
} |
|
236 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
237 |
TEST_VM(utilities, json_two_pairs_of_strings) { |
41335 | 238 |
JSON_GTest::test("{ \"key1\" : \"val1\", \"key2\" : \"val2\" }", true); |
239 |
} |
|
240 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
241 |
TEST_VM(utilities, json_two_pairs_of_strings_comma) { |
41335 | 242 |
JSON_GTest::test("{ \"key1\" : \"val1\", \"key2\" : \"val2\", }", true); |
243 |
} |
|
244 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
245 |
TEST_VM(utilities, json_array_outside) { |
41335 | 246 |
JSON_GTest::test("{ \"key\" : \"val\" } [ \"error\" ]", false); |
247 |
} |
|
248 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
249 |
TEST_VM(utilities, json_incorrect_object_end) { |
41335 | 250 |
JSON_GTest::test("{ \"key\" : \"val\" ", false); |
251 |
} |
|
252 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
253 |
TEST_VM(utilities, json_empty_comment) { |
41335 | 254 |
JSON_GTest::test("/**/ { }", true); |
255 |
} |
|
256 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
257 |
TEST_VM(utilities, json_space_comment) { |
41335 | 258 |
JSON_GTest::test("/* */ { }", true); |
259 |
} |
|
260 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
261 |
TEST_VM(utilities, json_comment) { |
41335 | 262 |
JSON_GTest::test("/*foo*/ { }", true); |
263 |
} |
|
264 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
265 |
TEST_VM(utilities, json_star_comment) { |
41335 | 266 |
JSON_GTest::test("/* *foo */ { }", true); |
267 |
} |
|
268 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
269 |
TEST_VM(utilities, json_stars_comment) { |
41335 | 270 |
JSON_GTest::test("/* *foo* */ { }", true); |
271 |
} |
|
272 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
273 |
TEST_VM(utilities, json_special_comment) { |
41335 | 274 |
JSON_GTest::test("/* /*foo */ { }", true); |
275 |
} |
|
276 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
277 |
TEST_VM(utilities, json_comment_after) { |
41335 | 278 |
JSON_GTest::test("{ } /* foo */", true); |
279 |
} |
|
280 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
281 |
TEST_VM(utilities, json_comment_after_and_space) { |
41335 | 282 |
JSON_GTest::test("{ } /* foo */ ", true); |
283 |
} |
|
284 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
285 |
TEST_VM(utilities, json_one_line_empty_comment_after) { |
41335 | 286 |
JSON_GTest::test("{ } //", true); |
287 |
} |
|
288 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
289 |
TEST_VM(utilities, json_one_line_space_comment_after) { |
41335 | 290 |
JSON_GTest::test("{ } // ", true); |
291 |
} |
|
292 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
293 |
TEST_VM(utilities, json_one_line_comment_after) { |
41335 | 294 |
JSON_GTest::test("{ } // foo", true); |
295 |
} |
|
296 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
297 |
TEST_VM(utilities, json_incorrect_multiline_comment) { |
41335 | 298 |
JSON_GTest::test("/* * / { }", false); |
299 |
} |
|
300 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
301 |
TEST_VM(utilities, json_incorrect_multiline_comment_begin) { |
41335 | 302 |
JSON_GTest::test("/ * */ { }", false); |
303 |
} |
|
304 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
305 |
TEST_VM(utilities, json_oneline_comment_only) { |
41335 | 306 |
JSON_GTest::test("// { }", false); |
307 |
} |
|
308 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
309 |
TEST_VM(utilities, json_multiline_comment_only) { |
41335 | 310 |
JSON_GTest::test("/* { } */", false); |
311 |
} |
|
312 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
313 |
TEST_VM(utilities, json_multiline_comment_2) { |
41335 | 314 |
JSON_GTest::test("/* { } */ ", false); |
315 |
} |
|
316 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
317 |
TEST_VM(utilities, json_incorrectly_commented_object) { |
41335 | 318 |
JSON_GTest::test("/* { } ", false); |
319 |
} |
|
320 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
321 |
TEST_VM(utilities, json_missing_multiline_end) { |
41335 | 322 |
JSON_GTest::test("{ } /* ", false); |
323 |
} |
|
324 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
325 |
TEST_VM(utilities, json_missing_multiline_slash) { |
41335 | 326 |
JSON_GTest::test("/* { } *", false); |
327 |
} |
|
328 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
329 |
TEST_VM(utilities, json_commented_object_end) { |
41335 | 330 |
JSON_GTest::test("{ /* } */", false); |
331 |
} |
|
332 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
333 |
TEST_VM(utilities, json_commented_array_end) { |
41335 | 334 |
JSON_GTest::test("[ /* ] */", false); |
335 |
} |
|
336 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
337 |
TEST_VM(utilities, json_missing_object_end) { |
41335 | 338 |
JSON_GTest::test("{ key : \"val\", /* } */", false); |
339 |
} |
|
340 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
341 |
TEST_VM(utilities, json_missing_array_end) { |
41335 | 342 |
JSON_GTest::test("[ \"val\", /* ] */", false); |
343 |
} |
|
344 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
345 |
TEST_VM(utilities, json_key_values_1) { |
41335 | 346 |
JSON_GTest::test("/* comment */{ key1 : { \"key2\" : { \"key3\" : [ \"elem1\", \"elem2\"," |
347 |
"{ \"key4\" : null }, 3 , 2 , 1 , 0 , -1 , -2 , -3 , true, false, null, ] }, \"key5\"" |
|
348 |
" : true }, \"key6\" : [ \"☃\" ], key7 : \"val\",}", true); |
|
349 |
} |
|
350 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
351 |
TEST_VM(utilities, json_key_values_2) { |
41335 | 352 |
JSON_GTest::test("/* comment */ { \"key1\" : { \"key2\" : { \"key3\" : [ \"elem1\", \"elem2\"," |
353 |
"{ \"key4\" : null }, 3 , 2 , 1 , 0 , -1 , -2 , -3 , true, false, null, ] }, \"key5\"" |
|
354 |
" : true }, \"key6\" : [ \"☃\" ], key7 : \"val\",}", true); |
|
355 |
} |
|
356 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
357 |
TEST_VM(utilities, json_quoted_symbols) { |
41335 | 358 |
JSON_GTest::test("/*comment*/{\"ff1 fsd\":{\"☃\":{\"☃\":[\"☃\",\"☃\"]}," |
359 |
"\"☃\":true},\"☃\":[\"☃\"],\"foo\":\"☃\",}", true); |
|
360 |
} |
|
361 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
362 |
TEST_VM(utilities, json_incorrect_key) { |
41335 | 363 |
JSON_GTest::test("/* comment */ { key1 error : { \"☃\" : { \"☃\" : [ \"☃\"," |
364 |
" \"☃\" ] }, \"☃\" : true }, \"baz\" : [ \"☃\" ], foo : \"☃\",}", |
|
365 |
false); // first key needs to be quoted since it contains a space |
|
366 |
} |
|
367 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
368 |
TEST_VM(utilities, json_array_with_newline) { |
41335 | 369 |
JSON_GTest::test("[\n]", true); |
370 |
} |
|
371 |
||
41671
9e0c6db4918a
8166925: several native TESTs should be changed to TEST_VM
iignatyev
parents:
41335
diff
changeset
|
372 |
TEST_VM(utilities, json_directives_file) { |
41335 | 373 |
JSON_GTest::test( |
374 |
"[" "\n" |
|
375 |
" {" |
|
376 |
" // pattern to match against class+method+signature" "\n" |
|
377 |
" // leading and trailing wildcard (*) allowed" "\n" |
|
378 |
" match: \"foo.bar.*\"," "\n" |
|
379 |
" " "\n" |
|
380 |
" // override defaults for specified compiler" "\n" |
|
381 |
" // we may differentiate between levels too. TBD." "\n" |
|
382 |
" c1: {" "\n" |
|
383 |
" //override c1 presets " "\n" |
|
384 |
" array_bounds_check_removal: false" "\n" |
|
385 |
" }," "\n" |
|
386 |
"" "\n" |
|
387 |
" c2: {" "\n" |
|
388 |
" // control inlining of method" "\n" |
|
389 |
" // + force inline, - dont inline" "\n" |
|
390 |
" inline : [ \"+java.util.*\", \"-com.sun.*\"]," "\n" |
|
391 |
" }," "\n" |
|
392 |
"" "\n" |
|
393 |
" // directives outside a specific preset applies to all compilers" "\n" |
|
394 |
" inline : [ \"+java.util.*\", \"-com.sun.*\"]," "\n" |
|
395 |
" print_assembly: true," "\n" |
|
396 |
" verify_oopmaps: true," "\n" |
|
397 |
" max_loop_unrolling: 5" "\n" |
|
398 |
" }," "\n" |
|
399 |
" {" "\n" |
|
400 |
" // matching several patterns require an array" "\n" |
|
401 |
" match: [\"baz.*\",\"frob*\"]," "\n" |
|
402 |
"" "\n" |
|
403 |
" // only enable c1 for this directive" "\n" |
|
404 |
" // all enabled by default. Command disables all not listed" "\n" |
|
405 |
" enable: \"c1\"," "\n" |
|
406 |
"" "\n" |
|
407 |
" // applies to all compilers" "\n" |
|
408 |
" // + force inline, - dont inline" "\n" |
|
409 |
" inline : [ \"+java.util.*\", \"-com.sun.*\"]," "\n" |
|
410 |
" print_inlining: true," "\n" |
|
411 |
"" "\n" |
|
412 |
" // force matching compiles to be blocking/syncronous" "\n" |
|
413 |
" blocking_compile: true" "\n" |
|
414 |
" }," "\n" |
|
415 |
"]" "\n", true); |
|
416 |
} |
|
417 |
||
418 |
void JSON_GTest::log(uint indent, const char* format, ...) { |
|
419 |
if (prev != JSON_KEY) { |
|
420 |
for (uint i = 0; i < indent; i++) { |
|
421 |
_st->print(" "); |
|
422 |
} |
|
423 |
} |
|
424 |
va_list args; |
|
425 |
va_start(args, format); |
|
426 |
_st->vprint(format, args); |
|
427 |
va_end(args); |
|
428 |
} |
|
429 |
||
430 |
bool JSON_GTest::callback(JSON_TYPE t, JSON_VAL* v, uint rlevel) { |
|
431 |
switch (t) { |
|
432 |
case JSON_OBJECT_BEGIN: |
|
433 |
log(rlevel, "{\n"); |
|
434 |
prev = JSON_NONE; // Only care about JSON_KEY, to indent correctly |
|
435 |
return true; |
|
436 |
||
437 |
case JSON_OBJECT_END: |
|
438 |
log(rlevel, "},\n"); |
|
439 |
prev = JSON_NONE; |
|
440 |
return true; |
|
441 |
||
442 |
case JSON_ARRAY_BEGIN: |
|
443 |
log(rlevel, "[\n"); |
|
444 |
prev = JSON_NONE; |
|
445 |
return true; |
|
446 |
||
447 |
case JSON_ARRAY_END: |
|
448 |
log(rlevel, "],\n"); |
|
449 |
prev = JSON_NONE; |
|
450 |
return true; |
|
451 |
||
452 |
case JSON_KEY: |
|
453 |
for (uint i = 0; i < rlevel; i++) { |
|
454 |
_st->print(" "); |
|
455 |
} |
|
456 |
_st->print("<key>"); |
|
457 |
for (size_t i = 0; i < v->str.length; i++) { |
|
458 |
u_char c = v->str.start[i]; |
|
459 |
if (c == 0) { |
|
460 |
return false; |
|
461 |
} |
|
462 |
_st->print("%c", c); |
|
463 |
} |
|
464 |
_st->print(" : "); |
|
465 |
prev = JSON_KEY; |
|
466 |
return true; |
|
467 |
||
468 |
case JSON_STRING: |
|
469 |
if (prev != JSON_KEY) { |
|
470 |
for (uint i = 0; i < rlevel; i++) { |
|
471 |
_st->print(" "); |
|
472 |
} |
|
473 |
} |
|
474 |
_st->print("<str>"); |
|
475 |
for (size_t i = 0; i < v->str.length; i++) { |
|
476 |
u_char c = v->str.start[i]; |
|
477 |
if (c == 0) { |
|
478 |
return false; |
|
479 |
} |
|
480 |
_st->print("%c", c); |
|
481 |
} |
|
482 |
_st->print(",\n"); |
|
483 |
prev = JSON_NONE; |
|
484 |
return true; |
|
485 |
||
486 |
case JSON_NUMBER_INT: |
|
487 |
log(rlevel, "<int>%" PRId64 ",\n", v->int_value); |
|
488 |
prev = JSON_NONE; |
|
489 |
return true; |
|
490 |
||
491 |
case JSON_NUMBER_FLOAT: |
|
492 |
log(rlevel, "<double>%lf,\n", v->double_value); |
|
493 |
prev = JSON_NONE; |
|
494 |
return true; |
|
495 |
||
496 |
case JSON_TRUE: |
|
497 |
log(rlevel, "<true>,\n"); |
|
498 |
prev = JSON_NONE; |
|
499 |
return true; |
|
500 |
||
501 |
case JSON_FALSE: |
|
502 |
log(rlevel, "<false>,\n"); |
|
503 |
prev = JSON_NONE; |
|
504 |
return true; |
|
505 |
||
506 |
case JSON_NULL: |
|
507 |
log(rlevel, "<null>,\n"); |
|
508 |
prev = JSON_NONE; |
|
509 |
return true; |
|
510 |
||
511 |
default: |
|
512 |
error(INTERNAL_ERROR, "unknown JSON type"); |
|
513 |
return false; |
|
514 |
} |
|
515 |
} |