summaryrefslogtreecommitdiff
path: root/test_json.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-08-19 03:14:12 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-08-19 03:14:12 +0000
commit6098283d8394544b97c70f473a9743d0c4527d2f (patch)
tree2b4415bf7a7749087fe8b6777cd08a1ff9adb59d /test_json.c
parent747088bbe5dc34c0902c0bddc492bc4815f4a7c3 (diff)
downloadgpsd-6098283d8394544b97c70f473a9743d0c4527d2f.tar.gz
Library parse code, and unit test, for DEVICE responses.
Diffstat (limited to 'test_json.c')
-rw-r--r--test_json.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/test_json.c b/test_json.c
index 728c1afe..f200a179 100644
--- a/test_json.c
+++ b/test_json.c
@@ -132,6 +132,14 @@ const struct json_array_t json_array_5 = {
.count = &enumcount,
};
+/* Case 6: test DEVICE parsing */
+
+const char *json_str6 = "{\"class\":\"DEVICE\",\
+ \"path\":\"/dev/ttyUSB0\",\
+ \"type\":[\"GPS\",\"AIS\"],\
+ \"driver\":\"Foonly\",\"subtype\":\"Foonly Frob\"\
+ }";
+
int main(int argc UNUSED, char *argv[] UNUSED)
{
int status;
@@ -178,10 +186,18 @@ int main(int argc UNUSED, char *argv[] UNUSED)
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);
+ ASSERT_INTEGER("enumcount", enumcount, 3);
+ ASSERT_INTEGER("enumstore[0]", enumstore[0], 3);
+ ASSERT_INTEGER("enumstore[1]", enumstore[1], 6);
+ ASSERT_INTEGER("enumstore[2]", enumstore[2], 14);
+
+ status = libgps_json_unpack(json_str6, &gpsdata);
+ ASSERT_CASE(6, status);
+ ASSERT_STRING("path", gpsdata.devices.list[0].path, "/dev/ttyUSB0");
+ ASSERT_INTEGER("ndatatypes", gpsdata.devices.list[0].ndatatypes, 2);
+ ASSERT_INTEGER("datatypes[0]",gpsdata.devices.list[0].datatypes[0],DEV_GPS);
+ ASSERT_INTEGER("datatypes[1]",gpsdata.devices.list[0].datatypes[1],DEV_AIS);
+ ASSERT_STRING("driver", gpsdata.devices.list[0].driver, "Foonly");
(void)fprintf(stderr, "succeeded.\n");