[asterisk-commits] dvossel: branch dvossel/test_api r235223 - in /team/dvossel/test_api: include...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Dec 15 17:18:58 CST 2009
Author: dvossel
Date: Tue Dec 15 17:18:56 2009
New Revision: 235223
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=235223
Log:
additional documentation updates, forces callback function to return enum result
Modified:
team/dvossel/test_api/include/asterisk/test.h
team/dvossel/test_api/main/test.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=235223&r1=235222&r2=235223
==============================================================================
--- team/dvossel/test_api/include/asterisk/test.h (original)
+++ team/dvossel/test_api/include/asterisk/test.h Tue Dec 15 17:18:56 2009
@@ -22,67 +22,69 @@
* \brief Test Framework API
*/
-/* How to use the test API
+#ifdef TEST_FRAMEWORK
+#include "asterisk/cli.h"
+#include "asterisk/strings.h"
+#endif
+
+/* USING THE TEST FRAMEWORK
1. DEFINE TEST: Create a callback function for the test
using the AST_TEST_DEFINE macro.
-AST_TEST_DEFINE(sample_test_cb, \\The first argument is the name of the callback function
-{ \\The second argument is the function's body *
- \test code
- .
- .
- .
+ AST_TEST_DEFINE(sample_test_cb, \\The first argument is the name of the callback function
+ { \\The second argument is the function's body *
+ \test code
+ .
+ .
+ .
+ if (fail) { \\ the following is just some example logic
+ ast_str_set(error_str, 0 , "an error occured because....");
+ res = AST_RESULT_FAIL;
+ } else {
+ res = AST_RESULT_PASS
+ }
+ \\ result must be of type enum ast_test_result_state
+ return res;
+ })
- \\ the following is just some example logic
-
- if (fail) {
- ast_str_set(error_str, 0 , "an error occured because....");
- res = AST_RESULT_FAIL;
- } else {
- res = AST_RESULT_PASS
- }
- \\ result must be of type enum ast_test_result_state
- return res;
-})
+ Every callback function is passed a string buffer which allows
+ the function to provide an optional short description of
+ what went wrong if the test failed.
-Every callback function is passed a string buffer which allows
-the function to provide an optional short description of
-what went wrong if the test failed.
-
-*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.
+ *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.
-AST_TEST_REGISTER("sample_test", \\ Test's Name
- "main/test", \\ Test's Catagory
- "this is sample test", \\ Brief summary of test
- "Sample test designed for test purposes", \\ Verbose discription of test
- sample_test_cb); \\ Test callback function defined by AST_TEST_DEFINE
+ AST_TEST_REGISTER("sample_test", \\ Test's Name
+ "main/test", \\ Test's Catagory
+ "this is sample test", \\ Brief summary of test
+ "Sample test designed for test purposes", \\ Verbose discription of test
+ sample_test_cb); \\ Test callback function defined by AST_TEST_DEFINE
-Tests are unregestered by using the AST_TEST_UNREGISTER macro.
+ Tests are unregestered by using the AST_TEST_UNREGISTER macro.
-AST_TEST_REGISTER(sample_test_cb); \\ Test callback function to match registered test
+ AST_TEST_REGISTER(sample_test_cb); \\ Test callback function to match registered test
3. EXECUTE: Execute and generate test results via CLI commands
-CLI Examples:
-'test show registered all' will show every registered test.
-'test execute all' will execute every registered test.
-'test show results all' will show detailed results for ever executed test
-'test generate results xml' will generate a test report in xml format
-'test generate results txt' will generate a test report in txt format
+ CLI Examples:
+ 'test show registered all' will show every registered test.
+ 'test execute all' will execute every registered test.
+ 'test show results all' will show detailed results for ever executed test
+ 'test generate results xml' will generate a test report in xml format
+ 'test generate results txt' will generate a test report in txt format
*/
/*! Macros used for defining and registering a test */
#ifdef TEST_FRAMEWORK
-#define AST_TEST_DEFINE(hdr, body) int hdr(struct ast_str **error_str); int hdr(struct ast_str **error_str) body
+#define AST_TEST_DEFINE(hdr, body) enum ast_test_result_state hdr(struct ast_str **error_str); enum ast_test_result_state hdr(struct ast_str **error_str) body
#define AST_TEST_REGISTER(name, cat, sum, des, cb) ast_test_register(name, cat, sum, des, cb)
#define AST_TEST_UNREGISTER(cb) ast_test_unregister(cb)
#else /* else no-op */
@@ -91,12 +93,7 @@
#define AST_TEST_UNREGISTER(cb)
#endif
-
#ifdef TEST_FRAMEWORK
-
-#include "asterisk/cli.h"
-#include "asterisk/strings.h"
-
/*!
* \brief Generic test callback function
*
@@ -104,7 +101,7 @@
*
* \return AST_TEST_PASS for pass, AST_TEST_FAIL for failure
*/
-typedef int (ast_test_cb_t)(struct ast_str **error_str);
+typedef enum ast_test_result_state (ast_test_cb_t)(struct ast_str **error_str);
enum ast_test_result_state {
AST_TEST_NOT_RUN = 0,
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=235223&r1=235222&r2=235223
==============================================================================
--- team/dvossel/test_api/main/test.c (original)
+++ team/dvossel/test_api/main/test.c Tue Dec 15 17:18:56 2009
@@ -601,8 +601,10 @@
case CLI_INIT:
e->command = "test show results";
e->usage =
- "Usage: test show results\n"
- " Displays test results for tests that has been run.\n";
+ "Usage: test show results can be used in three ways\n"
+ " 1. 'test show results all' Displays results for all executed tests.\n"
+ " 2. 'test show results passed' Displays results for all passed tests.\n"
+ " 3. 'test show results failed' Displays results for all failed tests.\n";
return NULL;
case CLI_GENERATE:
if (a->pos == 3) {
More information about the asterisk-commits
mailing list