logstr.c
19 KB
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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
/* This file is part of GNU Mailutils test suite
Copyright (C) 2017 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GNU Mailutils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#include <mailutils/mailutils.h>
#include <mailutils/locus.h>
/* Check normal operation.
Expected output: hello world
*/
static void
simple_print (mu_stream_t str)
{
mu_stream_printf (str, "hello world\n");
}
/* Check severity control.
Expected output:
info: one
emerg: two
mode was: 0x0001
*/
static void
check_severity (mu_stream_t str)
{
unsigned severity = MU_DIAG_INFO;
int mode = MU_LOGMODE_SEVERITY, old_mode;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "one\n");
severity = MU_DIAG_EMERG;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "two\n");
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_MODE, &old_mode);
mode = 0;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
mu_stream_printf (str, "mode was: 0x%04X\n", old_mode);
}
/* Check severity suppression mechanism.
Expected output:
info: this message is seen
emerg: and this one as well
*/
static void
check_suppress (mu_stream_t str)
{
unsigned severity;
int mode = MU_LOGMODE_SEVERITY;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
severity = MU_DIAG_INFO;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SUPPRESS_SEVERITY,
&severity);
severity = MU_DIAG_DEBUG;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "this message is not seen\n");
severity = MU_DIAG_INFO;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "this message is seen\n");
severity = MU_DIAG_EMERG;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "and this one as well\n");
}
/* Check suppression by severity name.
Expected output:
info: this message is seen
emerg: and this one as well
*/
static void
check_suppress_name (mu_stream_t str)
{
int mode = MU_LOGMODE_SEVERITY, severity;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SUPPRESS_SEVERITY_NAME,
"info");
severity = MU_DIAG_DEBUG;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "this message is not seen\n");
severity = MU_DIAG_INFO;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "this message is seen\n");
severity = MU_DIAG_EMERG;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "and this one as well\n");
}
/* Check setting locus point
Expected output:
input:1: filename and line number
input:1.3: filename, line and column numbers
*/
static void
set_locus_point (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus pt, pt2;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
pt.mu_file = "input";
pt.mu_line = 1;
pt.mu_col = 0;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, &pt);
mu_stream_printf (str, "filename and line number\n");
pt.mu_file = "input";
pt.mu_line = 1;
pt.mu_col = 3;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, &pt);
mu_stream_printf (str, "filename, line and column numbers\n");
MU_ASSERT (mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_LOCUS, &pt2));
if (strcmp (pt.mu_file, pt2.mu_file))
mu_error ("%s:%d: mu_file differs\n", __FILE__, __LINE__);
if (pt.mu_line != pt2.mu_line)
mu_error ("%s:%d: mu_line differs\n", __FILE__, __LINE__);
if (pt.mu_col != pt2.mu_col)
mu_error ("%s:%d: mu_col differs\n", __FILE__, __LINE__);
/* FIXME: remove this after switching to mu_locus_point */
free (pt2.mu_file);
}
static void
comp_range (mu_stream_t str, struct mu_locus_range *lr1,
char const *file, int line)
{
struct mu_locus_range lr2;
MU_ASSERT (mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE, &lr2));
if (strcmp (lr1->beg.mu_file, lr2.beg.mu_file))
mu_error ("%s:%d: beg.mu_file differs", file, line);
if (lr1->beg.mu_line != lr2.beg.mu_line)
mu_error ("%s:%d: beg.mu_line differs", file, line);
if (lr1->beg.mu_col != lr2.beg.mu_col)
mu_error ("%s:%d: beg.mu_col differs", file, line);
mu_ident_deref (lr2.beg.mu_file);
if (strcmp (lr1->end.mu_file, lr2.end.mu_file))
mu_error ("%s:%d: end.mu_file differs", __FILE__, __LINE__);
if (lr1->end.mu_line != lr2.end.mu_line)
mu_error ("%s:%d: end.mu_line differs", __FILE__, __LINE__);
if (lr1->end.mu_col != lr2.end.mu_col)
mu_error ("%s:%d: end.mu_col differs", __FILE__, __LINE__);
mu_ident_deref (lr2.end.mu_file);
}
/* Check MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE.
Passed: file, line.
Expected output:
input:1: file, line
*/
static void
lr_file_line (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 0;
lr.end.mu_file = "input";
lr.end.mu_line = 1;
lr.end.mu_col = 0;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "file, line\n");
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE.
Passed: file, line, col.
Expected output:
input:1.1-10: file, line, col
*/
static void
lr_file_line_col (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "input";
lr.end.mu_line = 1;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "file, line, col\n");
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE.
Passed: file, line-range
Expected output:
input:1-2: file, line-range
*/
static void
lr_file_line2 (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 0;
lr.end.mu_file = "input";
lr.end.mu_line = 2;
lr.end.mu_col = 0;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "file, line-range\n");
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE.
Passed: file, line-range, column
Expected output:
input:1.1-2.10: file, line-range, col
*/
static void
lr_file_line2_col (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "input";
lr.end.mu_line = 2;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "file, line-range, col\n");
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE.
Passed: file-range, line-range, column-range
Expected output:
input:1.1-next:2.10: file-range, line-range, col-range
*/
static void
lr_file2_line_col (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "next";
lr.end.mu_line = 2;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "file-range, line-range, col-range\n");
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check MU_IOCTL_LOGSTREAM_SET_LOCUS_LINE.
Expected output:
input:1.1-next:2.10: initial
input:8.1-next:2.10: locus line changed
*/
static void
set_locus_line (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
unsigned line;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "next";
lr.end.mu_line = 2;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "initial\n");
line = 8;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_LINE, &line);
mu_stream_printf (str, "locus line changed\n");
lr.beg.mu_line = line;
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check MU_IOCTL_LOGSTREAM_ADVANCE_LOCUS_LINE.
Expected output:
input:1.1-next:5.10: initial
input:3.1-next:5.10: locus line advanced
*/
static void
advance_locus_line (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
unsigned line;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "next";
lr.end.mu_line = 5;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "initial\n");
line = 2;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_ADVANCE_LOCUS_LINE, &line);
mu_stream_printf (str, "locus line advanced\n");
lr.beg.mu_line += line;
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check MU_IOCTL_LOGSTREAM_SET_LOCUS_COL.
Expected output:
input:1.1-next:2.10: initial
input:1.8-next:2.10: locus column changed
*/
static void
set_locus_col (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
unsigned col;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "next";
lr.end.mu_line = 2;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "initial\n");
col = 8;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_COL, &col);
mu_stream_printf (str, "locus column changed\n");
lr.beg.mu_col = col;
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check MU_IOCTL_LOGSTREAM_ADVANCE_LOCUS_COL.
Expected output:
input:1.1-next:5.10: initial
input:1.5-next:5.10: locus line advanced
*/
static void
advance_locus_col (mu_stream_t str)
{
int mode = MU_LOGMODE_LOCUS;
struct mu_locus_range lr;
unsigned col;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "next";
lr.end.mu_line = 5;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "initial\n");
col = 4;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_ADVANCE_LOCUS_COL, &col);
mu_stream_printf (str, "locus line advanced\n");
lr.beg.mu_col += col;
comp_range (str, &lr, __FILE__, __LINE__);
}
/* Check severity mask.
Expected output:
one
two
emerg: two
*/
static void
check_severity_mask (mu_stream_t str)
{
unsigned severity;
int mode = MU_LOGMODE_SEVERITY, mask;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
mask = MU_DEBUG_LEVEL_UPTO (MU_DIAG_NOTICE);
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY_MASK, &mask);
severity = MU_DIAG_INFO;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "one\n");
severity = MU_DIAG_NOTICE;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "two\n");
severity = MU_DIAG_EMERG;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY, &severity);
mu_stream_printf (str, "three\n");
}
/* Check ESC-s & ESC-O format specifiers.
Expected output:
info: severity
*/
static void
fmt_severity (mu_stream_t str)
{
mu_stream_printf (str, "\033s<%d>\033O<%d>severity\n",
MU_DIAG_INFO, MU_LOGMODE_SEVERITY);
}
/* Check ESC-f and ESC-l format specifiers.
Expected output:
a:10: one
*/
static void
fmt_locus1 (mu_stream_t str)
{
char *file = "a";
mu_stream_printf (str, "\033f<%d>%s\033l<%d>one\n",
strlen (file), file, 10);
}
/* Check ESC-f, ESC-l, and ESC-c format specifiers.
Expected output:
a:10.5: one
*/
static void
fmt_locus2 (mu_stream_t str)
{
char *file = "a";
mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>one\n",
strlen (file), file, 10, 5);
}
/* Check setting range with ESC-f, ESC-l, and ESC-c format specifiers.
Expected output:
a:10.5-b:14.8: one
*/
static void
fmt_locus3 (mu_stream_t str)
{
char *file[] = { "a", "b" };
mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>"
"\033f<%d>%s\033l<%d>\033c<%d>one\n",
strlen (file[0]), file[0], 10, 5,
strlen (file[1]), file[1], 14, 8);
}
/* Check that ESC-f, ESC-l, and ESC-c format specifiers don't clobber
default stream settings.
Expected output:
a:10.5-b:14.8: one
default
*/
static void
fmt_locus4 (mu_stream_t str)
{
char *file[] = { "a", "b" };
struct mu_locus_range lr;
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "next";
lr.end.mu_line = 5;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>"
"\033f<%d>%s\033l<%d>\033c<%d>one\n",
strlen (file[0]), file[0], 10, 5,
strlen (file[1]), file[1], 14, 8);
mu_stream_printf (str, "default\n");
}
/* Check that ESC-f, ESC-l, and ESC-c format specifiers don't clobber
default stream settings and locus.
Expected output:
a:10.5-b:14.8: one
input:1.1-next:5.10: default
*/
static void
fmt_locus5 (mu_stream_t str)
{
char *file[] = { "a", "b" };
struct mu_locus_range lr;
int mode;
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "next";
lr.end.mu_line = 5;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mode = MU_LOGMODE_LOCUS;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
mu_stream_printf (str, "\033f<%d>%s\033l<%d>\033c<%d>"
"\033f<%d>%s\033l<%d>\033c<%d>one\n",
strlen (file[0]), file[0], 10, 5,
strlen (file[1]), file[1], 14, 8);
mu_stream_printf (str, "default\n");
}
/* Check the ESC-S specifier (store locus).
Expected output:
a:10.5-b:14.8: one
a:10.5-b:14.8: default
*/
static void
fmt_locus6 (mu_stream_t str)
{
char *file[] = { "a", "b" };
struct mu_locus_range lr;
int mode;
lr.beg.mu_file = "input";
lr.beg.mu_line = 1;
lr.beg.mu_col = 1;
lr.end.mu_file = "next";
lr.end.mu_line = 5;
lr.end.mu_col = 10;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &lr);
mode = MU_LOGMODE_LOCUS;
mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode);
mu_stream_printf (str, "\033S\033f<%d>%s\033l<%d>\033c<%d>"
"\033f<%d>%s\033l<%d>\033c<%d>one\n",
strlen (file[0]), file[0], 10, 5,
strlen (file[1]), file[1], 14, 8);
mu_stream_printf (str, "default\n");
}
struct testcase
{
char const *id;
void (*handler) (mu_stream_t);
};
struct testcase testcases[] = {
{ "simple print", simple_print },
{ "severity", check_severity },
{ "suppress severity", check_suppress },
{ "suppress severity name", check_suppress_name },
{ "severity mask", check_severity_mask },
{ "set/get locus point", set_locus_point },
{ "locus: file, line", lr_file_line },
{ "locus: file, line, col", lr_file_line_col },
{ "locus: file, line-range", lr_file_line2 },
{ "locus: file, line-range, col", lr_file_line2_col },
{ "locus: file-range, line-range, col-range", lr_file2_line_col },
{ "set locus line", set_locus_line },
{ "advance locus line", advance_locus_line },
{ "set locus column", set_locus_col },
{ "advance locus column", advance_locus_col },
{ "fmt: severity", fmt_severity },
{ "fmt: locus (file, line)", fmt_locus1 },
{ "fmt: locus (file, line, column)", fmt_locus2 },
{ "fmt: locus (range)", fmt_locus3 },
{ "fmt: locus; restore defaults", fmt_locus4 },
{ "fmt: locus; restore defaults, display locus", fmt_locus5 },
{ "fmt: set locus", fmt_locus6 },
{ NULL }
};
static mu_stream_t
create_log (void)
{
mu_stream_t str, transport;
int yes = 1;
MU_ASSERT (mu_stdio_stream_create (&transport, MU_STDOUT_FD, 0));
mu_stream_ioctl (transport, MU_IOCTL_FD, MU_IOCTL_FD_SET_BORROW, &yes);
MU_ASSERT (mu_log_stream_create (&str, transport));
mu_stream_unref (transport);
return str;
}
static void
log_reset (mu_stream_t str)
{
int mode = 0;
MU_ASSERT (mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_MODE, &mode));
MU_ASSERT (mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, NULL));
mode = 0;
MU_ASSERT (mu_stream_ioctl (str, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_SEVERITY_MASK,
&mode));
}
int
main (int argc, char **argv)
{
mu_stream_t log;
struct testcase *tp;
int i;
mu_set_program_name (argv[0]);
mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
log = create_log ();
for (i = 0, tp = testcases; tp->id; tp++, i++)
{
mu_stream_printf (log, "%02d. %s\n", i, tp->id);
tp->handler (log);
log_reset (log);
}
return 0;
}