~vorlon/ubuntu/raring/upstart/lp.1199778

« back to all changes in this revision

Viewing changes to init/tests/test_util.c

  • Committer: Steve Langasek
  • Date: 2013-11-07 03:06:51 UTC
  • Revision ID: steve.langasek@canonical.com-20131107030651-f1jzeyi7ifvvw1h8
Attempt to cherry-pick fixes for bug #1199778 to raring; something is still
missing though, the test suite segfaults on one of the json loads.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "test_util.h"
 
2
#include "test_util_common.h"
2
3
#include <nih/logging.h>
3
4
#include <nih/test.h>
4
5
 
5
6
/**
6
 
 * string_check:
7
 
 *
8
 
 * @a: first string,
9
 
 * @b: second string.
10
 
 *
11
 
 * Compare @a and @b either or both of which may be NULL.
12
 
 *
13
 
 * Returns 0 if strings are identical or both NULL, else 1.
14
 
 **/
15
 
int
16
 
string_check (const char *a, const char *b)
17
 
{
18
 
        if (!a && !b)
19
 
                return 0;
20
 
 
21
 
        if (!a || !b)
22
 
                return 1;
23
 
 
24
 
        if (strcmp (a, b))
25
 
                return 1;
26
 
 
27
 
        return 0;
28
 
}
29
 
 
30
 
/**
31
7
 * event_operator_diff:
32
8
 * @a: first Blocked,
33
9
 * @b: second Blocked,
110
86
 
111
87
        return NULL;
112
88
}
 
89
 
 
90
/**
 
91
 * ensure_env_clean:
 
92
 *
 
93
 * Ensure most common data structures are empty.
 
94
 *
 
95
 * Note: Control connections are not handled as the init routine
 
96
 * does more than just initialise the structure.
 
97
 **/
 
98
void
 
99
ensure_env_clean (void)
 
100
{
 
101
        TEST_NE_P (sessions, NULL);
 
102
        TEST_NE_P (events, NULL);
 
103
        TEST_NE_P (conf_sources, NULL);
 
104
        TEST_NE_P (job_classes, NULL);
 
105
        TEST_NE_P (log_unflushed_files, NULL);
 
106
 
 
107
        /* Ensure environment is clean before test is run */
 
108
        TEST_LIST_EMPTY (sessions);
 
109
        TEST_LIST_EMPTY (events);
 
110
        TEST_LIST_EMPTY (conf_sources);
 
111
        TEST_HASH_EMPTY (job_classes);
 
112
        TEST_LIST_EMPTY (log_unflushed_files);
 
113
}
 
114
 
 
115
/**
 
116
 * clean_env:
 
117
 *
 
118
 * Re-initialise all common data structures.
 
119
 *
 
120
 * Note: Like ensure_env_clean(), control connections are not handled.
 
121
 **/
 
122
void
 
123
clean_env (void)
 
124
{
 
125
        session_init ();
 
126
        event_init ();
 
127
        job_class_init ();
 
128
        conf_init ();
 
129
        log_unflushed_init ();
 
130
 
 
131
        nih_free (sessions);
 
132
        nih_free (events);
 
133
        nih_free (job_classes);
 
134
        nih_free (conf_sources);
 
135
        nih_free (log_unflushed_files);
 
136
 
 
137
        sessions = NULL;
 
138
        events = NULL;
 
139
        job_classes = NULL;
 
140
        conf_sources = NULL;
 
141
        log_unflushed_files = NULL;
 
142
 
 
143
        session_init ();
 
144
        event_init ();
 
145
        job_class_init ();
 
146
        conf_init ();
 
147
        log_unflushed_init ();
 
148
}