ReactOS 0.4.16-dev-257-g6aa11ac
test_def.c
Go to the documentation of this file.
1#include "test_def.h"
2
3#include "lwip/def.h"
4
5#define MAGIC_UNTOUCHED_BYTE 0x7a
6#define TEST_BUFSIZE 32
7#define GUARD_SIZE 4
8
9/* Setups/teardown functions */
10
11static void
13{
14}
15
16static void
18{
19}
20
21static void
22def_check_range_untouched(const char *buf, size_t len)
23{
24 size_t i;
25
26 for (i = 0; i < len; i++) {
27 fail_unless(buf[i] == (char)MAGIC_UNTOUCHED_BYTE);
28 }
29}
30
31static void test_def_itoa(int number, const char *expected)
32{
33 char buf[TEST_BUFSIZE];
34 char *test_buf = &buf[GUARD_SIZE];
35
36 size_t exp_len = strlen(expected);
37 fail_unless(exp_len + 4 < (TEST_BUFSIZE - (2 * GUARD_SIZE)));
38
40 lwip_itoa(test_buf, exp_len + 1, number);
42 fail_unless(test_buf[exp_len] == 0);
43 fail_unless(!memcmp(test_buf, expected, exp_len));
44 def_check_range_untouched(&test_buf[exp_len + 1], TEST_BUFSIZE - GUARD_SIZE - exp_len - 1);
45
46 /* check with too small buffer */
48 lwip_itoa(test_buf, exp_len, number);
50 def_check_range_untouched(&test_buf[exp_len + 1], TEST_BUFSIZE - GUARD_SIZE - exp_len - 1);
51
52 /* check with too large buffer */
54 lwip_itoa(test_buf, exp_len + 4, number);
56 fail_unless(test_buf[exp_len] == 0);
57 fail_unless(!memcmp(test_buf, expected, exp_len));
58 def_check_range_untouched(&test_buf[exp_len + 4], TEST_BUFSIZE - GUARD_SIZE - exp_len - 4);
59}
60
61START_TEST(test_def_lwip_itoa)
62{
64
65 test_def_itoa(0, "0");
66 test_def_itoa(1, "1");
67 test_def_itoa(-1, "-1");
68 test_def_itoa(15, "15");
69 test_def_itoa(-15, "-15");
70 test_def_itoa(156, "156");
71 test_def_itoa(1192, "1192");
72 test_def_itoa(-156, "-156");
73}
74END_TEST
75
77Suite *
79{
80 testfunc tests[] = {
81 TESTFUNC(test_def_lwip_itoa)
82 };
83 return create_suite("DEF", tests, sizeof(tests)/sizeof(testfunc), def_setup, def_teardown);
84}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define START_TEST(x)
Definition: atltest.h:75
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:373
void lwip_itoa(char *result, size_t bufsize, int number)
Definition: def.c:222
Suite * create_suite(const char *name, testfunc *tests, size_t num_tests, SFun setup, SFun teardown)
#define TESTFUNC(x)
Definition: lwip_check.h:22
static struct test_info tests[]
BOOL expected
Definition: store.c:2063
static unsigned int number
Definition: dsound.c:1479
#define memset(x, y, z)
Definition: compat.h:39
END_TEST Suite * def_suite(void)
Definition: test_def.c:78
#define GUARD_SIZE
Definition: test_def.c:7
static void def_teardown(void)
Definition: test_def.c:17
#define TEST_BUFSIZE
Definition: test_def.c:6
static void test_def_itoa(int number, const char *expected)
Definition: test_def.c:31
static void def_check_range_untouched(const char *buf, size_t len)
Definition: test_def.c:22
#define MAGIC_UNTOUCHED_BYTE
Definition: test_def.c:5
static void def_setup(void)
Definition: test_def.c:12