46 const char *command =
"true";
47 char *
const args[] = {
"true",
NULL };
51 info->name =
"test_capture_true";
52 info->category =
"/main/test_capture/";
53 info->summary =
"capture true exit unit test";
55 "Capture exit code from true command.";
68 if (ast_test_capture_command(&cap, command,
args,
NULL, 0) != 1) {
96 ast_test_capture_free(&cap);
105 const char *command =
"false";
106 char *
const args[] = {
"false",
NULL };
110 info->name =
"test_capture_false";
111 info->category =
"/main/test_capture/";
112 info->summary =
"capture false exit unit test";
114 "Capture exit code from false command.";
127 if (ast_test_capture_command(&cap, command,
args,
NULL, 0) != 1) {
155 ast_test_capture_free(&cap);
164 const char *command =
"base64";
165 char *
const args[] = {
"base64",
NULL };
166 const char data[] =
"Mary had a little lamb.";
167 const unsigned datalen =
sizeof(data) - 1;
168 const char output[] =
"TWFyeSBoYWQgYSBsaXR0bGUgbGFtYi4=\n";
169 const unsigned outputlen =
sizeof(output) - 1;
173 info->name =
"test_capture_with_stdin";
174 info->category =
"/main/test_capture/";
175 info->summary =
"capture with stdin unit test";
177 "Capture output from stdin transformation command.";
190 if (ast_test_capture_command(&cap, command,
args, data, datalen) != 1) {
218 ast_test_capture_free(&cap);
227 const char *command =
"date";
228 char *
args[] = {
"date",
"DATE",
"FORMAT",
NULL };
230 const char format[] =
"+%a, %d %b %y %T %z";
231 const char format2[] =
"%a, %d %b %y %T %z\n";
233 unsigned myresultlen;
239 info->name =
"test_capture_with_dynamic";
240 info->category =
"/main/test_capture/";
241 info->summary =
"capture with dynamic argument unit test";
243 "Capture output from dynamic transformation command.";
257 snprintf(date,
sizeof(date),
"--date=@%lu", now);
259 tm = localtime(&now);
260 strftime(myresult,
sizeof(myresult), format2, tm);
261 myresultlen = strlen(myresult);
264 args[2] = (
char *)format;
266 if (ast_test_capture_command(&cap, command,
args,
NULL, 0) != 1) {
294 ast_test_capture_free(&cap);
303 const char *command =
"sh";
304 char *
const args[] = {
"sh",
"-c",
"echo -n 'foo' >&2 ; echo -n 'zzz' >&1 ; echo -n 'bar' >&2",
NULL };
308 info->name =
"test_capture_stdout_stderr";
309 info->category =
"/main/test_capture/";
310 info->summary =
"capture stdout & stderr unit test";
312 "Capture both stdout and stderr from shell.";
325 if (ast_test_capture_command(&cap, command,
args,
NULL, 0) != 1) {
335 if (cap.
errlen != 6 || memcmp(cap.
errbuf,
"foobar", 6)) {
353 ast_test_capture_free(&cap);
Asterisk main include file. File version handling, generic pbx functions.
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
static void * cleanup(void *unused)
A capture of running an external process.
char * outbuf
buffer holding stdout
char * errbuf
buffer holding stderr
size_t errlen
length of buffer holding stderr
pid_t pid
process id of child
size_t outlen
length of buffer holding stdout
int exitcode
exit code of child
#define AST_TEST_REGISTER(cb)
#define ast_test_status_update(a, b, c...)
#define AST_TEST_UNREGISTER(cb)
AST_TEST_DEFINE(test_capture_true)
static int load_module(void)
static int unload_module(void)
int ast_check_command_in_path(const char *cmd)
Test for the presence of an executable command in $PATH.