Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
test_def.c
00001 #include "test_def.h" 00002 00003 #include "lwip/def.h" 00004 00005 #define MAGIC_UNTOUCHED_BYTE 0x7a 00006 #define TEST_BUFSIZE 32 00007 #define GUARD_SIZE 4 00008 00009 /* Setups/teardown functions */ 00010 00011 static void 00012 def_setup(void) 00013 { 00014 } 00015 00016 static void 00017 def_teardown(void) 00018 { 00019 } 00020 00021 static void 00022 def_check_range_untouched(const char *buf, size_t len) 00023 { 00024 size_t i; 00025 00026 for (i = 0; i < len; i++) { 00027 fail_unless(buf[i] == (char)MAGIC_UNTOUCHED_BYTE); 00028 } 00029 } 00030 00031 static void test_def_itoa(int number, const char *expected) 00032 { 00033 char buf[TEST_BUFSIZE]; 00034 char *test_buf = &buf[GUARD_SIZE]; 00035 00036 size_t exp_len = strlen(expected); 00037 fail_unless(exp_len + 4 < (TEST_BUFSIZE - (2 * GUARD_SIZE))); 00038 00039 memset(buf, MAGIC_UNTOUCHED_BYTE, sizeof(buf)); 00040 lwip_itoa(test_buf, exp_len + 1, number); 00041 def_check_range_untouched(buf, GUARD_SIZE); 00042 fail_unless(test_buf[exp_len] == 0); 00043 fail_unless(!memcmp(test_buf, expected, exp_len)); 00044 def_check_range_untouched(&test_buf[exp_len + 1], TEST_BUFSIZE - GUARD_SIZE - exp_len - 1); 00045 00046 /* check with too small buffer */ 00047 memset(buf, MAGIC_UNTOUCHED_BYTE, sizeof(buf)); 00048 lwip_itoa(test_buf, exp_len, number); 00049 def_check_range_untouched(buf, GUARD_SIZE); 00050 def_check_range_untouched(&test_buf[exp_len + 1], TEST_BUFSIZE - GUARD_SIZE - exp_len - 1); 00051 00052 /* check with too large buffer */ 00053 memset(buf, MAGIC_UNTOUCHED_BYTE, sizeof(buf)); 00054 lwip_itoa(test_buf, exp_len + 4, number); 00055 def_check_range_untouched(buf, GUARD_SIZE); 00056 fail_unless(test_buf[exp_len] == 0); 00057 fail_unless(!memcmp(test_buf, expected, exp_len)); 00058 def_check_range_untouched(&test_buf[exp_len + 4], TEST_BUFSIZE - GUARD_SIZE - exp_len - 4); 00059 } 00060 00061 START_TEST(test_def_lwip_itoa) 00062 { 00063 LWIP_UNUSED_ARG(_i); 00064 00065 test_def_itoa(0, "0"); 00066 test_def_itoa(1, "1"); 00067 test_def_itoa(-1, "-1"); 00068 test_def_itoa(15, "15"); 00069 test_def_itoa(-15, "-15"); 00070 test_def_itoa(156, "156"); 00071 test_def_itoa(1192, "1192"); 00072 test_def_itoa(-156, "-156"); 00073 } 00074 END_TEST 00075 00076 /** Create the suite including all tests for this module */ 00077 Suite * 00078 def_suite(void) 00079 { 00080 testfunc tests[] = { 00081 TESTFUNC(test_def_lwip_itoa) 00082 }; 00083 return create_suite("DEF", tests, sizeof(tests)/sizeof(testfunc), def_setup, def_teardown); 00084 }
Generated on Tue Jul 12 2022 13:54:55 by
