[asterisk-commits] jrose: branch 13 r432556 - in /branches/13: include/asterisk/app.h main/app.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Mar 6 15:11:12 CST 2015
Author: jrose
Date: Fri Mar 6 15:11:11 2015
New Revision: 432556
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=432556
Log:
app: Add functions to swap voicemail function table for testing purposes
Modified:
branches/13/include/asterisk/app.h
branches/13/main/app.c
Modified: branches/13/include/asterisk/app.h
URL: http://svnview.digium.com/svn/asterisk/branches/13/include/asterisk/app.h?view=diff&rev=432556&r1=432555&r2=432556
==============================================================================
--- branches/13/include/asterisk/app.h (original)
+++ branches/13/include/asterisk/app.h Fri Mar 6 15:11:11 2015
@@ -595,6 +595,22 @@
*/
void ast_vm_unregister(const char *module_name);
+#ifdef TEST_FRAMEWORK
+/*!
+ * \brief Swap out existing voicemail functions with a temporary set of functions for use with unit tests
+ *
+ * \param vm_table function table to use for testing
+ *
+ * \note ast_vm_test_swap_table_out should be called to restore the original set before testing concludes
+ */
+void ast_vm_test_swap_table_in(const struct ast_vm_functions *vm_table);
+
+/*!
+ * \brief Used after ast_vm_test_swap_table_in to restore the original set of voicemail functions
+ */
+void ast_vm_test_swap_table_out(void);
+#endif
+
#define VM_GREETER_MODULE_VERSION 1
/*! \brief Voicemail greeter function table definition. */
Modified: branches/13/main/app.c
URL: http://svnview.digium.com/svn/asterisk/branches/13/main/app.c?view=diff&rev=432556&r1=432555&r2=432556
==============================================================================
--- branches/13/main/app.c (original)
+++ branches/13/main/app.c Fri Mar 6 15:11:11 2015
@@ -518,6 +518,57 @@
}
ao2_cleanup(table);
}
+
+#ifdef TEST_FRAMEWORK
+/*! \brief Holding container for the voicemail provider used while testing */
+static AO2_GLOBAL_OBJ_STATIC(vm_provider_holder);
+static int provider_is_swapped = 0;
+
+void ast_vm_test_swap_table_in(const struct ast_vm_functions *vm_table)
+{
+ RAII_VAR(struct ast_vm_functions *, holding_table, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_vm_functions *, new_table, NULL, ao2_cleanup);
+
+ if (provider_is_swapped) {
+ ast_log(LOG_ERROR, "Attempted to swap in test function table without swapping out old test table.\n");
+ return;
+ }
+
+ holding_table = ao2_global_obj_ref(vm_provider);
+
+ if (holding_table) {
+ ao2_global_obj_replace_unref(vm_provider_holder, holding_table);
+ }
+
+ new_table = ao2_alloc_options(sizeof(*new_table), NULL, AO2_ALLOC_OPT_LOCK_NOLOCK);
+ if (!new_table) {
+ return;
+ }
+ *new_table = *vm_table;
+
+ ao2_global_obj_replace_unref(vm_provider, new_table);
+ provider_is_swapped = 1;
+}
+
+void ast_vm_test_swap_table_out(void)
+{
+ RAII_VAR(struct ast_vm_functions *, held_table, NULL, ao2_cleanup);
+
+ if (!provider_is_swapped) {
+ ast_log(LOG_ERROR, "Attempted to swap out test function table, but none is currently installed.\n");
+ return;
+ }
+
+ held_table = ao2_global_obj_ref(vm_provider_holder);
+ if (!held_table) {
+ return;
+ }
+
+ ao2_global_obj_replace_unref(vm_provider, held_table);
+ ao2_global_obj_release(vm_provider_holder);
+ provider_is_swapped = 0;
+}
+#endif
/*! \brief The container for the voicemail greeter provider */
static AO2_GLOBAL_OBJ_STATIC(vm_greeter_provider);
More information about the asterisk-commits
mailing list