summaryrefslogtreecommitdiff
path: root/unittest
diff options
context:
space:
mode:
authorAlexey Botchkov <holyfoot@askmonty.org>2019-01-18 03:18:02 +0400
committerAlexey Botchkov <holyfoot@askmonty.org>2019-01-18 03:18:02 +0400
commitcc18a5db9bce667c9b8722cdf6f51ee83b55a4b0 (patch)
treeeb6aafe6d4bc36cacf68bc3d9955669ddbb37f3b /unittest
parentdd03cb3776e6d25dc1dd2c3a83473a1b78ae99f9 (diff)
downloadmariadb-git-cc18a5db9bce667c9b8722cdf6f51ee83b55a4b0.tar.gz
MDEV-5313 Improving audit API.
json_locate_key() implemented. get rid of 'key_len' argument in functions.
Diffstat (limited to 'unittest')
-rw-r--r--unittest/strings/json-t.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/unittest/strings/json-t.c b/unittest/strings/json-t.c
index 8af8636635e..ce0f04dc030 100644
--- a/unittest/strings/json-t.c
+++ b/unittest/strings/json-t.c
@@ -17,21 +17,29 @@
#include <my_sys.h>
#include <json_lib.h>
+int json_locate_key(const char *js, const char *js_end, const char *kname,
+ const char **key_start, const char **key_end,
+ int *comma_pos);
int main()
{
const char *json="{\"int\":1, \"str\":\"foo bar\", "
"\"array\":[10,20,{\"c\":\"d\"}],\"bool\":false}";
const char *json_ar="[1, \"foo bar\", " "[10,20,{\"c\":\"d\"}], false]";
+ const char *json_w="{\"int\" : 1 , \"str\" : \"foo bar\" , "
+ "\"array\" : [10,20,{\"c\":\"d\"}] , \"bool\" : false }";
+ const char *json_1="{ \"str\" : \"foo bar\" }";
enum json_types value_type;
const char *value_start;
int value_len;
+ const char *key_start, *key_end;
+ int result, comma_pos;
- plan(10);
+ plan(15);
#define do_json(V) \
do { \
value_type= json_get_object_key(json, json+strlen(json), \
- V, V + (sizeof(V) - 1),&value_start, &value_len); \
+ V, &value_start, &value_len); \
ok(value_type != JSV_BAD_JSON, V); \
diag("type=%d, value=\"%.*s\"", value_type, (int)value_len, value_start); \
} while(0)
@@ -42,6 +50,16 @@ int main()
ok(value_type != JSV_BAD_JSON, #N); \
diag("type=%d, value=\"%.*s\"", value_type, (int)value_len, value_start); \
} while(0)
+#define do_json_locate(J, V) \
+ do { \
+ result= json_locate_key(J, J+strlen(J), \
+ V, &key_start, &key_end, &comma_pos); \
+ ok(result == 0, V); \
+ if (key_start) \
+ diag("key_str=\"%.*s\" comma_pos= %d", (int)(key_end - key_start), key_start, comma_pos); \
+ else \
+ diag("no key found"); \
+ } while(0)
do_json("int");
do_json("str");
@@ -54,5 +72,11 @@ int main()
do_json_ar(2);
do_json_ar(3);
do_json_ar(4);
+
+ do_json_locate(json_w, "bool");
+ do_json_locate(json_w, "int");
+ do_json_locate(json_w, "array");
+ do_json_locate(json_1, "str");
+ do_json_locate(json_w, "c");
return exit_status();
}