nextcloud-desktop/tests/std_tests/check_std_c_alloc.c
Andreas Schneider 1b29a420bc Initial commit
2008-02-27 18:56:47 +01:00

74 lines
1.3 KiB
C

#include "support.h"
#include <string.h>
#include "std/c_alloc.h"
struct test_s {
int answer;
};
START_TEST (check_c_malloc)
{
struct test_s *p = NULL;
p = c_malloc(sizeof(struct test_s));
fail_unless(p != NULL, NULL);
fail_unless(p->answer == 0, NULL);
p->answer = 42;
fail_unless(p->answer == 42, NULL);
free(p);
}
END_TEST
START_TEST (check_c_malloc_zero)
{
void *p;
p = c_malloc((size_t) 0);
fail_unless(p == NULL, NULL);
}
END_TEST
START_TEST (check_c_strdup)
{
char *str = "test";
char *dup;
dup = c_strdup(str);
fail_unless(strcmp(dup, str) == 0, NULL);
free(dup);
}
END_TEST
static Suite *make_c_malloc_suite(void) {
Suite *s = suite_create("std:path:c_malloc");
create_case(s, "check_c_malloc", check_c_malloc);
create_case(s, "check_c_malloc_zero", check_c_malloc_zero);
return s;
}
static Suite *make_c_strdup_suite(void) {
Suite *s = suite_create("std:path:c_malloc");
create_case(s, "check_c_strdup", check_c_strdup);
return s;
}
int main(void) {
int nf;
Suite *s = make_c_malloc_suite();
Suite *s2 = make_c_strdup_suite();
SRunner *sr;
sr = srunner_create(s);
srunner_add_suite (sr, s2);
srunner_run_all(sr, CK_VERBOSE);
nf = srunner_ntests_failed(sr);
srunner_free(sr);
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}