Back to index

glibc  2.9
tst-fmtmsg.c
Go to the documentation of this file.
00001 #include <fmtmsg.h>
00002 #include <mcheck.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <string.h>
00006 
00007 
00008 #define MM_TEST 10
00009 
00010 int
00011 main (void)
00012 {
00013   int result = 0;
00014 
00015   mtrace ();
00016 
00017   char TEST[] = "ABCD";
00018   if (addseverity (MM_TEST, TEST) != MM_OK)
00019     {
00020       puts ("addseverity failed");
00021       result = 1;
00022     }
00023   strcpy (TEST, "TEST");
00024 
00025   if (fmtmsg (MM_PRINT, "GLIBC:tst-fmtmsg", MM_HALT, "halt",
00026              "should print message for MM_HALT", "GLIBC:tst-fmtmsg:1")
00027       != MM_OK)
00028     result = 1;
00029 
00030   if (fmtmsg (MM_PRINT, "GLIBC:tst-fmtmsg", MM_ERROR, "halt",
00031              "should print message for MM_ERROR", "GLIBC:tst-fmtmsg:2")
00032       != MM_OK)
00033     result = 1;
00034 
00035   if (fmtmsg (MM_PRINT, "GLIBC:tst-fmtmsg", MM_WARNING, "halt",
00036              "should print message for MM_WARNING", "GLIBC:tst-fmtmsg:3")
00037       != MM_OK)
00038     result = 1;
00039 
00040   if (fmtmsg (MM_PRINT, "GLIBC:tst-fmtmsg", MM_INFO, "halt",
00041              "should print message for MM_INFO", "GLIBC:tst-fmtmsg:4")
00042       != MM_OK)
00043     result = 1;
00044 
00045   if (fmtmsg (MM_PRINT, "GLIBC:tst-fmtmsg", MM_NOSEV, "halt",
00046              "should print message for MM_NOSEV", "GLIBC:tst-fmtmsg:5")
00047       != MM_OK)
00048     result = 1;
00049 
00050   if (fmtmsg (MM_PRINT, "GLIBC:tst-fmtmsg", MM_TEST, "halt",
00051              "should print message for MM_TEST", "GLIBC:tst-fmtmsg:6")
00052       != MM_OK)
00053     result = 1;
00054 
00055   if (addseverity (MM_TEST, NULL) != MM_OK)
00056     {
00057       puts ("second addseverity failed");
00058       result = 1;
00059     }
00060 
00061   if (addseverity (MM_TEST, NULL) != MM_NOTOK)
00062     {
00063       puts ("third addseverity unexpectedly succeeded");
00064       result = 1;
00065     }
00066 
00067   char *p = strdup ("TEST2");
00068   if (addseverity (MM_TEST, p) != MM_OK)
00069     {
00070       puts ("fourth addseverity failed");
00071       result = 1;
00072     }
00073   if (addseverity (MM_TEST, "TEST3") != MM_OK)
00074     {
00075       puts ("fifth addseverity failed");
00076       result = 1;
00077     }
00078 
00079   free (p);
00080 
00081   return result;
00082 }