diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2009-08-28 10:24:13 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2009-08-28 10:24:13 +0000 |
commit | 4769babfa5a2cad6666eb5d44e8ad109a5528d25 (patch) | |
tree | 9f6665a61592f84f5b8f68603ded5486f6833720 /test_json.c | |
parent | 511cfba4940624602c4ea5fbb622c7989d8acc2e (diff) | |
download | gpsd-4769babfa5a2cad6666eb5d44e8ad109a5528d25.tar.gz |
Allow mapping of strings to enumerated values in JSON.
Diffstat (limited to 'test_json.c')
-rw-r--r-- | test_json.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/test_json.c b/test_json.c index 82b78175..c0aeac10 100644 --- a/test_json.c +++ b/test_json.c @@ -109,7 +109,7 @@ static const char *json_str4 = "{\"flag1\":true,\"flag2\":false}"; static bool flag1, flag2; static double dftreal; static int dftinteger; -static int dftuinteger; +static unsigned int dftuinteger; static const struct json_attr_t json_attrs_4[] = { {"dftint", integer, .addr.integer = &dftinteger, .dflt.integer = -5}, @@ -168,6 +168,21 @@ static const char *json_str7 = "{\"class\":\"VERSION\",\ \"release\":\"2.40dev\",\"rev\":\"dummy-revision\",\ \"api_major\":3,\"api_minor\":1}"; +/* Case 8: test parsing arrays of enumerated types */ + +const char *json_str8 = "{\"fee\":\"FOO\",\"fie\":\"BAR\",\"foe\":\"BAZ\"}"; +const struct json_enum_t enum_table[] = { + {"BAR", 6}, {"FOO", 3}, {"BAZ", 14}, {NULL} +}; + +static int fee, fie, foe; +static const struct json_attr_t json_attrs_8[] = { + {"fee", integer, .addr.integer = &fee, .map=enum_table}, + {"fie", integer, .addr.integer = &fie, .map=enum_table}, + {"foe", integer, .addr.integer = &foe, .map=enum_table}, + {NULL}, +}; + #endif /* GPSDNG_ENABLE */ int main(int argc UNUSED, char *argv[] UNUSED) @@ -244,6 +259,13 @@ int main(int argc UNUSED, char *argv[] UNUSED) assert_string("rev", gpsdata.version.rev, "dummy-revision"); assert_integer("api_major", gpsdata.version.api_major, 3); assert_integer("api_minor", gpsdata.version.api_minor, 1); + + status = json_read_object(json_str8, json_attrs_8, NULL); + assert_case(8, status); + assert_integer("fee", fee, 3); + assert_integer("fie", fie, 6); + assert_integer("foe", foe, 14); + #endif /* GPSDNG_ENABLE */ (void)fprintf(stderr, "succeeded.\n"); |