[asterisk-commits] dlee: branch dlee/ASTERISK-22296 r397703 - in /team/dlee/ASTERISK-22296: buil...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 27 09:11:30 CDT 2013


Author: dlee
Date: Tue Aug 27 09:11:28 2013
New Revision: 397703

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=397703
Log:
Unit tests for optional_api

Added:
    team/dlee/ASTERISK-22296/tests/test_optional_api.c   (with props)
Modified:
    team/dlee/ASTERISK-22296/build_tools/cflags.xml
    team/dlee/ASTERISK-22296/include/asterisk/optional_api.h
    team/dlee/ASTERISK-22296/main/asterisk.c
    team/dlee/ASTERISK-22296/main/optional_api.c

Modified: team/dlee/ASTERISK-22296/build_tools/cflags.xml
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22296/build_tools/cflags.xml?view=diff&rev=397703&r1=397702&r2=397703
==============================================================================
--- team/dlee/ASTERISK-22296/build_tools/cflags.xml (original)
+++ team/dlee/ASTERISK-22296/build_tools/cflags.xml Tue Aug 27 09:11:28 2013
@@ -30,10 +30,11 @@
 			  -->
 			<support_level>extended</support_level>
 		</member>
-		<member name="DISABLE_OPTIONAL_API" displayname="Disable the optional API">
+		<member name="OPTIONAL_API" displayname="Enable the optional API">
 			<!-- Added to manually disable the optional API, since
 			     it's now supported on all systems.
 			  -->
+			<defaultenabled>yes</defaultenabled>
 			<support_level>extended</support_level>
 		</member>
 		<member name="BETTER_BACKTRACES" displayname="Use libbfd (GPL) to generate better inline backtraces">

Modified: team/dlee/ASTERISK-22296/include/asterisk/optional_api.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22296/include/asterisk/optional_api.h?view=diff&rev=397703&r1=397702&r2=397703
==============================================================================
--- team/dlee/ASTERISK-22296/include/asterisk/optional_api.h (original)
+++ team/dlee/ASTERISK-22296/include/asterisk/optional_api.h Tue Aug 27 09:11:28 2013
@@ -105,7 +105,7 @@
  * \param stub The code block that will be used by the hidden stub when needed
  */
 
-#if !defined(AST_NO_OPTIONAL_API)
+#if defined(OPTIONAL_API)
 
 /*!
  * \internal
@@ -231,7 +231,7 @@
 
 #endif /* defined(AST_API_MODULE) */
 
-#else /* !define(AST_NO_OPTIONAL_API) */
+#else /* defined(OPTIONAL_API) */
 
 /* Non-optional API */
 
@@ -243,7 +243,7 @@
 #define AST_OPTIONAL_API_ATTR(result, attr, name, proto, stub)	\
 	result __attribute__((attr)) AST_OPTIONAL_API_NAME(name) proto
 
-#endif
+#endif /* defined(OPTIONAL_API) */
 
 #undef AST_API_MODULE
 

Modified: team/dlee/ASTERISK-22296/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22296/main/asterisk.c?view=diff&rev=397703&r1=397702&r2=397703
==============================================================================
--- team/dlee/ASTERISK-22296/main/asterisk.c (original)
+++ team/dlee/ASTERISK-22296/main/asterisk.c Tue Aug 27 09:11:28 2013
@@ -4135,7 +4135,9 @@
 			ast_el_read_history(filename);
 	}
 
+#if defined(OPTIONAL_API)
 	ast_register_cleanup(optional_api_cleanup);
+#endif
 
 	ast_json_init();
 	ast_ulaw_init();

Modified: team/dlee/ASTERISK-22296/main/optional_api.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22296/main/optional_api.c?view=diff&rev=397703&r1=397702&r2=397703
==============================================================================
--- team/dlee/ASTERISK-22296/main/optional_api.c (original)
+++ team/dlee/ASTERISK-22296/main/optional_api.c Tue Aug 27 09:11:28 2013
@@ -22,6 +22,8 @@
 
 #include "asterisk/optional_api.h"
 #include "asterisk/utils.h"
+
+#if defined(OPTIONAL_API)
 
 /*
  * \file Optional API innards.
@@ -361,3 +363,5 @@
 
 	ast_log(LOG_ERROR, "%s: Could not find user %s\n", symname, module);
 }
+
+#endif /* defined(OPTIONAL_API) */

Added: team/dlee/ASTERISK-22296/tests/test_optional_api.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22296/tests/test_optional_api.c?view=auto&rev=397703
==============================================================================
--- team/dlee/ASTERISK-22296/tests/test_optional_api.c (added)
+++ team/dlee/ASTERISK-22296/tests/test_optional_api.c Tue Aug 27 09:11:28 2013
@@ -1,0 +1,187 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * David M. Lee, II <dlee at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file \brief Test optional API.
+ *
+ * This tests exercise the underlying implementation functions. Acutal usage
+ * won't look anything like this; it would use the wrapper macros.
+ *
+ * \author\verbatim David M. Lee, II <dlee at digium.com> \endverbatim
+ *
+ * \ingroup tests
+ */
+
+/*** MODULEINFO
+	<depend>TEST_FRAMEWORK</depend>
+	<depend>OPTIONAL_API</depend>
+	<support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/optional_api.h"
+#include "asterisk/test.h"
+
+#define CATEGORY "/main/optional_api/"
+
+enum was_called {
+	NONE,
+	STUB,
+	IMPL
+};
+
+enum was_called was_called_result;
+
+ast_optional_fn test_optional_ref;
+
+static void test_optional_stub(void)
+{
+	was_called_result = STUB;
+}
+
+static void test_optional_impl(void)
+{
+	was_called_result = IMPL;
+}
+
+static void test_optional(void)
+{
+	was_called_result = NONE;
+	if (test_optional_ref) {
+		test_optional_ref();
+	}
+}
+
+#define SYMNAME "test_option"
+
+AST_TEST_DEFINE(test_provide_first)
+{
+	enum ast_test_result_state res;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = __func__;
+		info->category = CATEGORY;
+		info->summary = "Test optional API publishing.";
+		info->description = "Test optional API publishing.";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	res = AST_TEST_FAIL;
+	test_optional_ref = 0;
+
+	ast_optional_api_provide(SYMNAME, test_optional_impl);
+
+	ast_optional_api_use(SYMNAME, &test_optional_ref, test_optional_stub,
+		AST_MODULE);
+
+	test_optional();
+
+	if (was_called_result != IMPL) {
+		ast_test_status_update(test, "Expected %d, was %d",
+			IMPL, was_called_result);
+		goto done;
+	}
+
+	res = AST_TEST_PASS;
+
+ done:
+	ast_optional_api_unuse(SYMNAME, &test_optional_ref, AST_MODULE);
+	ast_optional_api_unprovide(SYMNAME, test_optional_impl);
+	return res;
+}
+
+AST_TEST_DEFINE(test_provide_last)
+{
+	enum ast_test_result_state res;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = __func__;
+		info->category = CATEGORY;
+		info->summary = "Test optional API publishing.";
+		info->description = "Test optional API publishing.";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	res = AST_TEST_FAIL;
+	test_optional_ref = 0;
+
+	ast_optional_api_use(SYMNAME, &test_optional_ref, test_optional_stub,
+		AST_MODULE);
+
+	test_optional();
+	if (was_called_result != STUB) {
+		ast_test_status_update(test, "Expected %d, was %d",
+			STUB, was_called_result);
+		goto done;
+	}
+
+	ast_optional_api_provide(SYMNAME, test_optional_impl);
+
+	test_optional();
+	if (was_called_result != IMPL) {
+		ast_test_status_update(test, "Expected %d, was %d",
+			IMPL, was_called_result);
+		ast_optional_api_unprovide(SYMNAME, test_optional_impl);
+		goto done;
+	}
+
+	ast_optional_api_unprovide(SYMNAME, test_optional_impl);
+
+	test_optional();
+	if (was_called_result != STUB) {
+		ast_test_status_update(test, "Expected %d, was %d",
+			STUB, was_called_result);
+		ast_optional_api_unprovide(SYMNAME, test_optional_impl);
+		goto done;
+	}
+
+	res = AST_TEST_PASS;
+
+ done:
+	ast_optional_api_unuse(SYMNAME, &test_optional_ref, AST_MODULE);
+	return res;
+}
+
+static int unload_module(void)
+{
+	AST_TEST_UNREGISTER(test_provide_first);
+	AST_TEST_UNREGISTER(test_provide_last);
+	return 0;
+}
+
+static int load_module(void)
+{
+	AST_TEST_REGISTER(test_provide_first);
+	AST_TEST_REGISTER(test_provide_last);
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "ARI testing",
+	.load = load_module,
+	.unload = unload_module,
+	);

Propchange: team/dlee/ASTERISK-22296/tests/test_optional_api.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/dlee/ASTERISK-22296/tests/test_optional_api.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/dlee/ASTERISK-22296/tests/test_optional_api.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list