aboutsummaryrefslogtreecommitdiffstats
path: root/channels/sip
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2010-02-09 23:32:14 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2010-02-09 23:32:14 +0000
commitd8d63de32861045cd40b3036fac3077e7af90ed3 (patch)
treed10f5c6801b7a0d86ccd2dd6b5b3986e93b82fb5 /channels/sip
parent687dfce0fd28482651b03df103c6e630a3dc4317 (diff)
Various updates to the unit test API.
1) It occurred to me that the difference in usage between the error ast_str and the ast_test_update_status() usage has turned out to be a bit ambiguous in practice. In a lot of cases, the same message was being sent to both. In other cases, it was only sent to one or the other. My opinion now is that in every case, I think it makes sense to do both; we should output it to the CLI as well as save it off for logging purposes. This change results in most of the changes in this diff, since it required changes to all existing unit tests. It also allowed for some simplifications of unit test API implementation code. 2) Update ast_test_status_update() to include the file, function, and line number for the code providing the update. 3) There are some formatting tweaks here and there. Hopefully they aren't too distracting for code review purposes. Reviewboard's diff viewer seems to do a pretty good job of pointing out when something is a whitespace change. 4) I moved the md5_test and sha1_test into the test_utils module. It seemed like a better approach since these tests are so tiny. 5) I changed the number of nodes used in heap_test_2 from 1 million to 100 thousand. The only reason for this was to reduce the time it took for this test to run. 6) Remove an unused function prototype that was at the bottom of utils.h. 7) Simplify test_insert() using the LIST_INSERT_SORTALPHA() macro. The one minor difference in behavior is that it no longer checks for a test registered with the same name. 8) Expand the code in test_alloc() to provide specific error messages for each failure case, to clearly inform developers if they forget to set the name, summary, description, etc. 9) Tweak the output of the "test show registered" CLI command. I swapped the name and category to have the category first. It seemed more natural since that is the sort key. 10) Don't output the status ast_str in the "test show results" CLI command. This is going to tend to be pretty verbose, so just leave that for the detailed test logs (test generate results). Review: https://reviewboard.asterisk.org/r/493/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@245864 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels/sip')
-rw-r--r--channels/sip/config_parser.c79
-rw-r--r--channels/sip/reqresp_parser.c81
2 files changed, 73 insertions, 87 deletions
diff --git a/channels/sip/config_parser.c b/channels/sip/config_parser.c
index 68abafee0..cf040a928 100644
--- a/channels/sip/config_parser.c
+++ b/channels/sip/config_parser.c
@@ -263,7 +263,7 @@ AST_TEST_DEFINE(sip_parse_register_line_test)
reg->callid_valid != FALSE ||
reg->ocseq != INITIAL_CSEQ) {
- ast_str_append(&args->ast_test_error_str, 0, "Test 1: simple config failed\n");
+ ast_test_status_update(test, "Test 1: simple config failed\n");
res = AST_TEST_FAIL;
}
ast_string_field_free_memory(reg);
@@ -290,7 +290,7 @@ AST_TEST_DEFINE(sip_parse_register_line_test)
reg->callid_valid != FALSE ||
reg->ocseq != INITIAL_CSEQ) {
- ast_str_append(&args->ast_test_error_str, 0, "Test 2: add secret failed\n");
+ ast_test_status_update(test, "Test 2: add secret failed\n");
res = AST_TEST_FAIL;
}
ast_string_field_free_memory(reg);
@@ -317,7 +317,7 @@ AST_TEST_DEFINE(sip_parse_register_line_test)
reg->callid_valid != FALSE ||
reg->ocseq != INITIAL_CSEQ) {
- ast_str_append(&args->ast_test_error_str, 0, "Test 3: add userdomain and authuser failed\n");
+ ast_test_status_update(test, "Test 3: add userdomain and authuser failed\n");
res = AST_TEST_FAIL;
}
ast_string_field_free_memory(reg);
@@ -344,7 +344,7 @@ AST_TEST_DEFINE(sip_parse_register_line_test)
reg->callid_valid != FALSE ||
reg->ocseq != INITIAL_CSEQ) {
- ast_str_append(&args->ast_test_error_str, 0, "Test 4: add callback extension failed\n");
+ ast_test_status_update(test, "Test 4: add callback extension failed\n");
res = AST_TEST_FAIL;
}
ast_string_field_free_memory(reg);
@@ -371,7 +371,7 @@ AST_TEST_DEFINE(sip_parse_register_line_test)
reg->callid_valid != FALSE ||
reg->ocseq != INITIAL_CSEQ) {
- ast_str_append(&args->ast_test_error_str, 0, "Test 5: add transport failed\n");
+ ast_test_status_update(test, "Test 5: add transport failed\n");
res = AST_TEST_FAIL;
}
ast_string_field_free_memory(reg);
@@ -398,7 +398,7 @@ AST_TEST_DEFINE(sip_parse_register_line_test)
reg->callid_valid != FALSE ||
reg->ocseq != INITIAL_CSEQ) {
- ast_str_append(&args->ast_test_error_str, 0, "Test 6: change to tls transport and add expiry failed\n");
+ ast_test_status_update(test, "Test 6: change to tls transport and add expiry failed\n");
res = AST_TEST_FAIL;
}
ast_string_field_free_memory(reg);
@@ -425,7 +425,7 @@ AST_TEST_DEFINE(sip_parse_register_line_test)
reg->callid_valid != FALSE ||
reg->ocseq != INITIAL_CSEQ) {
- ast_str_append(&args->ast_test_error_str, 0, "Test 7, change transport to tcp, add custom port, and add peer failed.\n");
+ ast_test_status_update(test, "Test 7, change transport to tcp, add custom port, and add peer failed.\n");
res = AST_TEST_FAIL;
}
ast_string_field_free_memory(reg);
@@ -452,7 +452,7 @@ AST_TEST_DEFINE(sip_parse_register_line_test)
reg->callid_valid != FALSE ||
reg->ocseq != INITIAL_CSEQ) {
- ast_str_append(&args->ast_test_error_str, 0, "Test 8, remove transport failed.\n");
+ ast_test_status_update(test, "Test 8, remove transport failed.\n");
res = AST_TEST_FAIL;
}
ast_string_field_free_memory(reg);
@@ -462,8 +462,8 @@ AST_TEST_DEFINE(sip_parse_register_line_test)
if (!(reg = ast_calloc_with_stringfields(1, struct sip_registry, 256))) {
goto alloc_fail;
} else if (!sip_parse_register_line(reg, default_expiry, reg9, 1)) {
-
- ast_str_append(&args->ast_test_error_str, 0, "Test 9, missing domain, expected to fail but did not.\n");
+ ast_test_status_update(test,
+ "Test 9, missing domain, expected to fail but did not.\n");
res = AST_TEST_FAIL;
}
ast_string_field_free_memory(reg);
@@ -473,8 +473,8 @@ AST_TEST_DEFINE(sip_parse_register_line_test)
if (!(reg = ast_calloc_with_stringfields(1, struct sip_registry, 256))) {
goto alloc_fail;
} else if (!sip_parse_register_line(reg, default_expiry, reg10, 1)) {
-
- ast_str_append(&args->ast_test_error_str, 0, "Test 10, missing user expected to fail but did not\n");
+ ast_test_status_update(test,
+ "Test 10, missing user expected to fail but did not\n");
res = AST_TEST_FAIL;
}
ast_string_field_free_memory(reg);
@@ -482,8 +482,8 @@ AST_TEST_DEFINE(sip_parse_register_line_test)
/* ---Test reg 11, no registry object, expected to fail--- */
if (!sip_parse_register_line(NULL, default_expiry, reg1, 1)) {
-
- ast_str_append(&args->ast_test_error_str, 0, "Test 11, no registery object, expected to fail but did not.\n");
+ ast_test_status_update(test,
+ "Test 11, no registery object, expected to fail but did not.\n");
res = AST_TEST_FAIL;
}
@@ -492,7 +492,8 @@ AST_TEST_DEFINE(sip_parse_register_line_test)
goto alloc_fail;
} else if (!sip_parse_register_line(reg, default_expiry, NULL, 1)) {
- ast_str_append(&args->ast_test_error_str, 0, "Test 11, NULL register line expected to fail but did not.\n");
+ ast_test_status_update(test,
+ "Test 11, NULL register line expected to fail but did not.\n");
res = AST_TEST_FAIL;
}
ast_string_field_free_memory(reg);
@@ -502,7 +503,7 @@ AST_TEST_DEFINE(sip_parse_register_line_test)
return res;
alloc_fail:
- ast_str_set(&args->ast_test_error_str, 0, "Out of memory. \n");
+ ast_test_status_update(test, "Out of memory. \n");
return res;
}
@@ -582,60 +583,54 @@ AST_TEST_DEFINE(sip_parse_host_line_test)
/* test 1, simple host */
sip_parse_host(host1, 1, &host, &port, &transport);
if (port != STANDARD_SIP_PORT ||
- ast_strlen_zero(host) || strcmp(host, "www.blah.com") ||
- transport != SIP_TRANSPORT_UDP) {
-
- ast_str_append(&args->ast_test_error_str, 0, "Test 1: simple host failed.\n");
+ ast_strlen_zero(host) || strcmp(host, "www.blah.com") ||
+ transport != SIP_TRANSPORT_UDP) {
+ ast_test_status_update(test, "Test 1: simple host failed.\n");
res = AST_TEST_FAIL;
}
/* test 2, add tcp transport */
sip_parse_host(host2, 1, &host, &port, &transport);
if (port != STANDARD_SIP_PORT ||
- ast_strlen_zero(host) || strcmp(host, "www.blah.com") ||
- transport != SIP_TRANSPORT_TCP) {
-
- ast_str_append(&args->ast_test_error_str, 0, "Test 2: tcp host failed.\n");
+ ast_strlen_zero(host) || strcmp(host, "www.blah.com") ||
+ transport != SIP_TRANSPORT_TCP) {
+ ast_test_status_update(test, "Test 2: tcp host failed.\n");
res = AST_TEST_FAIL;
}
/* test 3, add tls transport */
sip_parse_host(host3, 1, &host, &port, &transport);
if (port != STANDARD_TLS_PORT ||
- ast_strlen_zero(host) || strcmp(host, "10.10.10.10") ||
- transport != SIP_TRANSPORT_TLS) {
-
- ast_str_append(&args->ast_test_error_str, 0, "Test 3: tls host failed. \n");
+ ast_strlen_zero(host) || strcmp(host, "10.10.10.10") ||
+ transport != SIP_TRANSPORT_TLS) {
+ ast_test_status_update(test, "Test 3: tls host failed. \n");
res = AST_TEST_FAIL;
}
/* test 4, add custom port with tls */
sip_parse_host(host4, 1, &host, &port, &transport);
- if (port != 1234 ||
- ast_strlen_zero(host) || strcmp(host, "10.10.10.10") ||
- transport != SIP_TRANSPORT_TLS) {
-
- ast_str_append(&args->ast_test_error_str, 0, "Test 4: tls host with custom port failed.\n");
+ if (port != 1234 || ast_strlen_zero(host) ||
+ strcmp(host, "10.10.10.10") ||
+ transport != SIP_TRANSPORT_TLS) {
+ ast_test_status_update(test, "Test 4: tls host with custom port failed.\n");
res = AST_TEST_FAIL;
}
/* test 5, simple host with custom port */
sip_parse_host(host5, 1, &host, &port, &transport);
- if (port != 1234 ||
- ast_strlen_zero(host) || strcmp(host, "10.10.10.10") ||
- transport != SIP_TRANSPORT_UDP) {
-
- ast_str_append(&args->ast_test_error_str, 0, "Test 5: simple host with custom port failed.\n");
+ if (port != 1234 || ast_strlen_zero(host) ||
+ strcmp(host, "10.10.10.10") ||
+ transport != SIP_TRANSPORT_UDP) {
+ ast_test_status_update(test, "Test 5: simple host with custom port failed.\n");
res = AST_TEST_FAIL;
}
- return res;
/* test 6, expected failure with NULL input */
- if (sip_parse_host(NULL, 1, &host, &port, &transport)) {
-
- ast_str_append(&args->ast_test_error_str, 0, "Test 6: expected error on NULL input did not occur.\n");
+ if (!sip_parse_host(NULL, 1, &host, &port, &transport)) {
+ ast_test_status_update(test, "Test 6: expected error on NULL input did not occur.\n");
res = AST_TEST_FAIL;
}
+
return res;
}
diff --git a/channels/sip/reqresp_parser.c b/channels/sip/reqresp_parser.c
index 6fec362cc..fe6ce0e1c 100644
--- a/channels/sip/reqresp_parser.c
+++ b/channels/sip/reqresp_parser.c
@@ -139,66 +139,62 @@ AST_TEST_DEFINE(sip_parse_uri_test)
/* Test 1, simple URI */
name = pass = domain = port = transport = NULL;
if (parse_uri(uri1, "sip:,sips:", &name, &pass, &domain, &port, &transport) ||
- strcmp(name, "name") ||
- !ast_strlen_zero(pass) ||
- strcmp(domain, "host") ||
- !ast_strlen_zero(port) ||
- !ast_strlen_zero(transport)) {
-
- ast_str_append(&args->ast_test_error_str, 0, "Test 1: simple uri failed. \n");
+ strcmp(name, "name") ||
+ !ast_strlen_zero(pass) ||
+ strcmp(domain, "host") ||
+ !ast_strlen_zero(port) ||
+ !ast_strlen_zero(transport)) {
+ ast_test_status_update(test, "Test 1: simple uri failed. \n");
res = AST_TEST_FAIL;
}
/* Test 2, add tcp transport */
name = pass = domain = port = transport = NULL;
if (parse_uri(uri2, "sip:,sips:", &name, &pass, &domain, &port, &transport) ||
- strcmp(name, "name") ||
- !ast_strlen_zero(pass) ||
- strcmp(domain, "host") ||
- !ast_strlen_zero(port) ||
- strcmp(transport, "tcp")) {
-
- ast_str_append(&args->ast_test_error_str, 0, "Test 2: uri with addtion of tcp transport failed. \n");
+ strcmp(name, "name") ||
+ !ast_strlen_zero(pass) ||
+ strcmp(domain, "host") ||
+ !ast_strlen_zero(port) ||
+ strcmp(transport, "tcp")) {
+ ast_test_status_update(test, "Test 2: uri with addtion of tcp transport failed. \n");
res = AST_TEST_FAIL;
}
/* Test 3, add secret */
name = pass = domain = port = transport = NULL;
if (parse_uri(uri3, "sip:,sips:", &name, &pass, &domain, &port, &transport) ||
- strcmp(name, "name") ||
- strcmp(pass, "secret") ||
- strcmp(domain, "host") ||
- !ast_strlen_zero(port) ||
- strcmp(transport, "tcp")) {
-
- ast_str_append(&args->ast_test_error_str, 0, "Test 3: uri with addition of secret failed.\n");
+ strcmp(name, "name") ||
+ strcmp(pass, "secret") ||
+ strcmp(domain, "host") ||
+ !ast_strlen_zero(port) ||
+ strcmp(transport, "tcp")) {
+ ast_test_status_update(test, "Test 3: uri with addition of secret failed.\n");
res = AST_TEST_FAIL;
}
/* Test 4, add port and unparsed header field*/
name = pass = domain = port = transport = NULL;
if (parse_uri(uri4, "sip:,sips:", &name, &pass, &domain, &port, &transport) ||
- strcmp(name, "name") ||
- strcmp(pass, "secret") ||
- strcmp(domain, "host") ||
- strcmp(port, "port") ||
- strcmp(transport, "tcp")) {
-
- ast_str_append(&args->ast_test_error_str, 0, "Test 4: add port and unparsed header field failed.\n");
+ strcmp(name, "name") ||
+ strcmp(pass, "secret") ||
+ strcmp(domain, "host") ||
+ strcmp(port, "port") ||
+ strcmp(transport, "tcp")) {
+ ast_test_status_update(test, "Test 4: add port and unparsed header field failed.\n");
res = AST_TEST_FAIL;
}
/* Test 5, verify parse_uri does not crash when given a NULL uri */
name = pass = domain = port = transport = NULL;
if (!parse_uri(NULL, "sip:,sips:", &name, &pass, &domain, &port, &transport)) {
- ast_str_append(&args->ast_test_error_str, 0, "Test 5: passing a NULL uri failed.\n");
+ ast_test_status_update(test, "Test 5: passing a NULL uri failed.\n");
res = AST_TEST_FAIL;
}
/* Test 6, verify parse_uri does not crash when given a NULL output parameters */
name = pass = domain = port = transport = NULL;
if (parse_uri(uri4, "sip:,sips:", NULL, NULL, NULL, NULL, NULL)) {
- ast_str_append(&args->ast_test_error_str, 0, "Test 6: passing NULL output parameters failed.\n");
+ ast_test_status_update(test, "Test 6: passing NULL output parameters failed.\n");
res = AST_TEST_FAIL;
}
@@ -339,46 +335,41 @@ AST_TEST_DEFINE(get_calleridname_test)
/* quoted-text with backslash escaped quote */
after_dname = get_calleridname(in1, dname, sizeof(dname));
- ast_test_status_update(&args->status_update, "display-name1: %s\nafter: %s\n", dname, after_dname);
+ ast_test_status_update(test, "display-name1: %s\nafter: %s\n", dname, after_dname);
if (strcmp(dname, " quoted-text internal \" quote ")) {
- ast_test_status_update(&args->status_update, "display-name1 test failed\n");
- ast_str_append(&args->ast_test_error_str, 0, "quoted-text with internal backslash decode failed. \n");
+ ast_test_status_update(test, "display-name1 test failed\n");
res = AST_TEST_FAIL;
}
/* token text */
after_dname = get_calleridname(in2, dname, sizeof(dname));
- ast_test_status_update(&args->status_update, "display-name2: %s\nafter: %s\n", dname, after_dname);
+ ast_test_status_update(test, "display-name2: %s\nafter: %s\n", dname, after_dname);
if (strcmp(dname, "token text with no quotes")) {
- ast_test_status_update(&args->status_update, "display-name2 test failed\n");
- ast_str_append(&args->ast_test_error_str, 0, "token text with decode failed. \n");
+ ast_test_status_update(test, "display-name2 test failed\n");
res = AST_TEST_FAIL;
}
/* quoted-text buffer overflow */
after_dname = get_calleridname(overflow1, dname, sizeof(dname));
- ast_test_status_update(&args->status_update, "overflow display-name1: %s\nafter: %s\n", dname, after_dname);
+ ast_test_status_update(test, "overflow display-name1: %s\nafter: %s\n", dname, after_dname);
if (*dname != '\0' && after_dname != overflow1) {
- ast_test_status_update(&args->status_update, "overflow display-name1 test failed\n");
- ast_str_append(&args->ast_test_error_str, 0, "quoted-text buffer overflow check failed. \n");
+ ast_test_status_update(test, "overflow display-name1 test failed\n");
res = AST_TEST_FAIL;
}
/* quoted-text buffer with no terminating end quote */
after_dname = get_calleridname(noendquote, dname, sizeof(dname));
- ast_test_status_update(&args->status_update, "noendquote display-name1: %s\nafter: %s\n", dname, after_dname);
+ ast_test_status_update(test, "noendquote display-name1: %s\nafter: %s\n", dname, after_dname);
if (*dname != '\0' && after_dname != noendquote) {
- ast_test_status_update(&args->status_update, "no end quote for quoted-text display-name failed\n");
- ast_str_append(&args->ast_test_error_str, 0, "quoted-text buffer check no terminating end quote failed. \n");
+ ast_test_status_update(test, "no end quote for quoted-text display-name failed\n");
res = AST_TEST_FAIL;
}
/* addr-spec rather than display-name. */
after_dname = get_calleridname(addrspec, dname, sizeof(dname));
- ast_test_status_update(&args->status_update, "noendquote display-name1: %s\nafter: %s\n", dname, after_dname);
+ ast_test_status_update(test, "noendquote display-name1: %s\nafter: %s\n", dname, after_dname);
if (*dname != '\0' && after_dname != addrspec) {
- ast_test_status_update(&args->status_update, "detection of addr-spec failed\n");
- ast_str_append(&args->ast_test_error_str, 0, "detection of addr-spec failed. \n");
+ ast_test_status_update(test, "detection of addr-spec failed\n");
res = AST_TEST_FAIL;
}