Index: tests/test_pbx.c
===================================================================
--- tests/test_pbx.c	(revision 0)
+++ tests/test_pbx.c	(revision 0)
@@ -0,0 +1,142 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2008, Mark Michelson
+ *
+ * Mark Michelson <mmichelson@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 PBX Tests
+ *
+ * \author\verbatim Mark Michelson <mmichelson@digium.com> \endverbatim
+ * 
+ * This module will run some PBX tests.
+ * \ingroup tests
+ */
+
+/*** MODULEINFO
+	<defaultenabled>no</defaultenabled>
+ ***/
+
+#include "asterisk.h"
+#include "asterisk/module.h"
+#include "asterisk/pbx.h"
+#include "asterisk/test.h"
+
+struct exten_info {
+	const char *exten;
+	const char *cid;
+};
+
+struct pbx_test_pattern {
+	const char *test_exten;
+	const char *test_cid;
+	const struct exten_info *exten;
+};
+
+static int test_exten(const char * const context_name, struct pbx_test_pattern *test_pattern, struct ast_test *test)
+{
+	struct pbx_find_info pfi = {{0},};
+	struct ast_exten *exten;
+	if (!(exten = pbx_find_extension(NULL, NULL, &pfi, context_name, test_pattern->test_exten, 1, NULL, test_pattern->test_cid, E_MATCH))) {
+		ast_test_status_update(test, "Cannot find extension %s in context %s. Test failed.\n", test_pattern->test_exten, context_name);
+		return -1;
+	}
+	if (strcmp(ast_get_extension_name(exten), test_pattern->exten->exten)) {
+		ast_test_status_update(test, "Expected extension %s but got extension %s instead. Test failed.\n", test_pattern->exten->exten, ast_get_extension_name(exten));
+		return -1;
+	}
+	if (test_pattern->test_cid && strcmp(ast_get_extension_cidmatch(exten), test_pattern->test_cid)) {
+		ast_test_status_update(test, "Expected CID match %s but got CID match %s instead. Test failed.\n", test_pattern->exten->cid, ast_get_extension_cidmatch(exten));
+		return -1;
+	}
+	ast_test_status_update(test, "Successfully matched %s to exten %s in context %s\n", test_pattern->test_exten, test_pattern->exten->exten, context_name);
+	return 0;
+}
+
+AST_TEST_DEFINE(pattern_match_test)
+{
+	struct ast_context *con;
+	static const char *context_name = "pattern_match_test_barbie_crap_brutal_stink";
+
+	/* The array of extensions to add to our context.
+	 * Add any additional extensions to this array and they will automatically be
+	 * added to our context when the test is run
+	 */
+	struct exten_info extens [] = {
+		{ "_2.", NULL },
+		{ "2000", NULL },
+	};
+
+	/* This array contains our test material. The first
+	 * component is the string we wish to test, the second is the CID
+	 * of the supposed caller for our test, and the third is
+	 * the extension we expect to be matched when we execute our search.
+	 * Adding new entries to this array will automatically cause the test
+	 * strings to be searched for when we run our test
+	 */
+	struct pbx_test_pattern tests [] = {
+		{ "200", NULL, &extens[0] },
+		{ "2000", NULL, &extens[1] },
+	};
+
+	int i;
+	enum ast_test_result_state res = AST_TEST_PASS;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "pattern_match_test";
+		info->category = "main/pbx";
+		info->summary = "Test pattern matching";
+		info->description = "Create a context with a bunch of extensions within. Then attempt\n"
+			"to match some strings to the extensions.";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	if (!(con = ast_context_find_or_create(NULL, NULL, context_name, "test_pbx"))) {
+		return AST_TEST_FAIL;
+	}
+
+	for (i = 0; i < ARRAY_LEN(extens); ++i) {
+		ast_add_extension2(con, 0, extens[i].exten, 1, NULL, extens[i].cid, "Noop", (void *) extens[i].exten, NULL, "test_pbx");
+	}
+
+	for (i = 0; i < ARRAY_LEN(tests); ++i) {
+		if (test_exten(context_name, &tests[i], test)) {
+			res = AST_TEST_FAIL;
+			break;
+		}
+	}
+
+	ast_context_destroy(con, "test_pbx");
+
+	return res;
+}
+
+static int unload_module(void)
+{
+	AST_TEST_UNREGISTER(pattern_match_test);
+	return 0;
+}
+
+static int load_module(void)
+{
+	AST_TEST_REGISTER(pattern_match_test);
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "PBX test module");
