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

CDR unit tests. More...

#include "asterisk.h"
#include <math.h>
#include "asterisk/module.h"
#include "asterisk/test.h"
#include "asterisk/cdr.h"
#include "asterisk/linkedlists.h"
#include "asterisk/chanvars.h"
#include "asterisk/utils.h"
#include "asterisk/causes.h"
#include "asterisk/time.h"
#include "asterisk/bridge.h"
#include "asterisk/bridge_basic.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/stasis_bridges.h"
#include "asterisk/format_cache.h"

Go to the source code of this file.

Data Structures

struct  test_cdr_entry
 

Macros

#define ALICE_CALLERID   { .id.name.str = "Alice", .id.name.valid = 1, .id.number.str = "100", .id.number.valid = 1, }
 Alice's Caller ID.
 
#define BOB_CALLERID   { .id.name.str = "Bob", .id.name.valid = 1, .id.number.str = "200", .id.number.valid = 1, }
 Bob's Caller ID.
 
#define CHANNEL_TECH_NAME   "CDRTestChannel"
 
#define CHARLIE_CALLERID   { .id.name.str = "Charlie", .id.name.valid = 1, .id.number.str = "300", .id.number.valid = 1, }
 Charlie's Caller ID.
 
#define COPY_IDS(channel_var, expected_record)
 Copy the linkedid and uniqueid from a channel to an expected CDR. More...
 
#define CREATE_ALICE_CHANNEL(channel_var, caller_id, expected_record)
 Create a test_cdr_chan_tech for Alice, and set the expected CDR records' linkedid and uniqueid.
 
#define CREATE_BOB_CHANNEL(channel_var, caller_id, expected_record)
 Create a test_cdr_chan_tech for Bob, and set the expected CDR records' linkedid and uniqueid.
 
#define CREATE_CHARLIE_CHANNEL(channel_var, caller_id, expected_record)
 Create a test_cdr_chan_tech for Charlie, and set the expected CDR records' linkedid and uniqueid.
 
#define CREATE_DAVID_CHANNEL(channel_var, caller_id, expected_record)
 Create a test_cdr_chan_tech for Charlie, and set the expected CDR records' linkedid and uniqueid.
 
#define DAVID_CALLERID   { .id.name.str = "David", .id.name.valid = 1, .id.number.str = "400", .id.number.valid = 1, }
 David's Caller ID.
 
#define EMULATE_APP_DATA(channel, priority, application, data)
 Emulate a channel entering into an application.
 
#define EPSILON   0.001
 
#define HANGUP_CHANNEL(channel, cause)
 Hang up a test channel safely. More...
 
#define MOCK_CDR_BACKEND   "mock_cdr_backend"
 
#define SET_FORMATS(chan)
 Set ulaw format on channel.
 
#define SWAP_CONFIG(ao2_config, template)
 Macro to swap a configuration out from the CDR engine. This should be used at the beginning of each test to set the needed configuration for that test. More...
 
#define TEST_CATEGORY   "/main/cdr/"
 
#define VERIFY_NUMERIC_FIELD(field, actual, expected)
 Verify a numeric field. This will set the test status result to fail; as such, it assumes that (a) test is the test object variable, and (b) that a return variable res exists.
 
#define VERIFY_STRING_FIELD(field, actual, expected)
 Verify a string field. This will set the test status result to fail; as such, it assumes that (a) test is the test object variable, and (b) that a return variable res exists.
 
#define VERIFY_TIME_VALUE(field, actual)
 Verify a time field. This will set the test status result to fail; as such, it assumes that (a) test is the test object variable, and (b) that a return variable res exists.
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (test_cdr_channel_creation)
 
 AST_TEST_DEFINE (test_cdr_unanswered_inbound_call)
 
 AST_TEST_DEFINE (test_cdr_unanswered_outbound_call)
 
 AST_TEST_DEFINE (test_cdr_outbound_bridged_call)
 
 AST_TEST_DEFINE (test_cdr_single_party)
 
 AST_TEST_DEFINE (test_cdr_single_bridge)
 
 AST_TEST_DEFINE (test_cdr_single_bridge_continue)
 
 AST_TEST_DEFINE (test_cdr_single_twoparty_bridge_a)
 
 AST_TEST_DEFINE (test_cdr_single_twoparty_bridge_b)
 
 AST_TEST_DEFINE (test_cdr_single_multiparty_bridge)
 
 AST_TEST_DEFINE (test_cdr_dial_unanswered)
 
 AST_TEST_DEFINE (test_cdr_dial_busy)
 
 AST_TEST_DEFINE (test_cdr_dial_congestion)
 
 AST_TEST_DEFINE (test_cdr_dial_unavailable)
 
 AST_TEST_DEFINE (test_cdr_dial_caller_cancel)
 
 AST_TEST_DEFINE (test_cdr_dial_parallel_failed)
 
 AST_TEST_DEFINE (test_cdr_dial_answer_no_bridge)
 
 AST_TEST_DEFINE (test_cdr_dial_answer_twoparty_bridge_a)
 
 AST_TEST_DEFINE (test_cdr_dial_answer_twoparty_bridge_b)
 
 AST_TEST_DEFINE (test_cdr_dial_answer_multiparty)
 
 AST_TEST_DEFINE (test_cdr_park)
 
 AST_TEST_DEFINE (test_cdr_fields)
 
 AST_TEST_DEFINE (test_cdr_no_reset_cdr)
 
 AST_TEST_DEFINE (test_cdr_fork_cdr)
 
static void clear_mock_cdr_backend (void)
 
static void do_sleep (struct timespec *to_sleep)
 
static int load_module (void)
 
static int mock_cdr_backend_cb (struct ast_cdr *cdr)
 
static void safe_bridge_destroy (struct ast_bridge *bridge)
 
static void safe_channel_release (struct ast_channel *chan)
 
static int test_cdr_cleanup_cb (struct ast_test_info *info, struct ast_test *test)
 
static int test_cdr_init_cb (struct ast_test_info *info, struct ast_test *test)
 
static int unload_module (void)
 
static enum ast_test_result_state verify_mock_cdr_record (struct ast_test *test, struct ast_cdr *expected, int record)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "CDR unit tests" , .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, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
struct {
   struct test_cdr_entry *   first
 
   struct test_cdr_entry *   last
 
   ast_mutex_t   lock
 
actual_cdr_entries = AST_LIST_HEAD_INIT_VALUE
 A linked list of received CDR entries from the engine.
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_cdr_config congestion_cdr_config
 A configuration suitable for CDRs with congestion enabled. More...
 
static struct ast_cdr_config debug_cdr_config
 A configuration suitable for 'normal' CDRs. More...
 
static int global_mock_cdr_count
 The number of CDRs the mock backend has received.
 
static ast_cond_t mock_cdr_cond
 The Mock CDR backend condition wait.
 
static struct ast_cdr_configsaved_config
 A placeholder for Asterisk's 'real' CDR configuration.
 
static struct ast_channel_tech test_cdr_chan_tech
 A channel technology used for the unit tests. More...
 
static struct ast_cdr_config unanswered_cdr_config
 A configuration suitable for CDRs with unanswered records. More...
 

Detailed Description

CDR unit tests.

Author
Matt Jordan mjord.nosp@m.an@d.nosp@m.igium.nosp@m..com

Definition in file test_cdr.c.

Macro Definition Documentation

#define COPY_IDS (   channel_var,
  expected_record 
)
Value:
do { \
ast_copy_string((expected_record)->uniqueid, ast_channel_uniqueid((channel_var)), sizeof((expected_record)->uniqueid)); \
ast_copy_string((expected_record)->linkedid, ast_channel_linkedid((channel_var)), sizeof((expected_record)->linkedid)); \
} while (0)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425

Copy the linkedid and uniqueid from a channel to an expected CDR.

Definition at line 228 of file test_cdr.c.

#define HANGUP_CHANNEL (   channel,
  cause 
)
Value:
do { \
ast_channel_hangupcause_set((channel), (cause)); \
ast_hangup(channel); \
channel = NULL; \
} while (0)
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2541

Hang up a test channel safely.

Definition at line 303 of file test_cdr.c.

#define SWAP_CONFIG (   ao2_config,
  template 
)
Value:
do { \
*(ao2_config) = (template); \
ast_cdr_set_config((ao2_config)); \
} while (0)
void ast_cdr_set_config(struct ast_cdr_config *config)
Set the current CDR configuration.
Definition: cdr.c:2902

Macro to swap a configuration out from the CDR engine. This should be used at the beginning of each test to set the needed configuration for that test.

Definition at line 79 of file test_cdr.c.

Variable Documentation

struct ast_cdr_config congestion_cdr_config
static
Initial value:

A configuration suitable for CDRs with congestion enabled.

Definition at line 71 of file test_cdr.c.

struct ast_cdr_config debug_cdr_config
static
Initial value:

A configuration suitable for 'normal' CDRs.

Definition at line 61 of file test_cdr.c.

struct ast_channel_tech test_cdr_chan_tech
static
Initial value:
= {
.type = CHANNEL_TECH_NAME,
.description = "Mock channel technology for CDR tests",
}

A channel technology used for the unit tests.

Definition at line 91 of file test_cdr.c.

struct ast_cdr_config unanswered_cdr_config
static
Initial value:

A configuration suitable for CDRs with unanswered records.

Definition at line 66 of file test_cdr.c.