|
| 1 | +package org.json.stream; |
| 2 | + |
| 3 | +import org.json.JSONException; |
| 4 | +import org.json.JSONStrictTokener; |
| 5 | +import org.junit.Test; |
| 6 | + |
| 7 | +import java.io.InputStream; |
| 8 | +import java.nio.charset.Charset; |
| 9 | +import java.nio.charset.StandardCharsets; |
| 10 | + |
| 11 | +/** |
| 12 | + * @author NCULL |
| 13 | + * @version 3/11/2016 4:40 PM. |
| 14 | + */ |
| 15 | +public class JSONTestSuiteUndefined { |
| 16 | + |
| 17 | + public JSONTestSuiteUndefined() { |
| 18 | + } |
| 19 | + |
| 20 | + @Test |
| 21 | + public void i_number_double_huge_neg_exp() throws Exception { |
| 22 | + String filename = "i_number_double_huge_neg_exp.json"; |
| 23 | + |
| 24 | + try { |
| 25 | + runTest(filename, StandardCharsets.UTF_8); |
| 26 | + } catch (JSONException e) { |
| 27 | + // pass |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void i_number_huge_exp() throws Exception { |
| 33 | + String filename = "i_number_huge_exp.json"; |
| 34 | + |
| 35 | + try { |
| 36 | + // number parses as infinity, exception thrown |
| 37 | + runTest(filename, StandardCharsets.UTF_8); |
| 38 | + } catch (JSONException e) { |
| 39 | + // pass |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void i_number_neg_int_huge_exp() throws Exception { |
| 45 | + String filename = "i_number_neg_int_huge_exp.json"; |
| 46 | + |
| 47 | + try { |
| 48 | + // number parses as minus infinity, exception thrown |
| 49 | + runTest(filename, StandardCharsets.UTF_8); |
| 50 | + } catch (JSONException e) { |
| 51 | + // pass |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void i_number_pos_double_huge_exp() throws Exception { |
| 57 | + String filename = "i_number_pos_double_huge_exp.json"; |
| 58 | + |
| 59 | + try { |
| 60 | + // number parses as infinity, exception thrown |
| 61 | + runTest(filename, StandardCharsets.UTF_8); |
| 62 | + } catch (JSONException e) { |
| 63 | + // pass |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + public void i_number_real_neg_overflow() throws Exception { |
| 69 | + String filename = "i_number_real_neg_overflow.json"; |
| 70 | + |
| 71 | + try { |
| 72 | + // number parses as minus infinity, exception thrown |
| 73 | + runTest(filename, StandardCharsets.UTF_8); |
| 74 | + } catch (JSONException e) { |
| 75 | + // pass |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + public void i_number_real_pos_overflow() throws Exception { |
| 81 | + String filename = "i_number_real_pos_overflow.json"; |
| 82 | + |
| 83 | + try { |
| 84 | + // number parses as infinity, exception thrown |
| 85 | + runTest(filename, StandardCharsets.UTF_8); |
| 86 | + } catch (JSONException e) { |
| 87 | + // pass |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + public void i_number_real_underflow() throws Exception { |
| 93 | + String filename = "i_number_real_underflow.json"; |
| 94 | + |
| 95 | + try { |
| 96 | + runTest(filename, StandardCharsets.UTF_8); |
| 97 | + } catch (JSONException e) { |
| 98 | + // pass |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + @Test |
| 103 | + public void i_number_too_big_neg_int() throws Exception { |
| 104 | + String filename = "i_number_too_big_neg_int.json"; |
| 105 | + |
| 106 | + try { |
| 107 | + // NumberFormatException thrown, too big for long value |
| 108 | + runTest(filename, StandardCharsets.UTF_8); |
| 109 | + } catch (JSONException e) { |
| 110 | + // pass |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + @Test |
| 115 | + public void i_number_too_big_pos_int() throws Exception { |
| 116 | + String filename = "i_number_too_big_pos_int.json"; |
| 117 | + |
| 118 | + try { |
| 119 | + // NumberFormatException thrown, too big for long value |
| 120 | + runTest(filename, StandardCharsets.UTF_8); |
| 121 | + } catch (JSONException e) { |
| 122 | + // pass |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + public void i_number_very_big_negative_int() throws Exception { |
| 128 | + String filename = "i_number_very_big_negative_int.json"; |
| 129 | + |
| 130 | + try { |
| 131 | + // NumberFormatException thrown, too big for long value |
| 132 | + runTest(filename, StandardCharsets.UTF_8); |
| 133 | + } catch (JSONException e) { |
| 134 | + // pass |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + @Test |
| 139 | + public void i_object_key_lone_2nd_surrogate() throws Exception { |
| 140 | + String filename = "i_object_key_lone_2nd_surrogate.json"; |
| 141 | + |
| 142 | + try { |
| 143 | + runTest(filename, StandardCharsets.UTF_8); |
| 144 | + } catch (JSONException e) { |
| 145 | + // pass |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + @Test |
| 150 | + public void i_string_1st_surrogate_but_2nd_missing() throws Exception { |
| 151 | + String filename = "i_string_1st_surrogate_but_2nd_missing.json"; |
| 152 | + |
| 153 | + try { |
| 154 | + runTest(filename, StandardCharsets.UTF_8); |
| 155 | + } catch (JSONException e) { |
| 156 | + // pass |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + @Test |
| 161 | + public void i_string_1st_valid_surrogate_2nd_invalid() throws Exception { |
| 162 | + String filename = "i_string_1st_valid_surrogate_2nd_invalid.json"; |
| 163 | + |
| 164 | + try { |
| 165 | + runTest(filename, StandardCharsets.UTF_8); |
| 166 | + } catch (JSONException e) { |
| 167 | + // pass |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + @Test |
| 172 | + public void i_string_incomplete_surrogate_and_escape_valid() throws Exception { |
| 173 | + String filename = "i_string_incomplete_surrogate_and_escape_valid.json"; |
| 174 | + |
| 175 | + try { |
| 176 | + runTest(filename, StandardCharsets.UTF_8); |
| 177 | + } catch (JSONException e) { |
| 178 | + // pass |
| 179 | + } |
| 180 | + } |
| 181 | + |
| 182 | + @Test |
| 183 | + public void i_string_incomplete_surrogate_pair() throws Exception { |
| 184 | + String filename = "i_string_incomplete_surrogate_pair.json"; |
| 185 | + |
| 186 | + try { |
| 187 | + runTest(filename, StandardCharsets.UTF_8); |
| 188 | + } catch (JSONException e) { |
| 189 | + // pass |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + @Test |
| 194 | + public void i_string_incomplete_surrogates_escape_valid() throws Exception { |
| 195 | + String filename = "i_string_incomplete_surrogates_escape_valid.json"; |
| 196 | + |
| 197 | + try { |
| 198 | + runTest(filename, StandardCharsets.UTF_8); |
| 199 | + } catch (JSONException e) { |
| 200 | + // pass |
| 201 | + } |
| 202 | + } |
| 203 | + |
| 204 | + @Test |
| 205 | + public void i_string_invalid_lonely_surrogate() throws Exception { |
| 206 | + String filename = "i_string_invalid_lonely_surrogate.json"; |
| 207 | + |
| 208 | + try { |
| 209 | + runTest(filename, StandardCharsets.UTF_8); |
| 210 | + } catch (JSONException e) { |
| 211 | + // pass |
| 212 | + } |
| 213 | + } |
| 214 | + |
| 215 | + @Test |
| 216 | + public void i_string_invalid_surrogate() throws Exception { |
| 217 | + String filename = "i_string_invalid_surrogate.json"; |
| 218 | + |
| 219 | + try { |
| 220 | + runTest(filename, StandardCharsets.UTF_8); |
| 221 | + } catch (JSONException e) { |
| 222 | + // pass |
| 223 | + } |
| 224 | + } |
| 225 | + |
| 226 | + @Test |
| 227 | + public void i_string_inverted_surrogates_Uplus1D11E() throws Exception { |
| 228 | + String filename = "i_string_inverted_surrogates_U+1D11E.json"; |
| 229 | + |
| 230 | + try { |
| 231 | + runTest(filename, StandardCharsets.UTF_8); |
| 232 | + } catch (JSONException e) { |
| 233 | + // pass |
| 234 | + } |
| 235 | + } |
| 236 | + |
| 237 | + @Test |
| 238 | + public void i_string_lone_second_surrogate() throws Exception { |
| 239 | + String filename = "i_string_lone_second_surrogate.json"; |
| 240 | + |
| 241 | + try { |
| 242 | + runTest(filename, StandardCharsets.UTF_8); |
| 243 | + } catch (JSONException e) { |
| 244 | + // pass |
| 245 | + } |
| 246 | + } |
| 247 | + |
| 248 | + @Test |
| 249 | + public void i_string_not_in_unicode_range() throws Exception { |
| 250 | + String filename = "i_string_not_in_unicode_range.json"; |
| 251 | + |
| 252 | + try { |
| 253 | + runTest(filename, StandardCharsets.UTF_8); |
| 254 | + } catch (JSONException e) { |
| 255 | + // pass |
| 256 | + } |
| 257 | + } |
| 258 | + |
| 259 | + @Test |
| 260 | + public void i_string_truncated_utf8() throws Exception { |
| 261 | + String filename = "i_string_truncated-utf-8.json"; |
| 262 | + |
| 263 | + try { |
| 264 | + runTest(filename, StandardCharsets.UTF_8); |
| 265 | + } catch (JSONException e) { |
| 266 | + // pass |
| 267 | + } |
| 268 | + } |
| 269 | + |
| 270 | + @Test |
| 271 | + public void i_string_unicode_Uplus1FFFE_nonchar() throws Exception { |
| 272 | + String filename = "i_string_unicode_U+1FFFE_nonchar.json"; |
| 273 | + |
| 274 | + try { |
| 275 | + runTest(filename, StandardCharsets.UTF_8); |
| 276 | + } catch (JSONException e) { |
| 277 | + // pass |
| 278 | + } |
| 279 | + } |
| 280 | + |
| 281 | + @Test |
| 282 | + public void i_string_unicode_Uplus10FFFE_nonchar() throws Exception { |
| 283 | + String filename = "i_string_unicode_U+10FFFE_nonchar.json"; |
| 284 | + |
| 285 | + try { |
| 286 | + runTest(filename, StandardCharsets.UTF_8); |
| 287 | + } catch (JSONException e) { |
| 288 | + // pass |
| 289 | + } |
| 290 | + } |
| 291 | + |
| 292 | + @Test |
| 293 | + public void i_string_unicode_UplusFDD0_nonchar() throws Exception { |
| 294 | + String filename = "i_string_unicode_U+FDD0_nonchar.json"; |
| 295 | + |
| 296 | + try { |
| 297 | + runTest(filename, StandardCharsets.UTF_8); |
| 298 | + } catch (JSONException e) { |
| 299 | + // pass |
| 300 | + } |
| 301 | + } |
| 302 | + |
| 303 | + @Test |
| 304 | + public void i_string_unicode_UplusFFFE_nonchar() throws Exception { |
| 305 | + String filename = "i_string_unicode_U+FFFE_nonchar.json"; |
| 306 | + |
| 307 | + try { |
| 308 | + runTest(filename, StandardCharsets.UTF_8); |
| 309 | + } catch (JSONException e) { |
| 310 | + // pass |
| 311 | + } |
| 312 | + } |
| 313 | + |
| 314 | + @Test |
| 315 | + public void i_string_UTF8_invalid_sequence() throws Exception { |
| 316 | + String filename = "i_string_UTF-8_invalid_sequence.json"; |
| 317 | + |
| 318 | + try { |
| 319 | + // UTF-8 decoding swallows close quote, exception thrown |
| 320 | + runTest(filename, StandardCharsets.UTF_8); |
| 321 | + } catch (JSONException e) { |
| 322 | + // pass |
| 323 | + } |
| 324 | + } |
| 325 | + |
| 326 | + @Test |
| 327 | + public void i_string_UTF16LE_with_BOM() throws Exception { |
| 328 | + String filename = "i_string_UTF-16LE_with_BOM.json"; |
| 329 | + |
| 330 | + try { |
| 331 | + // Byte order mark found, exception thrown |
| 332 | + runTest(filename, StandardCharsets.UTF_16LE); |
| 333 | + } catch (JSONException e) { |
| 334 | + // pass |
| 335 | + } |
| 336 | + } |
| 337 | + |
| 338 | + @Test |
| 339 | + public void i_structure_500_nested_arrays() throws Exception { |
| 340 | + String filename = "i_structure_500_nested_arrays.json"; |
| 341 | + |
| 342 | + try { |
| 343 | + runTest(filename, StandardCharsets.UTF_8); |
| 344 | + } catch (JSONException e) { |
| 345 | + // pass |
| 346 | + } |
| 347 | + } |
| 348 | + |
| 349 | + @Test |
| 350 | + public void i_structure_UTF8_BOM_empty_object() throws Exception { |
| 351 | + String filename = "i_structure_UTF-8_BOM_empty_object.json"; |
| 352 | + |
| 353 | + try { |
| 354 | + // Byte order mark found, exception thrown |
| 355 | + runTest(filename, StandardCharsets.UTF_8); |
| 356 | + } catch (JSONException e) { |
| 357 | + // pass |
| 358 | + } |
| 359 | + } |
| 360 | + |
| 361 | + private Object runTest(String filename, Charset encoding) throws Exception { |
| 362 | + |
| 363 | + try (InputStream inputStream = this.getClass().getResourceAsStream("/" + filename)) { |
| 364 | + Object result = JSONStrictTokener.parseJSONValue(inputStream, encoding); |
| 365 | + System.out.println(result); |
| 366 | + return result; |
| 367 | + } |
| 368 | + } |
| 369 | +} |
0 commit comments