diff options
author | Liong Sauw Ming <ming@teluu.com> | 2014-01-16 05:30:46 +0000 |
---|---|---|
committer | Liong Sauw Ming <ming@teluu.com> | 2014-01-16 05:30:46 +0000 |
commit | e56ea14ab8531ee3cec375460577d1b89bf62e26 (patch) | |
tree | df77c3acb961514b2022ee9e030071b691145920 /pjlib-util/src/pjlib-util-test | |
parent | bd1c47e995a3a844868f1d4dcc8f77f163ae721b (diff) |
Closed #1723: Merging pjsua2 branch into trunk
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4704 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib-util/src/pjlib-util-test')
-rw-r--r-- | pjlib-util/src/pjlib-util-test/json_test.c | 106 | ||||
-rw-r--r-- | pjlib-util/src/pjlib-util-test/test.c | 4 | ||||
-rw-r--r-- | pjlib-util/src/pjlib-util-test/test.h | 2 |
3 files changed, 112 insertions, 0 deletions
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 <pjlib-util/json.h> +#include <pj/log.h> +#include <pj/string.h> + +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 diff --git a/pjlib-util/src/pjlib-util-test/test.c b/pjlib-util/src/pjlib-util-test/test.c index feb2c011..223d57d8 100644 --- a/pjlib-util/src/pjlib-util-test/test.c +++ b/pjlib-util/src/pjlib-util-test/test.c @@ -72,6 +72,10 @@ static int test_inner(void) DO_TEST(xml_test()); #endif +#if INCLUDE_JSON_TEST + DO_TEST(json_test()); +#endif + #if INCLUDE_ENCRYPTION_TEST DO_TEST(encryption_test()); DO_TEST(encryption_benchmark()); diff --git a/pjlib-util/src/pjlib-util-test/test.h b/pjlib-util/src/pjlib-util-test/test.h index 37b1d909..b0e77c78 100644 --- a/pjlib-util/src/pjlib-util-test/test.h +++ b/pjlib-util/src/pjlib-util-test/test.h @@ -20,12 +20,14 @@ #include <pj/types.h> #define INCLUDE_XML_TEST 1 +#define INCLUDE_JSON_TEST 1 #define INCLUDE_ENCRYPTION_TEST 1 #define INCLUDE_STUN_TEST 1 #define INCLUDE_RESOLVER_TEST 1 #define INCLUDE_HTTP_CLIENT_TEST 1 extern int xml_test(void); +extern int json_test(void); extern int encryption_test(); extern int encryption_benchmark(); extern int stun_test(); |