1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#include "test_util.h"
#include "test_util_common.h"
#include <nih/logging.h>
#include <nih/test.h>
/**
* event_operator_diff:
* @a: first Blocked,
* @b: second Blocked,
* @seen: object type that has already been seen.
*
* Compare two Blocked objects for equivalence.
*
* Returns: 0 if @a and @b are identical, else 1.
**/
int
event_operator_diff (EventOperator *a, EventOperator *b)
{
if (! a && ! b)
return 0;
if ((! a && b) || (a && ! b))
return 1;
TEST_TWO_TREES_FOREACH (&a->node, &b->node, iter_a, iter_b) {
EventOperator *opera = (EventOperator *)iter_a;
EventOperator *operb = (EventOperator *)iter_b;
nih_local char *env_a = NULL;
nih_local char *env_b = NULL;
if ((! opera && operb) || (! operb && opera))
return 1;
TEST_NE_P (opera, NULL);
TEST_NE_P (operb, NULL);
if (opera->type != operb->type)
return 1;
if (opera->value != operb->value)
return 1;
if (opera->type == EVENT_MATCH && opera->env) {
env_a = state_collapse_env ((const char **)opera->env);
if (! env_a)
return 1;
}
if (operb->type == EVENT_MATCH && operb->env) {
env_b = state_collapse_env ((const char **)operb->env);
if (! env_b)
return 1;
}
if (string_check (env_a, env_b))
return 1;
if (opera->event != operb->event)
return 1;
}
return 0;
}
/**
* session_from_chroot:
* @chroot: full path to chroot.
*
* Obtain the session relating to the specified chroot.
*
* Returns: Session, or NULL if no session found.
**/
Session *
session_from_chroot (const char *chroot)
{
nih_assert (chroot);
session_init ();
NIH_LIST_FOREACH (sessions, iter) {
Session *session = (Session *)iter;
if (! strcmp (session->chroot, chroot))
return session;
}
return NULL;
}
/**
* ensure_env_clean:
*
* Ensure most common data structures are empty.
*
* Note: Control connections are not handled as the init routine
* does more than just initialise the structure.
**/
void
ensure_env_clean (void)
{
TEST_NE_P (sessions, NULL);
TEST_NE_P (events, NULL);
TEST_NE_P (conf_sources, NULL);
TEST_NE_P (job_classes, NULL);
TEST_NE_P (log_unflushed_files, NULL);
/* Ensure environment is clean before test is run */
TEST_LIST_EMPTY (sessions);
TEST_LIST_EMPTY (events);
TEST_LIST_EMPTY (conf_sources);
TEST_HASH_EMPTY (job_classes);
TEST_LIST_EMPTY (log_unflushed_files);
}
/**
* clean_env:
*
* Re-initialise all common data structures.
*
* Note: Like ensure_env_clean(), control connections are not handled.
**/
void
clean_env (void)
{
session_init ();
event_init ();
job_class_init ();
conf_init ();
log_unflushed_init ();
nih_free (sessions);
nih_free (events);
nih_free (job_classes);
nih_free (conf_sources);
nih_free (log_unflushed_files);
sessions = NULL;
events = NULL;
job_classes = NULL;
conf_sources = NULL;
log_unflushed_files = NULL;
session_init ();
event_init ();
job_class_init ();
conf_init ();
log_unflushed_init ();
}
|