Asterisk - The Open Source Telephony Project GIT-master-8f1982c
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Functions | Variables
test_skel.c File Reference

Skeleton Test. More...

#include "asterisk.h"
#include "asterisk/utils.h"
#include "asterisk/module.h"
#include "asterisk/test.h"
Include dependency graph for test_skel.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (sample_test)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Skeleton (sample) Test" , .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, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Skeleton Test.

Author
<Your Name Here> <<Your Email Here>> 

This is a skeleton for development of an Asterisk test module

Definition in file test_skel.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 140 of file test_skel.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 140 of file test_skel.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 140 of file test_skel.c.

◆ AST_TEST_DEFINE()

AST_TEST_DEFINE ( sample_test  )

Definition at line 40 of file test_skel.c.

41{
42 /* Retrieve the command line arguments used to invoke the test */
43 struct ast_cli_args *cli_args = ast_test_get_cli_args(test);
44 /* Set default values for the options */
45 int test_option = 999;
46 char test_option2[128] = { 0 };
47 void *ptr = NULL;
48 void *ptr2 = NULL;
49 int i;
51
52 switch (cmd) {
53 case TEST_INIT:
54 info->name = "sample_test";
55 info->category = "/main/sample/";
56 info->summary = "sample unit test";
57 info->description =
58 "This demonstrates what is required to implement "
59 "a unit test. You can pass in test-option and "
60 "test-option2 as command line arguments to this "
61 "test. test-option is an integer and test-option2 "
62 "is a string.";
63 return AST_TEST_NOT_RUN;
64 case TEST_EXECUTE:
65 break;
66 }
67
68 /*
69 * This is an example of how to get command line arguments
70 * from the test framework. The arguments are "test-option"
71 * (expected to be an integer) and "test-option2" (expected
72 * to be a string).
73 *
74 * NOTES:
75 *
76 * cli_args will contain all of the command line arguments
77 * including "test execute", etc. so the location of the options
78 * will vary depending on how the test was invoked.
79 * For instance, this test could be run by either of the following:
80 *
81 * test execute category /main/sample/ options test-option=444
82 * test execute category /main/sample/ name sample_test options test-option=444
83 *
84 * You therefore need to test each of the items in the argv array
85 * to find the ones you are looking for.
86 *
87 * No special processing is done on string arguments so if your
88 * option value is a string, you must deal with the possibility
89 * of embedded spaces yourself.
90 */
91
92 for (i = 0; i < cli_args->argc; i++) {
93 ast_test_status_update(test, "Test argument: %d: %s\n", i, cli_args->argv[i]);
94 if (ast_begins_with(cli_args->argv[i], "test-option=")) {
95 sscanf(cli_args->argv[i], "test-option=%d", &test_option);
96 }
97 if (ast_begins_with(cli_args->argv[i], "test-option2=")) {
98 sscanf(cli_args->argv[i], "test-option2=%s", test_option2);
99 }
100 }
101
102 ast_test_status_update(test, "Executing sample test with test-option=%d and test-option2=%s\n",
103 test_option, test_option2);
104
105 if (!(ptr = ast_malloc(8))) {
106 ast_test_status_update(test, "ast_malloc() failed\n");
107 return AST_TEST_FAIL;
108 }
109
110 ptr2 = ast_malloc(8);
111 /*
112 * This is an example of how to use the ast_test_validate_cleanup_custom
113 * macro to check a condition and cleanup if it fails.
114 * If ptr2 is NULL, rc will be set to AST_TEST_FAIL, the specified
115 * message will be printed, and the test will jump to the "done"
116 * label to perform cleanup.
117 */
118 ast_test_validate_cleanup_custom(test, ptr2, rc, done, "ptr2 is NULL\n");
119
120done:
121
122 ast_free(ptr);
123 ast_free(ptr2);
124
125 return rc;
126}
#define ast_free(a)
Definition: astmm.h:180
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
def info(msg)
#define NULL
Definition: resample.c:96
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Checks whether a string begins with another.
Definition: strings.h:97
const int argc
Definition: cli.h:160
const char *const * argv
Definition: cli.h:161
@ TEST_INIT
Definition: test.h:200
@ TEST_EXECUTE
Definition: test.h:201
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
ast_test_result_state
Definition: test.h:193
@ AST_TEST_PASS
Definition: test.h:195
@ AST_TEST_FAIL
Definition: test.h:196
@ AST_TEST_NOT_RUN
Definition: test.h:194
int done
Definition: test_amihooks.c:48

References ast_cli_args::argc, ast_cli_args::argv, ast_begins_with(), ast_free, ast_malloc, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, done, sip_to_pjsip::info(), NULL, TEST_EXECUTE, and TEST_INIT.

◆ load_module()

static int load_module ( void  )
static

Definition at line 134 of file test_skel.c.

135{
136 AST_TEST_REGISTER(sample_test);
138}
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
#define AST_TEST_REGISTER(cb)
Definition: test.h:127

References AST_MODULE_LOAD_SUCCESS, and AST_TEST_REGISTER.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 128 of file test_skel.c.

129{
130 AST_TEST_UNREGISTER(sample_test);
131 return 0;
132}
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128

References AST_TEST_UNREGISTER.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Skeleton (sample) Test" , .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, }
static

Definition at line 140 of file test_skel.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 140 of file test_skel.c.