8156852: Convert JSON_test to Gtest
authorppunegov
Wed, 17 Aug 2016 18:48:34 +0300
changeset 41335 27115e2e42cc
parent 41334 8b28be7b8613
child 41336 b1fe5872f8f0
8156852: Convert JSON_test to Gtest Summary: convert test from InternalVMTests to Gtest Reviewed-by: kvn, kzhaldyb
hotspot/src/share/vm/utilities/internalVMTests.cpp
hotspot/src/share/vm/utilities/json.cpp
hotspot/test/native/utilities/test_json.cpp
--- a/hotspot/src/share/vm/utilities/internalVMTests.cpp	Thu Sep 22 12:17:24 2016 +0200
+++ b/hotspot/src/share/vm/utilities/internalVMTests.cpp	Wed Aug 17 18:48:34 2016 +0300
@@ -64,7 +64,6 @@
   run_unit_test(ObjectMonitor_test);
   run_unit_test(Test_linked_list);
   run_unit_test(TestChunkedList_test);
-  run_unit_test(JSON_test);
   run_unit_test(Test_log_tag_combinations_limit);
   run_unit_test(Test_logtarget);
   run_unit_test(Test_logstream);
--- a/hotspot/src/share/vm/utilities/json.cpp	Thu Sep 22 12:17:24 2016 +0200
+++ b/hotspot/src/share/vm/utilities/json.cpp	Wed Aug 17 18:48:34 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -686,286 +686,3 @@
   }
 }
 
-#ifndef PRODUCT
-class JSONTest : public JSON {
- public:
-  static void test();
-
- private:
-  JSONTest(const char* text);
-  static void test(const char* json, bool valid);
-
-  void log(uint level, const char* format, ...) ATTRIBUTE_PRINTF(3, 4);
-
-  bool callback(JSON_TYPE t, JSON_VAL* v, uint level);
-  JSON_TYPE prev;
-};
-
-void JSON_test() {
-  JSONTest::test();
-}
-
-void JSONTest::test(const char* text, bool should_pass) {
-  JSONTest json(text);
-  if (should_pass) {
-    assert(json.valid() == true, "failed on a valid json string");
-    if (VerboseInternalVMTests) {
-      tty->print_cr("-- json test passed as expected --");
-    }
-  } else {
-    assert(json.valid() == false, "succeeded on an invalid json string");
-    if (VerboseInternalVMTests) {
-      tty->print_cr("-- json test failed as expected --");
-    }
-  }
-}
-
-JSONTest::JSONTest(const char* text) : JSON(text, !VerboseInternalVMTests, tty) {
-  prev = JSON_NONE;
-  parse();
-}
-
-void JSONTest::test() {
-  JSONTest::test("{}", true);
-  JSONTest::test("[]", true);
-  JSONTest::test("  {  }  ", true);
-  JSONTest::test("  [  ]  ", true);
-
-  JSONTest::test("\"error\"", false);
-  JSONTest::test("error", false);
-  JSONTest::test("1", false);
-  JSONTest::test("1.2", false);
-  JSONTest::test("true", false);
-  JSONTest::test("false", false);
-  JSONTest::test("null", false);
-
-  JSONTest::test("[ 1 ]", true);
-  JSONTest::test("[ 1, ]", true);
-  JSONTest::test("[ true ]", true);
-  JSONTest::test("[ true, ]", true);
-  JSONTest::test("[ false ]", true);
-  JSONTest::test("[ false, ]", true);
-  JSONTest::test("[ null ]", true);
-  JSONTest::test("[ null, ]", true);
-  JSONTest::test("[ \"\" ]", true);
-  JSONTest::test("[ \"\", ]", true);
-  JSONTest::test("[ \"elem1\" ]", true);
-  JSONTest::test("[ \"elem1\", ]", true);
-  JSONTest::test("[ \"elem1\", ]", true);
-  JSONTest::test("[ \"elem1\" ]", true);
-  JSONTest::test("[ \"elem1\", \"elem2\" ]", true);
-  JSONTest::test("[ \"elem1\", \"elem2\", ]", true);
-
-
-  JSONTest::test("[ \"elem1\" ] { }", false);
-  JSONTest::test("[ elem1, \"elem2\" ]", false);
-  JSONTest::test("[ \"elem1\"", false);
-  JSONTest::test("[ \"elem1 ]", false);
-  JSONTest::test("[ \"elem1\", \"elem2\"", false);
-  JSONTest::test("[ truefoo ]", false);
-  JSONTest::test("[ falsefoo ]", false);
-  JSONTest::test("[ nullfoo ]", false);
-
-  JSONTest::test("{ key : 1 }", true);
-  JSONTest::test("{ key : 1, }", true);
-  JSONTest::test("{ key : true }", true);
-  JSONTest::test("{ key : true, }", true);
-  JSONTest::test("{ key : false }", true);
-  JSONTest::test("{ key : false, }", true);
-  JSONTest::test("{ key : null }", true);
-  JSONTest::test("{ key : null, }", true);
-  JSONTest::test("{ \"\" : \"\" }", true);
-  JSONTest::test("{ \"\" : \"\", }", true);
-  JSONTest::test("{ \"key1\" : \"val1\" }", true);
-  JSONTest::test("{ \"key1\" : \"val1\", }", true);
-  JSONTest::test("{ \"key1\" : \"val1\", \"key2\" : \"val2\" }", true);
-  JSONTest::test("{ \"key1\" : \"val1\", \"key2\" : \"val2\", }", true);
-
-  JSONTest::test("{ \"key\" : \"val\" } [ \"error\" ]", false);
-  JSONTest::test("{ \"key\" : \"val\" ", false);
-
-  JSONTest::test("/**/ { }", true);
-  JSONTest::test("/* */ { }", true);
-  JSONTest::test("/*foo*/ { }", true);
-  JSONTest::test("/* *foo */ { }", true);
-  JSONTest::test("/* *foo* */ { }", true);
-  JSONTest::test("/* /*foo */ { }", true);
-  JSONTest::test("{ } /* foo */", true);
-  JSONTest::test("{ } /* foo */ ", true);
-  JSONTest::test("{ } //", true);
-  JSONTest::test("{ } // ", true);
-  JSONTest::test("{ } // foo", true);
-
-  JSONTest::test("/* * / { }", false);
-  JSONTest::test("/ * */ { }", false);
-  JSONTest::test("// { }", false);
-  JSONTest::test("/* { } */", false);
-  JSONTest::test("/* { } */ ", false);
-  JSONTest::test("/* { } ", false);
-  JSONTest::test("{ } /* ", false);
-  JSONTest::test("/* { } *", false);
-  JSONTest::test("{ /* } */", false);
-  JSONTest::test("[ /* ] */", false);
-  JSONTest::test("{ key : \"val\", /* } */", false);
-  JSONTest::test("[ \"val\", /* ] */", false);
-
-  JSONTest::test("/* comment */{ key1 : { \"key2\" : { \"key3\" : [ \"elem1\", \"elem2\", { \"key4\" : null }, 3 , 2 , 1 , 0 , -1 , -2 , -3 , true, false, null, ] }, \"key5\" : true }, \"key6\" : [ \"☃\" ], key7 : \"val\",}", true);
-  JSONTest::test("/* comment */ { \"key1\" : { \"key2\" : { \"key3\" : [ \"elem1\", \"elem2\", { \"key4\" : null }, 3 , 2 , 1 , 0 , -1 , -2 , -3 , true, false, null, ] }, \"key5\" : true }, \"key6\" : [ \"☃\" ], key7 : \"val\",}", true);
-  JSONTest::test("/*comment*/{\"ff1 fsd\":{\"☃\":{\"☃\":[\"☃\",\"☃\"]},\"☃\":true},\"☃\":[\"☃\"],\"foo\":\"☃\",}", true);
-  JSONTest::test("/* comment */ { key1 error : { \"☃\" : { \"☃\" : [ \"☃\", \"☃\" ] }, \"☃\" : true }, \"baz\" : [ \"☃\" ], foo : \"☃\",}", false); // first key needs to be quoted since it contains a space
-
-
-  JSONTest::test("[\n]", true);
-
-  JSONTest::test(
-      "[" "\n"
-      "   {"
-      "         // pattern to match against class+method+signature" "\n"
-      "         // leading and trailing wildcard (*) allowed" "\n"
-      "         match: \"foo.bar.*\"," "\n"
-      " " "\n"
-      "         // override defaults for specified compiler" "\n"
-      "         // we may differentiate between levels too. TBD." "\n"
-      "         c1:  {" "\n"
-      "           //override c1 presets " "\n"
-      "           array_bounds_check_removal: false" "\n"
-      "         }," "\n"
-      "" "\n"
-      "         c2: {" "\n"
-      "           // control inlining of method" "\n"
-      "           // + force inline, - dont inline" "\n"
-      "           inline : [ \"+java.util.*\", \"-com.sun.*\"]," "\n"
-      "         }," "\n"
-      "" "\n"
-      "         // directives outside a specific preset applies to all compilers" "\n"
-      "         inline : [ \"+java.util.*\", \"-com.sun.*\"]," "\n"
-      "         print_assembly: true," "\n"
-      "         verify_oopmaps: true," "\n"
-      "         max_loop_unrolling: 5" "\n"
-      "   }," "\n"
-      "   {" "\n"
-      "         // matching several patterns require an array" "\n"
-      "         match: [\"baz.*\",\"frob*\"]," "\n"
-      "" "\n"
-      "         // only enable c1 for this directive" "\n"
-      "         // all enabled by default. Command disables all not listed" "\n"
-      "         enable: \"c1\"," "\n"
-      "" "\n"
-      "         // applies to all compilers" "\n"
-      "         // + force inline, - dont inline" "\n"
-      "         inline : [ \"+java.util.*\", \"-com.sun.*\"]," "\n"
-      "         print_inlining: true," "\n"
-      "" "\n"
-      "         // force matching compiles to be blocking/syncronous" "\n"
-      "         blocking_compile: true" "\n"
-      "   }," "\n"
-      "]" "\n", true);
-}
-
-void JSONTest::log(uint indent, const char* format, ...) {
-  if (VerboseInternalVMTests) {
-    if (prev != JSON_KEY) {
-      for (uint i = 0; i < indent; i++) {
-        _st->print("  ");
-      }
-    }
-    va_list args;
-    va_start(args, format);
-    _st->vprint(format, args);
-    va_end(args);
-  }
-}
-
-bool JSONTest::callback(JSON_TYPE t, JSON_VAL* v, uint rlevel) {
-  switch (t) {
-  case JSON_OBJECT_BEGIN:
-    log(rlevel, "{\n");
-    prev = JSON_NONE; // Only care about JSON_KEY, to indent correctly
-    return true;
-
-  case JSON_OBJECT_END:
-    log(rlevel, "},\n");
-    prev = JSON_NONE;
-    return true;
-
-  case JSON_ARRAY_BEGIN:
-    log(rlevel, "[\n");
-    prev = JSON_NONE;
-    return true;
-
-  case JSON_ARRAY_END:
-    log(rlevel, "],\n");
-    prev = JSON_NONE;
-    return true;
-
-  case JSON_KEY:
-    if (VerboseInternalVMTests) {
-      for (uint i = 0; i < rlevel; i++) {
-        _st->print("  ");
-      }
-      _st->print("<key>");
-      for (size_t i = 0; i < v->str.length; i++) {
-        u_char c = v->str.start[i];
-        assert(c != 0, "string overrun");
-        if (c == 0) {
-          return false;
-        }
-        _st->print("%c", c);
-      }
-      _st->print(" : ");
-    }
-    prev = JSON_KEY;
-    return true;
-
-  case JSON_STRING:
-    if (VerboseInternalVMTests) {
-      if (prev != JSON_KEY) {
-        for (uint i = 0; i < rlevel; i++) {
-          _st->print("  ");
-        }
-      }
-      _st->print("<str>");
-      for (size_t i = 0; i < v->str.length; i++) {
-        u_char c = v->str.start[i];
-        assert(c != 0, "string overrun");
-        if (c == 0) {
-          return false;
-        }
-        _st->print("%c", c);
-      }
-      _st->print(",\n");
-    }
-    prev = JSON_NONE;
-    return true;
-
-  case JSON_NUMBER_INT:
-    log(rlevel, "<int>%" PRId64 ",\n", v->int_value);
-    prev = JSON_NONE;
-    return true;
-
-  case JSON_NUMBER_FLOAT:
-    log(rlevel, "<double>%lf,\n", v->double_value);
-    prev = JSON_NONE;
-    return true;
-
-  case JSON_TRUE:
-    log(rlevel, "<true>,\n");
-    prev = JSON_NONE;
-    return true;
-
-  case JSON_FALSE:
-    log(rlevel, "<false>,\n");
-    prev = JSON_NONE;
-    return true;
-
-  case JSON_NULL:
-    log(rlevel, "<null>,\n");
-    prev = JSON_NONE;
-    return true;
-
-  default:
-    error(INTERNAL_ERROR, "unknown JSON type");
-    return false;
-  }
-}
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/native/utilities/test_json.cpp	Wed Aug 17 18:48:34 2016 +0300
@@ -0,0 +1,515 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+#include "precompiled.hpp"
+#include "prims/jvm.h"
+#include "utilities/json.hpp"
+#include "unittest.hpp"
+
+class JSON_GTest : public JSON {
+public:
+    static void test(const char* json, bool valid);
+
+private:
+    JSON_GTest(const char* text);
+
+    void log(uint level, const char* format, ...) ATTRIBUTE_PRINTF(3, 4);
+
+    bool callback(JSON_TYPE t, JSON_VAL* v, uint level);
+    JSON_TYPE prev;
+};
+
+void JSON_GTest::test(const char* text, bool should_pass) {
+    JSON_GTest json(text);
+    if (should_pass) {
+        ASSERT_TRUE(json.valid()) << "failed on a valid json string";
+    } else {
+        ASSERT_FALSE(json.valid()) << "succeeded on an invalid json string";
+    }
+}
+
+JSON_GTest::JSON_GTest(const char* text) : JSON(text, false, tty) {
+    prev = JSON_NONE;
+    parse();
+}
+
+TEST(utilities, json_curly_braces) {
+    JSON_GTest::test("{}", true);
+}
+
+TEST(utilities, json_brackets) {
+    JSON_GTest::test("[]", true);
+}
+
+TEST(utilities, json_space_braces) {
+    JSON_GTest::test("  {  }  ", true);
+}
+
+TEST(utilities, json_space_bracketes) {
+    JSON_GTest::test("  [  ]  ", true);
+}
+
+TEST(utilities, json_quoted_error) {
+    JSON_GTest::test("\"error\"", false);
+}
+
+TEST(utilities, json_error_string) {
+    JSON_GTest::test("error", false);
+}
+
+TEST(utilities, json_simple_integer) {
+    JSON_GTest::test("1", false);
+}
+
+TEST(utilities, json_siple_float) {
+    JSON_GTest::test("1.2", false);
+}
+
+TEST(utilities, json_simple_boolean_true) {
+    JSON_GTest::test("true", false);
+}
+
+TEST(utilities, json_simple_boolean_false) {
+    JSON_GTest::test("false", false);
+}
+
+TEST(utilities, json_simple_null) {
+    JSON_GTest::test("null", false);
+}
+
+TEST(utilities, json_one_element_int_array) {
+    JSON_GTest::test("[ 1 ]", true);
+}
+
+TEST(utilities, json_int_array) {
+    JSON_GTest::test("[ 1, ]", true);
+}
+
+TEST(utilities, json_one_element_bool_array) {
+    JSON_GTest::test("[ true ]", true);
+}
+
+TEST(utilities, json_bool_array) {
+    JSON_GTest::test("[ true, ]", true);
+}
+
+TEST(utilities, json_one_element_false_array) {
+    JSON_GTest::test("[ false ]", true);
+}
+
+TEST(utilities, json_false_bool_array) {
+    JSON_GTest::test("[ false, ]", true);
+}
+
+TEST(utilities, json_one_null_array) {
+    JSON_GTest::test("[ null ]", true);
+}
+
+TEST(utilities, json_null_array) {
+    JSON_GTest::test("[ null, ]", true);
+}
+
+TEST(utilities, json_one_empty_string_array) {
+    JSON_GTest::test("[ \"\" ]", true);
+}
+
+TEST(utilities, json_empty_string_array) {
+    JSON_GTest::test("[ \"\", ]", true);
+}
+
+TEST(utilities, json_single_string_array) {
+    JSON_GTest::test("[ \"elem1\" ]", true);
+}
+
+TEST(utilities, json_string_comma_arrray) {
+    JSON_GTest::test("[ \"elem1\", ]", true);
+}
+
+TEST(utilities, json_two_strings_array) {
+    JSON_GTest::test("[ \"elem1\", \"elem2\" ]", true);
+}
+
+TEST(utilities, json_two_strings_comma_array) {
+    JSON_GTest::test("[ \"elem1\", \"elem2\", ]", true);
+}
+
+TEST(utilities, json_curly_braces_outside) {
+    JSON_GTest::test("[ \"elem1\" ] { }", false);
+}
+
+TEST(utilities, json_element_in_array) {
+    JSON_GTest::test("[ elem1, \"elem2\" ]", false);
+}
+
+TEST(utilities, json_incorrect_end_array) {
+    JSON_GTest::test("[ \"elem1\"", false);
+}
+
+TEST(utilities, json_incorrect_string_end) {
+    JSON_GTest::test("[ \"elem1 ]", false);
+}
+
+TEST(utilities, json_incorrect_end_of_two_elements_array) {
+    JSON_GTest::test("[ \"elem1\", \"elem2\"", false);
+}
+
+TEST(utilities, json_incorrect_bool_true_array) {
+    JSON_GTest::test("[ truefoo ]", false);
+}
+
+TEST(utilities, json_incorrect_bool_false_array) {
+    JSON_GTest::test("[ falsefoo ]", false);
+}
+
+TEST(utilities, json_incorrect_null_array) {
+    JSON_GTest::test("[ nullfoo ]", false);
+}
+
+TEST(utilities, json_key_pair) {
+    JSON_GTest::test("{ key : 1 }", true);
+}
+
+TEST(utilities, json_key_pair_comma) {
+    JSON_GTest::test("{ key : 1, }", true);
+}
+
+TEST(utilities, json_bool_true_key) {
+    JSON_GTest::test("{ key : true }", true);
+}
+
+TEST(utilities, json_bool_true_key_comma) {
+    JSON_GTest::test("{ key : true, }", true);
+}
+
+TEST(utilities, json_bool_false_key) {
+    JSON_GTest::test("{ key : false }", true);
+}
+
+TEST(utilities, json_bool_false_key_comma) {
+    JSON_GTest::test("{ key : false, }", true);
+}
+
+TEST(utilities, json_null_key) {
+    JSON_GTest::test("{ key : null }", true);
+}
+
+TEST(utilities, json_null_key_comma) {
+    JSON_GTest::test("{ key : null, }", true);
+}
+
+TEST(utilities, json_pair_of_empty_strings) {
+    JSON_GTest::test("{ \"\" : \"\" }", true);
+}
+
+TEST(utilities, json_pair_of_empty_strings_comma) {
+    JSON_GTest::test("{ \"\" : \"\", }", true);
+}
+
+TEST(utilities, json_pair_of_strings) {
+    JSON_GTest::test("{ \"key1\" : \"val1\" }", true);
+}
+
+TEST(utilities, json_pair_of_strings_comma) {
+    JSON_GTest::test("{ \"key1\" : \"val1\", }", true);
+}
+
+TEST(utilities, json_two_pairs_of_strings) {
+    JSON_GTest::test("{ \"key1\" : \"val1\", \"key2\" : \"val2\" }", true);
+}
+
+TEST(utilities, json_two_pairs_of_strings_comma) {
+    JSON_GTest::test("{ \"key1\" : \"val1\", \"key2\" : \"val2\", }", true);
+}
+
+TEST(utilities, json_array_outside) {
+    JSON_GTest::test("{ \"key\" : \"val\" } [ \"error\" ]", false);
+}
+
+TEST(utilities, json_incorrect_object_end) {
+    JSON_GTest::test("{ \"key\" : \"val\" ", false);
+}
+
+TEST(utilities, json_empty_comment) {
+    JSON_GTest::test("/**/ { }", true);
+}
+
+TEST(utilities, json_space_comment) {
+    JSON_GTest::test("/* */ { }", true);
+}
+
+TEST(utilities, json_comment) {
+    JSON_GTest::test("/*foo*/ { }", true);
+}
+
+TEST(utilities, json_star_comment) {
+    JSON_GTest::test("/* *foo */ { }", true);
+}
+
+TEST(utilities, json_stars_comment) {
+    JSON_GTest::test("/* *foo* */ { }", true);
+}
+
+TEST(utilities, json_special_comment) {
+    JSON_GTest::test("/* /*foo */ { }", true);
+}
+
+TEST(utilities, json_comment_after) {
+    JSON_GTest::test("{ } /* foo */", true);
+}
+
+TEST(utilities, json_comment_after_and_space) {
+    JSON_GTest::test("{ } /* foo */ ", true);
+}
+
+TEST(utilities, json_one_line_empty_comment_after) {
+    JSON_GTest::test("{ } //", true);
+}
+
+TEST(utilities, json_one_line_space_comment_after) {
+    JSON_GTest::test("{ } // ", true);
+}
+
+TEST(utilities, json_one_line_comment_after) {
+    JSON_GTest::test("{ } // foo", true);
+}
+
+TEST(utilities, json_incorrect_multiline_comment) {
+    JSON_GTest::test("/* * / { }", false);
+}
+
+TEST(utilities, json_incorrect_multiline_comment_begin) {
+    JSON_GTest::test("/ * */ { }", false);
+}
+
+TEST(utilities, json_oneline_comment_only) {
+    JSON_GTest::test("// { }", false);
+}
+
+TEST(utilities, json_multiline_comment_only) {
+    JSON_GTest::test("/* { } */", false);
+}
+
+TEST(utilities, json_multiline_comment_2) {
+    JSON_GTest::test("/* { } */ ", false);
+}
+
+TEST(utilities, json_incorrectly_commented_object) {
+    JSON_GTest::test("/* { } ", false);
+}
+
+TEST(utilities, json_missing_multiline_end) {
+    JSON_GTest::test("{ } /* ", false);
+}
+
+TEST(utilities, json_missing_multiline_slash) {
+    JSON_GTest::test("/* { } *", false);
+}
+
+TEST(utilities, json_commented_object_end) {
+    JSON_GTest::test("{ /* } */", false);
+}
+
+TEST(utilities, json_commented_array_end) {
+    JSON_GTest::test("[ /* ] */", false);
+}
+
+TEST(utilities, json_missing_object_end) {
+    JSON_GTest::test("{ key : \"val\", /* } */", false);
+}
+
+TEST(utilities, json_missing_array_end) {
+    JSON_GTest::test("[ \"val\", /* ] */", false);
+}
+
+TEST(utilities, json_key_values_1) {
+    JSON_GTest::test("/* comment */{ key1 : { \"key2\" : { \"key3\" : [ \"elem1\", \"elem2\","
+            "{ \"key4\" : null }, 3 , 2 , 1 , 0 , -1 , -2 , -3 , true, false, null, ] }, \"key5\""
+            " : true }, \"key6\" : [ \"☃\" ], key7 : \"val\",}", true);
+}
+
+TEST(utilities, json_key_values_2) {
+    JSON_GTest::test("/* comment */ { \"key1\" : { \"key2\" : { \"key3\" : [ \"elem1\", \"elem2\","
+            "{ \"key4\" : null }, 3 , 2 , 1 , 0 , -1 , -2 , -3 , true, false, null, ] }, \"key5\""
+            " : true }, \"key6\" : [ \"☃\" ], key7 : \"val\",}", true);
+}
+
+TEST(utilities, json_quoted_symbols) {
+    JSON_GTest::test("/*comment*/{\"ff1 fsd\":{\"☃\":{\"☃\":[\"☃\",\"☃\"]},"
+            "\"☃\":true},\"☃\":[\"☃\"],\"foo\":\"☃\",}", true);
+}
+
+TEST(utilities, json_incorrect_key) {
+    JSON_GTest::test("/* comment */ { key1 error : { \"☃\" : { \"☃\" : [ \"☃\","
+            " \"☃\" ] }, \"☃\" : true }, \"baz\" : [ \"☃\" ], foo : \"☃\",}",
+            false); // first key needs to be quoted since it contains a space
+}
+
+TEST(utilities, json_array_with_newline) {
+    JSON_GTest::test("[\n]", true);
+}
+
+TEST(utilities, json_directives_file) {
+    JSON_GTest::test(
+            "[" "\n"
+            "   {"
+            "         // pattern to match against class+method+signature" "\n"
+            "         // leading and trailing wildcard (*) allowed" "\n"
+            "         match: \"foo.bar.*\"," "\n"
+            " " "\n"
+            "         // override defaults for specified compiler" "\n"
+            "         // we may differentiate between levels too. TBD." "\n"
+            "         c1:  {" "\n"
+            "           //override c1 presets " "\n"
+            "           array_bounds_check_removal: false" "\n"
+            "         }," "\n"
+            "" "\n"
+            "         c2: {" "\n"
+            "           // control inlining of method" "\n"
+            "           // + force inline, - dont inline" "\n"
+            "           inline : [ \"+java.util.*\", \"-com.sun.*\"]," "\n"
+            "         }," "\n"
+            "" "\n"
+            "         // directives outside a specific preset applies to all compilers" "\n"
+            "         inline : [ \"+java.util.*\", \"-com.sun.*\"]," "\n"
+            "         print_assembly: true," "\n"
+            "         verify_oopmaps: true," "\n"
+            "         max_loop_unrolling: 5" "\n"
+            "   }," "\n"
+            "   {" "\n"
+            "         // matching several patterns require an array" "\n"
+            "         match: [\"baz.*\",\"frob*\"]," "\n"
+            "" "\n"
+            "         // only enable c1 for this directive" "\n"
+            "         // all enabled by default. Command disables all not listed" "\n"
+            "         enable: \"c1\"," "\n"
+            "" "\n"
+            "         // applies to all compilers" "\n"
+            "         // + force inline, - dont inline" "\n"
+            "         inline : [ \"+java.util.*\", \"-com.sun.*\"]," "\n"
+            "         print_inlining: true," "\n"
+            "" "\n"
+            "         // force matching compiles to be blocking/syncronous" "\n"
+            "         blocking_compile: true" "\n"
+            "   }," "\n"
+            "]" "\n", true);
+}
+
+void JSON_GTest::log(uint indent, const char* format, ...) {
+    if (prev != JSON_KEY) {
+        for (uint i = 0; i < indent; i++) {
+            _st->print("  ");
+        }
+    }
+    va_list args;
+    va_start(args, format);
+    _st->vprint(format, args);
+    va_end(args);
+}
+
+bool JSON_GTest::callback(JSON_TYPE t, JSON_VAL* v, uint rlevel) {
+    switch (t) {
+        case JSON_OBJECT_BEGIN:
+            log(rlevel, "{\n");
+            prev = JSON_NONE; // Only care about JSON_KEY, to indent correctly
+            return true;
+
+        case JSON_OBJECT_END:
+            log(rlevel, "},\n");
+            prev = JSON_NONE;
+            return true;
+
+        case JSON_ARRAY_BEGIN:
+            log(rlevel, "[\n");
+            prev = JSON_NONE;
+            return true;
+
+        case JSON_ARRAY_END:
+            log(rlevel, "],\n");
+            prev = JSON_NONE;
+            return true;
+
+        case JSON_KEY:
+            for (uint i = 0; i < rlevel; i++) {
+                _st->print("  ");
+            }
+            _st->print("<key>");
+            for (size_t i = 0; i < v->str.length; i++) {
+                u_char c = v->str.start[i];
+                if (c == 0) {
+                    return false;
+                }
+                _st->print("%c", c);
+            }
+            _st->print(" : ");
+            prev = JSON_KEY;
+            return true;
+
+        case JSON_STRING:
+            if (prev != JSON_KEY) {
+                for (uint i = 0; i < rlevel; i++) {
+                    _st->print("  ");
+                }
+            }
+            _st->print("<str>");
+            for (size_t i = 0; i < v->str.length; i++) {
+                u_char c = v->str.start[i];
+                if (c == 0) {
+                    return false;
+                }
+                _st->print("%c", c);
+            }
+            _st->print(",\n");
+            prev = JSON_NONE;
+            return true;
+
+        case JSON_NUMBER_INT:
+            log(rlevel, "<int>%" PRId64 ",\n", v->int_value);
+            prev = JSON_NONE;
+            return true;
+
+        case JSON_NUMBER_FLOAT:
+            log(rlevel, "<double>%lf,\n", v->double_value);
+            prev = JSON_NONE;
+            return true;
+
+        case JSON_TRUE:
+            log(rlevel, "<true>,\n");
+            prev = JSON_NONE;
+            return true;
+
+        case JSON_FALSE:
+            log(rlevel, "<false>,\n");
+            prev = JSON_NONE;
+            return true;
+
+        case JSON_NULL:
+            log(rlevel, "<null>,\n");
+            prev = JSON_NONE;
+            return true;
+
+        default:
+            error(INTERNAL_ERROR, "unknown JSON type");
+            return false;
+    }
+}