svn commit: r1920373 - in /apr/apr-util/branches/1.7.x: ./ json/apr_json.c test/testjson.c
[email protected] Sun, 01 Sep 2024 21:47:19 -0000
Newsgroups
gmane.comp.apache.apr.cvs
Message-ID
<[email protected] >
Author: ivan
Date: Sun Sep 1 21:47:19 2024
New Revision: 1920373
URL: http://svn.apache.org/viewvc?rev=1920373&view=rev
Log:
Merge r1860152 from apr/trunk:
* Fix bug in apr_json_double_create().
Modified:
apr/apr-util/branches/1.7.x/ (props changed)
apr/apr-util/branches/1.7.x/json/apr_json.c
apr/apr-util/branches/1.7.x/test/testjson.c
Propchange: apr/apr-util/branches/1.7.x/
------------------------------------------------------------------------------
Merged /apr/apr/trunk:r1860152
Modified: apr/apr-util/branches/1.7.x/json/apr_json.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/json/apr_json.c?rev=1920373&r1=1920372&r2=1920373&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/json/apr_json.c (original)
+++ apr/apr-util/branches/1.7.x/json/apr_json.c Sun Sep 1 21:47:19 2024
@@ -100,7 +100,7 @@ apr_json_value_t *apr_json_double_create
if (json) {
json->type = APR_JSON_DOUBLE;
- json->value.lnumber = dnumber;
+ json->value.dnumber = dnumber;
}
return json;
Modified: apr/apr-util/branches/1.7.x/test/testjson.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/test/testjson.c?rev=1920373&r1=1920372&r2=1920373&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/test/testjson.c (original)
+++ apr/apr-util/branches/1.7.x/test/testjson.c Sun Sep 1 21:47:19 2024
@@ -230,6 +230,52 @@ static void test_json_array_iterate(abts
}
+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;
}