[svn-commits] eliel: branch eliel/data_api_providers_gsoc2010 r260747 - /team/eliel/data_ap...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon May 3 13:15:52 CDT 2010


Author: eliel
Date: Mon May  3 13:15:48 2010
New Revision: 260747

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=260747
Log:
iax2 data provider unit tests.


Modified:
    team/eliel/data_api_providers_gsoc2010/channels/chan_iax2.c

Modified: team/eliel/data_api_providers_gsoc2010/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/eliel/data_api_providers_gsoc2010/channels/chan_iax2.c?view=diff&rev=260747&r1=260746&r2=260747
==============================================================================
--- team/eliel/data_api_providers_gsoc2010/channels/chan_iax2.c (original)
+++ team/eliel/data_api_providers_gsoc2010/channels/chan_iax2.c Mon May  3 13:15:48 2010
@@ -90,6 +90,7 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/timing.h"
 #include "asterisk/taskprocessor.h"
+#include "asterisk/test.h"
 #include "asterisk/data.h"
 
 #include "iax2.h"
@@ -13792,6 +13793,123 @@
 #endif /* IAXTESTS */
 };
 
+#ifdef TEST_FRAMEWORK
+AST_TEST_DEFINE(test_iax2_peers_get)
+{
+	struct ast_data_query query = {
+		.path = "/asterisk/channel/chan_iax2/peers",
+		.search = "peers/peer/name=test_peer_data_provider"
+	};
+	struct ast_data *node;
+	struct iax2_peer *peer;
+
+	switch (cmd) {
+		case TEST_INIT:
+			info->name = "iax2_peers_get_data_test";
+			info->category = "main/data/chan_iax2/peers";
+			info->summary = "IAX2 peers data providers unit test";
+			info->description =
+				"Tests whether the IAX2 peers data provider implementation works as expected.";
+			return AST_TEST_NOT_RUN;
+		case TEST_EXECUTE:
+			break;
+	}
+
+	/* build a test peer */
+	peer = build_peer("test_peer_data_provider", NULL, NULL, 0);
+	if (!peer) {
+		return AST_TEST_FAIL;
+	}
+	peer->expiry= 1010;
+	ao2_link(peers, peer);
+
+	node = ast_data_get(&query);
+	if (!node) {
+		ao2_unlink(peers, peer);
+		peer_unref(peer);
+		return AST_TEST_FAIL;
+	}
+
+	/* check returned data node. */
+	if (strcmp(ast_data_retrieve_string(node, "peer/name"), "test_peer_data_provider")) {
+		ao2_unlink(peers, peer);
+		peer_unref(peer);
+		ast_data_free(node);
+		return AST_TEST_FAIL;
+	}
+
+	if (ast_data_retrieve_int(node, "peer/expiry") != 1010) {
+		ao2_unlink(peers, peer);
+		peer_unref(peer);
+		ast_data_free(node);
+		return AST_TEST_FAIL;
+	}
+
+	/* release resources */
+	ast_data_free(node);
+
+	ao2_unlink(peers, peer);
+	peer_unref(peer);
+
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(test_iax2_users_get)
+{
+	struct ast_data_query query = {
+		.path = "/asterisk/channel/chan_iax2/users",
+		.search = "users/user/name=test_user_data_provider"
+	};
+	struct ast_data *node;
+	struct iax2_user *user;
+
+	switch (cmd) {
+		case TEST_INIT:
+			info->name = "iax2_users_get_data_test";
+			info->category = "main/data/chan_iax2/users";
+			info->summary = "IAX2 users data providers unit test";
+			info->description =
+				"Tests whether the IAX2 users data provider implementation works as expected.";
+			return AST_TEST_NOT_RUN;
+		case TEST_EXECUTE:
+			break;
+	}
+
+	user = build_user("test_user_data_provider", NULL, NULL, 0);
+	if (!user) {
+		return AST_TEST_FAIL;
+	}
+	user->amaflags = 1010; 
+	ao2_link(users, user);
+
+	node = ast_data_get(&query);
+	if (!node) {
+		return AST_TEST_FAIL;
+	}
+
+	if (strcmp(ast_data_retrieve_string(node, "user/name"), "test_user_data_provider")) {
+		ao2_unlink(users, user);
+		user_unref(user);
+		ast_data_free(node);
+		return AST_TEST_FAIL;
+	}
+
+	if (ast_data_retrieve_int(node, "user/amaflags") != 1010) {
+		ao2_unlink(users, user);
+		user_unref(user);
+		ast_data_free(node);
+		return AST_TEST_FAIL;
+	}
+
+	ast_data_free(node);
+
+	ao2_unlink(users, user);
+	user_unref(user);
+
+	return AST_TEST_PASS;
+}
+#endif
+
 static int __unload_module(void)
 {
 	struct iax2_thread *thread = NULL;
@@ -13838,6 +13956,10 @@
 	ast_manager_unregister( "IAXnetstats" );
 	ast_manager_unregister( "IAXregistry" );
 	ast_unregister_application(papp);
+#ifdef TEST_FRAMEWORK
+	AST_TEST_UNREGISTER(test_iax2_peers_get);
+	AST_TEST_UNREGISTER(test_iax2_users_get);
+#endif
 	ast_data_unregister(NULL);
 	ast_cli_unregister_multiple(cli_iax2, ARRAY_LEN(cli_iax2));
 	ast_unregister_switch(&iax2_switch);
@@ -13982,33 +14104,34 @@
 	return AST_MODULE_LOAD_FAILURE;
 }
 
+
 #define DATA_EXPORT_IAX2_PEER(MEMBER)				\
-        MEMBER(iax2_peer, name, AST_DATA_STRING)		\
-        MEMBER(iax2_peer, username, AST_DATA_STRING)		\
-        MEMBER(iax2_peer, secret, AST_DATA_STRING)		\
-        MEMBER(iax2_peer, dbsecret, AST_DATA_STRING)		\
-        MEMBER(iax2_peer, outkey, AST_DATA_STRING)		\
-        MEMBER(iax2_peer, regexten, AST_DATA_STRING)		\
-        MEMBER(iax2_peer, context, AST_DATA_STRING)		\
-        MEMBER(iax2_peer, peercontext, AST_DATA_STRING)		\
-        MEMBER(iax2_peer, mailbox, AST_DATA_STRING)		\
-        MEMBER(iax2_peer, mohinterpret, AST_DATA_STRING)	\
-        MEMBER(iax2_peer, mohsuggest, AST_DATA_STRING)		\
-        MEMBER(iax2_peer, inkeys, AST_DATA_STRING)		\
-        MEMBER(iax2_peer, cid_num, AST_DATA_STRING)		\
-        MEMBER(iax2_peer, cid_name, AST_DATA_STRING)		\
-        MEMBER(iax2_peer, zonetag, AST_DATA_STRING)		\
-        MEMBER(iax2_peer, parkinglot, AST_DATA_STRING)		\
-        MEMBER(iax2_peer, expire, AST_DATA_INTEGER)		\
-        MEMBER(iax2_peer, expiry, AST_DATA_INTEGER)		\
-        MEMBER(iax2_peer, callno, AST_DATA_INTEGER)		\
-        MEMBER(iax2_peer, pokeexpire, AST_DATA_INTEGER)		\
-        MEMBER(iax2_peer, lastms, AST_DATA_INTEGER)		\
-        MEMBER(iax2_peer, maxms, AST_DATA_INTEGER)		\
-        MEMBER(iax2_peer, pokefreqok, AST_DATA_INTEGER)		\
-        MEMBER(iax2_peer, pokefreqnotok, AST_DATA_INTEGER)	\
-        MEMBER(iax2_peer, historicms, AST_DATA_INTEGER)		\
-        MEMBER(iax2_peer, smoothing, AST_DATA_INTEGER)		\
+	MEMBER(iax2_peer, name, AST_DATA_STRING)		\
+	MEMBER(iax2_peer, username, AST_DATA_STRING)		\
+	MEMBER(iax2_peer, secret, AST_DATA_STRING)		\
+	MEMBER(iax2_peer, dbsecret, AST_DATA_STRING)		\
+	MEMBER(iax2_peer, outkey, AST_DATA_STRING)		\
+	MEMBER(iax2_peer, regexten, AST_DATA_STRING)		\
+	MEMBER(iax2_peer, context, AST_DATA_STRING)		\
+	MEMBER(iax2_peer, peercontext, AST_DATA_STRING)		\
+	MEMBER(iax2_peer, mailbox, AST_DATA_STRING)		\
+	MEMBER(iax2_peer, mohinterpret, AST_DATA_STRING)	\
+	MEMBER(iax2_peer, mohsuggest, AST_DATA_STRING)		\
+	MEMBER(iax2_peer, inkeys, AST_DATA_STRING)		\
+	MEMBER(iax2_peer, cid_num, AST_DATA_STRING)		\
+	MEMBER(iax2_peer, cid_name, AST_DATA_STRING)		\
+	MEMBER(iax2_peer, zonetag, AST_DATA_STRING)		\
+	MEMBER(iax2_peer, parkinglot, AST_DATA_STRING)		\
+	MEMBER(iax2_peer, expire, AST_DATA_INTEGER)		\
+	MEMBER(iax2_peer, expiry, AST_DATA_INTEGER)		\
+	MEMBER(iax2_peer, callno, AST_DATA_INTEGER)		\
+	MEMBER(iax2_peer, pokeexpire, AST_DATA_INTEGER)		\
+	MEMBER(iax2_peer, lastms, AST_DATA_INTEGER)		\
+	MEMBER(iax2_peer, maxms, AST_DATA_INTEGER)		\
+	MEMBER(iax2_peer, pokefreqok, AST_DATA_INTEGER)		\
+	MEMBER(iax2_peer, pokefreqnotok, AST_DATA_INTEGER)	\
+	MEMBER(iax2_peer, historicms, AST_DATA_INTEGER)		\
+	MEMBER(iax2_peer, smoothing, AST_DATA_INTEGER)		\
         MEMBER(iax2_peer, maxcallno, AST_DATA_INTEGER)
 
 AST_DATA_STRUCTURE(iax2_peer, DATA_EXPORT_IAX2_PEER);
@@ -14201,6 +14324,10 @@
 	}
 	ast_netsock_init(outsock);
 
+#ifdef TEST_FRAMEWORK
+	AST_TEST_REGISTER(test_iax2_peers_get);
+	AST_TEST_REGISTER(test_iax2_users_get);
+#endif
 	/* Register AstData providers */
 	ast_data_register_multiple(iax2_data_providers, ARRAY_LEN(iax2_data_providers));
 




More information about the svn-commits mailing list