Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Functions | Variables
test_callerid.c File Reference

Callerid Tests. More...

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

Go to the source code of this file.

Data Structures

struct  cid_set
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (parse_nominal)
 
 AST_TEST_DEFINE (parse_off_nominal)
 
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 = "Callerid Parse 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, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Callerid Tests.

Author
Kinsey Moore <[email protected]> 

This is an Asterisk test module for callerid functionality

Definition in file test_callerid.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 167 of file test_callerid.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 167 of file test_callerid.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 167 of file test_callerid.c.

◆ AST_TEST_DEFINE() [1/2]

AST_TEST_DEFINE ( parse_nominal  )

Definition at line 47 of file test_callerid.c.

References ARRAY_LEN, ast_callerid_parse(), ast_free, ast_strdup, ast_strlen_zero, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, cid_set::cid, sip_to_pjsip::info(), cid_set::name, NULL, cid_set::number, RAII_VAR, TEST_EXECUTE, and TEST_INIT.

48 {
49  static const struct cid_set cid_sets[] = {
50  {"\"name\" <number>", "name", "number"},
51  {"\" name \" <number>", " name ", "number"},
52  {"name <number>", "name", "number"},
53  {" name <number>", "name", "number"},
54  {"\"\" <number>", NULL, "number"},
55  {"<number>", NULL, "number"},
56  {"name", "name", NULL},
57  {" name", "name", NULL},
58  {"\"name\"", "name", NULL},
59  {"\"*10\"", "*10", NULL},
60  {" \"*10\"", "*10", NULL},
61  {"\"name\" <>", "name", NULL},
62  {"name <>", "name", NULL},
63  {"1234", NULL, "1234"},
64  {" 1234", NULL, "1234"},
65  {"\"na\\\"me\" <number>", "na\"me", "number"},
66  };
67  char *name;
68  char *number;
69  int i;
70 
71  switch (cmd) {
72  case TEST_INIT:
73  info->name = "parse_nominal";
74  info->category = "/main/callerid/";
75  info->summary = "Callerid nominal parse unit test";
76  info->description =
77  "This tests parsing of nominal callerid strings.";
78  return AST_TEST_NOT_RUN;
79  case TEST_EXECUTE:
80  break;
81  }
82 
83  for (i = 0; i < ARRAY_LEN(cid_sets); i++) {
84  RAII_VAR(char *, callerid, ast_strdup(cid_sets[i].cid), ast_free);
85 
86  ast_callerid_parse(callerid, &name, &number);
87  if (!cid_sets[i].name == !ast_strlen_zero(name) || (cid_sets[i].name && strcmp(name, cid_sets[i].name))) {
89  "Expected callerid name '%s' instead of '%s'\n",
90  cid_sets[i].name, name);
91  return AST_TEST_FAIL;
92  }
93 
94  if (!cid_sets[i].number == !ast_strlen_zero(number) || (cid_sets[i].number && strcmp(number, cid_sets[i].number))) {
96  "Expected callerid number '%s' instead of '%s'\n",
97  cid_sets[i].number, number);
98  return AST_TEST_FAIL;
99  }
100  }
101 
102  return AST_TEST_PASS;
103 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
char * number
Definition: test_callerid.c:44
def info(msg)
static const char name[]
Definition: cdr_mysql.c:74
#define ast_free(a)
Definition: astmm.h:182
char * cid
Definition: test_callerid.c:42
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1008

◆ AST_TEST_DEFINE() [2/2]

AST_TEST_DEFINE ( parse_off_nominal  )

Definition at line 105 of file test_callerid.c.

References ARRAY_LEN, ast_callerid_parse(), ast_free, ast_strdup, ast_strlen_zero, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, cid_set::cid, sip_to_pjsip::info(), cid_set::name, cid_set::number, RAII_VAR, TEST_EXECUTE, and TEST_INIT.

106 {
107  static const struct cid_set cid_sets[] = {
108  {"na\\\"me <number>", "na\"me", "number"},
109  {"\"na\"me\" <number>", "na\"me", "number"},
110  {"na\"me <number>", "na\"me", "number"},
111  {"\"name <number>", "\"name", "number"},
112  {"name <number", "name", "number"},
113  {"\"name <number>\"", "name", "number"},
114  };
115  char *name;
116  char *number;
117  int i;
118 
119  switch (cmd) {
120  case TEST_INIT:
121  info->name = "parse_off_nominal";
122  info->category = "/main/callerid/";
123  info->summary = "Callerid off-nominal parse unit test";
124  info->description =
125  "This tests parsing of off-nominal callerid strings.";
126  return AST_TEST_NOT_RUN;
127  case TEST_EXECUTE:
128  break;
129  }
130 
131  for (i = 0; i < ARRAY_LEN(cid_sets); i++) {
132  RAII_VAR(char *, callerid, ast_strdup(cid_sets[i].cid), ast_free);
133 
134  ast_callerid_parse(callerid, &name, &number);
135  if (!cid_sets[i].name == !ast_strlen_zero(name) || (cid_sets[i].name && strcmp(name, cid_sets[i].name))) {
137  "Expected callerid name '%s' instead of '%s'\n",
138  cid_sets[i].name, name);
139  return AST_TEST_FAIL;
140  }
141 
142  if (!cid_sets[i].number == !ast_strlen_zero(number) || (cid_sets[i].number && strcmp(number, cid_sets[i].number))) {
144  "Expected callerid number '%s' instead of '%s'\n",
145  cid_sets[i].number, number);
146  return AST_TEST_FAIL;
147  }
148  }
149 
150  return AST_TEST_PASS;
151 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
char * number
Definition: test_callerid.c:44
def info(msg)
static const char name[]
Definition: cdr_mysql.c:74
#define ast_free(a)
Definition: astmm.h:182
char * cid
Definition: test_callerid.c:42
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1008

◆ load_module()

static int load_module ( void  )
static

Definition at line 160 of file test_callerid.c.

References AST_MODULE_LOAD_SUCCESS, and AST_TEST_REGISTER.

161 {
162  AST_TEST_REGISTER(parse_nominal);
163  AST_TEST_REGISTER(parse_off_nominal);
165 }
#define AST_TEST_REGISTER(cb)
Definition: test.h:127

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 153 of file test_callerid.c.

References AST_TEST_UNREGISTER.

154 {
155  AST_TEST_UNREGISTER(parse_nominal);
156  AST_TEST_UNREGISTER(parse_off_nominal);
157  return 0;
158 }
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Callerid Parse 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, }
static

Definition at line 167 of file test_callerid.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 167 of file test_callerid.c.