Asterisk - The Open Source Telephony Project  21.4.1
Macros | Functions | Variables
test_json.c File Reference

Test JSON API. More...

#include "asterisk.h"
#include "asterisk/config.h"
#include "asterisk/json.h"
#include "asterisk/module.h"
#include "asterisk/test.h"
#include "asterisk/file.h"
#include <stdio.h>
#include <unistd.h>

Go to the source code of this file.

Macros

#define CATEGORY   "/main/json/"
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (json_test_false)
 
 AST_TEST_DEFINE (json_test_true)
 
 AST_TEST_DEFINE (json_test_bool0)
 
 AST_TEST_DEFINE (json_test_bool1)
 
 AST_TEST_DEFINE (json_test_null)
 
 AST_TEST_DEFINE (json_test_null_val)
 
 AST_TEST_DEFINE (json_test_string)
 
 AST_TEST_DEFINE (json_test_string_null)
 
 AST_TEST_DEFINE (json_test_stringf)
 
 AST_TEST_DEFINE (json_test_int)
 
 AST_TEST_DEFINE (json_test_non_int)
 
 AST_TEST_DEFINE (json_test_array_create)
 
 AST_TEST_DEFINE (json_test_array_append)
 
 AST_TEST_DEFINE (json_test_array_inset)
 
 AST_TEST_DEFINE (json_test_array_set)
 
 AST_TEST_DEFINE (json_test_array_remove)
 
 AST_TEST_DEFINE (json_test_array_clear)
 
 AST_TEST_DEFINE (json_test_array_extend)
 
 AST_TEST_DEFINE (json_test_array_null)
 
 AST_TEST_DEFINE (json_test_object_alloc)
 
 AST_TEST_DEFINE (json_test_object_set)
 
 AST_TEST_DEFINE (json_test_object_set_overwrite)
 
 AST_TEST_DEFINE (json_test_object_get)
 
 AST_TEST_DEFINE (json_test_object_del)
 
 AST_TEST_DEFINE (json_test_object_clear)
 
 AST_TEST_DEFINE (json_test_object_merge_all)
 
 AST_TEST_DEFINE (json_test_object_merge_existing)
 
 AST_TEST_DEFINE (json_test_object_merge_missing)
 
 AST_TEST_DEFINE (json_test_object_null)
 
 AST_TEST_DEFINE (json_test_object_iter)
 
 AST_TEST_DEFINE (json_test_object_iter_null)
 
 AST_TEST_DEFINE (json_test_object_create_vars)
 
 AST_TEST_DEFINE (json_test_dump_load_string)
 
 AST_TEST_DEFINE (json_test_dump_load_str)
 
 AST_TEST_DEFINE (json_test_dump_str_fail)
 
 AST_TEST_DEFINE (json_test_load_buffer)
 
 AST_TEST_DEFINE (json_test_dump_load_file)
 
 AST_TEST_DEFINE (json_test_dump_load_new_file)
 
 AST_TEST_DEFINE (json_test_dump_load_null)
 
 AST_TEST_DEFINE (json_test_parse_errors)
 
 AST_TEST_DEFINE (json_test_pack)
 
 AST_TEST_DEFINE (json_test_pack_ownership)
 
 AST_TEST_DEFINE (json_test_pack_errors)
 
 AST_TEST_DEFINE (json_test_copy)
 
 AST_TEST_DEFINE (json_test_deep_copy)
 
 AST_TEST_DEFINE (json_test_copy_null)
 
 AST_TEST_DEFINE (json_test_circular_object)
 
 AST_TEST_DEFINE (json_test_circular_array)
 
 AST_TEST_DEFINE (json_test_clever_circle)
 
 AST_TEST_DEFINE (json_test_name_number)
 
 AST_TEST_DEFINE (json_test_timeval)
 
 AST_TEST_DEFINE (json_test_cep)
 
static int load_module (void)
 
static int safe_fclose (FILE *f)
 fclose isn't NULL safe.
 
static int test_name_number (const char *name, const char *number)
 
static int unload_module (void)
 
static void * json_debug_malloc (size_t size)
 
static void json_debug_free (void *p)
 
static int json_test_init (struct ast_test_info *info, struct ast_test *test)
 
static int json_test_cleanup (struct ast_test_info *info, struct ast_test *test)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = 0 , .description = "JSON testing" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module }
 
static size_t alloc_count
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

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
David M. Lee, II <dlee@digium.com> 

Definition in file test_json.c.

Function Documentation

static void* json_debug_malloc ( size_t  size)
static

JSON library has its own reference counting, so we'll provide our own allocators to test that everything gets freed as expected.

Definition at line 61 of file test_json.c.

References alloc_count, and ast_json_malloc().

62 {
63  void *p = ast_json_malloc(size);
64  if (p) {
65  ++alloc_count;
66  }
67  return p;
68 }
static size_t alloc_count
Definition: test_json.c:54
void * ast_json_malloc(size_t size)
Asterisk's custom JSON allocator. Exposed for use by unit tests.
Definition: json.c:47

Variable Documentation

size_t alloc_count
static

Number of allocations from JSON library that have not yet been freed.

Definition at line 54 of file test_json.c.

Referenced by json_debug_malloc().