diff options
author | Russell Bryant <russell@russellbryant.com> | 2010-02-09 23:32:14 +0000 |
---|---|---|
committer | Russell Bryant <russell@russellbryant.com> | 2010-02-09 23:32:14 +0000 |
commit | bbed34f76455df0250862ba4c4c324452ad6c0bb (patch) | |
tree | d10f5c6801b7a0d86ccd2dd6b5b3986e93b82fb5 /channels/sip/config_parser.c | |
parent | dd48c7eb407db16ac60d013319b893f021253af9 (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: https://origsvn.digium.com/svn/asterisk/trunk@245864 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels/sip/config_parser.c')
-rw-r--r-- | channels/sip/config_parser.c | 79 |
1 files changed, 37 insertions, 42 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; } |