diff options
author | Ivan Zhakov <ivan@apache.org> | 2019-05-27 17:23:43 +0000 |
---|---|---|
committer | Ivan Zhakov <ivan@apache.org> | 2019-05-27 17:23:43 +0000 |
commit | 8b1e1fcd578d3dcaa3a305065a630ec9a7a50710 (patch) | |
tree | ac1ec35fd72c013f11774ed6fa941be8e5607e04 | |
parent | ae0d7b51ab4f90df87be68b4808886ef03ca7002 (diff) | |
download | apr-8b1e1fcd578d3dcaa3a305065a630ec9a7a50710.tar.gz |
Fix bug in apr_json_double_create().
* json/apr_json.c
(apr_json_double_create): Assign double number to DNUMBER instead of LNUMBER.
* test/testjson.c
(test_json_create): New test.
(testjson): Call test_json_create test.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1860152 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | json/apr_json.c | 2 | ||||
-rw-r--r-- | test/testjson.c | 47 |
2 files changed, 48 insertions, 1 deletions
diff --git a/json/apr_json.c b/json/apr_json.c index 4b5867fc0..67dfadb76 100644 --- a/json/apr_json.c +++ b/json/apr_json.c @@ -100,7 +100,7 @@ apr_json_value_t *apr_json_double_create(apr_pool_t *pool, double dnumber) if (json) { json->type = APR_JSON_DOUBLE; - json->value.lnumber = dnumber; + json->value.dnumber = dnumber; } return json; diff --git a/test/testjson.c b/test/testjson.c index f1c3e9f3c..7f2fd9c8b 100644 --- a/test/testjson.c +++ b/test/testjson.c @@ -230,6 +230,52 @@ static void test_json_array_iterate(abts_case * tc, void *data) } +static void test_json_create(abts_case* tc, void* data) +{ + apr_json_value_t *json; + apr_status_t status; + apr_bucket_brigade *bb; + apr_bucket_alloc_t *ba; + char buf[1024]; + apr_size_t len; + + ba = apr_bucket_alloc_create(p); + bb = apr_brigade_create(p, ba); + + json = apr_json_object_create(p); + apr_json_object_set(json, "null", APR_JSON_VALUE_STRING, + apr_json_null_create(p), p); + + apr_json_object_set(json, "bool", APR_JSON_VALUE_STRING, + apr_json_boolean_create(p, 1), p); + + apr_json_object_set(json, "double", APR_JSON_VALUE_STRING, + apr_json_double_create(p, 12.34), p); + + apr_json_object_set(json, "long", APR_JSON_VALUE_STRING, + apr_json_long_create(p, 1234), p); + + apr_json_object_set(json, "string", APR_JSON_VALUE_STRING, + apr_json_string_create(p, "str", + APR_JSON_VALUE_STRING), + p); + + status = apr_json_encode(bb, NULL, NULL, json, + APR_JSON_FLAGS_WHITESPACE, p); + + ABTS_INT_EQUAL(tc, APR_SUCCESS, status); + + len = sizeof(buf); + status = apr_brigade_flatten(bb, buf, &len); + ABTS_INT_EQUAL(tc, APR_SUCCESS, status); + buf[len] = 0; + + ABTS_STR_EQUAL(tc, + "{\"null\":null,\"bool\":true,\"double\":12.340000," + "\"long\":1234,\"string\":\"str\"}", + buf); +} + abts_suite *testjson(abts_suite * suite) { suite = ADD_SUITE(suite); @@ -241,6 +287,7 @@ abts_suite *testjson(abts_suite * suite) abts_run_test(suite, test_json_overlay, NULL); abts_run_test(suite, test_json_object_iterate, NULL); abts_run_test(suite, test_json_array_iterate, NULL); + abts_run_test(suite, test_json_create, NULL); return suite; } |