[asterisk-commits] dvossel: branch dvossel/test_api r235428 - in /team/dvossel/test_api: include...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Dec 17 12:02:22 CST 2009


Author: dvossel
Date: Thu Dec 17 12:02:21 2009
New Revision: 235428

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=235428
Log:
fixes the ',' issue causing multiple arguments to AST_TEST_DEFINE macro

Modified:
    team/dvossel/test_api/include/asterisk/test.h
    team/dvossel/test_api/main/test.c
    team/dvossel/test_api/tests/test_heap.c

Modified: team/dvossel/test_api/include/asterisk/test.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/test_api/include/asterisk/test.h?view=diff&rev=235428&r1=235427&r2=235428
==============================================================================
--- team/dvossel/test_api/include/asterisk/test.h (original)
+++ team/dvossel/test_api/include/asterisk/test.h Thu Dec 17 12:02:21 2009
@@ -41,12 +41,12 @@
        \param struct ast_test_args *args
 
    While these arguments are not visible they are passed to every test function
-   defined using the AST_TEST_DEFINE macro.
+   defined using the AST_TEST_DEFINE macros.
 
    Below is an example of how to define and write a test function.
 
-   AST_TEST_DEFINE(sample_test_cb, \\The first argument is the name of the callback function
-   {                               \\The second argument is the function's body *
+   AST_TEST_DEFINE_BEGIN(sample_test_cb) \\The name of the callback function
+   {                                     \\The the function's body 
       switch (cmd) {
       case TEST_INIT:
           info->name = "sample_test";
@@ -69,20 +69,13 @@
           res = AST_RESULT_PASS
       }
       return res;                 \\ result must be of type enum ast_test_result_state
-   })
+   }
+   AST_TEST_DEFINE_END            \\ defines the end of the test code.
 
    Every callback function is passed an ast_test_args object which contains
    an ast_str allowing the function to provide an optional short description of
    what went wrong if the test failed. This is done by writing to
    args->ast_test_error_str.
-
-   *NOTE: It is possible for a ',' within the code body to mess up the macro
-   depending on how it is used.  If this happens (it will be obvious because
-   code won't compile) and can not be avoided, a separate static function must
-   be created to hold the test's code.  In this case the callback's message body
-   should just contain a call to the static function. Any supporting static
-   functions must be wrapped by an '#ifdef TEST_FRAMEWORK' block if they are
-   not also called by another none test defined function.
 
 2. REGISTER TEST: Register the test using the AST_TEST_REGISTER macro.
 
@@ -108,11 +101,13 @@
 
 /*! Macros used for defining and registering a test */
 #ifdef TEST_FRAMEWORK
-#define AST_TEST_DEFINE(hdr, body) static enum ast_test_result_state hdr(struct ast_test_info *info, enum ast_test_command cmd, struct ast_test_args *args) body
+#define AST_TEST_DEFINE_BEGIN(hdr) static enum ast_test_result_state hdr(struct ast_test_info *info, enum ast_test_command cmd, struct ast_test_args *args)
+#define AST_TEST_DEFINE_END /* no-op, TEST_FRAMEWORK is already defined */
 #define AST_TEST_REGISTER(cb) ast_test_register(cb)
 #define AST_TEST_UNREGISTER(cb) ast_test_unregister(cb)
-#else /* else no-op */
-#define AST_TEST_DEFINE(hdr, body)
+#else
+#define AST_TEST_DEFINE_BEGIN(hdr) #ifdef TEST_FRAMEWORK
+#define AST_TEST_DEFINE_END #endif
 #define AST_TEST_REGISTER(cb)
 #define AST_TEST_UNREGISTER(cb)
 #endif

Modified: team/dvossel/test_api/main/test.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/test_api/main/test.c?view=diff&rev=235428&r1=235427&r2=235428
==============================================================================
--- team/dvossel/test_api/main/test.c (original)
+++ team/dvossel/test_api/main/test.c Thu Dec 17 12:02:21 2009
@@ -245,7 +245,7 @@
 
 		if (execute) {
 			if (fd) {
-				ast_cli(fd, "START  %s/%s \n", test->info.category, test->info.name);
+				ast_cli(fd, "START  %s - %s \n", test->info.category, test->info.name);
 			}
 
 			/* execute the test and save results */
@@ -265,7 +265,7 @@
 					(test->state == AST_TEST_FAIL) ? COLOR_RED : COLOR_GREEN,
 					0,
 					sizeof(result_buf));
-				ast_cli(fd, "END    %s/%s Time: %dms Result: %s %s\n",
+				ast_cli(fd, "END    %s - %s Time: %dms Result: %s %s\n",
 					test->info.category,
 					test->info.name,
 					test->time,

Modified: team/dvossel/test_api/tests/test_heap.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/test_api/tests/test_heap.c?view=diff&rev=235428&r1=235427&r2=235428
==============================================================================
--- team/dvossel/test_api/tests/test_heap.c (original)
+++ team/dvossel/test_api/tests/test_heap.c Thu Dec 17 12:02:21 2009
@@ -57,7 +57,7 @@
 }
 #endif
 
-AST_TEST_DEFINE(heap_test_1,
+AST_TEST_DEFINE_BEGIN(heap_test_1)
 {
 	struct ast_heap *h;
 	struct node *obj;
@@ -113,9 +113,10 @@
 	h = ast_heap_destroy(h);
 
 	return AST_TEST_PASS;
-})
-
-AST_TEST_DEFINE(heap_test_2,
+}
+AST_TEST_DEFINE_END
+
+AST_TEST_DEFINE_BEGIN(heap_test_2)
 {
 	struct ast_heap *h = NULL;
 	static const unsigned int one_million = 1000000;
@@ -184,7 +185,8 @@
 	}
 
 	return res;
-})
+}
+AST_TEST_DEFINE_END
 
 
 static int unload_module(void)




More information about the asterisk-commits mailing list