From e56ea14ab8531ee3cec375460577d1b89bf62e26 Mon Sep 17 00:00:00 2001 From: Liong Sauw Ming Date: Thu, 16 Jan 2014 05:30:46 +0000 Subject: Closed #1723: Merging pjsua2 branch into trunk git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4704 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib-util/src/pjlib-util-test/json_test.c | 106 +++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 pjlib-util/src/pjlib-util-test/json_test.c (limited to 'pjlib-util/src/pjlib-util-test/json_test.c') diff --git a/pjlib-util/src/pjlib-util-test/json_test.c b/pjlib-util/src/pjlib-util-test/json_test.c new file mode 100644 index 00000000..cd9a8138 --- /dev/null +++ b/pjlib-util/src/pjlib-util-test/json_test.c @@ -0,0 +1,106 @@ +/* $Id$ */ +/* + * Copyright (C) 2013 Teluu Inc. (http://www.teluu.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "test.h" + +#define THIS_FILE "json_test.c" + +#if INCLUDE_JSON_TEST + +#include +#include +#include + +static char json_doc1[] = +"{\ + \"Object\": {\ + \"Integer\": 800,\ + \"Negative\": -12,\ + \"Float\": -7.2,\ + \"String\": \"A\\tString with tab\",\ + \"Object2\": {\ + \"True\": true,\ + \"False\": false,\ + \"Null\": null\ + },\ + \"Array1\": [116, false, \"string\", {}],\ + \"Array2\": [\ + {\ + \"Float\": 123.,\ + },\ + {\ + \"Float\": 123.,\ + }\ + ]\ + },\ + \"Integer\": 800,\ + \"Array1\": [116, false, \"string\"]\ +}\ +"; + +static int json_verify_1() +{ + pj_pool_t *pool; + pj_json_elem *elem; + char *out_buf; + unsigned size; + pj_json_err_info err; + + pool = pj_pool_create(mem, "json", 1000, 1000, NULL); + + size = strlen(json_doc1); + elem = pj_json_parse(pool, json_doc1, &size, &err); + if (!elem) { + PJ_LOG(1, (THIS_FILE, " Error: json_verify_1() parse error")); + goto on_error; + } + + size = strlen(json_doc1) * 2; + out_buf = pj_pool_alloc(pool, size); + + if (pj_json_write(elem, out_buf, &size)) { + PJ_LOG(1, (THIS_FILE, " Error: json_verify_1() write error")); + goto on_error; + } + + PJ_LOG(3,(THIS_FILE, "Json document:\n%s", out_buf)); + pj_pool_release(pool); + return 0; + +on_error: + pj_pool_release(pool); + return 10; +} + + +int json_test(void) +{ + int rc; + + rc = json_verify_1(); + if (rc) + return rc; + + return 0; +} + + + +#else +int json_dummy; +#endif -- cgit v1.2.3