1#include <fmtmsg.h>
2#include <mcheck.h>
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6
7
8#define MM_TEST 10
9
10static int
11do_test (void)
12{
13 int result = 0;
14
15 mtrace ();
16
17 char TEST[] = "ABCD";
18 if (addseverity (MM_TEST, string: TEST) != MM_OK)
19 {
20 puts (s: "addseverity failed");
21 result = 1;
22 }
23 strcpy (TEST, "TEST");
24
25 if (fmtmsg (MM_PRINT, label: "GLIBC:tst-fmtmsg", MM_HALT, text: "halt",
26 action: "should print message for MM_HALT", tag: "GLIBC:tst-fmtmsg:1")
27 != MM_OK)
28 result = 1;
29
30 if (fmtmsg (MM_PRINT, label: "GLIBC:tst-fmtmsg", MM_ERROR, text: "halt",
31 action: "should print message for MM_ERROR", tag: "GLIBC:tst-fmtmsg:2")
32 != MM_OK)
33 result = 1;
34
35 if (fmtmsg (MM_PRINT, label: "GLIBC:tst-fmtmsg", MM_WARNING, text: "halt",
36 action: "should print message for MM_WARNING", tag: "GLIBC:tst-fmtmsg:3")
37 != MM_OK)
38 result = 1;
39
40 if (fmtmsg (MM_PRINT, label: "GLIBC:tst-fmtmsg", MM_INFO, text: "halt",
41 action: "should print message for MM_INFO", tag: "GLIBC:tst-fmtmsg:4")
42 != MM_OK)
43 result = 1;
44
45 if (fmtmsg (MM_PRINT, label: "GLIBC:tst-fmtmsg", MM_NOSEV, text: "halt",
46 action: "should print message for MM_NOSEV", tag: "GLIBC:tst-fmtmsg:5")
47 != MM_OK)
48 result = 1;
49
50 if (fmtmsg (MM_PRINT, label: "GLIBC:tst-fmtmsg", MM_TEST, text: "halt",
51 action: "should print message for MM_TEST", tag: "GLIBC:tst-fmtmsg:6")
52 != MM_OK)
53 result = 1;
54
55 if (addseverity (MM_TEST, NULL) != MM_OK)
56 {
57 puts (s: "second addseverity failed");
58 result = 1;
59 }
60
61 if (addseverity (MM_TEST, NULL) != MM_NOTOK)
62 {
63 puts (s: "third addseverity unexpectedly succeeded");
64 result = 1;
65 }
66
67 char *p = strdup (s: "TEST2");
68 if (addseverity (MM_TEST, string: p) != MM_OK)
69 {
70 puts (s: "fourth addseverity failed");
71 result = 1;
72 }
73 if (addseverity (MM_TEST, string: "TEST3") != MM_OK)
74 {
75 puts (s: "fifth addseverity failed");
76 result = 1;
77 }
78
79 free (ptr: p);
80
81 return result;
82}
83
84#define TEST_FUNCTION do_test ()
85#include "../test-skeleton.c"
86

source code of glibc/stdlib/tst-fmtmsg.c