diff --git a/tests/stdio/fseek.c b/tests/stdio/fseek.c index c370cc4e6dc43812850568a4445fd47e79cd2a5f..9b8bc1b04624387422c2163e9ebecc5bb13f8198 100644 --- a/tests/stdio/fseek.c +++ b/tests/stdio/fseek.c @@ -16,5 +16,5 @@ int main(void) { off_t pos = ftello(f); ERROR_IF(ftello, pos, == -1); - printf("ftell: %ld\n", pos); + printf("ftello: %ld\n", pos); } diff --git a/tests/stdio/rename.c b/tests/stdio/rename.c index 62592a5e284abf8908be052d55e081ecde9dfa4b..840916c9011b5df7e82652a7bf6481baaddeadb9 100644 --- a/tests/stdio/rename.c +++ b/tests/stdio/rename.c @@ -49,9 +49,8 @@ int main(void) { UNEXP_IF(remove, rm_status, != 0); // Compare file contents - if (strcmp(str, buf) == 0) { - exit(EXIT_SUCCESS); - } else { + if (strcmp(str, buf) != 0) { + puts("Comparison failed!"); exit(EXIT_FAILURE); } } diff --git a/tests/stdlib/realpath.c b/tests/stdlib/realpath.c index a1583f864df1d78853763994794c8a570ad860e2..d6406dd52e05fd9adc00406c0cd72a1a79159abe 100644 --- a/tests/stdlib/realpath.c +++ b/tests/stdlib/realpath.c @@ -7,25 +7,14 @@ #include "test_helpers.h" int main(void) { - char* path = realpath("stdlib/realpath.c", NULL); - if (!path) { - perror("realpath"); - exit(EXIT_FAILURE); - } - puts(path); + char *path_res = realpath("stdlib/realpath.c", NULL); + ERROR_IF(realpath, path_res, == NULL); + puts(path_res); + free(path_res); - free(path); - - path = malloc(PATH_MAX); - memset(path, 0, PATH_MAX); - - realpath("stdlib/realpath.c", path); - if (!path) { - perror("realpath"); - free(path); - exit(EXIT_FAILURE); - } - puts(path); - - free(path); + char path_arg[PATH_MAX] = { 0 }; + char *res = realpath("stdlib/realpath.c", path_arg); + ERROR_IF(realpath, res, == NULL); + puts(path_arg); + free(path_arg); } diff --git a/tests/time/gmtime.c b/tests/time/gmtime.c index a77d19fb9a172040c82ae15d2d14b3505ca691b7..f5a16f2af3deb0c01146a5c140a68391322a8d9f 100644 --- a/tests/time/gmtime.c +++ b/tests/time/gmtime.c @@ -18,12 +18,4 @@ int main(void) { info->tm_gmtoff != expected.tm_gmtoff || strcmp(info->tm_zone, expected.tm_zone) != 0) { exit(EXIT_FAILURE); } - - if (info->tm_sec != expected.tm_sec || info->tm_min != expected.tm_min || - info->tm_hour != expected.tm_hour || info->tm_mday != expected.tm_mday || - info->tm_year != expected.tm_year || info->tm_wday != expected.tm_wday || - info->tm_yday != expected.tm_yday || info->tm_isdst != expected.tm_isdst || - info->tm_gmtoff != expected.tm_gmtoff || strcmp(info->tm_zone, expected.tm_zone) != 0) { - exit(EXIT_FAILURE); - } } diff --git a/tests/time/mktime.c b/tests/time/mktime.c index 79e5e3cf6787be32b6bfc0f07e8e101462540cf1..bc8c9c755d435d525797e2aa282b2bbf4d34b73d 100644 --- a/tests/time/mktime.c +++ b/tests/time/mktime.c @@ -6,11 +6,15 @@ #include "test_helpers.h" int check(time_t input) { - struct tm* t = localtime(&input); + struct tm *t = localtime(&input); + ERROR_IF(localtime, t, == NULL); - printf("%ld = %ld\n", input, mktime(t)); + time_t output = mktime(t); + ERROR_IF(mktime, output, == (time_t)-1); - if (input != mktime(t)) { + printf("%ld = %ld\n", input, output); + + if (input != output) { printf( "Year %d, Day of year: %d, Month %d, Day of month: %d, Day of week: %d, %d:%d:%d\n", t->tm_year, t->tm_yday, t->tm_mon, t->tm_mday, t->tm_wday, t->tm_hour, t->tm_min, t->tm_sec @@ -41,8 +45,13 @@ int main(void) { for (int i = 0; i < 10; i += 1) { time_t input = (time_t) rand(); - struct tm* time = localtime(&input); + + struct tm *time = localtime(&input); + ERROR_IF(localtime, time, == NULL); + time_t output = mktime(time); + ERROR_IF(mktime, output, == (time_t)-1); + if (input != output) { // asctime has newline printf("Comparison %ld == %ld failed. Time: %s", input, output, asctime(time)); diff --git a/tests/unistd/pipe.c b/tests/unistd/pipe.c index 88403c40adc5f922911d3ddf5b586bc41eefee55..85e6db5abfe4858031557d55437fd7d2f9f0e750 100644 --- a/tests/unistd/pipe.c +++ b/tests/unistd/pipe.c @@ -7,57 +7,56 @@ #include "test_helpers.h" int main(void) { - int pid, pip[2]; + int pip[2]; char instring[20]; - char * outstring = "Hello World!"; + char *outstring = "Hello World!"; - if (pipe(pip) < 0) { - perror("pipe"); - exit(EXIT_FAILURE); - } + int pipe_status = pipe(pip); + ERROR_IF(pipe, pipe_status, == -1); + UNEXP_IF(pipe, pipe_status, != 0); - pid = fork(); - if (pid == 0) /* child : sends message to parent*/ - { - /* close read end */ - close(pip[0]); + int pid = fork(); + ERROR_IF(fork, pid, == -1); - /* send 7 characters in the string, including end-of-string */ - int bytes = write(pip[1], outstring, strlen(outstring)); + if (pid == 0) { + // child: sends message to parent + // close read end + int cr = close(pip[0]); + ERROR_IF(close, cr, == -1); + UNEXP_IF(close, cr, != 0); - /* close write end */ - close(pip[1]); + // send 7 characters in the string, including end-of-string + int bytes = write(pip[1], outstring, strlen(outstring)); + ERROR_IF(write, bytes, == -1); - /* check result */ - if (bytes < 0) { - perror("pipe write"); - exit(EXIT_FAILURE); - } else if (bytes != strlen(outstring)) { + // check result + if (bytes != strlen(outstring)) { fprintf(stderr, "pipe write: %d != %ld\n", bytes, strlen(outstring)); exit(EXIT_FAILURE); } + // close write end + int cw = close(pip[1]); + ERROR_IF(close, cw, == -1); + UNEXP_IF(close, cw, != 0); + exit(EXIT_SUCCESS); - } - else /* parent : receives message from child */ - { - /* close write end */ - close(pip[1]); + } else { + // parent: receives message from child + // close write end + int cw = close(pip[1]); + ERROR_IF(close, cw, == -1); + UNEXP_IF(close, cw, != 0); - /* clear memory */ + // clear memory memset(instring, 0, sizeof(instring)); - /* read from the pipe */ + // read from the pipe int bytes = read(pip[0], instring, sizeof(instring) - 1); + ERROR_IF(read, bytes, == -1); - /* close read end */ - close(pip[0]); - - /* check result */ - if (bytes < 0) { - perror("pipe read"); - exit(EXIT_FAILURE); - } else if (bytes != strlen(outstring)) { + // check result + if (bytes != strlen(outstring)) { fprintf(stderr, "pipe read: %d != %ld\n", bytes, strlen(outstring)); exit(EXIT_FAILURE); } else if (memcmp(instring, outstring, strlen(outstring)) != 0) { @@ -67,6 +66,11 @@ int main(void) { printf("%s\n", instring); } + // close read end + int cr = close(pip[0]); + ERROR_IF(close, cr, == -1); + UNEXP_IF(close, cr, != 0); + exit(EXIT_SUCCESS); } } diff --git a/tests/wchar/putwchar.c b/tests/wchar/putwchar.c index 7b11264f7dd31799cebd2a8767d04b45e1fe98ac..fc25911468f243dcb7023fb16c11d43fb8416de0 100644 --- a/tests/wchar/putwchar.c +++ b/tests/wchar/putwchar.c @@ -8,13 +8,8 @@ int main(void) { wchar_t *wcs = L"zß水ðŸŒ"; - int i; - for (i = 0; wcs[i] != L'\0'; i++) - { - if (0xFFFFFFFFu == putwchar(wcs[i])) - { - printf("Unable to putwchar() the wide character.\n"); - exit(EXIT_FAILURE); - } + for (int i = 0; wcs[i] != L'\0'; i++) { + wint_t status = putwchar(wcs[i]); + ERROR_IF(putwchar, status, == WEOF); } }