Select Git revision
test_json.c
test_json.c 54.41 KiB
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2012 - 2013, Digium, Inc.
*
* David M. Lee, II <dlee@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*!
* \file \brief Test JSON API.
*
* While some of these tests are actually testing our JSON library wrapper, the bulk of
* them are exploratory tests to determine what the behavior of the underlying JSON
* library is. This also gives us a good indicator if that behavior changes between
* Jansson revisions.
*
* \author\verbatim David M. Lee, II <dlee@digium.com> \endverbatim
*
* \ingroup tests
*/
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
<support_level>core</support_level>
***/
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/json.h"
#include "asterisk/module.h"
#include "asterisk/test.h"
#include <stdio.h>
#include <unistd.h>
#define CATEGORY "/main/json/"
/*!
* Number of allocations from JSON library that have not yet been freed.
*/
static size_t alloc_count;
/*!@{*/
/*!
* JSON library has its own reference counting, so we'll provide our own allocators to
* test that everything gets freed as expected.
*/
static void *json_debug_malloc(size_t size)
{
void *p = ast_json_malloc(size);
if (p) {
++alloc_count;
}
return p;
}
static void json_debug_free(void *p)
{
if (p) {