diff options
author | Gary E. Miller <gem@rellim.com> | 2015-04-02 12:13:49 -0700 |
---|---|---|
committer | Gary E. Miller <gem@rellim.com> | 2015-04-02 12:13:49 -0700 |
commit | ef1b8529ce7a6e53f8f6b2dab785022bfbc28a09 (patch) | |
tree | 6ed85e9dfb620bb3b5fac4aad93ab192cb84112f /test_json.c | |
parent | 52a737ef1057cdbfe6c50591bf186904428ad1d2 (diff) | |
download | gpsd-ef1b8529ce7a6e53f8f6b2dab785022bfbc28a09.tar.gz |
Add a JSON test for the PPS message.
Still need a place for PPS precision.
Diffstat (limited to 'test_json.c')
-rw-r--r-- | test_json.c | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/test_json.c b/test_json.c index d054e273..e710d69c 100644 --- a/test_json.c +++ b/test_json.c @@ -205,39 +205,46 @@ static const struct json_attr_t json_attrs_8[] = { static const char *json_str9 = "{\"parts\":[]}"; +/* Case 10: test parsing of PPS message */ + +static const char *json_strPPS = "{\"class\":\"PPS\",\"device\":\"GPS#1\"," \ + "\"real_sec\":1428001514, \"real_nsec\":1000000," \ + "\"clock_sec\":1428001513,\"clock_nsec\":999999999," \ + "\"precision\":-20}"; + #ifndef JSON_MINIMAL -/* Case 10: Read array of integers */ +/* Case 11: Read array of integers */ -static const char *json_str10 = "[23,-17,5]"; +static const char *json_str11 = "[23,-17,5]"; static int intstore[4], intcount; -static const struct json_array_t json_array_10 = { +static const struct json_array_t json_array_11 = { .element_type = t_integer, .arr.integers.store = intstore, .count = &intcount, .maxlen = sizeof(intstore)/sizeof(intstore[0]), }; -/* Case 11: Read array of booleans */ +/* Case 12: Read array of booleans */ -static const char *json_str11 = "[true,false,true]"; +static const char *json_str12 = "[true,false,true]"; static bool boolstore[4]; static int boolcount; -static const struct json_array_t json_array_11 = { +static const struct json_array_t json_array_12 = { .element_type = t_boolean, .arr.booleans.store = boolstore, .count = &boolcount, .maxlen = sizeof(boolstore)/sizeof(boolstore[0]), }; -/* Case 12: Read array of reals */ +/* Case 13: Read array of reals */ -static const char *json_str12 = "[23.1,-17.2,5.3]"; +static const char *json_str13 = "[23.1,-17.2,5.3]"; static double realstore[4]; static int realcount; -static const struct json_array_t json_array_12 = { +static const struct json_array_t json_array_13 = { .element_type = t_real, .arr.reals.store = realstore, .count = &realcount, @@ -348,11 +355,21 @@ static void jsontest(int i) assert_integer("dumbcount", dumbcount, 0); break; + case 10: + status = json_pps_read(json_strPPS, &gpsdata, NULL); + assert_case(10, status); + assert_string("device", gpsdata.dev.path, "GPS#1"); + assert_integer("real_sec", gpsdata.pps.real.tv_sec, 1428001514); + assert_integer("real_nsec", gpsdata.pps.real.tv_nsec, 1000000); + assert_integer("clock_sec", gpsdata.pps.clock.tv_sec, 1428001513); + assert_integer("clock_nsec", gpsdata.pps.clock.tv_nsec, 999999999); + break; + #ifdef JSON_MINIMAL -#define MAXTEST 9 +#define MAXTEST 10 #else - case 10: - status = json_read_array(json_str10, &json_array_10, NULL); + case 11: + status = json_read_array(json_str11, &json_array_11, NULL); assert_integer("count", intcount, 3); assert_integer("intstore[0]", intstore[0], 23); assert_integer("intstore[1]", intstore[1], -17); @@ -360,8 +377,8 @@ static void jsontest(int i) assert_integer("intstore[3]", intstore[3], 0); break; - case 11: - status = json_read_array(json_str11, &json_array_11, NULL); + case 12: + status = json_read_array(json_str12, &json_array_12, NULL); assert_integer("count", boolcount, 3); assert_boolean("boolstore[0]", boolstore[0], true); assert_boolean("boolstore[1]", boolstore[1], false); @@ -369,8 +386,8 @@ static void jsontest(int i) assert_boolean("boolstore[3]", boolstore[3], false); break; - case 12: - status = json_read_array(json_str12, &json_array_12, NULL); + case 13: + status = json_read_array(json_str13, &json_array_13, NULL); assert_integer("count", realcount, 3); assert_real("realstore[0]", realstore[0], 23.1); assert_real("realstore[1]", realstore[1], -17.2); @@ -378,7 +395,7 @@ static void jsontest(int i) assert_real("realstore[3]", realstore[3], 0); break; -#define MAXTEST 12 +#define MAXTEST 13 #endif /* JSON_MINIMAL */ default: |