~ubuntu-branches/ubuntu/raring/libnih/raring

« back to all changes in this revision

Viewing changes to nih/tests/test_logging.c

  • Committer: James Hunt
  • Date: 2013-03-14 10:27:34 UTC
  • mfrom: (1027.1.34 upstart-devel-libnih)
  • Revision ID: james.hunt@ubuntu.com-20130314102734-blit21ei3v9n0u2o
Tags: 1.0.3-4ubuntu16
Merge of important fixes from lp:~upstart-devel/libnih/nih
(LP: #776532, LP: #777097, LP: #834813, LP: #1123588).

Show diffs side-by-side

added added

removed removed

Lines of Context:
159
159
        /* Check that a fatal message is also stored in the __nih_abort_msg
160
160
         * variable.
161
161
         */
162
 
        if (&__nih_abort_msg) {
163
 
                TEST_FEATURE ("with fatal message");
164
 
                TEST_ALLOC_FAIL {
165
 
                        __nih_abort_msg = NULL;
166
 
                        last_priority = NIH_LOG_UNKNOWN;
167
 
                        last_message = NULL;
168
 
 
169
 
                        ret = nih_log_message (NIH_LOG_FATAL,
170
 
                                               "message with %s %d formatting",
171
 
                                               "some", 20);
172
 
 
173
 
                        TEST_EQ (ret, 0);
174
 
                        TEST_EQ (last_priority, NIH_LOG_FATAL);
175
 
                        TEST_EQ_STR (last_message, "message with some 20 formatting");
176
 
 
177
 
                        TEST_NE_P (__nih_abort_msg, NULL);
178
 
                        TEST_ALLOC_PARENT (__nih_abort_msg, NULL);
179
 
                        TEST_EQ_STR (__nih_abort_msg, "message with some 20 formatting");
180
 
 
181
 
                        free (last_message);
182
 
                }
183
 
 
184
 
 
185
 
                /* Check that a fatal message can safely overwrite one already stored
186
 
                 * in the __nih_abort_msg variable.
187
 
                 */
188
 
                TEST_FEATURE ("with second fatal message");
189
 
                TEST_ALLOC_FAIL {
190
 
                        TEST_ALLOC_SAFE {
191
 
                                msg = nih_strdup (NULL, "test");
192
 
                        }
193
 
 
194
 
                        __nih_abort_msg = msg;
195
 
                        TEST_FREE_TAG (msg);
196
 
 
197
 
                        last_priority = NIH_LOG_UNKNOWN;
198
 
                        last_message = NULL;
199
 
 
200
 
                        ret = nih_log_message (NIH_LOG_FATAL,
201
 
                                               "message with %s %d formatting",
202
 
                                               "some", 20);
203
 
 
204
 
                        TEST_EQ (ret, 0);
205
 
                        TEST_EQ (last_priority, NIH_LOG_FATAL);
206
 
                        TEST_EQ_STR (last_message, "message with some 20 formatting");
207
 
 
208
 
                        TEST_FREE (msg);
209
 
 
210
 
                        TEST_NE_P (__nih_abort_msg, NULL);
211
 
                        TEST_ALLOC_PARENT (__nih_abort_msg, NULL);
212
 
                        TEST_EQ_STR (__nih_abort_msg, "message with some 20 formatting");
213
 
 
214
 
                        free (last_message);
215
 
                }
216
 
        } else {
217
 
                printf ("SKIP: __nih_abort_msg not available\n");
218
 
        }
219
 
 
 
162
        TEST_FEATURE ("with fatal message");
 
163
        TEST_ALLOC_FAIL {
 
164
                __nih_abort_msg = NULL;
 
165
                last_priority = NIH_LOG_UNKNOWN;
 
166
                last_message = NULL;
 
167
 
 
168
                ret = nih_log_message (NIH_LOG_FATAL,
 
169
                                "message with %s %d formatting",
 
170
                                "some", 20);
 
171
 
 
172
                TEST_EQ (ret, 0);
 
173
                TEST_EQ (last_priority, NIH_LOG_FATAL);
 
174
                TEST_EQ_STR (last_message, "message with some 20 formatting");
 
175
 
 
176
                TEST_NE_P (__nih_abort_msg, NULL);
 
177
                TEST_ALLOC_PARENT (__nih_abort_msg, NULL);
 
178
                TEST_EQ_STR (__nih_abort_msg, "message with some 20 formatting");
 
179
 
 
180
                free (last_message);
 
181
        }
 
182
 
 
183
 
 
184
        /* Check that a fatal message can safely overwrite one already stored
 
185
         * in the __nih_abort_msg variable.
 
186
         */
 
187
        TEST_FEATURE ("with second fatal message");
 
188
        TEST_ALLOC_FAIL {
 
189
                TEST_ALLOC_SAFE {
 
190
                        msg = nih_strdup (NULL, "test");
 
191
                }
 
192
 
 
193
                __nih_abort_msg = msg;
 
194
                TEST_FREE_TAG (msg);
 
195
 
 
196
                last_priority = NIH_LOG_UNKNOWN;
 
197
                last_message = NULL;
 
198
 
 
199
                ret = nih_log_message (NIH_LOG_FATAL,
 
200
                                "message with %s %d formatting",
 
201
                                "some", 20);
 
202
 
 
203
                TEST_EQ (ret, 0);
 
204
                TEST_EQ (last_priority, NIH_LOG_FATAL);
 
205
                TEST_EQ_STR (last_message, "message with some 20 formatting");
 
206
 
 
207
                TEST_FREE (msg);
 
208
 
 
209
                TEST_NE_P (__nih_abort_msg, NULL);
 
210
                TEST_ALLOC_PARENT (__nih_abort_msg, NULL);
 
211
                TEST_EQ_STR (__nih_abort_msg, "message with some 20 formatting");
 
212
 
 
213
                free (last_message);
 
214
        }
220
215
 
221
216
        /* Check that the nih_debug macro wraps the call properly and
222
217
         * includes the function in which the message occurred.