aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorrmudgett <rmudgett@f38db490-d61c-443f-a65b-d21fe96a405b>2011-06-03 21:02:32 +0000
committerrmudgett <rmudgett@f38db490-d61c-443f-a65b-d21fe96a405b>2011-06-03 21:02:32 +0000
commita574bf31b25197b863fe14fa018bd5651426c8df (patch)
treea6413693b240c08f5a9ff42f943ea0c2c02a29b2 /tests
parent3abc32f081747b834820a7b634f99eace12e1c56 (diff)
Merged revisions 321871 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8 ........ r321871 | rmudgett | 2011-06-03 15:58:13 -0500 (Fri, 03 Jun 2011) | 27 lines Event subscription fixes. Must commit the subscription fixes together with the integration subscription tests. The subscription fixes cause an erroneously passing test to fail. The new subscription tests detect errors without the subscription fixes. * Added missing event_names[] table entry. * Reworked ast_event_check_subscriber()/match_sub_ie_val_to_event() to correctly detect if a subscriber exists for the proposed event. * Made match_ie_val() and match_sub_ie_val_to_event() check the buffer length for RAW payload types. * Fixed error handling memory leak in ast_event_sub_activate(), ast_event_unsubscribe(), and ast_event_queue(). * Made ast_event_new() and ast_event_check_subscriber() better protect themselves from an invalid payload type. * Added container lock protection between removing old cache events and adding the new cached event in ast_event_queue_and_cache()/event_update_cache(). * Added new event subscription tests. ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@321872 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'tests')
-rw-r--r--tests/test_event.c565
1 files changed, 472 insertions, 93 deletions
diff --git a/tests/test_event.c b/tests/test_event.c
index 4331d742f..5f0c1003c 100644
--- a/tests/test_event.c
+++ b/tests/test_event.c
@@ -240,6 +240,53 @@ static void event_sub_cb(const struct ast_event *event, void *d)
data->count++;
}
+enum test_subs_class_type {
+ TEST_SUBS_ALL_STR,
+ TEST_SUBS_CUSTOM_STR,
+ TEST_SUBS_CUSTOM_RAW,
+ TEST_SUBS_CUSTOM_UINT,
+ TEST_SUBS_CUSTOM_BITFLAGS,
+ TEST_SUBS_CUSTOM_EXISTS,
+ TEST_SUBS_CUSTOM_DYNAMIC,
+ TEST_SUBS_CUSTOM_ANY,
+
+ /* Must be last. */
+ TEST_SUBS_TOTAL,
+};
+
+/*!
+ * \internal
+ * \brief Convert enum test_subs_class_type to string.
+ *
+ * \param val Enum value to convert to string.
+ *
+ * \return String equivalent of enum value.
+ */
+static const char *test_subs_class_type_str(enum test_subs_class_type val)
+{
+ switch (val) {
+ case TEST_SUBS_ALL_STR:
+ return "TEST_SUBS_ALL_STR";
+ case TEST_SUBS_CUSTOM_STR:
+ return "TEST_SUBS_CUSTOM_STR";
+ case TEST_SUBS_CUSTOM_RAW:
+ return "TEST_SUBS_CUSTOM_RAW";
+ case TEST_SUBS_CUSTOM_UINT:
+ return "TEST_SUBS_CUSTOM_UINT";
+ case TEST_SUBS_CUSTOM_BITFLAGS:
+ return "TEST_SUBS_CUSTOM_BITFLAGS";
+ case TEST_SUBS_CUSTOM_EXISTS:
+ return "TEST_SUBS_CUSTOM_EXISTS";
+ case TEST_SUBS_CUSTOM_DYNAMIC:
+ return "TEST_SUBS_CUSTOM_DYNAMIC";
+ case TEST_SUBS_CUSTOM_ANY:
+ return "TEST_SUBS_CUSTOM_ANY";
+ case TEST_SUBS_TOTAL:
+ break;
+ }
+ return "Unknown";
+}
+
/*!
* \internal
* \brief Test event subscriptions
@@ -257,16 +304,31 @@ AST_TEST_DEFINE(event_sub_test)
struct ast_event_sub *sub;
struct event_sub_data data;
const unsigned int expected_count;
- } test_subs[] = {
- [0] = {
- .expected_count = 3,
+ } test_subs[TEST_SUBS_TOTAL] = {
+ [TEST_SUBS_ALL_STR] = {
+ .expected_count = 2,
},
- [1] = {
+ [TEST_SUBS_CUSTOM_STR] = {
+ .expected_count = 2,
+ },
+ [TEST_SUBS_CUSTOM_RAW] = {
+ .expected_count = 1,
+ },
+ [TEST_SUBS_CUSTOM_UINT] = {
.expected_count = 1,
},
- [2] = {
+ [TEST_SUBS_CUSTOM_BITFLAGS] = {
+ .expected_count = 4,
+ },
+ [TEST_SUBS_CUSTOM_EXISTS] = {
.expected_count = 2,
},
+ [TEST_SUBS_CUSTOM_DYNAMIC] = {
+ .expected_count = 1,
+ },
+ [TEST_SUBS_CUSTOM_ANY] = {
+ .expected_count = 6,
+ },
};
switch (cmd) {
@@ -283,115 +345,230 @@ AST_TEST_DEFINE(event_sub_test)
}
/*
- * Subscription #1:
+ * Subscription TEST_SUBS_ALL_STR:
* - allocate normally
- * - subscribe to all CUSTOM events
- *
- * Subscription #2:
- * - allocate dynamically
- * - subscribe to all CUSTOM events
- * - add payload checks
- *
- * Subscription #3:
+ * - subscribe to ALL events with a DEVICE STR IE check
+ */
+ ast_test_status_update(test, "Adding TEST_SUBS_ALL_STR subscription\n");
+ test_subs[TEST_SUBS_ALL_STR].sub = ast_event_subscribe(AST_EVENT_ALL, event_sub_cb,
+ test_subs_class_type_str(TEST_SUBS_ALL_STR), &test_subs[TEST_SUBS_ALL_STR].data,
+ AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, "FOO/bar",
+ AST_EVENT_IE_END);
+ if (!test_subs[TEST_SUBS_ALL_STR].sub) {
+ ast_test_status_update(test, "Failed to create TEST_SUBS_ALL_STR subscription\n");
+ res = AST_TEST_FAIL;
+ goto return_cleanup;
+ }
+
+ if (strcmp(ast_event_subscriber_get_description(test_subs[TEST_SUBS_ALL_STR].sub),
+ test_subs_class_type_str(TEST_SUBS_ALL_STR))) {
+ ast_test_status_update(test,
+ "Unexpected subscription description on TEST_SUBS_ALL_STR subscription\n");
+ res = AST_TEST_FAIL;
+ goto return_cleanup;
+ }
+
+ /*
+ * Subscription TEST_SUBS_CUSTOM_STR:
* - allocate normally
- * - subscribe to all events with an IE check
+ * - subscribe to CUSTOM events with a DEVICE STR IE check
*/
+ ast_test_status_update(test, "Adding TEST_SUBS_CUSTOM_STR subscription\n");
+ test_subs[TEST_SUBS_CUSTOM_STR].sub = ast_event_subscribe(AST_EVENT_CUSTOM, event_sub_cb,
+ test_subs_class_type_str(TEST_SUBS_CUSTOM_STR), &test_subs[TEST_SUBS_CUSTOM_STR].data,
+ AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, "FOO/bar",
+ AST_EVENT_IE_END);
+ if (!test_subs[TEST_SUBS_CUSTOM_STR].sub) {
+ ast_test_status_update(test, "Failed to create TEST_SUBS_CUSTOM_STR subscription\n");
+ res = AST_TEST_FAIL;
+ goto return_cleanup;
+ }
- test_subs[0].sub = ast_event_subscribe(AST_EVENT_CUSTOM, event_sub_cb, "test_sub", &test_subs[0].data,
- AST_EVENT_IE_END);
- if (!test_subs[0].sub) {
- ast_test_status_update(test, "Failed to create test_subs[0].sub\n");
+ if (strcmp(ast_event_subscriber_get_description(test_subs[TEST_SUBS_CUSTOM_STR].sub),
+ test_subs_class_type_str(TEST_SUBS_CUSTOM_STR))) {
+ ast_test_status_update(test,
+ "Unexpected subscription description on TEST_SUBS_CUSTOM_STR subscription\n");
res = AST_TEST_FAIL;
goto return_cleanup;
}
- if (strcmp(ast_event_subscriber_get_description(test_subs[0].sub), "test_sub")) {
+ /*
+ * Subscription TEST_SUBS_CUSTOM_RAW:
+ * - allocate normally
+ * - subscribe to CUSTOM events with a MAILBOX RAW IE check
+ */
+ ast_test_status_update(test, "Adding TEST_SUBS_CUSTOM_RAW subscription\n");
+ test_subs[TEST_SUBS_CUSTOM_RAW].sub = ast_event_subscribe(AST_EVENT_CUSTOM, event_sub_cb,
+ test_subs_class_type_str(TEST_SUBS_CUSTOM_RAW), &test_subs[TEST_SUBS_CUSTOM_RAW].data,
+ AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_RAW, "FOO/bar", sizeof("FOO/bar"),
+ AST_EVENT_IE_END);
+ if (!test_subs[TEST_SUBS_CUSTOM_RAW].sub) {
+ ast_test_status_update(test, "Failed to create TEST_SUBS_CUSTOM_RAW subscription\n");
+ res = AST_TEST_FAIL;
+ goto return_cleanup;
+ }
+
+ if (strcmp(ast_event_subscriber_get_description(test_subs[TEST_SUBS_CUSTOM_RAW].sub),
+ test_subs_class_type_str(TEST_SUBS_CUSTOM_RAW))) {
ast_test_status_update(test,
- "Unexpected subscription description on test_subs[0].sub\n");
+ "Unexpected subscription description on TEST_SUBS_CUSTOM_RAW subscription\n");
res = AST_TEST_FAIL;
goto return_cleanup;
}
- test_subs[1].sub = ast_event_subscribe_new(AST_EVENT_CUSTOM, event_sub_cb, &test_subs[1].data);
- if (!test_subs[1].sub) {
- ast_test_status_update(test, "Failed to create test_subs[1].sub\n");
+ /*
+ * Subscription TEST_SUBS_CUSTOM_UINT:
+ * - allocate normally
+ * - subscribe to CUSTOM events with a NEWMSGS UINT IE check
+ */
+ ast_test_status_update(test, "Adding TEST_SUBS_CUSTOM_UINT subscription\n");
+ test_subs[TEST_SUBS_CUSTOM_UINT].sub = ast_event_subscribe(AST_EVENT_CUSTOM, event_sub_cb,
+ test_subs_class_type_str(TEST_SUBS_CUSTOM_UINT), &test_subs[TEST_SUBS_CUSTOM_UINT].data,
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, 5,
+ AST_EVENT_IE_END);
+ if (!test_subs[TEST_SUBS_CUSTOM_UINT].sub) {
+ ast_test_status_update(test, "Failed to create TEST_SUBS_CUSTOM_UINT subscription\n");
res = AST_TEST_FAIL;
goto return_cleanup;
}
- /* For the sake of exercising destruction before activation */
- ast_event_sub_destroy(test_subs[1].sub);
+ if (strcmp(ast_event_subscriber_get_description(test_subs[TEST_SUBS_CUSTOM_UINT].sub),
+ test_subs_class_type_str(TEST_SUBS_CUSTOM_UINT))) {
+ ast_test_status_update(test,
+ "Unexpected subscription description on TEST_SUBS_CUSTOM_UINT subscription\n");
+ res = AST_TEST_FAIL;
+ goto return_cleanup;
+ }
- test_subs[1].sub = ast_event_subscribe_new(AST_EVENT_CUSTOM, event_sub_cb, &test_subs[1].data);
- if (!test_subs[1].sub) {
- ast_test_status_update(test, "Failed to create test_subs[1].sub\n");
+ /*
+ * Subscription TEST_SUBS_CUSTOM_BITFLAGS:
+ * - allocate normally
+ * - subscribe to CUSTOM events with a NEWMSGS BITFLAGS IE check
+ */
+ ast_test_status_update(test, "Adding TEST_SUBS_CUSTOM_BITFLAGS subscription\n");
+ test_subs[TEST_SUBS_CUSTOM_BITFLAGS].sub = ast_event_subscribe(AST_EVENT_CUSTOM, event_sub_cb,
+ test_subs_class_type_str(TEST_SUBS_CUSTOM_BITFLAGS), &test_subs[TEST_SUBS_CUSTOM_BITFLAGS].data,
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_BITFLAGS, 0x06,
+ AST_EVENT_IE_END);
+ if (!test_subs[TEST_SUBS_CUSTOM_BITFLAGS].sub) {
+ ast_test_status_update(test, "Failed to create TEST_SUBS_CUSTOM_BITFLAGS subscription\n");
res = AST_TEST_FAIL;
goto return_cleanup;
}
- if (strcmp(ast_event_subscriber_get_description(test_subs[1].sub), "")) {
- ast_event_sub_destroy(test_subs[1].sub);
- test_subs[1].sub = NULL;
+ if (strcmp(ast_event_subscriber_get_description(test_subs[TEST_SUBS_CUSTOM_BITFLAGS].sub),
+ test_subs_class_type_str(TEST_SUBS_CUSTOM_BITFLAGS))) {
ast_test_status_update(test,
- "Unexpected subscription description on test_subs[1].sub\n");
+ "Unexpected subscription description on TEST_SUBS_CUSTOM_BITFLAGS subscription\n");
res = AST_TEST_FAIL;
goto return_cleanup;
}
- if (ast_event_sub_append_ie_uint(test_subs[1].sub, AST_EVENT_IE_NEWMSGS, 3)) {
- ast_event_sub_destroy(test_subs[1].sub);
- test_subs[1].sub = NULL;
- ast_test_status_update(test, "Failed to append uint IE to test_subs[1].sub\n");
+ /*
+ * Subscription TEST_SUBS_CUSTOM_EXISTS:
+ * - allocate normally
+ * - subscribe to CUSTOM events with a NEWMSGS UINT and OLDMSGS EXISTS IE check
+ */
+ ast_test_status_update(test, "Adding TEST_SUBS_CUSTOM_EXISTS subscription\n");
+ test_subs[TEST_SUBS_CUSTOM_EXISTS].sub = ast_event_subscribe(AST_EVENT_CUSTOM, event_sub_cb,
+ test_subs_class_type_str(TEST_SUBS_CUSTOM_EXISTS), &test_subs[TEST_SUBS_CUSTOM_EXISTS].data,
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, 4,
+ AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
+ AST_EVENT_IE_END);
+ if (!test_subs[TEST_SUBS_CUSTOM_EXISTS].sub) {
+ ast_test_status_update(test, "Failed to create TEST_SUBS_CUSTOM_EXISTS subscription\n");
res = AST_TEST_FAIL;
goto return_cleanup;
}
- if (ast_event_sub_append_ie_bitflags(test_subs[1].sub, AST_EVENT_IE_NEWMSGS, 1)) {
- ast_event_sub_destroy(test_subs[1].sub);
- test_subs[1].sub = NULL;
- ast_test_status_update(test, "Failed to append bitflags IE to test_subs[1].sub\n");
+ if (strcmp(ast_event_subscriber_get_description(test_subs[TEST_SUBS_CUSTOM_EXISTS].sub),
+ test_subs_class_type_str(TEST_SUBS_CUSTOM_EXISTS))) {
+ ast_test_status_update(test,
+ "Unexpected subscription description on TEST_SUBS_CUSTOM_EXISTS subscription\n");
res = AST_TEST_FAIL;
goto return_cleanup;
}
- if (ast_event_sub_append_ie_str(test_subs[1].sub, AST_EVENT_IE_DEVICE, "FOO/bar")) {
- ast_event_sub_destroy(test_subs[1].sub);
- test_subs[1].sub = NULL;
- ast_test_status_update(test, "Failed to append str IE to test_subs[1].sub\n");
+ /* For the sake of exercising destruction before activation */
+ test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub = ast_event_subscribe_new(AST_EVENT_CUSTOM,
+ event_sub_cb, &test_subs[TEST_SUBS_CUSTOM_DYNAMIC].data);
+ if (!test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub) {
+ ast_test_status_update(test, "Failed to create TEST_SUBS_CUSTOM_DYNAMIC subscription\n");
res = AST_TEST_FAIL;
goto return_cleanup;
}
+ ast_event_sub_destroy(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub);
- if (ast_event_sub_append_ie_raw(test_subs[1].sub, AST_EVENT_IE_MAILBOX, "800 km",
- strlen("800 km"))) {
- ast_event_sub_destroy(test_subs[1].sub);
- test_subs[1].sub = NULL;
- ast_test_status_update(test, "Failed to append raw IE to test_subs[1].sub\n");
+ /*
+ * Subscription TEST_SUBS_CUSTOM_DYNAMIC:
+ * - allocate dynamically
+ * - subscribe to all CUSTOM events
+ * - add IE checks for all types
+ */
+ ast_test_status_update(test, "Adding TEST_SUBS_CUSTOM_DYNAMIC subscription\n");
+ test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub = ast_event_subscribe_new(AST_EVENT_CUSTOM,
+ event_sub_cb, &test_subs[TEST_SUBS_CUSTOM_DYNAMIC].data);
+ if (!test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub) {
+ ast_test_status_update(test, "Failed to create TEST_SUBS_CUSTOM_DYNAMIC subscription\n");
res = AST_TEST_FAIL;
goto return_cleanup;
}
- if (ast_event_sub_append_ie_exists(test_subs[1].sub, AST_EVENT_IE_DEVICE)) {
- ast_event_sub_destroy(test_subs[1].sub);
- test_subs[1].sub = NULL;
- ast_test_status_update(test, "Failed to append exists IE to test_subs[1].sub\n");
+ if (strcmp(ast_event_subscriber_get_description(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub),
+ "")) {
+ ast_event_sub_destroy(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub);
+ test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub = NULL;
+ ast_test_status_update(test,
+ "Unexpected subscription description on TEST_SUBS_CUSTOM_DYNAMIC subscription\n");
res = AST_TEST_FAIL;
goto return_cleanup;
}
- if (ast_event_sub_activate(test_subs[1].sub)) {
- ast_event_sub_destroy(test_subs[1].sub);
- test_subs[1].sub = NULL;
- ast_test_status_update(test, "Failed to activate test_subs[1].sub\n");
+ if (ast_event_sub_append_ie_uint(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub, AST_EVENT_IE_NEWMSGS, 4)) {
+ ast_event_sub_destroy(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub);
+ test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub = NULL;
+ ast_test_status_update(test, "Failed to append UINT IE to TEST_SUBS_CUSTOM_DYNAMIC subscription\n");
res = AST_TEST_FAIL;
goto return_cleanup;
}
- test_subs[2].sub = ast_event_subscribe(AST_EVENT_ALL, event_sub_cb, "test_sub", &test_subs[2].data,
- AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, "FOO/bar",
- AST_EVENT_IE_END);
- if (!test_subs[2].sub) {
- ast_test_status_update(test, "Failed to create test_subs[2].sub\n");
+ if (ast_event_sub_append_ie_bitflags(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub, AST_EVENT_IE_OLDMSGS, 1)) {
+ ast_event_sub_destroy(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub);
+ test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub = NULL;
+ ast_test_status_update(test, "Failed to append BITFLAGS IE to TEST_SUBS_CUSTOM_DYNAMIC subscription\n");
+ res = AST_TEST_FAIL;
+ goto return_cleanup;
+ }
+
+ if (ast_event_sub_append_ie_str(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub, AST_EVENT_IE_DEVICE, "FOO/bar")) {
+ ast_event_sub_destroy(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub);
+ test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub = NULL;
+ ast_test_status_update(test, "Failed to append STR IE to TEST_SUBS_CUSTOM_DYNAMIC subscription\n");
+ res = AST_TEST_FAIL;
+ goto return_cleanup;
+ }
+
+ if (ast_event_sub_append_ie_raw(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub, AST_EVENT_IE_MAILBOX, "800 km",
+ strlen("800 km"))) {
+ ast_event_sub_destroy(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub);
+ test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub = NULL;
+ ast_test_status_update(test, "Failed to append RAW IE to TEST_SUBS_CUSTOM_DYNAMIC subscription\n");
+ res = AST_TEST_FAIL;
+ goto return_cleanup;
+ }
+
+ if (ast_event_sub_append_ie_exists(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub, AST_EVENT_IE_STATE)) {
+ ast_event_sub_destroy(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub);
+ test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub = NULL;
+ ast_test_status_update(test, "Failed to append EXISTS IE to TEST_SUBS_CUSTOM_DYNAMIC subscription\n");
+ res = AST_TEST_FAIL;
+ goto return_cleanup;
+ }
+
+ if (ast_event_sub_activate(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub)) {
+ ast_event_sub_destroy(test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub);
+ test_subs[TEST_SUBS_CUSTOM_DYNAMIC].sub = NULL;
+ ast_test_status_update(test, "Failed to activate TEST_SUBS_CUSTOM_DYNAMIC subscription\n");
res = AST_TEST_FAIL;
goto return_cleanup;
}
@@ -399,42 +576,219 @@ AST_TEST_DEFINE(event_sub_test)
/*
* Exercise the API call to check for existing subscriptions.
*/
+ ast_test_status_update(test, "Checking for subscribers to events\n");
+ /* Check STR matching. */
sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM,
- AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, "FOO/bar",
- AST_EVENT_IE_END);
+ AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, "FOO/bar",
+ AST_EVENT_IE_END);
if (sub_res != AST_EVENT_SUB_EXISTS) {
- ast_test_status_update(test, "subscription did not exist\n");
+ ast_test_status_update(test, "Str FOO/bar subscription did not exist\n");
res = AST_TEST_FAIL;
- goto return_cleanup;
}
sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM,
- AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, "BOOBS",
- AST_EVENT_IE_END);
+ AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, "Money",
+ AST_EVENT_IE_END);
+ if (sub_res != AST_EVENT_SUB_NONE) {
+ ast_test_status_update(test, "Str Money subscription should not exist! (%d)\n",
+ sub_res);
+ res = AST_TEST_FAIL;
+ }
+
+ /* Check RAW matching. */
+ sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM,
+ AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_RAW, "FOO/bar", sizeof("FOO/bar"),
+ AST_EVENT_IE_END);
+ if (sub_res != AST_EVENT_SUB_EXISTS) {
+ ast_test_status_update(test, "Raw FOO/bar subscription did not exist\n");
+ res = AST_TEST_FAIL;
+ }
+
+ sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM,
+ AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_RAW, "FOO/bar", sizeof("FOO/bar") - 1,
+ AST_EVENT_IE_END);
+ if (sub_res != AST_EVENT_SUB_NONE) {
+ ast_test_status_update(test, "Raw FOO/bar-1 subscription should not exist! (%d)\n",
+ sub_res);
+ res = AST_TEST_FAIL;
+ }
+
+ sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM,
+ AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_RAW, "Monkeys", sizeof("Monkeys"),
+ AST_EVENT_IE_END);
+ if (sub_res != AST_EVENT_SUB_NONE) {
+ ast_test_status_update(test, "Raw Monkeys subscription should not exist! (%d)\n",
+ sub_res);
+ res = AST_TEST_FAIL;
+ }
+
+ /* Check UINT matching. */
+ sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM,
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, 5,
+ AST_EVENT_IE_END);
+ if (sub_res != AST_EVENT_SUB_EXISTS) {
+ ast_test_status_update(test, "UINT=5 subscription did not exist\n");
+ res = AST_TEST_FAIL;
+ }
+
+ sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM,
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, 1,
+ AST_EVENT_IE_END);
if (sub_res != AST_EVENT_SUB_NONE) {
- ast_test_status_update(test, "Someone subscribed to updates on boobs, lol? (%d)\n", sub_res);
+ ast_test_status_update(test, "UINT=1 subscription should not exist! (%d)\n",
+ sub_res);
+ res = AST_TEST_FAIL;
+ }
+
+ /* Check BITFLAGS matching. */
+ sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM,
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_BITFLAGS, 2,
+ AST_EVENT_IE_END);
+ if (sub_res != AST_EVENT_SUB_EXISTS) {
+ ast_test_status_update(test, "BITFLAGS=2 subscription did not exist\n");
+ res = AST_TEST_FAIL;
+ }
+
+ sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM,
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_BITFLAGS, 8,
+ AST_EVENT_IE_END);
+ if (sub_res != AST_EVENT_SUB_NONE) {
+ ast_test_status_update(test, "BITFLAGS=8 subscription should not exist! (%d)\n",
+ sub_res);
+ res = AST_TEST_FAIL;
+ }
+
+ /* Check EXISTS matching. */
+ sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM,
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, 4,
+ AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, 100,
+ AST_EVENT_IE_END);
+ if (sub_res != AST_EVENT_SUB_EXISTS) {
+ ast_test_status_update(test, "EXISTS subscription did not exist\n");
+ res = AST_TEST_FAIL;
+ }
+
+ sub_res = ast_event_check_subscriber(AST_EVENT_CUSTOM,
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, 4,
+ AST_EVENT_IE_END);
+ if (sub_res != AST_EVENT_SUB_NONE) {
+ ast_test_status_update(test, "EXISTS subscription should not exist! (%d)\n",
+ sub_res);
+ res = AST_TEST_FAIL;
+ }
+
+ /*
+ * Subscription TEST_SUBS_CUSTOM_ANY:
+ * - allocate normally
+ * - subscribe to all CUSTOM events
+ */
+ ast_test_status_update(test, "Adding TEST_SUBS_CUSTOM_ANY subscription\n");
+ test_subs[TEST_SUBS_CUSTOM_ANY].sub = ast_event_subscribe(AST_EVENT_CUSTOM, event_sub_cb,
+ test_subs_class_type_str(TEST_SUBS_CUSTOM_ANY), &test_subs[TEST_SUBS_CUSTOM_ANY].data,
+ AST_EVENT_IE_END);
+ if (!test_subs[TEST_SUBS_CUSTOM_ANY].sub) {
+ ast_test_status_update(test, "Failed to create TEST_SUBS_CUSTOM_ANY subscription\n");
+ res = AST_TEST_FAIL;
+ goto return_cleanup;
+ }
+
+ if (strcmp(ast_event_subscriber_get_description(test_subs[TEST_SUBS_CUSTOM_ANY].sub),
+ test_subs_class_type_str(TEST_SUBS_CUSTOM_ANY))) {
+ ast_test_status_update(test,
+ "Unexpected subscription description on TEST_SUBS_CUSTOM_ANY subscription\n");
res = AST_TEST_FAIL;
goto return_cleanup;
}
/*
* Fire off some events and track what was received in the callback
+ */
+ ast_test_status_update(test, "Posting test events\n");
+
+ /*
+ * Event to check STR matching.
*
- * event #1:
- * - simple custom event (will match sub 1 and 3)
+ * Matching subscriptions:
+ * TEST_SUBS_ALL_STR
+ * TEST_SUBS_CUSTOM_STR
+ * TEST_SUBS_CUSTOM_ANY
+ */
+ event = ast_event_new(AST_EVENT_CUSTOM,
+ AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_RAW, "FOO/bar", sizeof("FOO/bar") - 1,
+ AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, "FOO/bar",
+ AST_EVENT_IE_END);
+ if (!event) {
+ ast_test_status_update(test, "Failed to create event\n");
+ res = AST_TEST_FAIL;
+ goto return_cleanup;
+ }
+ if (ast_event_queue(event)) {
+ ast_event_destroy(event);
+ event = NULL;
+ ast_test_status_update(test, "Failed to queue event\n");
+ res = AST_TEST_FAIL;
+ goto return_cleanup;
+ }
+
+ /*
+ * Event to check RAW matching.
*
- * event #2:
- * - custom event with payloads that satisfy every payload check
- * for sub #2 (will match sub 1, 2, and 3)
+ * Matching subscriptions:
+ * TEST_SUBS_CUSTOM_RAW
+ * TEST_SUBS_CUSTOM_ANY
+ */
+ event = ast_event_new(AST_EVENT_CUSTOM,
+ AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, "Misery",
+ AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_RAW, "FOO/bar", sizeof("FOO/bar"),
+ AST_EVENT_IE_END);
+ if (!event) {
+ ast_test_status_update(test, "Failed to create event\n");
+ res = AST_TEST_FAIL;
+ goto return_cleanup;
+ }
+ if (ast_event_queue(event)) {
+ ast_event_destroy(event);
+ event = NULL;
+ ast_test_status_update(test, "Failed to queue event\n");
+ res = AST_TEST_FAIL;
+ goto return_cleanup;
+ }
+
+ /*
+ * Event to check UINT matching.
*
- * event #3:
- * - custom event that should only match sub #1
+ * Matching subscriptions:
+ * TEST_SUBS_CUSTOM_UINT
+ * TEST_SUBS_CUSTOM_BITFLAGS
+ * TEST_SUBS_CUSTOM_ANY
*/
+ event = ast_event_new(AST_EVENT_CUSTOM,
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, 5,
+ AST_EVENT_IE_END);
+ if (!event) {
+ ast_test_status_update(test, "Failed to create event\n");
+ res = AST_TEST_FAIL;
+ goto return_cleanup;
+ }
+ if (ast_event_queue(event)) {
+ ast_event_destroy(event);
+ event = NULL;
+ ast_test_status_update(test, "Failed to queue event\n");
+ res = AST_TEST_FAIL;
+ goto return_cleanup;
+ }
+ /*
+ * Event to check BITFLAGS matching.
+ *
+ * Matching subscriptions:
+ * TEST_SUBS_CUSTOM_BITFLAGS
+ * TEST_SUBS_CUSTOM_ANY
+ */
event = ast_event_new(AST_EVENT_CUSTOM,
- AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, "FOO/bar",
- AST_EVENT_IE_END);
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, 4,
+ AST_EVENT_IE_END);
if (!event) {
ast_test_status_update(test, "Failed to create event\n");
res = AST_TEST_FAIL;
@@ -448,11 +802,18 @@ AST_TEST_DEFINE(event_sub_test)
goto return_cleanup;
}
+ /*
+ * Event to check EXISTS matching.
+ *
+ * Matching subscriptions:
+ * TEST_SUBS_CUSTOM_EXISTS
+ * TEST_SUBS_CUSTOM_BITFLAGS
+ * TEST_SUBS_CUSTOM_ANY
+ */
event = ast_event_new(AST_EVENT_CUSTOM,
- AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, "FOO/bar",
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_RAW, "800 km", strlen("800 km"),
- AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, 3,
- AST_EVENT_IE_END);
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, 4,
+ AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, 4,
+ AST_EVENT_IE_END);
if (!event) {
ast_test_status_update(test, "Failed to create event\n");
res = AST_TEST_FAIL;
@@ -466,11 +827,24 @@ AST_TEST_DEFINE(event_sub_test)
goto return_cleanup;
}
+ /*
+ * Event to get dynamic subscription to have an event.
+ *
+ * Matching subscriptions:
+ * TEST_SUBS_CUSTOM_DYNAMIC
+ * TEST_SUBS_CUSTOM_BITFLAGS
+ * TEST_SUBS_CUSTOM_EXISTS
+ * TEST_SUBS_ALL_STR
+ * TEST_SUBS_CUSTOM_STR
+ * TEST_SUBS_CUSTOM_ANY
+ */
event = ast_event_new(AST_EVENT_CUSTOM,
- AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, "blah",
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_RAW, "801 km", strlen("801 km"),
- AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, 0,
- AST_EVENT_IE_END);
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, 4,
+ AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, 5,
+ AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_RAW, "800 km", strlen("800 km"),
+ AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, "FOO/bar",
+ AST_EVENT_IE_STATE, AST_EVENT_IE_PLTYPE_UINT, 5,
+ AST_EVENT_IE_END);
if (!event) {
ast_test_status_update(test, "Failed to create event\n");
res = AST_TEST_FAIL;
@@ -483,6 +857,7 @@ AST_TEST_DEFINE(event_sub_test)
res = AST_TEST_FAIL;
goto return_cleanup;
}
+
event = NULL;
/*
@@ -494,19 +869,23 @@ AST_TEST_DEFINE(event_sub_test)
* If something was actually blocking event distribution that long, I would call
* it a bug.
*
- * Expected results:
- * - sub 1, 2 events
- * - sub 2, 1 event
- * - sub 3, 2 events
+ * See test_subs[] initialization for expected results.
*/
ast_test_status_update(test, "Sleeping a few seconds to allow event propagation...\n");
sleep(3);
for (i = 0; i < ARRAY_LEN(test_subs); i++) {
+ if (!test_subs[i].sub) {
+ ast_test_status_update(test, "Missing a test subscription for %s\n",
+ test_subs_class_type_str(i));
+ res = AST_TEST_FAIL;
+ }
if (test_subs[i].data.count != test_subs[i].expected_count) {
- ast_test_status_update(test, "Unexpected callback count, %u != %u for #%d\n",
- test_subs[i].data.count, test_subs[i].expected_count, i);
+ ast_test_status_update(test,
+ "Unexpected callback count, got %u expected %u for %s\n",
+ test_subs[i].data.count, test_subs[i].expected_count,
+ test_subs_class_type_str(i));
res = AST_TEST_FAIL;
}
}