From 3a5e4317f569abc860a8554f6dcdd573e5211adb Mon Sep 17 00:00:00 2001
From: Richard Mudgett <rmudgett@digium.com>
Date: Fri, 13 Dec 2013 00:40:49 +0000
Subject: [PATCH] test_voicemail_api: Add check for a registered voicemail
 provider before tests.

It is much nicer diagnosing a test failure if app_voicemail is actually
loaded.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@403726 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 include/asterisk/app.h     |  9 +++++++++
 main/app.c                 | 11 +++++++++++
 tests/test_voicemail_api.c |  5 ++++-
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/include/asterisk/app.h b/include/asterisk/app.h
index 2b5d5bf164..623f0884ee 100644
--- a/include/asterisk/app.h
+++ b/include/asterisk/app.h
@@ -567,6 +567,15 @@ struct ast_vm_functions {
 	ast_vm_msg_play_fn *msg_play;
 };
 
+/*!
+ * \brief Determine if a voicemail provider is registered.
+ * \since 13.0.0
+ *
+ * \retval 0 if no privider registered.
+ * \retval 1 if a privider is registered.
+ */
+int ast_vm_is_registered(void);
+
 /*!
  * \brief Set voicemail function callbacks
  *
diff --git a/main/app.c b/main/app.c
index 140afde7b9..579984dab4 100644
--- a/main/app.c
+++ b/main/app.c
@@ -432,6 +432,17 @@ static AO2_GLOBAL_OBJ_STATIC(vm_provider);
 /*! Voicemail not registered warning */
 static int vm_warnings;
 
+int ast_vm_is_registered(void)
+{
+	struct ast_vm_functions *table;
+	int is_registered;
+
+	table = ao2_global_obj_ref(vm_provider);
+	is_registered = table ? 1 : 0;
+	ao2_cleanup(table);
+	return is_registered;
+}
+
 int __ast_vm_register(const struct ast_vm_functions *vm_table, struct ast_module *module)
 {
 	RAII_VAR(struct ast_vm_functions *, table, NULL, ao2_cleanup);
diff --git a/tests/test_voicemail_api.c b/tests/test_voicemail_api.c
index 2357b0a3da..01efeeec2d 100644
--- a/tests/test_voicemail_api.c
+++ b/tests/test_voicemail_api.c
@@ -72,7 +72,10 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  * envelope files on the file system
  */
 #define VM_API_TEST_SETUP do { \
-	if (test_vm_api_test_setup()) { \
+	if (!ast_vm_is_registered()) { \
+		ast_test_status_update(test, "No voicemail provider registered.\n"); \
+		return AST_TEST_FAIL; \
+	} else if (test_vm_api_test_setup()) { \
 		VM_API_TEST_CLEANUP; \
 		ast_test_status_update(test, "Failed to set up necessary mock objects for voicemail API test\n"); \
 		return AST_TEST_FAIL; \
-- 
GitLab