diff options
Diffstat (limited to 'test_json.c')
-rw-r--r-- | test_json.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test_json.c b/test_json.c index c0a0263a..728c1afe 100644 --- a/test_json.c +++ b/test_json.c @@ -116,6 +116,22 @@ const struct json_attr_t json_attrs_4[] = { {NULL}, }; +/* Case 5: test parsing arrays of enumerated types */ + +const char *json_str5 = "[\"FOO\",\"BAR\",\"BAZ\"]"; +const struct json_enum_t enum_table[] = {{"BAR", 6}, {"FOO", 3}, {"BAZ", 14}, {NULL}}; + +static int enumstore[256]; +static int enumcount; + +const struct json_array_t json_array_5 = { + .element_type = enumerated, + .arr.enumerated.map = enum_table, + .arr.enumerated.store = enumstore, + .maxlen = sizeof(enumstore)/sizeof(enumstore[0]), + .count = &enumcount, +}; + int main(int argc UNUSED, char *argv[] UNUSED) { int status; @@ -160,6 +176,14 @@ int main(int argc UNUSED, char *argv[] UNUSED) ASSERT_BOOLEAN("flag1", flag1, true); ASSERT_BOOLEAN("flag2", flag2, false); + status = json_read_array(json_str5, &json_array_5, NULL); + ASSERT_CASE(5, status); + assert(enumcount == 3); + assert(enumstore[0] == 3); + assert(enumstore[1] == 6); + assert(enumstore[2] == 14); + (void)fprintf(stderr, "succeeded.\n"); + exit(0); } |