tests: Portability fixes, replaced 0/1/-1 return codes with macros
This commit is contained in:
+7
-7
@@ -9,7 +9,7 @@ int main(void) {
|
||||
arr[50] = 1;
|
||||
if ((size_t)memchr((void *)arr, 1, 100) - (size_t)arr != 50) {
|
||||
puts("Incorrect memchr");
|
||||
exit(1);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
puts("Correct memchr");
|
||||
char arr2[51];
|
||||
@@ -17,26 +17,26 @@ int main(void) {
|
||||
memccpy((void *)arr2, (void *)arr, 1, 100);
|
||||
if (arr[50] != 1) {
|
||||
puts("Incorrect memccpy");
|
||||
exit(1);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
puts("Correct memccpy");
|
||||
int res;
|
||||
if ((res = memcmp("hello world", "hello world", 11))) {
|
||||
printf("Incorrect memcmp (1), expected 0 found %d\n", res);
|
||||
exit(1);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if ((res = memcmp("hello world", "hello worlt", 11)) >= 0) {
|
||||
printf("Incorrect memcmp (2), expected -, found %d\n", res);
|
||||
exit(1);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if ((res = memcmp("hello world", "hallo world", 5)) <= 0) {
|
||||
printf("Incorrect memcmp (3), expected +, found %d\n", res);
|
||||
exit(1);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if ((res = memcmp("hello world", "henlo world", 5)) >= 0) {
|
||||
printf("Incorrect memcmp (4), expected -, found %d\n", res);
|
||||
exit(1);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
puts("Correct memcmp");
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
char dest1[12] = "hello";
|
||||
@@ -8,5 +9,5 @@ int main(void) {
|
||||
char dest2[12] = "hello";
|
||||
printf("%s\n", strncat(dest2, " world foobar", 6)); // should be hello world
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
printf("%s\n", strchr("hello", 'e')); // should be ello
|
||||
printf("%s\n", strchr("world", 'l')); // should be ld
|
||||
printf("%i\n", strchr("world", 0) == NULL); // should be 1
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
char *world = "world";
|
||||
printf("%ld\n", strcspn("hello", world)); // should be 2
|
||||
printf("%ld\n", strcspn("banana", world)); // should be 6
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
printf("%d\n", strncmp("a", "aa", 2));
|
||||
@@ -9,5 +10,5 @@ int main(void) {
|
||||
printf("%d\n", strncmp("a", "c", 1));
|
||||
printf("%d\n", strncmp("a", "a", 2));
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
char* source = "The quick drawn fix jumps over the lazy bug";
|
||||
@@ -16,5 +17,5 @@ int main(void) {
|
||||
char* res3 = strpbrk(source, "404");
|
||||
printf("%s\n", (res3) ? res3 : "NULL");
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
char s0[] = "hello, world";
|
||||
@@ -7,15 +8,15 @@ int main(void) {
|
||||
if (ptr != &s0[10]) {
|
||||
printf("%p != %p\n", ptr, &s0[10]);
|
||||
printf("strrchr FAIL , exit with status code %d\n", 1);
|
||||
return 1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
char s1[] = "";
|
||||
ptr = strrchr(s1, 'a');
|
||||
if (ptr != NULL) {
|
||||
printf("%p != 0\n", ptr);
|
||||
printf("strrchr FAIL, exit with status code %d\n", 1);
|
||||
return 1;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("strrch PASS, exiting with status code %d\n", 0);
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
char *hello = "hello";
|
||||
@@ -9,5 +10,5 @@ int main(void) {
|
||||
printf("%lu\n", strspn(world, "wendy")); // should be 1
|
||||
printf("%lu\n", strspn(banana, "apple")); // should be 0
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
printf("%s\n", strstr("In relibc we trust", "rust"));
|
||||
@@ -8,5 +9,5 @@ int main(void) {
|
||||
printf("%s\n", strstr("IN RELIBC WE TRUST", "rust"));
|
||||
printf("%s\n", strcasestr("IN RELIBC WE TRUST", "rust"));
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
char source[] = "I'd just like to interject for a moment. What you're referring to as Linux, "
|
||||
@@ -13,5 +14,5 @@ int main(void) {
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
char source[] = "I'd just like to interject for a moment. What you're referring to as Linux, "
|
||||
@@ -14,5 +15,5 @@ int main(void) {
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user