[asterisk-commits] app: Add functions to swap vm function table (asterisk[certified/13.1])
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jul 6 11:34:19 CDT 2015
Joshua Colp has submitted this change and it was merged.
Change subject: app: Add functions to swap vm function table
......................................................................
app: Add functions to swap vm function table
This patch adds function-mocking methods for testing voicemail
features in external modules. It is being pulled over from r432556
on SVN because DPMA won't presently compile with TEST_FRAMEWORK
set in Asterisk 13.1 certified.
Change-Id: I1c2cf6d5a8589104154a86538ecd3f62a2694681
---
M include/asterisk/app.h
M main/app.c
2 files changed, 67 insertions(+), 0 deletions(-)
Approvals:
Anonymous Coward #1000019: Verified
Matt Jordan: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved
diff --git a/include/asterisk/app.h b/include/asterisk/app.h
index d5a0e27..d70d8a6 100644
--- a/include/asterisk/app.h
+++ b/include/asterisk/app.h
@@ -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. */
diff --git a/main/app.c b/main/app.c
index 46589ea..f612684 100644
--- a/main/app.c
+++ b/main/app.c
@@ -519,6 +519,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);
--
To view, visit https://gerrit.asterisk.org/776
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1c2cf6d5a8589104154a86538ecd3f62a2694681
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: certified/13.1
Gerrit-Owner: Jonathan Rose <jrose at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <george.joseph at fairview5.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>
Gerrit-Reviewer: Scott Griepentrog <sgriepentrog at digium.com>
More information about the asterisk-commits
mailing list