import RT-Thread@9217865c without bsp, libcpu and components/net
This commit is contained in:
commit
e2376a3709
1414 changed files with 390370 additions and 0 deletions
67
examples/utest/testcases/posix/stdlib_h/functions/atoi_tc.c
Normal file
67
examples/utest/testcases/posix/stdlib_h/functions/atoi_tc.c
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
struct atoi_data
|
||||
{
|
||||
char string[15]; // int max 2147483647
|
||||
int ret_num;
|
||||
};
|
||||
|
||||
struct atoi_data test_data[] =
|
||||
{
|
||||
/* positive integer */
|
||||
{"0", 0},
|
||||
{"1", 1},
|
||||
{"1.123", 1},
|
||||
{"123", 123},
|
||||
{"98993489", 98993489},
|
||||
{"98993489.12", 98993489},
|
||||
{"2147483647", 2147483647},
|
||||
|
||||
/* negtive integer */
|
||||
{"-1", -1},
|
||||
{"-1.123", -1},
|
||||
{"-123", -123},
|
||||
{"-98993489", -98993489},
|
||||
{"-98993489.12", -98993489},
|
||||
{"-2147483647", -2147483647},
|
||||
|
||||
/* letters and numbers */
|
||||
{"12a45", 12},
|
||||
{"-12a45", -12},
|
||||
{"12/45", 12},
|
||||
{"-12/45", -12},
|
||||
|
||||
/* cannot be resolved */
|
||||
{"", 0},
|
||||
{" ", 0},
|
||||
{"abc12", 0},
|
||||
{" abc12", 0},
|
||||
/* {NULL, -1} compiler warning */
|
||||
};
|
||||
|
||||
#include <utest.h>
|
||||
int atoi_entry(void)
|
||||
{
|
||||
int i = 0;
|
||||
int res = 0;
|
||||
for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++)
|
||||
{
|
||||
res = atoi(test_data[i].string);
|
||||
uassert_int_equal(res, test_data[i].ret_num);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_atoi(void)
|
||||
{
|
||||
atoi_entry();
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_atoi);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdlib_h.atoi_tc.c", RT_NULL, RT_NULL, 10);
|
||||
|
69
examples/utest/testcases/posix/stdlib_h/functions/atol_tc.c
Normal file
69
examples/utest/testcases/posix/stdlib_h/functions/atol_tc.c
Normal file
|
@ -0,0 +1,69 @@
|
|||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
struct atol_data
|
||||
{
|
||||
char string[15]; // long max 2147483647
|
||||
int ret_num;
|
||||
};
|
||||
|
||||
struct atol_data test_data1[] =
|
||||
{
|
||||
/* positive integer */
|
||||
{"0", 0},
|
||||
{"1", 1},
|
||||
{"1.123", 1},
|
||||
{"123", 123},
|
||||
{"98993489", 98993489},
|
||||
{"98993489.12", 98993489},
|
||||
{"2147483647", 2147483647},
|
||||
|
||||
/* negtive integer */
|
||||
{"-1", -1},
|
||||
{"-1.123", -1},
|
||||
{"-123", -123},
|
||||
{"-98993489", -98993489},
|
||||
{"-98993489.12", -98993489},
|
||||
{"-2147483647", -2147483647},
|
||||
|
||||
/* letters and numbers */
|
||||
{"12a45", 12},
|
||||
{"-12a45", -12},
|
||||
{"12/45", 12},
|
||||
{"-12/45", -12},
|
||||
|
||||
/* cannot be resolved */
|
||||
{"", 0},
|
||||
{" ", 0},
|
||||
{"abc12", 0},
|
||||
{" abc12", 0},
|
||||
/* {NULL, -1} compiler warning */
|
||||
};
|
||||
|
||||
#include <utest.h>
|
||||
int atol_entry(void)
|
||||
{
|
||||
int i = 0;
|
||||
int res = 0;
|
||||
for (i = 0; i < sizeof(test_data1) / sizeof(test_data1[0]); i++)
|
||||
{
|
||||
res = atol(test_data1[i].string);
|
||||
uassert_int_equal(res, test_data1[i].ret_num);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_atol(void)
|
||||
{
|
||||
atol_entry();
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_atol);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdlib_h.atol_tc.c", RT_NULL, RT_NULL, 10);
|
||||
|
136
examples/utest/testcases/posix/stdlib_h/functions/qsort_tc.c
Normal file
136
examples/utest/testcases/posix/stdlib_h/functions/qsort_tc.c
Normal file
|
@ -0,0 +1,136 @@
|
|||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <utest.h>
|
||||
|
||||
static int scmp(const void *a, const void *b)
|
||||
{
|
||||
return strcmp(*(char **)a, *(char **)b);
|
||||
}
|
||||
|
||||
static int icmp(const void *a, const void *b)
|
||||
{
|
||||
return *(int *)a - *(int *)b;
|
||||
}
|
||||
|
||||
static int ccmp(const void *a, const void *b)
|
||||
{
|
||||
return *(char *)a - *(char *)b;
|
||||
}
|
||||
|
||||
/**
|
||||
* static int cmp64(const void *a, const void *b)
|
||||
* {
|
||||
* const uint64_t *ua = a, *ub = b;
|
||||
* return *ua < *ub ? -1 : *ua != *ub;
|
||||
* }
|
||||
*/
|
||||
|
||||
/* 26 items -- even */
|
||||
static const char *s[] =
|
||||
{
|
||||
"Bob", "Alice", "John", "Ceres",
|
||||
"Helga", "Drepper", "Emeralda", "Zoran",
|
||||
"Momo", "Frank", "Pema", "Xavier",
|
||||
"Yeva", "Gedun", "Irina", "Nono",
|
||||
"Wiener", "Vincent", "Tsering", "Karnica",
|
||||
"Lulu", "Quincy", "Osama", "Riley",
|
||||
"Ursula", "Sam"
|
||||
};
|
||||
static const char *s_sorted[] =
|
||||
{
|
||||
"Alice", "Bob", "Ceres", "Drepper",
|
||||
"Emeralda", "Frank", "Gedun", "Helga",
|
||||
"Irina", "John", "Karnica", "Lulu",
|
||||
"Momo", "Nono", "Osama", "Pema",
|
||||
"Quincy", "Riley", "Sam", "Tsering",
|
||||
"Ursula", "Vincent", "Wiener", "Xavier",
|
||||
"Yeva", "Zoran"
|
||||
};
|
||||
|
||||
/* 23 items -- odd, prime */
|
||||
static int n[] =
|
||||
{
|
||||
879045, 394, 99405644, 33434, 232323, 4334, 5454,
|
||||
343, 45545, 454, 324, 22, 34344, 233, 45345, 343,
|
||||
848405, 3434, 3434344, 3535, 93994, 2230404, 4334
|
||||
};
|
||||
static int n_sorted[] =
|
||||
{
|
||||
22, 233, 324, 343, 343, 394, 454, 3434,
|
||||
3535, 4334, 4334, 5454, 33434, 34344, 45345, 45545,
|
||||
93994, 232323, 848405, 879045, 2230404, 3434344, 99405644
|
||||
};
|
||||
|
||||
static void str_test(const char **a, const char **a_sorted, int len)
|
||||
{
|
||||
int i;
|
||||
qsort(a, len, sizeof * a, scmp);
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
uassert_true(strcmp(a[i], a_sorted[i]) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void int_test(int *a, int *a_sorted, int len)
|
||||
{
|
||||
int i;
|
||||
qsort(a, len, sizeof * a, icmp);
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
uassert_true(a[i] == a_sorted[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#define T(a, a_sorted) do { \
|
||||
char p[] = a; \
|
||||
qsort(p, sizeof p - 1, 1, ccmp); \
|
||||
uassert_true(memcmp(p, a_sorted, sizeof p) == 0);\
|
||||
} while(0)
|
||||
|
||||
static void char_test(void)
|
||||
{
|
||||
T("", "");
|
||||
T("1", "1");
|
||||
T("11", "11");
|
||||
T("12", "12");
|
||||
T("21", "12");
|
||||
T("111", "111");
|
||||
T("211", "112");
|
||||
T("121", "112");
|
||||
T("112", "112");
|
||||
T("221", "122");
|
||||
T("212", "122");
|
||||
T("122", "122");
|
||||
T("123", "123");
|
||||
T("132", "123");
|
||||
T("213", "123");
|
||||
T("231", "123");
|
||||
T("321", "123");
|
||||
T("312", "123");
|
||||
T("1423", "1234");
|
||||
T("51342", "12345");
|
||||
T("261435", "123456");
|
||||
T("4517263", "1234567");
|
||||
T("37245618", "12345678");
|
||||
T("812436597", "123456789");
|
||||
T("987654321", "123456789");
|
||||
T("321321321", "111222333");
|
||||
T("49735862185236174", "11223344556677889");
|
||||
}
|
||||
|
||||
void posix_testcase(void)
|
||||
{
|
||||
str_test(s, s_sorted, sizeof s / sizeof * s);
|
||||
int_test(n, n_sorted, sizeof n / sizeof * n);
|
||||
char_test();
|
||||
/* todo uint64 test */
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(posix_testcase);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdlib_h.qsort_tc.c", RT_NULL, RT_NULL, 10);
|
||||
|
125
examples/utest/testcases/posix/stdlib_h/functions/strtol_tc.c
Normal file
125
examples/utest/testcases/posix/stdlib_h/functions/strtol_tc.c
Normal file
|
@ -0,0 +1,125 @@
|
|||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define TEST(r, f, x, m) uassert_int_equal(f, x)
|
||||
#define TEST2(r, f, x, m) uassert_int_equal(f, x)
|
||||
#define TEST3(r, f, x, m) uassert_int_not_equal(f, x)
|
||||
|
||||
#include <utest.h>
|
||||
#define ERANGE 34
|
||||
#define EINVAL 22
|
||||
|
||||
int strtol_entry(void)
|
||||
{
|
||||
__attribute__((unused)) int i;
|
||||
__attribute__((unused)) long l;
|
||||
__attribute__((unused)) unsigned long ul;
|
||||
__attribute__((unused)) long long ll;
|
||||
__attribute__((unused)) unsigned long long ull;
|
||||
__attribute__((unused)) char *msg = "";
|
||||
__attribute__((unused)) char *s, *c;
|
||||
|
||||
TEST(l, atol("2147483647"), 2147483647L, "max 32bit signed %ld != %ld");
|
||||
TEST(l, strtol("2147483647", 0, 0), 2147483647L, "max 32bit signed %ld != %ld");
|
||||
TEST(ul, strtoul("4294967295", 0, 0), 4294967295UL, "max 32bit unsigned %lu != %lu");
|
||||
|
||||
if (sizeof(long) == 4)
|
||||
{
|
||||
TEST(l, strtol(s = "2147483648", &c, 0), 2147483647L, "uncaught overflow %ld != %ld");
|
||||
TEST2(i, c - s, 10, "wrong final position %d != %d");
|
||||
TEST(l, strtol(s = "-2147483649", &c, 0), -2147483647L - 1, "uncaught overflow %ld != %ld");
|
||||
TEST2(i, c - s, 11, "wrong final position %d != %d");
|
||||
TEST(ul, strtoul(s = "4294967296", &c, 0), 4294967295UL, "uncaught overflow %lu != %lu");
|
||||
TEST2(i, c - s, 10, "wrong final position %d != %d");
|
||||
TEST(ul, strtoul(s = "-1", &c, 0), -1UL, "rejected negative %lu != %lu");
|
||||
TEST2(i, c - s, 2, "wrong final position %d != %d");
|
||||
TEST(ul, strtoul(s = "-2", &c, 0), -2UL, "rejected negative %lu != %lu");
|
||||
TEST2(i, c - s, 2, "wrong final position %d != %d");
|
||||
TEST(ul, strtoul(s = "-2147483648", &c, 0), -2147483648UL, "rejected negative %lu != %lu");
|
||||
TEST2(i, c - s, 11, "wrong final position %d != %d");
|
||||
TEST(ul, strtoul(s = "-2147483649", &c, 0), -2147483649UL, "rejected negative %lu != %lu");
|
||||
TEST2(i, c - s, 11, "wrong final position %d != %d");
|
||||
TEST(ul, strtoul(s = "-4294967296", &c, 0), 4294967295UL, "uncaught negative overflow %lu != %lu");
|
||||
TEST2(i, c - s, 11, "wrong final position %d != %d");
|
||||
}
|
||||
else if (sizeof(long) == 8)
|
||||
{
|
||||
TEST(l, strtol(s = "9223372036854775808", &c, 0), 9223372036854775807L, "uncaught overflow %ld != %ld");
|
||||
TEST2(i, c - s, 19, "wrong final position %d != %d");
|
||||
TEST(l, strtol(s = "-9223372036854775809", &c, 0), -9223372036854775807L - 1, "uncaught overflow %ld != %ld");
|
||||
TEST2(i, c - s, 20, "wrong final position %d != %d");
|
||||
TEST(ul, strtoul(s = "18446744073709551616", &c, 0), 18446744073709551615UL, "uncaught overflow %lu != %lu");
|
||||
TEST2(i, c - s, 20, "wrong final position %d != %d");
|
||||
TEST(ul, strtoul(s = "-1", &c, 0), -1UL, "rejected negative %lu != %lu");
|
||||
TEST2(i, c - s, 2, "wrong final position %d != %d");
|
||||
TEST(ul, strtoul(s = "-2", &c, 0), -2UL, "rejected negative %lu != %lu");
|
||||
TEST2(i, c - s, 2, "wrong final position %d != %d");
|
||||
TEST(ul, strtoul(s = "-9223372036854775808", &c, 0), -9223372036854775808UL, "rejected negative %lu != %lu");
|
||||
TEST2(i, c - s, 20, "wrong final position %d != %d");
|
||||
TEST(ul, strtoul(s = "-9223372036854775809", &c, 0), -9223372036854775809UL, "rejected negative %lu != %lu");
|
||||
TEST2(i, c - s, 20, "wrong final position %d != %d");
|
||||
TEST(ul, strtoul(s = "-18446744073709551616", &c, 0), 18446744073709551615UL, "uncaught negative overflow %lu != %lu");
|
||||
TEST2(i, c - s, 21, "wrong final position %d != %d");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("sizeof(long) == %d, not implemented\n", (int)sizeof(long));
|
||||
}
|
||||
|
||||
if (sizeof(long long) == 8)
|
||||
{
|
||||
TEST(ll, strtoll(s = "9223372036854775808", &c, 0), 9223372036854775807LL, "uncaught overflow %lld != %lld");
|
||||
TEST2(i, c - s, 19, "wrong final position %d != %d");
|
||||
TEST(ll, strtoll(s = "-9223372036854775809", &c, 0), -9223372036854775807LL - 1, "uncaught overflow %lld != %lld");
|
||||
TEST2(i, c - s, 20, "wrong final position %d != %d");
|
||||
TEST(ull, strtoull(s = "18446744073709551616", &c, 0), 18446744073709551615ULL, "uncaught overflow %llu != %llu");
|
||||
TEST2(i, c - s, 20, "wrong final position %d != %d");
|
||||
TEST(ull, strtoull(s = "-1", &c, 0), -1ULL, "rejected negative %llu != %llu");
|
||||
TEST2(i, c - s, 2, "wrong final position %d != %d");
|
||||
TEST(ull, strtoull(s = "-2", &c, 0), -2ULL, "rejected negative %llu != %llu");
|
||||
TEST2(i, c - s, 2, "wrong final position %d != %d");
|
||||
TEST(ull, strtoull(s = "-9223372036854775808", &c, 0), -9223372036854775808ULL, "rejected negative %llu != %llu");
|
||||
TEST2(i, c - s, 20, "wrong final position %d != %d");
|
||||
TEST(ull, strtoull(s = "-9223372036854775809", &c, 0), -9223372036854775809ULL, "rejected negative %llu != %llu");
|
||||
TEST2(i, c - s, 20, "wrong final position %d != %d");
|
||||
TEST(ull, strtoull(s = "-18446744073709551616", &c, 0), 18446744073709551615ULL, "uncaught negative overflow %llu != %llu");
|
||||
TEST2(i, c - s, 21, "wrong final position %d != %d");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("sizeof(long long) == %d, not implemented\n", (int)sizeof(long long));
|
||||
}
|
||||
|
||||
TEST(l, strtol("z", 0, 36), 35L, "%ld != %ld");
|
||||
TEST(l, strtol("00010010001101000101011001111000", 0, 2), 0x12345678L, "%ld != %ld");
|
||||
TEST(l, strtol(s = "0F5F", &c, 16), 0x0f5fL, "%ld != %ld");
|
||||
|
||||
TEST(l, strtol(s = "0xz", &c, 16), 0L, "%ld != %ld");
|
||||
TEST3(i, c - s, 1, "wrong final position %ld != %ld");
|
||||
|
||||
TEST(l, strtol(s = "0x1234", &c, 16), 0x1234, "%ld != %ld");
|
||||
TEST2(i, c - s, 6, "wrong final position %ld != %ld");
|
||||
|
||||
c = NULL;
|
||||
TEST3(l, strtol(s = "123", &c, 37), 0, "%ld != %ld");
|
||||
TEST3(i, c - s, 0, "wrong final position %d != %d");
|
||||
|
||||
TEST(l, strtol(s = " 15437", &c, 8), 015437, "%ld != %ld");
|
||||
TEST2(i, c - s, 7, "wrong final position %d != %d");
|
||||
|
||||
TEST(l, strtol(s = " 1", &c, 0), 1, "%ld != %ld");
|
||||
TEST2(i, c - s, 3, "wrong final position %d != %d");
|
||||
return 0;
|
||||
}
|
||||
static void test_strtol(void)
|
||||
{
|
||||
strtol_entry();
|
||||
}
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(test_strtol);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "posix.stdlib_h.strtol_tc.c", RT_NULL, RT_NULL, 10);
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue