39 #include "asterisk/res_pjsip.h"
43 #include "asterisk/res_pjsip_session.h"
44 #include "asterisk/res_pjsip_session_caps.h"
46 static enum ast_test_result_state test_create_joint(
struct ast_test *
test,
const char *local_string,
47 const char *remote_string,
const char *pref_string,
int is_outgoing,
const char *expected_string,
48 enum ast_test_result_state expected_result)
54 const char *joint_string;
60 ast_test_status_update(test,
"Testing local: (%s), remote: (%s), pref: (%-12s), outgoing: (%s), expected: (%s) expected result: (%s)\n",
61 local_string, remote_string, pref_string, is_outgoing ?
"yes" :
"no ", expected_string,
62 expected_result == AST_TEST_PASS ?
"PASS" :
"FAIL");
64 ast_test_validate(test, local != NULL && remote != NULL && joint != NULL);
68 ast_test_status_update(test,
" %sxpected Failure: Coulldn't parse local codecs (%s)\n",
69 expected_result == AST_TEST_FAIL ?
"E" :
"Une", local_string);
70 return expected_result == AST_TEST_FAIL ? AST_TEST_PASS : AST_TEST_FAIL;
74 ast_test_status_update(test,
" %sxpected Failure: Coulldn't parse remote codecs (%s)\n",
75 expected_result == AST_TEST_FAIL ?
"E" :
"Une", remote_string);
76 return expected_result == AST_TEST_FAIL ? AST_TEST_PASS : AST_TEST_FAIL;
79 rc = ast_sip_call_codec_str_to_pref(&codec_prefs, pref_string, is_outgoing);
81 ast_test_status_update(test,
" %sxpected Failure: Invalid preference string incoming/outgoing combination.\n",
82 expected_result == AST_TEST_FAIL ?
"E" :
"Une");
83 return expected_result == AST_TEST_FAIL ? AST_TEST_PASS : AST_TEST_FAIL;
86 joint = ast_sip_create_joint_call_cap(remote, local, AST_MEDIA_TYPE_AUDIO, codec_prefs);
88 ast_test_status_update(test,
" %sxpected Failure: No joint caps.\n",
89 expected_result == AST_TEST_FAIL ?
"E" :
"Une");
90 return expected_result == AST_TEST_FAIL ? AST_TEST_PASS : AST_TEST_FAIL;
95 for(i = 0; i <= strlen(stripped_joint); i++) {
96 if(stripped_joint[i] ==
'|') {
97 stripped_joint[i] =
',';
101 if (!joint_string || strcmp(stripped_joint, expected_string) != 0) {
102 ast_test_status_update(test,
" %sxpected Failure: Expected: (%s) Actual: (%s)\n",
103 expected_result == AST_TEST_FAIL ?
"E" :
"Une", expected_string, stripped_joint);
104 return expected_result == AST_TEST_FAIL ? AST_TEST_PASS : AST_TEST_FAIL;
107 return AST_TEST_PASS;
110 #define RUN_CREATE_JOINT(local, remote, pref, outgoing, expected, result) \
112 if (test_create_joint(test, local, remote, pref, outgoing, expected, result) != AST_TEST_PASS) { \
123 info->name = __func__;
124 info->category =
"/res/res_pjsip_session/caps/";
125 info->summary =
"Test res_pjsip_session_caps";
126 info->description =
"Test res_pjsip_session_caps";
127 return AST_TEST_NOT_RUN;
134 ast_test_status_update(test,
"Testing incoming expected pass\n");
135 RUN_CREATE_JOINT(
"ulaw,alaw,g722",
"g722,alaw,g729",
"local", 0,
"alaw,g722", AST_TEST_PASS);
136 RUN_CREATE_JOINT(
"ulaw,alaw,g722",
"g722,alaw,g729",
"local_first", 0,
"alaw", AST_TEST_PASS);
137 RUN_CREATE_JOINT(
"slin",
"all",
"local", 0,
"slin", AST_TEST_PASS);
138 RUN_CREATE_JOINT(
"ulaw,alaw,g722",
"g722,alaw,g729",
"remote", 0,
"g722,alaw", AST_TEST_PASS);
139 RUN_CREATE_JOINT(
"ulaw,alaw,g722",
"g722,alaw,g729",
"remote_first", 0,
"g722", AST_TEST_PASS);
140 RUN_CREATE_JOINT(
"all",
"slin",
"remote_first", 0,
"slin", AST_TEST_PASS);
142 ast_test_status_update(test,
"Testing incoming expected fail\n");
143 RUN_CREATE_JOINT(
"ulaw,alaw,g722",
"g729",
"local", 0,
"", AST_TEST_FAIL);
144 RUN_CREATE_JOINT(
"ulaw,alaw,g722",
"g722,alaw,g729",
"local_merge", 0,
"", AST_TEST_FAIL);
145 RUN_CREATE_JOINT(
"ulaw,alaw,g722",
"g722,alaw,g729",
"remote_merge", 0,
"", AST_TEST_FAIL);
147 ast_test_status_update(test,
"Testing outgoing expected pass\n");
148 RUN_CREATE_JOINT(
"ulaw,alaw,g722",
"g722,g729,alaw",
"local", 1,
"alaw,g722", AST_TEST_PASS);
149 RUN_CREATE_JOINT(
"ulaw,alaw,g722",
"g722,g729,alaw",
"local_first", 1,
"alaw", AST_TEST_PASS);
150 RUN_CREATE_JOINT(
"ulaw,alaw,g722",
"g722,g729,alaw",
"local_merge", 1,
"ulaw,alaw,g722", AST_TEST_PASS);
151 RUN_CREATE_JOINT(
"ulaw,alaw,g722",
"g722,g729,alaw",
"remote", 1,
"g722,alaw", AST_TEST_PASS);
152 RUN_CREATE_JOINT(
"ulaw,alaw,g722",
"g722,g729,alaw",
"remote_first", 1,
"g722", AST_TEST_PASS);
153 RUN_CREATE_JOINT(
"ulaw,alaw,g722",
"g722,g729,alaw",
"remote_merge", 1,
"g722,alaw,ulaw", AST_TEST_PASS);
154 RUN_CREATE_JOINT(
"!all",
"g722,g729,alaw",
"remote_merge", 1,
"nothing", AST_TEST_PASS);
156 return rc >= 1 ? AST_TEST_FAIL : AST_TEST_PASS;
159 static int load_module(
void)
161 AST_TEST_REGISTER(low_level);
165 static int unload_module(
void)
167 AST_TEST_UNREGISTER(low_level);
171 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,
"res_pjsip_session caps test module",
172 .support_level = AST_MODULE_SUPPORT_CORE,
174 .unload = unload_module,
175 .requires =
"res_pjsip_session",
Asterisk main include file. File version handling, generic pbx functions.
char * ast_str_truncate(struct ast_str *buf, ssize_t len)
Truncates the enclosed string to the given length.
Support for dynamic strings.
Structure used to handle boolean flags.
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
#define AST_TEST_DEFINE(hdr)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.