nextcloud-desktop/tests/std_tests/check_std_c_alloc.c

75 lines
1.3 KiB
C
Raw Normal View History

2008-02-27 20:56:47 +03:00
#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)
{
2008-03-04 11:01:58 +03:00
char *str = (char *) "test";
2008-02-27 20:56:47 +03:00
char *dup;
dup = c_strdup(str);
fail_unless(strcmp(dup, str) == 0, NULL);
free(dup);
}
END_TEST
static Suite *make_c_malloc_suite(void) {
2008-03-04 11:01:58 +03:00
Suite *s = suite_create("std:alloc:malloc");
2008-02-27 20:56:47 +03:00
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) {
2008-03-04 11:01:58 +03:00
Suite *s = suite_create("std:alloc:strdup");
2008-02-27 20:56:47 +03:00
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;
}