Mercurial > hg > th-libs
comparison tests.c @ 362:a688d34c11d4
Sanitize test_snprintf().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 25 Feb 2016 11:59:06 +0200 |
parents | 9ca9ef4e3656 |
children | 68e8ad3327b8 |
comparison
equal
deleted
inserted
replaced
361:ad9719373fe3 | 362:a688d34c11d4 |
---|---|
203 test_result_msg(&ctx, strcmp(buf1, buf2) == 0, "result mismatch '%s' [th] != '%s' [libc]", buf1, buf2); | 203 test_result_msg(&ctx, strcmp(buf1, buf2) == 0, "result mismatch '%s' [th] != '%s' [libc]", buf1, buf2); |
204 | 204 |
205 test_result_msg(&ctx, (unsigned char) buf1[len] == SET_SENTINEL_BYTE, "buffer #1 overflow, sentinel 0x%02x", buf1[len]); | 205 test_result_msg(&ctx, (unsigned char) buf1[len] == SET_SENTINEL_BYTE, "buffer #1 overflow, sentinel 0x%02x", buf1[len]); |
206 test_result_msg(&ctx, (unsigned char) buf2[len] == SET_SENTINEL_BYTE, "buffer #2 overflow, sentinel 0x%02x", buf2[len]); | 206 test_result_msg(&ctx, (unsigned char) buf2[len] == SET_SENTINEL_BYTE, "buffer #2 overflow, sentinel 0x%02x", buf2[len]); |
207 | 207 |
208 // Test th_strdup_vprintf() | |
209 test_start(&ctx, "th_strdup_vprintf('%s')", fmt); | |
210 va_copy(tmp, ap); | |
211 char *str = th_strdup_vprintf(fmt, tmp); | |
212 test_result_msg(&ctx, str != NULL, "result NULL"); | |
213 th_free(str); | |
214 test_end(&ctx); | 208 test_end(&ctx); |
215 } | 209 } |
216 | 210 |
217 | 211 |
218 void test_snprintf(const char *msg, const char *fmt, ...) | 212 void test_snprintf(const char *msg, const char *fmt, ...) |
219 { | 213 { |
214 test_ctx ctx; | |
220 va_list ap, tmp; | 215 va_list ap, tmp; |
221 va_start(ap, fmt); | 216 va_start(ap, fmt); |
222 va_copy(tmp, ap); test_snprintf_do(0, msg, fmt, tmp); | 217 va_copy(tmp, ap); test_snprintf_do(0, msg, fmt, tmp); |
223 va_copy(tmp, ap); test_snprintf_do(1, msg, fmt, tmp); | 218 va_copy(tmp, ap); test_snprintf_do(1, msg, fmt, tmp); |
224 va_copy(tmp, ap); test_snprintf_do(2, msg, fmt, tmp); | 219 va_copy(tmp, ap); test_snprintf_do(2, msg, fmt, tmp); |
225 va_copy(tmp, ap); test_snprintf_do(16, msg, fmt, tmp); | 220 va_copy(tmp, ap); test_snprintf_do(16, msg, fmt, tmp); |
226 va_copy(tmp, ap); test_snprintf_do(SET_BUF_SIZE, msg, fmt, tmp); | 221 va_copy(tmp, ap); test_snprintf_do(SET_BUF_SIZE, msg, fmt, tmp); |
222 | |
223 // Test th_strdup_vprintf() | |
224 test_init(&ctx); | |
225 test_start(&ctx, "th_strdup_vprintf('%s')", fmt); | |
226 va_copy(tmp, ap); | |
227 char *str = th_strdup_vprintf(fmt, tmp); | |
228 test_result_msg(&ctx, str != NULL, "result NULL"); | |
229 th_free(str); | |
230 test_end(&ctx); | |
231 | |
227 va_end(ap); | 232 va_end(ap); |
228 tprint(2, | 233 tprint(2, |
229 "-----------------------------------------------------\n"); | 234 "-----------------------------------------------------\n"); |
230 } | 235 } |
231 | 236 |