int main (void) { addseverity (5, "NOTE2"); fmtmsg (MM_PRINT, "only1field", MM_INFO, "text2", "action2", "tag2"); fmtmsg (MM_PRINT, "UX:cat", 5, "invalid syntax", "refer to manual", "UX:cat:001"); fmtmsg (MM_PRINT, "label:foo", 6, "text", "action", "tag"); return 0; }
static int do_test (void) { /* Ugly, but fmtmsg would otherwise print to stderr which we do not want. */ fclose (stderr); stderr = stdout; int e1; e1 = fmtmsg (MM_PRINT, "label:part", MM_WARNING, "text", "action", "tag"); int e2; e2 = fmtmsg (MM_PRINT, "label2:part2", 11, "text2", "action2", "tag2"); addseverity (10, "additional severity"); int e3; e3 = fmtmsg (MM_PRINT, "label3:part3", 10, "text3", "action3", "tag3"); return e1 != 0 || e2 != 0 || e3 != 0; }
/*--------------------------------------------------------------*/ int main(int argc, char *argv[]) { int fd, ret_val; FILE *fp; setup(); /* temp file is now open */ /*--------------------------------------------------------------*/ blenter(); /* Check that system SEV_LEVEL output is correct */ close(2); /* redirect stderr to file */ fd = creat("fmtfile", 0644); ret_val = fmtmsg(MM_PRINT | MM_SOFT, "LTP:fmtmsg", MM_INFO, "LTP fmtmsg() test1 message, NOT an error", "This is correct output, no action needed", "LTP:msg:001"); close(fd); if (ret_val != 0) { fprintf(temp, "fmtmsg returned %d, expected 0\n\n", ret_val); local_flag = FAILED; } fp = fopen("fmtfile", "r"); clearbuf(); fread(buf, sizeof(buf[0]), strlen(str1), fp); if (strcmp(str1, buf) != 0) { fprintf(temp, "Expected string: %s\n", str1); fprintf(temp, "does not match\n"); fprintf(temp, "received string: %s\n\n", buf); local_flag = FAILED; } /* Read past spaces in output */ fread(&ch, sizeof(ch), 1, fp); while (isspace(ch)) fread(&ch, sizeof(ch), 1, fp); ungetc(ch, fp); clearbuf(); fread(buf, sizeof(buf[0]), strlen(str2), fp); fclose(fp); if (strcmp(str2, buf) != 0) { fprintf(temp, "Expected string: %s\n", str2); fprintf(temp, "does not match\n"); fprintf(temp, "received string: %s\n\n", buf); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ blenter(); /* Check that a system defined SEV_LEVEL cannot get redefined */ ret_val = addseverity(3, "INVALID"); if (ret_val != MM_NOTOK) { fprintf(temp, "addseverity returned %d, expected MM_NOTOK\n", ret_val); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ blenter(); /* Check that we can define our own */ /* SEV_LEVEL and output is correct */ ret_val = addseverity(5, "LTP_TEST"); if (ret_val != MM_OK) { fprintf(temp, "addseverity returned %d, expected MM_OK\n", ret_val); local_flag = FAILED; } close(2); /* redirect stderr to file */ fd = creat("fmtfile", 0644); ret_val = fmtmsg(MM_PRINT | MM_HARD | MM_OPSYS, "LTP:fmtmsg", 5, "LTP fmtmsg() test2 message, NOT an error", "This is correct output, no action needed", "LTP:msg:002"); close(fd); if (ret_val != 0) { fprintf(temp, "fmtmsg returned %d, expected 0\n", ret_val); local_flag = FAILED; } fp = fopen("fmtfile", "r"); clearbuf(); fread(buf, sizeof(buf[0]), strlen(str3), fp); if (strcmp(str3, buf) != 0) { fprintf(temp, "Expected string: %s\n", str3); fprintf(temp, "does not match\n"); fprintf(temp, "received string: %s\n\n", buf); local_flag = FAILED; } /* Read past spaces in output */ fread(&ch, sizeof(ch), 1, fp); while (isspace(ch)) fread(&ch, sizeof(ch), 1, fp); ungetc(ch, fp); clearbuf(); fread(buf, sizeof(buf[0]), strlen(str4), fp); if (strcmp(str4, buf) != 0) { fprintf(temp, "Expected string: %s\n", str4); fprintf(temp, "does not match\n"); fprintf(temp, "received string: %s\n\n", buf); local_flag = FAILED; } fclose(fp); remove("fmtfile"); blexit(); /*--------------------------------------------------------------*/ blenter(); /* Test result of writing to /dev/console */ ret_val = fmtmsg(MM_CONSOLE | MM_HARD | MM_OPSYS, "LTP:fmtmsg", 5, "LTP fmtmsg() test3 message, NOT an error", "This is correct output, no action needed", "LTP:msg:003"); if (ret_val != MM_OK) { fprintf(temp, "fmtmsg returned %d, expected MM_OK\n", ret_val); fprintf(temp, "failed to write to console\n\n"); local_flag = FAILED; } blexit(); /*--------------------------------------------------------------*/ /* Clean up any files created by test before call to anyfail. */ anyfail(); /* THIS CALL DOES NOT RETURN - EXITS!! */ tst_exit(); }
int zmain (void) { int result = 0; mtrace (); char TEST[] = "ABCD"; if (addseverity (MM_TEST, TEST) != MM_OK) { puts ("addseverity failed"); result = 1; } strcpy (TEST, "TEST"); if (fmtmsg (MM_PRINT, "GLIBC:tst-fmtmsg", MM_HALT, "halt", "should print message for MM_HALT", "GLIBC:tst-fmtmsg:1") != MM_OK) result = 1; if (fmtmsg (MM_PRINT, "GLIBC:tst-fmtmsg", MM_ERROR, "halt", "should print message for MM_ERROR", "GLIBC:tst-fmtmsg:2") != MM_OK) result = 1; if (fmtmsg (MM_PRINT, "GLIBC:tst-fmtmsg", MM_WARNING, "halt", "should print message for MM_WARNING", "GLIBC:tst-fmtmsg:3") != MM_OK) result = 1; if (fmtmsg (MM_PRINT, "GLIBC:tst-fmtmsg", MM_INFO, "halt", "should print message for MM_INFO", "GLIBC:tst-fmtmsg:4") != MM_OK) result = 1; if (fmtmsg (MM_PRINT, "GLIBC:tst-fmtmsg", MM_NOSEV, "halt", "should print message for MM_NOSEV", "GLIBC:tst-fmtmsg:5") != MM_OK) result = 1; if (fmtmsg (MM_PRINT, "GLIBC:tst-fmtmsg", MM_TEST, "halt", "should print message for MM_TEST", "GLIBC:tst-fmtmsg:6") != MM_OK) result = 1; if (addseverity (MM_TEST, NULL) != MM_OK) { puts ("second addseverity failed"); result = 1; } if (addseverity (MM_TEST, NULL) != MM_NOTOK) { puts ("third addseverity unexpectedly succeeded"); result = 1; } char *p = strdup ("TEST2"); if (addseverity (MM_TEST, p) != MM_OK) { puts ("fourth addseverity failed"); result = 1; } if (addseverity (MM_TEST, "TEST3") != MM_OK) { puts ("fifth addseverity failed"); result = 1; } free (p); return result; }