summaryrefslogtreecommitdiff
path: root/test/basictests.c
blob: a331b2f4004f1aabad03e2b98731babdd16ee85d (plain)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
/* test/basictests.c
 *
 * Basic tests for the test suite for libnslog
 *
 * Copyright 2009,2017 The NetSurf Browser Project
 *                Daniel Silverstone <dsilvers@netsurf-browser.org>
 */

#include <check.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>

#include "tests.h"

#ifndef UNUSED
#define UNUSED(x) (void)(x)
#endif

NSLOG_DEFINE_CATEGORY(test, "Top level test category");
NSLOG_DEFINE_SUBCATEGORY(test, sub, "Lower level test category");

static void *captured_render_context = NULL;
static nslog_entry_context_t captured_context = { 0 };
static char captured_rendered_message[4096] = { 0 };
static int captured_rendered_message_length = 0;
static int captured_message_count = 0;

static const char* anchor_context_1 = "1";

static void
nslog__test__render_function(void *_ctx, nslog_entry_context_t *ctx,
			     const char *fmt, va_list args)
{
	captured_context = *ctx;
	captured_render_context = _ctx;
	captured_rendered_message_length =
		vsnprintf(captured_rendered_message,
			  sizeof(captured_rendered_message),
			  fmt, args);
	captured_message_count++;
}

/**** The next set of tests need a fixture set ****/

static void
with_simple_context_setup(void)
{
	captured_render_context = NULL;
	memset(&captured_context, 0, sizeof(captured_context));
	memset(captured_rendered_message, 0, sizeof(captured_rendered_message));
	captured_rendered_message_length = 0;
	captured_message_count = 0;
	fail_unless(nslog_set_render_callback(
			    nslog__test__render_function,
			    (void *)anchor_context_1) == NSLOG_NO_ERROR,
		    "Unable to set up render callback");
}

static void
with_simple_context_teardown(void)
{
        /* Nothing to do to tear down */
}

START_TEST (test_nslog_trivial_corked_message)
{
	NSLOG(test, INFO, "Hello %s", "world");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	fail_unless(captured_message_count == 1,
		    "Captured message count was wrong");
	fail_unless(captured_render_context == anchor_context_1,
		    "Captured context wasn't passed through");
	fail_unless(strcmp(captured_context.category->name, "test") == 0,
		    "Captured context category wasn't normalised");
	fail_unless(captured_context.category == &__nslog_category_test,
		    "Captured context category wasn't the one we wanted");
	fail_unless(captured_rendered_message_length == 11,
		    "Captured message wasn't correct length");
	fail_unless(strcmp(captured_rendered_message, "Hello world") == 0,
		    "Captured message wasn't correct");
	fail_unless(strcmp(captured_context.filename, "test/basictests.c") == 0,
		    "Captured message wasn't correct filename");
	fail_unless(strcmp(captured_context.funcname, "test_nslog_trivial_corked_message") == 0,
		    "Captured message wasn't correct function name");
}
END_TEST

START_TEST (test_nslog_trivial_uncorked_message)
{
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	fail_unless(captured_message_count == 0,
		    "Unusual, we had messages from before uncorking");
	NSLOG(test, INFO, "Hello %s", "world");
	fail_unless(captured_message_count == 1,
		    "Captured message count was wrong");
	fail_unless(captured_render_context == anchor_context_1,
		    "Captured context wasn't passed through");
	fail_unless(strcmp(captured_context.category->name, "test") == 0,
		    "Captured context category wasn't normalised");
	fail_unless(captured_context.category == &__nslog_category_test,
		    "Captured context category wasn't the one we wanted");
	fail_unless(captured_rendered_message_length == 11,
		    "Captured message wasn't correct length");
	fail_unless(strcmp(captured_rendered_message, "Hello world") == 0,
		    "Captured message wasn't correct");
	fail_unless(strcmp(captured_context.filename, "test/basictests.c") == 0,
		    "Captured message wasn't correct filename");
	fail_unless(strcmp(captured_context.funcname, "test_nslog_trivial_uncorked_message") == 0,
		    "Captured message wasn't correct function name");
}
END_TEST

START_TEST (test_nslog_subcategory_name)
{
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	fail_unless(captured_message_count == 0,
		    "Unusual, we had messages from before uncorking");
	NSLOG(sub, INFO, "Hello %s", "world");
	fail_unless(captured_message_count == 1,
		    "Captured message count was wrong");
	fail_unless(captured_render_context == anchor_context_1,
		    "Captured context wasn't passed through");
	fail_unless(strcmp(captured_context.category->name, "test/sub") == 0,
		    "Captured context category wasn't normalised");
}
END_TEST

START_TEST (test_nslog_two_corked_messages)
{
	NSLOG(test, INFO, "First");
	NSLOG(sub, CRIT, "Second");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	fail_unless(captured_message_count == 2,
		    "Captured message count was wrong");
	fail_unless(captured_render_context == anchor_context_1,
		    "Captured context wasn't passed through");
	fail_unless(strcmp(captured_context.category->name, "test/sub") == 0,
		    "Captured context category wasn't normalised");
	fail_unless(captured_context.category == &__nslog_category_sub,
		    "Captured context category wasn't the one we wanted");
	fail_unless(captured_rendered_message_length == 6,
		    "Captured message wasn't correct length");
	fail_unless(strcmp(captured_rendered_message, "Second") == 0,
		    "Captured message wasn't correct");
	fail_unless(strcmp(captured_context.filename, "test/basictests.c") == 0,
		    "Captured message wasn't correct filename");
	fail_unless(strcmp(captured_context.funcname, "test_nslog_two_corked_messages") == 0,
		    "Captured message wasn't correct function name");
}
END_TEST

START_TEST (test_nslog_check_bad_level)
{
	fail_unless(strcmp(nslog_level_name((nslog_level)-1),
			   "**UNKNOWN**") == 0,
		    "Failed to fail to render bad level");
}
END_TEST

/**** The next set of tests need a fixture set for filters ****/

static nslog_filter_t *cat_test = NULL;
static nslog_filter_t *cat_another = NULL;
static nslog_filter_t *cat_test_sub = NULL;

static const char *anchor_context_2 = "2";

static void
with_simple_filter_context_setup(void)
{
	captured_render_context = NULL;
	memset(&captured_context, 0, sizeof(captured_context));
	memset(captured_rendered_message, 0, sizeof(captured_rendered_message));
	captured_rendered_message_length = 0;
	captured_message_count = 0;
	fail_unless(nslog_set_render_callback(
			    nslog__test__render_function,
			    (void *)anchor_context_2) == NSLOG_NO_ERROR,
		    "Unable to set up render callback");
	fail_unless(nslog_filter_category_new("test", &cat_test) == NSLOG_NO_ERROR,
		    "Unable to create a category filter for 'test'");
	fail_unless(nslog_filter_category_new("another", &cat_another) == NSLOG_NO_ERROR,
		    "Unable to create a category filter for 'another'");
	fail_unless(nslog_filter_category_new("test/sub", &cat_test_sub) == NSLOG_NO_ERROR,
		    "Unable to create a category filter for 'test/sub'");
}

static void
with_simple_filter_context_teardown(void)
{
        /* Nothing to do to tear down */
	fail_unless(nslog_filter_set_active(NULL, NULL) == NSLOG_NO_ERROR,
		    "Unable to clear active filter");
	cat_test = nslog_filter_unref(cat_test);
	cat_another = nslog_filter_unref(cat_another);
	cat_test_sub = nslog_filter_unref(cat_test_sub);
}

START_TEST (test_nslog_simple_filter_corked_message)
{
	NSLOG(test, INFO, "Hello world");
	fail_unless(nslog_filter_set_active(cat_test, NULL) == NSLOG_NO_ERROR,
		    "Unable to set active filter to cat:test");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	fail_unless(captured_message_count == 1,
		    "Captured message count was wrong");
	fail_unless(captured_render_context == anchor_context_2,
		    "Captured context wasn't passed through");
	fail_unless(strcmp(captured_context.category->name, "test") == 0,
		    "Captured context category wasn't normalised");
	fail_unless(captured_context.category == &__nslog_category_test,
		    "Captured context category wasn't the one we wanted");
	fail_unless(captured_rendered_message_length == 11,
		    "Captured message wasn't correct length");
	fail_unless(strcmp(captured_rendered_message, "Hello world") == 0,
		    "Captured message wasn't correct");
	fail_unless(strcmp(captured_context.filename, "test/basictests.c") == 0,
		    "Captured message wasn't correct filename");
	fail_unless(strcmp(captured_context.funcname, "test_nslog_simple_filter_corked_message") == 0,
		    "Captured message wasn't correct function name");

}
END_TEST

START_TEST (test_nslog_simple_filter_uncorked_message)
{
	fail_unless(nslog_filter_set_active(cat_test, NULL) == NSLOG_NO_ERROR,
		    "Unable to set active filter to cat:test");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	NSLOG(test, INFO, "Hello world");
	fail_unless(captured_message_count == 1,
		    "Captured message count was wrong");
	fail_unless(captured_render_context == anchor_context_2,
		    "Captured context wasn't passed through");
	fail_unless(strcmp(captured_context.category->name, "test") == 0,
		    "Captured context category wasn't normalised");
	fail_unless(captured_context.category == &__nslog_category_test,
		    "Captured context category wasn't the one we wanted");
	fail_unless(captured_rendered_message_length == 11,
		    "Captured message wasn't correct length");
	fail_unless(strcmp(captured_rendered_message, "Hello world") == 0,
		    "Captured message wasn't correct");
	fail_unless(strcmp(captured_context.filename, "test/basictests.c") == 0,
		    "Captured message wasn't correct filename");
	fail_unless(strcmp(captured_context.funcname, "test_nslog_simple_filter_uncorked_message") == 0,
		    "Captured message wasn't correct function name");

}
END_TEST

START_TEST (test_nslog_simple_filter_subcategory_message)
{
	fail_unless(nslog_filter_set_active(cat_test, NULL) == NSLOG_NO_ERROR,
		    "Unable to set active filter to cat:test");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	NSLOG(sub, INFO, "Hello world");
	fail_unless(captured_message_count == 1,
		    "Captured message count was wrong");
	fail_unless(captured_render_context == anchor_context_2,
		    "Captured context wasn't passed through");
	fail_unless(strcmp(captured_context.category->name, "test/sub") == 0,
		    "Captured context category wasn't normalised");
	fail_unless(captured_context.category == &__nslog_category_sub,
		    "Captured context category wasn't the one we wanted");
	fail_unless(captured_rendered_message_length == 11,
		    "Captured message wasn't correct length");
	fail_unless(strcmp(captured_rendered_message, "Hello world") == 0,
		    "Captured message wasn't correct");
	fail_unless(strcmp(captured_context.filename, "test/basictests.c") == 0,
		    "Captured message wasn't correct filename");
	fail_unless(strcmp(captured_context.funcname, "test_nslog_simple_filter_subcategory_message") == 0,
		    "Captured message wasn't correct function name");

}
END_TEST

START_TEST (test_nslog_simple_filter_out_subcategory_message)
{
	fail_unless(nslog_filter_set_active(cat_test_sub, NULL) == NSLOG_NO_ERROR,
		    "Unable to set active filter to cat:test/sub");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	NSLOG(test, INFO, "Hello world");
	fail_unless(captured_message_count == 0,
		    "Captured message count was wrong");
}
END_TEST

START_TEST (test_nslog_basic_filter_sprintf)
{
	char *ct = nslog_filter_sprintf(cat_test);
	fail_unless(ct != NULL, "Unable to sprintf");
	fail_unless(strcmp(ct, "cat:test") == 0,
		    "Printed category test is wrong");
	free(ct);
	ct = nslog_filter_sprintf(cat_another);
	fail_unless(ct != NULL, "Unable to sprintf");
	fail_unless(strcmp(ct, "cat:another") == 0,
		    "Printed category another is wrong");
	free(ct);
}
END_TEST

START_TEST (test_nslog_parse_and_sprintf)
{
	nslog_filter_t *filt = NULL;
	fail_unless(nslog_filter_from_text("cat:test", &filt) == NSLOG_NO_ERROR,
		    "Unable to parse cat:test");
	fail_unless(filt != NULL,
		    "Strange, despite parsing okay, filt was NULL");
	char *ct = nslog_filter_sprintf(filt);
	nslog_filter_unref(filt);
	fail_unless(strcmp(ct, "cat:test") == 0,
		    "Printed parsed cat:test not right");
}
END_TEST

START_TEST (test_nslog_parse_and_sprintf_all_levels)
{
	nslog_filter_t *filt = NULL;
	const char *input =
		"((((((lvl:DEEPDEBUG || lvl:DEBUG) || lvl:VERBOSE) || lvl:INFO) || lvl:WARNING) || lvl:ERROR) || lvl:CRITICAL)";
	fail_unless(nslog_filter_from_text(input, &filt) == NSLOG_NO_ERROR,
		    "Unable to parse all level test");
	fail_unless(filt != NULL,
		    "Strange, despite parsing okay, filt was NULL");
	char *ct = nslog_filter_sprintf(filt);
	nslog_filter_unref(filt);
	fail_unless(strcmp(ct, input) == 0,
		    "Printed parsed all-level not right");
}
END_TEST

START_TEST (test_nslog_parse_and_sprintf_all_kinds)
{
	nslog_filter_t *filt = NULL;
	const char *input =
		"!((((lvl:WARNING || cat:test) && file:foo) ^ dir:bar) || func:baz)";
	fail_unless(nslog_filter_from_text(input, &filt) == NSLOG_NO_ERROR,
		    "Unable to parse all kind test");
	fail_unless(filt != NULL,
		    "Strange, despite parsing okay, filt was NULL");
	char *ct = nslog_filter_sprintf(filt);
	nslog_filter_unref(filt);
	fail_unless(strcmp(ct, input) == 0,
		    "Printed parsed all-kind not right");
}
END_TEST

/**** The next set of tests need a fixture set for a variety of filters ****/

static const char *anchor_context_3 = "3";

static void
with_trivial_filter_context_setup(void)
{
	captured_render_context = NULL;
	memset(&captured_context, 0, sizeof(captured_context));
	memset(captured_rendered_message, 0, sizeof(captured_rendered_message));
	captured_rendered_message_length = 0;
	captured_message_count = 0;
	fail_unless(nslog_set_render_callback(
			    nslog__test__render_function,
			    (void *)anchor_context_3) == NSLOG_NO_ERROR,
		    "Unable to set up render callback");
}

static void
with_trivial_filter_context_teardown(void)
{
        /* Nothing to do to tear down */
	fail_unless(nslog_filter_set_active(NULL, NULL) == NSLOG_NO_ERROR,
		    "Unable to clear active filter");
}

START_TEST (test_nslog_filter_filename)
{
	nslog_filter_t *filter;
	fail_unless(nslog_filter_filename_new("basictests.c", &filter) == NSLOG_NO_ERROR,
		    "Unable to create filename filter");
	fail_unless(nslog_filter_set_active(filter, NULL) == NSLOG_NO_ERROR,
		    "Unable to set active filter to file:basictests.c");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	NSLOG(test, WARN, "Hello");
	fail_unless(captured_message_count == 1,
		    "Captured message count was wrong");
	fail_unless(captured_render_context == anchor_context_3,
		    "Captured context wasn't passed through");
	fail_unless(captured_rendered_message_length == 5,
		    "Captured message wasn't correct length");
	fail_unless(strcmp(captured_rendered_message, "Hello") == 0,
		    "Mesage wasn't as expected");
}
END_TEST

START_TEST (test_nslog_filter_full_filename)
{
	nslog_filter_t *filter;
	fail_unless(nslog_filter_filename_new("test/basictests.c", &filter) == NSLOG_NO_ERROR,
		    "Unable to create filename filter");
	fail_unless(nslog_filter_set_active(filter, NULL) == NSLOG_NO_ERROR,
		    "Unable to set active filter to file:test/basictests.c");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	NSLOG(test, WARN, "Hello");
	fail_unless(captured_message_count == 1,
		    "Captured message count was wrong");
	fail_unless(captured_render_context == anchor_context_3,
		    "Captured context wasn't passed through");
	fail_unless(captured_rendered_message_length == 5,
		    "Captured message wasn't correct length");
	fail_unless(strcmp(captured_rendered_message, "Hello") == 0,
		    "Mesage wasn't as expected");
}
END_TEST

START_TEST (test_nslog_filter_out_filename)
{
	nslog_filter_t *filter;
	fail_unless(nslog_filter_filename_new("testmain.c", &filter) == NSLOG_NO_ERROR,
		    "Unable to create filename filter");
	fail_unless(nslog_filter_set_active(filter, NULL) == NSLOG_NO_ERROR,
		    "Unable to set active filter to file:testmain.c");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	NSLOG(test, WARN, "Hello");
	fail_unless(captured_message_count == 0,
		    "Captured message count was wrong");
}
END_TEST

START_TEST (test_nslog_filter_level)
{
	nslog_filter_t *filter;
	fail_unless(nslog_filter_level_new(NSLOG_LEVEL_WARN, &filter) == NSLOG_NO_ERROR,
		    "Unable to create level filter");
	fail_unless(nslog_filter_set_active(filter, NULL) == NSLOG_NO_ERROR,
		    "Unable to set active filter to lvl:WARN");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	NSLOG(test, WARN, "Hello");
	fail_unless(captured_message_count == 1,
		    "Captured message count was wrong");
	fail_unless(captured_render_context == anchor_context_3,
		    "Captured context wasn't passed through");
	fail_unless(captured_rendered_message_length == 5,
		    "Captured message wasn't correct length");
	fail_unless(strcmp(captured_rendered_message, "Hello") == 0,
		    "Mesage wasn't as expected");
}
END_TEST

START_TEST (test_nslog_filter_out_level)
{
	nslog_filter_t *filter;
	fail_unless(nslog_filter_level_new(NSLOG_LEVEL_ERR, &filter) == NSLOG_NO_ERROR,
		    "Unable to create filename filter");
	fail_unless(nslog_filter_set_active(filter, NULL) == NSLOG_NO_ERROR,
		    "Unable to set active filter to lvl:ERR");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	NSLOG(test, WARN, "Hello");
	fail_unless(captured_message_count == 0,
		    "Captured message count was wrong");
}
END_TEST

START_TEST (test_nslog_filter_dirname)
{
	nslog_filter_t *filter;
	fail_unless(nslog_filter_dirname_new("test", &filter) == NSLOG_NO_ERROR,
		    "Unable to create level filter");
	fail_unless(nslog_filter_set_active(filter, NULL) == NSLOG_NO_ERROR,
		    "Unable to set active filter to dir:test");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	NSLOG(test, WARN, "Hello");
	fail_unless(captured_message_count == 1,
		    "Captured message count was wrong");
	fail_unless(captured_render_context == anchor_context_3,
		    "Captured context wasn't passed through");
	fail_unless(captured_rendered_message_length == 5,
		    "Captured message wasn't correct length");
	fail_unless(strcmp(captured_rendered_message, "Hello") == 0,
		    "Mesage wasn't as expected");
}
END_TEST

START_TEST (test_nslog_filter_out_dirname)
{
	nslog_filter_t *filter;
	fail_unless(nslog_filter_dirname_new("src", &filter) == NSLOG_NO_ERROR,
		    "Unable to create filename filter");
	fail_unless(nslog_filter_set_active(filter, NULL) == NSLOG_NO_ERROR,
		    "Unable to set active filter to dir:src");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	NSLOG(test, WARN, "Hello");
	fail_unless(captured_message_count == 0,
		    "Captured message count was wrong");
}
END_TEST

START_TEST (test_nslog_filter_funcname)
{
	nslog_filter_t *filter;
	fail_unless(nslog_filter_funcname_new("test_nslog_filter_funcname", &filter) == NSLOG_NO_ERROR,
		    "Unable to create level filter");
	fail_unless(nslog_filter_set_active(filter, NULL) == NSLOG_NO_ERROR,
		    "Unable to set active filter to dir:test");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	NSLOG(test, WARN, "Hello");
	fail_unless(captured_message_count == 1,
		    "Captured message count was wrong");
	fail_unless(captured_render_context == anchor_context_3,
		    "Captured context wasn't passed through");
	fail_unless(captured_rendered_message_length == 5,
		    "Captured message wasn't correct length");
	fail_unless(strcmp(captured_rendered_message, "Hello") == 0,
		    "Mesage wasn't as expected");
}
END_TEST

START_TEST (test_nslog_filter_out_funcname)
{
	nslog_filter_t *filter;
	fail_unless(nslog_filter_funcname_new("test_nslog_filter_funcname", &filter) == NSLOG_NO_ERROR,
		    "Unable to create filename filter");
	fail_unless(nslog_filter_set_active(filter, NULL) == NSLOG_NO_ERROR,
		    "Unable to set active filter to dir:src");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	NSLOG(test, WARN, "Hello");
	fail_unless(captured_message_count == 0,
		    "Captured message count was wrong");
}
END_TEST

START_TEST (test_nslog_complex_filter1)
{
	nslog_filter_t *filter;
	fail_unless(nslog_filter_from_text("(lvl:WARN || (lvl:DEBUG && cat:test/sub))", &filter) == NSLOG_NO_ERROR,
		    "Unable to create filename filter");
	fail_unless(nslog_filter_set_active(filter, NULL) == NSLOG_NO_ERROR,
		    "Unable to set active filter to dir:src");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	NSLOG(sub, WARN, "Hello");
	fail_unless(captured_message_count == 1,
		    "Captured message count was wrong (1)");
	NSLOG(test, DEBUG, "Hello");
	fail_unless(captured_message_count == 1,
		    "Captured message count was wrong (2)");
	NSLOG(sub, DEBUG, "Hello");
	fail_unless(captured_message_count == 2,
		    "Captured message count was wrong (3)");
}
END_TEST

START_TEST (test_nslog_complex_filter2)
{
	nslog_filter_t *filter;
	fail_unless(nslog_filter_from_text("!(lvl:WARN ^ cat:test/sub)", &filter) == NSLOG_NO_ERROR,
		    "Unable to create filename filter");
	fail_unless(nslog_filter_set_active(filter, NULL) == NSLOG_NO_ERROR,
		    "Unable to set active filter to dir:src");
	fail_unless(nslog_uncork() == NSLOG_NO_ERROR,
		    "Unable to uncork");
	NSLOG(sub, WARN, "Hello");
	fail_unless(captured_message_count == 1,
		    "Captured message count was wrong (1)");
	NSLOG(test, WARN, "Hello");
	fail_unless(captured_message_count == 1,
		    "Captured message count was wrong (2)");
	NSLOG(test, DEBUG, "Hello");
	fail_unless(captured_message_count == 2,
		    "Captured message count was wrong (3)");
}
END_TEST

/**** And the suites are set up here ****/

void
nslog_basic_suite(SRunner *sr)
{
        Suite *s = suite_create("libnslog: Basic tests");
        TCase *tc_basic = NULL;

	tc_basic = tcase_create("Simple log checks, no filters");

        tcase_add_checked_fixture(tc_basic, with_simple_context_setup,
                                  with_simple_context_teardown);
        tcase_add_test(tc_basic, test_nslog_trivial_corked_message);
        tcase_add_test(tc_basic, test_nslog_trivial_uncorked_message);
	tcase_add_test(tc_basic, test_nslog_subcategory_name);
	tcase_add_test(tc_basic, test_nslog_two_corked_messages);
	tcase_add_test(tc_basic, test_nslog_check_bad_level);
        suite_add_tcase(s, tc_basic);

        tc_basic = tcase_create("Simple filter checks");

        tcase_add_checked_fixture(tc_basic, with_simple_filter_context_setup,
                                  with_simple_filter_context_teardown);
        tcase_add_test(tc_basic, test_nslog_simple_filter_corked_message);
        tcase_add_test(tc_basic, test_nslog_simple_filter_uncorked_message);
        tcase_add_test(tc_basic, test_nslog_simple_filter_subcategory_message);
        tcase_add_test(tc_basic, test_nslog_simple_filter_out_subcategory_message);
        tcase_add_test(tc_basic, test_nslog_basic_filter_sprintf);
        tcase_add_test(tc_basic, test_nslog_parse_and_sprintf);
        tcase_add_test(tc_basic, test_nslog_parse_and_sprintf_all_levels);
	tcase_add_test(tc_basic, test_nslog_parse_and_sprintf_all_kinds);
        suite_add_tcase(s, tc_basic);

	tc_basic = tcase_create("Trivial, varied, filter checks");
	tcase_add_checked_fixture(tc_basic, with_trivial_filter_context_setup,
				  with_trivial_filter_context_teardown);
	tcase_add_test(tc_basic, test_nslog_filter_filename);
	tcase_add_test(tc_basic, test_nslog_filter_full_filename);
	tcase_add_test(tc_basic, test_nslog_filter_out_filename);
	tcase_add_test(tc_basic, test_nslog_filter_level);
	tcase_add_test(tc_basic, test_nslog_filter_out_level);
	tcase_add_test(tc_basic, test_nslog_filter_dirname);
	tcase_add_test(tc_basic, test_nslog_filter_out_dirname);
	tcase_add_test(tc_basic, test_nslog_filter_funcname);
	tcase_add_test(tc_basic, test_nslog_filter_out_funcname);
	tcase_add_test(tc_basic, test_nslog_complex_filter1);
	tcase_add_test(tc_basic, test_nslog_complex_filter2);
	suite_add_tcase(s, tc_basic);

        srunner_add_suite(sr, s);
}