/** * nih_error_init: * * Initialise the context stack. **/ void nih_error_init (void) { if (! context_stack) { context_stack = NIH_MUST (nih_list_new (NULL)); nih_error_push_context (); nih_assert (atexit (nih_error_clear) == 0); } }
/** * session_init: * * Initialise the sessions list. **/ void session_init (void) { if (! sessions) sessions = NIH_MUST (nih_list_new (NULL)); }
void test_operator_events (void) { EventOperator *root, *oper1, *oper2, *oper3, *oper4, *oper5, *oper6; Event *event1, *event2, *event3; NihList *list = NULL; Blocked *blocked; TEST_FUNCTION ("event_operator_events"); root = event_operator_new (NULL, EVENT_OR, NULL, NULL); oper1 = event_operator_new (root, EVENT_AND, NULL, NULL); oper2 = event_operator_new (root, EVENT_AND, NULL, NULL); oper3 = event_operator_new (root, EVENT_MATCH, "foo", NULL); oper4 = event_operator_new (root, EVENT_MATCH, "bar", NULL); oper5 = event_operator_new (root, EVENT_MATCH, "frodo", NULL); oper6 = event_operator_new (root, EVENT_MATCH, "bilbo", NULL); nih_tree_add (&root->node, &oper1->node, NIH_TREE_LEFT); nih_tree_add (&root->node, &oper2->node, NIH_TREE_RIGHT); nih_tree_add (&oper1->node, &oper3->node, NIH_TREE_LEFT); nih_tree_add (&oper1->node, &oper4->node, NIH_TREE_RIGHT); nih_tree_add (&oper2->node, &oper5->node, NIH_TREE_LEFT); nih_tree_add (&oper2->node, &oper6->node, NIH_TREE_RIGHT); root->value = TRUE; oper1->value = TRUE; oper3->value = TRUE; oper3->event = event1 = event_new (NULL, "foo", NULL); event_block (oper3->event); oper4->value = TRUE; oper4->event = event2 = event_new (NULL, "bar", NULL); event_block (oper4->event); oper6->value = TRUE; oper6->event = event3 = event_new (NULL, "bilbo", NULL); event_block (oper6->event); /* Check that the events are appended in tree order to the list * and each event is referenced and blocked; the event that was * matched, but not in the operator tree, should not be added. */ TEST_FEATURE ("with matches in tree"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { list = nih_list_new (NULL); } event_operator_events (root, NULL, list); TEST_LIST_NOT_EMPTY (list); blocked = (Blocked *)list->next; TEST_ALLOC_SIZE (blocked, sizeof (Blocked)); TEST_EQ (blocked->type, BLOCKED_EVENT); TEST_EQ_P (blocked->event, oper3->event); TEST_EQ (blocked->event->blockers, 2); event_unblock (blocked->event); nih_free (blocked); blocked = (Blocked *)list->next; TEST_ALLOC_SIZE (blocked, sizeof (Blocked)); TEST_EQ (blocked->type, BLOCKED_EVENT); TEST_EQ_P (blocked->event, oper4->event); TEST_EQ (blocked->event->blockers, 2); event_unblock (blocked->event); nih_free (blocked); TEST_LIST_EMPTY (list); TEST_EQ (oper6->event->blockers, 1); nih_free (list); } /* Check that if no events are matched, the list remains empty. */ TEST_FEATURE ("with no matches"); TEST_ALLOC_FAIL { TEST_ALLOC_SAFE { list = nih_list_new (NULL); } event_operator_events (oper5, NULL, list); TEST_LIST_EMPTY (list); TEST_EQ (oper3->event->blockers, 1); TEST_EQ (oper4->event->blockers, 1); TEST_EQ (oper6->event->blockers, 1); nih_free (list); } nih_free (root); nih_free (event1); nih_free (event2); nih_free (event3); }