[Asterisk-code-review] Unit tests: Use AST TEST DEFINE in conditional code only. (asterisk[11])

Anonymous Coward asteriskteam at digium.com
Wed Jul 20 10:57:51 CDT 2016


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: Unit tests: Use AST_TEST_DEFINE in conditional code only.
......................................................................


Unit tests: Use AST_TEST_DEFINE in conditional code only.

If AST_TEST_DEFINE is not conditional to TEST_FRAMEWORK it produces dead
code.  This places all existing unit tests into a conditional block if
they weren't already.

ASTERISK-26211 #close

Change-Id: I8ef83ee11cbc991b07b7a37ecb41433e8c734686
---
M apps/app_voicemail.c
M channels/sip/config_parser.c
M channels/sip/reqresp_parser.c
M funcs/func_curl.c
4 files changed, 32 insertions(+), 3 deletions(-)

Approvals:
  George Joseph: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved



diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 56ea179..4f8302b 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -11828,6 +11828,7 @@
 	return 0;
 }
 
+#ifdef TEST_FRAMEWORK
 AST_TEST_DEFINE(test_voicemail_vmuser)
 {
 	int res = 0;
@@ -12015,6 +12016,7 @@
 	free_user(vmu);
 	return res ? AST_TEST_FAIL : AST_TEST_PASS;
 }
+#endif
 
 static int vm_box_exists(struct ast_channel *chan, const char *data) 
 {
diff --git a/channels/sip/config_parser.c b/channels/sip/config_parser.c
index 45221e0..17e5321 100644
--- a/channels/sip/config_parser.c
+++ b/channels/sip/config_parser.c
@@ -274,6 +274,7 @@
 	return 0;
 }
 
+#ifdef TEST_FRAMEWORK
 AST_TEST_DEFINE(sip_parse_register_line_test)
 {
 	int res = AST_TEST_PASS;
@@ -643,6 +644,7 @@
 	ast_test_status_update(test, "Out of memory. \n");
 	return res;
 }
+#endif
 
 int sip_parse_host(char *line, int lineno, char **hostname, int *portnum, enum sip_transport *transport)
 {
@@ -708,6 +710,7 @@
 	return 0;
 }
 
+#ifdef TEST_FRAMEWORK
 AST_TEST_DEFINE(sip_parse_host_line_test)
 {
 	int res = AST_TEST_PASS;
@@ -787,6 +790,7 @@
 	return res;
 
 }
+#endif
 
 /*! \brief Parse the comma-separated nat= option values */
 void sip_parse_nat_option(const char *value, struct ast_flags *mask, struct ast_flags *flags)
@@ -834,6 +838,7 @@
 	}
 }
 
+#ifdef TEST_FRAMEWORK
 #define TEST_FORCE_RPORT      1 << 0
 #define TEST_COMEDIA          1 << 1
 #define TEST_AUTO_FORCE_RPORT 1 << 2
@@ -904,6 +909,8 @@
 
 	return res;
 }
+#endif
+
 /*! \brief SIP test registration */
 void sip_config_parser_register_tests(void)
 {
diff --git a/channels/sip/reqresp_parser.c b/channels/sip/reqresp_parser.c
index 9b435d0..30a718a 100644
--- a/channels/sip/reqresp_parser.c
+++ b/channels/sip/reqresp_parser.c
@@ -220,7 +220,7 @@
 	return error;
 }
 
-
+#ifdef TEST_FRAMEWORK
 AST_TEST_DEFINE(sip_parse_uri_full_test)
 {
 	int res = AST_TEST_PASS;
@@ -429,7 +429,7 @@
 
 	return res;
 }
-
+#endif
 
 int parse_uri(char *uri, const char *scheme, char **user, char **pass,
 	      char **hostport, char **transport) {
@@ -445,6 +445,7 @@
 	return ret;
 }
 
+#ifdef TEST_FRAMEWORK
 AST_TEST_DEFINE(sip_parse_uri_test)
 {
 	int res = AST_TEST_PASS;
@@ -590,6 +591,7 @@
 
 	return res;
 }
+#endif
 
 /*! \brief  Get caller id name from SIP headers, copy into output buffer
  *
@@ -720,6 +722,7 @@
 	return input;
 }
 
+#ifdef TEST_FRAMEWORK
 AST_TEST_DEFINE(get_calleridname_test)
 {
 	int res = AST_TEST_PASS;
@@ -802,6 +805,7 @@
 
 	return res;
 }
+#endif
 
 int get_name_and_number(const char *hdr, char **name, char **number)
 {
@@ -843,6 +847,7 @@
 	return 0;
 }
 
+#ifdef TEST_FRAMEWORK
 AST_TEST_DEFINE(get_name_and_number_test)
 {
 	int res = AST_TEST_PASS;
@@ -947,6 +952,7 @@
 
 	return res;
 }
+#endif
 
 int get_in_brackets_const(const char *src,const char **start,int *length)
 {
@@ -1079,6 +1085,7 @@
 	return out;
 }
 
+#ifdef TEST_FRAMEWORK
 AST_TEST_DEFINE(get_in_brackets_test)
 {
 	int res = AST_TEST_PASS;
@@ -1155,7 +1162,7 @@
 
 	return res;
 }
-
+#endif
 
 int parse_name_andor_addr(char *uri, const char *scheme, char **name,
 			  char **user, char **pass, char **hostport,
@@ -1201,6 +1208,7 @@
 	return parse_uri_full(uri, scheme, user, pass, hostport, params, headers, residue2);
 }
 
+#ifdef TEST_FRAMEWORK
 AST_TEST_DEFINE(parse_name_andor_addr_test)
 {
 	int res = AST_TEST_PASS;
@@ -1330,6 +1338,7 @@
 
 	return res;
 }
+#endif
 
 int get_comma(char *in, char **out)
 {
@@ -1426,6 +1435,7 @@
 	return last;
 }
 
+#ifdef TEST_FRAMEWORK
 AST_TEST_DEFINE(parse_contact_header_test)
 {
 	int res = AST_TEST_PASS;
@@ -1571,6 +1581,7 @@
 
 	return res;
 }
+#endif
 
 /*!
  * \brief Parse supported header in incoming packet
@@ -1658,6 +1669,7 @@
 	return profile;
 }
 
+#ifdef TEST_FRAMEWORK
 AST_TEST_DEFINE(sip_parse_options_test)
 {
 	int res = AST_TEST_PASS;
@@ -1795,6 +1807,7 @@
 
 	return res;
 }
+#endif
 
 /*! \brief helper routine for sip_uri_cmp to compare URI parameters
  *
@@ -2149,6 +2162,7 @@
 #define URI_CMP_MATCH 0
 #define URI_CMP_NOMATCH 1
 
+#ifdef TEST_FRAMEWORK
 AST_TEST_DEFINE(sip_uri_cmp_test)
 {
 	static const struct {
@@ -2265,6 +2279,7 @@
 
 	return test_res;
 }
+#endif
 
 void free_via(struct sip_via *v)
 {
@@ -2351,6 +2366,7 @@
 	return v;
 }
 
+#ifdef TEST_FRAMEWORK
 AST_TEST_DEFINE(parse_via_test)
 {
 	int res = AST_TEST_PASS;
@@ -2528,6 +2544,7 @@
 	}
 	return res;
 }
+#endif
 
 void sip_request_parser_register_tests(void)
 {
@@ -2542,6 +2559,7 @@
 	AST_TEST_REGISTER(sip_uri_cmp_test);
 	AST_TEST_REGISTER(parse_via_test);
 }
+
 void sip_request_parser_unregister_tests(void)
 {
 	AST_TEST_UNREGISTER(sip_parse_uri_test);
diff --git a/funcs/func_curl.c b/funcs/func_curl.c
index 1795a81..991da30 100644
--- a/funcs/func_curl.c
+++ b/funcs/func_curl.c
@@ -794,6 +794,7 @@
 	.write = acf_curlopt_write,
 };
 
+#ifdef TEST_FRAMEWORK
 AST_TEST_DEFINE(vulnerable_url)
 {
 	const char *bad_urls [] = {
@@ -841,6 +842,7 @@
 
 	return res;
 }
+#endif
 
 static int unload_module(void)
 {

-- 
To view, visit https://gerrit.asterisk.org/3225
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I8ef83ee11cbc991b07b7a37ecb41433e8c734686
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 11
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list