123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- /*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2013, Digium, Inc.
- *
- * David M. Lee, II <dlee@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@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 %u",
- 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 %u",
- 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 %u",
- 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 %u",
- 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",
- .support_level = AST_MODULE_SUPPORT_CORE,
- .load = load_module,
- .unload = unload_module,
- );
|