| 1 |
/*------------------------------------------------------------------ |
| 2 |
* test_memcmp16_s |
| 3 |
* |
| 4 |
*------------------------------------------------------------------ |
| 5 |
*/ |
| 6 |
|
| 7 |
#include "test_private.h" |
| 8 |
#include "safe_mem_lib.h" |
| 9 |
|
| 10 |
#define LEN ( 128 ) |
| 11 |
|
| 12 |
int test_memcmp16_s() |
| 13 |
{ |
| 14 |
errno_t rc; |
| 15 |
|
| 16 |
uint32_t len; |
| 17 |
int32_t ind; |
| 18 |
int32_t std_ind; |
| 19 |
uint32_t i; |
| 20 |
|
| 21 |
uint16_t mem1[LEN]; |
| 22 |
uint16_t mem2[LEN]; |
| 23 |
|
| 24 |
/*--------------------------------------------------*/ |
| 25 |
|
| 26 |
rc = memcmp16_s(NULL, LEN, mem2, LEN, &ind); |
| 27 |
if (rc != ESNULLP) { |
| 28 |
debug_printf("%s %u Ind=%d Error rc=%u \n", |
| 29 |
__FUNCTION__, __LINE__, ind, rc ); |
| 30 |
} |
| 31 |
|
| 32 |
/*--------------------------------------------------*/ |
| 33 |
|
| 34 |
rc = memcmp16_s(mem1, LEN, NULL, LEN, &ind); |
| 35 |
if (rc != ESNULLP) { |
| 36 |
debug_printf("%s %u Ind=%d Error rc=%u \n", |
| 37 |
__FUNCTION__, __LINE__, ind, rc ); |
| 38 |
} |
| 39 |
|
| 40 |
/*--------------------------------------------------*/ |
| 41 |
|
| 42 |
rc = memcmp16_s(mem1, LEN, mem2, LEN, NULL); |
| 43 |
if (rc != ESNULLP) { |
| 44 |
debug_printf("%s %u Ind=%d Error rc=%u \n", |
| 45 |
__FUNCTION__, __LINE__, ind, rc ); |
| 46 |
} |
| 47 |
|
| 48 |
/*--------------------------------------------------*/ |
| 49 |
|
| 50 |
rc = memcmp16_s(mem1, 0, mem2, LEN, &ind); |
| 51 |
if (rc != ESZEROL) { |
| 52 |
debug_printf("%s %u Ind=%d Error rc=%u \n", |
| 53 |
__FUNCTION__, __LINE__, ind, rc ); |
| 54 |
} |
| 55 |
|
| 56 |
/*--------------------------------------------------*/ |
| 57 |
|
| 58 |
rc = memcmp16_s(mem1, LEN, mem2, 0, &ind); |
| 59 |
if (rc != ESZEROL) { |
| 60 |
debug_printf("%s %u Ind=%d Error rc=%u \n", |
| 61 |
__FUNCTION__, __LINE__, ind, rc ); |
| 62 |
} |
| 63 |
|
| 64 |
/*--------------------------------------------------*/ |
| 65 |
|
| 66 |
rc = memcmp16_s(mem1, RSIZE_MAX_MEM+1, mem2, LEN, &ind); |
| 67 |
if (rc != ESLEMAX) { |
| 68 |
debug_printf("%s %u Ind=%d Error rc=%u \n", |
| 69 |
__FUNCTION__, __LINE__, ind, rc ); |
| 70 |
} |
| 71 |
|
| 72 |
/*--------------------------------------------------*/ |
| 73 |
|
| 74 |
rc = memcmp16_s(mem1, LEN, mem2, RSIZE_MAX_MEM+1, &ind); |
| 75 |
if (rc != ESLEMAX) { |
| 76 |
debug_printf("%s %u Ind=%d Error rc=%u \n", |
| 77 |
__FUNCTION__, __LINE__, ind, rc ); |
| 78 |
} |
| 79 |
|
| 80 |
/*--------------------------------------------------*/ |
| 81 |
|
| 82 |
for (i=0; i<LEN; i++) { mem1[i] = i; } |
| 83 |
for (i=0; i<LEN; i++) { mem2[i] = i; } |
| 84 |
|
| 85 |
len = 1; |
| 86 |
rc = memcmp16_s(mem1, len, mem2, len, &ind); |
| 87 |
if (rc != EOK) { |
| 88 |
debug_printf("%s %u Ind=%d Error rc=%u \n", |
| 89 |
__FUNCTION__, __LINE__, ind, rc ); |
| 90 |
} |
| 91 |
|
| 92 |
if (ind != 0) { |
| 93 |
debug_printf("%s %u Ind=%d rc=%u \n", |
| 94 |
__FUNCTION__, __LINE__, ind, rc ); |
| 95 |
} |
| 96 |
|
| 97 |
std_ind = memcmp(mem1, mem2, len*2); |
| 98 |
if (ind != std_ind) { |
| 99 |
debug_printf("%s %u Ind=%d rc=%u \n", |
| 100 |
__FUNCTION__, __LINE__, ind, rc ); |
| 101 |
} |
| 102 |
|
| 103 |
/*--------------------------------------------------*/ |
| 104 |
|
| 105 |
for (i=0; i<LEN; i++) { mem1[i] = i; } |
| 106 |
for (i=0; i<LEN; i++) { mem2[i] = i; } |
| 107 |
|
| 108 |
len = 2; |
| 109 |
rc = memcmp16_s(mem1, len, mem2, len, &ind); |
| 110 |
if (rc != EOK) { |
| 111 |
debug_printf("%s %u Ind=%d Error rc=%u \n", |
| 112 |
__FUNCTION__, __LINE__, ind, rc ); |
| 113 |
} |
| 114 |
|
| 115 |
if (ind != 0) { |
| 116 |
debug_printf("%s %u Ind=%d rc=%u \n", |
| 117 |
__FUNCTION__, __LINE__, ind, rc ); |
| 118 |
} |
| 119 |
|
| 120 |
std_ind = memcmp(mem1, mem2, len*2); |
| 121 |
if (ind != std_ind) { |
| 122 |
debug_printf("%s %u Ind=%d rc=%u \n", |
| 123 |
__FUNCTION__, __LINE__, ind, rc ); |
| 124 |
} |
| 125 |
|
| 126 |
/*--------------------------------------------------*/ |
| 127 |
|
| 128 |
for (i=0; i<LEN; i++) { mem1[i] = i; } |
| 129 |
for (i=0; i<LEN; i++) { mem2[i] = i; } |
| 130 |
|
| 131 |
rc = memcmp16_s(mem1, LEN, mem2, LEN, &ind); |
| 132 |
if (rc != EOK) { |
| 133 |
debug_printf("%s %u Ind=%d Error rc=%u \n", |
| 134 |
__FUNCTION__, __LINE__, ind, rc ); |
| 135 |
} |
| 136 |
|
| 137 |
if (ind != 0) { |
| 138 |
debug_printf("%s %u Ind=%d rc=%u \n", |
| 139 |
__FUNCTION__, __LINE__, ind, rc ); |
| 140 |
} |
| 141 |
|
| 142 |
std_ind = memcmp(mem1, mem2, LEN*2); |
| 143 |
if (ind != std_ind) { |
| 144 |
debug_printf("%s %u Ind=%d rc=%u \n", |
| 145 |
__FUNCTION__, __LINE__, ind, rc ); |
| 146 |
} |
| 147 |
|
| 148 |
/*--------------------------------------------------*/ |
| 149 |
|
| 150 |
for (i=0; i<LEN; i++) { mem1[i] = i; } |
| 151 |
for (i=0; i<LEN; i++) { mem2[i] = i; } |
| 152 |
|
| 153 |
for (i=10; i<LEN-10; i++) { mem2[i] = 5; } |
| 154 |
|
| 155 |
rc = memcmp16_s(mem1, LEN, mem2, LEN, &ind); |
| 156 |
if (rc != EOK) { |
| 157 |
debug_printf("%s %u Ind=%d Error rc=%u \n", |
| 158 |
__FUNCTION__, __LINE__, ind, rc ); |
| 159 |
} |
| 160 |
|
| 161 |
if (ind == 0) { |
| 162 |
debug_printf("%s %u Ind=%d rc=%u \n", |
| 163 |
__FUNCTION__, __LINE__, ind, rc ); |
| 164 |
} |
| 165 |
|
| 166 |
std_ind = memcmp(mem1, mem2, LEN*2); |
| 167 |
if (ind != std_ind) { |
| 168 |
debug_printf("%s %u Ind=%d rc=%u \n", |
| 169 |
__FUNCTION__, __LINE__, ind, rc ); |
| 170 |
} |
| 171 |
|
| 172 |
/*--------------------------------------------------*/ |
| 173 |
/*--------------------------------------------------*/ |
| 174 |
|
| 175 |
return (0); |
| 176 |
} |