Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
test_ast_format_str_reduce.c File Reference

Test ast_format_str_reduce. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/file.h"
#include "asterisk/test.h"
Include dependency graph for test_ast_format_str_reduce.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 (ast_format_str_reduce_test_1)
 
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 = "ast_format_str_reduce() test module" , .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
 
static char * fail_strings []
 
static char * test_strings [][2]
 

Detailed Description

Test ast_format_str_reduce.

Author
Matthew Nicholson mnich.nosp@m.iols.nosp@m.on@di.nosp@m.gium.nosp@m..com

Definition in file test_ast_format_str_reduce.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 135 of file test_ast_format_str_reduce.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 135 of file test_ast_format_str_reduce.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 135 of file test_ast_format_str_reduce.c.

◆ AST_TEST_DEFINE()

AST_TEST_DEFINE ( ast_format_str_reduce_test_1  )

Definition at line 77 of file test_ast_format_str_reduce.c.

References ast_format_str_reduce(), ast_strdupa, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, c, fail_strings, sip_to_pjsip::info(), TEST_EXECUTE, TEST_INIT, and test_strings.

78 {
79  int i;
80  char *c;
81 
82  switch (cmd) {
83  case TEST_INIT:
84  info->name = "ast_format_str_reduce_test_1";
85  info->category = "/main/file/";
86  info->summary = "reduce format strings";
87  info->description = "Reduce some format strings and make sure the results match what we expect.";
88  return AST_TEST_NOT_RUN;
89  case TEST_EXECUTE:
90  break;
91  }
92 
93  for (i = 0; test_strings[i][0]; i++) {
94  c = ast_strdupa(test_strings[i][0]);
95  if (!(c = ast_format_str_reduce(c))) {
96  ast_test_status_update(test, "Error running ast_format_str_reduce() on string '%s'\n",
97  test_strings[i][0]);
98  return AST_TEST_FAIL;
99  }
100 
101  if (strcmp(test_strings[i][1], c)) {
102  ast_test_status_update(test, "Format string '%s' reduced to '%s'. Expected '%s'\n",
103  test_strings[i][0], c, test_strings[i][1]);
104  return AST_TEST_FAIL;
105  }
106  }
107 
108  for (i = 0; fail_strings[i]; i++) {
109  c = ast_strdupa(fail_strings[i]);
110  if ((c = ast_format_str_reduce(c))) {
111  ast_test_status_update(test, "ast_format_str_reduce() succeded on string '%s' "
112  "with result '%s', but we expected it to fail\n",
113  fail_strings[i], c);
114  return AST_TEST_FAIL;
115  }
116  }
117 
118  return AST_TEST_PASS;
119 }
static char * fail_strings[]
static char * test_strings[][2]
static struct test_val c
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
char * ast_format_str_reduce(char *fmts)
Definition: file.c:1826
def info(msg)

◆ load_module()

static int load_module ( void  )
static

Definition at line 127 of file test_ast_format_str_reduce.c.

References AST_MODULE_LOAD_SUCCESS, and AST_TEST_REGISTER.

128 {
129 
130  AST_TEST_REGISTER(ast_format_str_reduce_test_1);
131 
133 }
#define AST_TEST_REGISTER(cb)
Definition: test.h:127

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 121 of file test_ast_format_str_reduce.c.

References AST_TEST_UNREGISTER.

122 {
123  AST_TEST_UNREGISTER(ast_format_str_reduce_test_1);
124  return 0;
125 }
#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 = "ast_format_str_reduce() test module" , .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 135 of file test_ast_format_str_reduce.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 135 of file test_ast_format_str_reduce.c.

◆ fail_strings

char* fail_strings[]
static
Initial value:
= {
"this will fail",
"this one|should|fail also",
}
#define NULL
Definition: resample.c:96

Definition at line 71 of file test_ast_format_str_reduce.c.

Referenced by AST_TEST_DEFINE().

◆ test_strings

char* test_strings[][2]
static

Definition at line 51 of file test_ast_format_str_reduce.c.

Referenced by AST_TEST_DEFINE().