HelenOS sources
This source file includes following definitions.
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- dummy_exit_handler
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- test_compar
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
- PCUT_TEST
#include <pcut/pcut.h>
#include <stdlib.h>
PCUT_INIT;
PCUT_TEST_SUITE(stdlib);
PCUT_TEST(decls)
{
size_t sz = 0;
(void) sz;
char32_t wc = L'\0';
(void) wc;
if (0)
exit(EXIT_FAILURE);
if (0)
exit(EXIT_SUCCESS);
void *ptr = NULL;
(void) ptr;
}
#include <stdio.h>
PCUT_TEST(strtold)
{
long double ld;
const char *str = " \t4.2e1@";
char *endptr;
ld = strtold(str, &endptr);
printf("ld=%.10lf\n", (double)ld);
PCUT_ASSERT_TRUE(ld == 42.0);
}
PCUT_TEST(rand)
{
int i;
int r;
for (i = 0; i < 100; i++) {
r = rand();
PCUT_ASSERT_TRUE(r >= 0);
PCUT_ASSERT_TRUE(r <= RAND_MAX);
}
PCUT_ASSERT_TRUE(RAND_MAX >= 32767);
}
PCUT_TEST(srand)
{
int r1;
int r2;
srand(1);
r1 = rand();
srand(1);
r2 = rand();
PCUT_ASSERT_INT_EQUALS(r2, r1);
srand(42);
r1 = rand();
srand(42);
r2 = rand();
PCUT_ASSERT_INT_EQUALS(r2, r1);
}
PCUT_TEST(malloc)
{
void *p;
#if 0
p = aligned_alloc(4, 8);
PCUT_ASSERT_NOT_NULL(p);
free(p);
#endif
p = calloc(4, 4);
PCUT_ASSERT_NOT_NULL(p);
free(p);
p = malloc(4);
PCUT_ASSERT_NOT_NULL(p);
p = realloc(p, 2);
PCUT_ASSERT_NOT_NULL(p);
free(p);
}
PCUT_TEST(abort)
{
if (0)
abort();
}
static void dummy_exit_handler(void)
{
}
PCUT_TEST(atexit)
{
int rc;
rc = atexit(dummy_exit_handler);
PCUT_ASSERT_INT_EQUALS(0, rc);
}
PCUT_TEST(exit)
{
if (0)
exit(0);
}
PCUT_TEST(at_quick_exit)
{
int rc;
rc = at_quick_exit(dummy_exit_handler);
PCUT_ASSERT_INT_EQUALS(0, rc);
}
PCUT_TEST(quick_exit)
{
if (0)
quick_exit(0);
}
PCUT_TEST(getenv)
{
char *s;
s = getenv("FOO");
PCUT_ASSERT_NULL(s);
}
PCUT_TEST(system_null)
{
int rc;
rc = system(NULL);
PCUT_ASSERT_INT_EQUALS(0, rc);
}
PCUT_TEST(system_cmd)
{
int rc;
rc = system("/app/bdsh");
PCUT_ASSERT_INT_EQUALS(1, rc);
}
static int test_compar(const void *a, const void *b)
{
const int *ia, *ib;
ia = (const int *)a;
ib = (const int *)b;
return *ia - *ib;
}
PCUT_TEST(bsearch)
{
int numbers[] = { 1, 2, 6, 7, 7, 10, 100, 120 };
int k;
void *r;
k = 0;
r = bsearch(&k, numbers, sizeof(numbers) / sizeof(int), sizeof(int),
test_compar);
PCUT_ASSERT_NULL(r);
k = 1;
r = bsearch(&k, numbers, sizeof(numbers) / sizeof(int), sizeof(int),
test_compar);
PCUT_ASSERT_NOT_NULL(r);
PCUT_ASSERT_INT_EQUALS(1, *(int *)r);
k = 3;
r = bsearch(&k, numbers, sizeof(numbers) / sizeof(int), sizeof(int),
test_compar);
PCUT_ASSERT_NULL(r);
k = 6;
r = bsearch(&k, numbers, sizeof(numbers) / sizeof(int), sizeof(int),
test_compar);
PCUT_ASSERT_NOT_NULL(r);
PCUT_ASSERT_INT_EQUALS(6, *(int *)r);
k = 7;
r = bsearch(&k, numbers, sizeof(numbers) / sizeof(int), sizeof(int),
test_compar);
PCUT_ASSERT_NOT_NULL(r);
PCUT_ASSERT_INT_EQUALS(7, *(int *)r);
k = 200;
r = bsearch(&k, numbers, sizeof(numbers) / sizeof(int), sizeof(int),
test_compar);
PCUT_ASSERT_NULL(r);
}
PCUT_TEST(abs_pos)
{
int i;
i = abs(1);
PCUT_ASSERT_TRUE(i == 1);
}
PCUT_TEST(abs_neg)
{
int i;
i = abs(-1);
PCUT_ASSERT_TRUE(i == 1);
}
PCUT_TEST(labs_pos)
{
long li;
li = labs(1);
PCUT_ASSERT_TRUE(li == 1);
}
PCUT_TEST(labs_neg)
{
long li;
li = labs(-1);
PCUT_ASSERT_TRUE(li == 1);
}
PCUT_TEST(llabs_pos)
{
long long lli;
lli = llabs(1);
PCUT_ASSERT_TRUE(lli == 1);
}
PCUT_TEST(llabs_neg)
{
long long lli;
lli = llabs(-1);
PCUT_ASSERT_TRUE(lli == 1);
}
PCUT_TEST(div_func)
{
div_t d;
d = div(41, 7);
PCUT_ASSERT_INT_EQUALS(5, d.quot);
PCUT_ASSERT_INT_EQUALS(6, d.rem);
}
PCUT_TEST(ldiv_func)
{
ldiv_t d;
d = ldiv(41, 7);
PCUT_ASSERT_INT_EQUALS(5, d.quot);
PCUT_ASSERT_INT_EQUALS(6, d.rem);
}
PCUT_TEST(lldiv_func)
{
lldiv_t d;
d = lldiv(41, 7);
PCUT_ASSERT_INT_EQUALS(5, d.quot);
PCUT_ASSERT_INT_EQUALS(6, d.rem);
}
PCUT_EXPORT(stdlib);
HelenOS homepage, sources at GitHub