Annotation of embedaddon/lighttpd/src/test_buffer.c, revision 1.1
1.1 ! misho 1: #include "first.h"
! 2:
! 3: #include "buffer.h"
! 4:
! 5: static void run_buffer_path_simplify(buffer *psrc, buffer *pdest, const char *in, size_t in_len, const char *out, size_t out_len) {
! 6: buffer_copy_string_len(psrc, in, in_len);
! 7:
! 8: buffer_path_simplify(pdest, psrc);
! 9:
! 10: if (!buffer_is_equal_string(pdest, out, out_len)) {
! 11: fprintf(stderr,
! 12: "%s.%d: buffer_path_simplify('%s') failed: expected '%s', got '%s'\n",
! 13: __FILE__,
! 14: __LINE__,
! 15: in,
! 16: out,
! 17: pdest->ptr ? pdest->ptr : "");
! 18: fflush(stderr);
! 19: abort();
! 20: } else {
! 21: fprintf(stdout,
! 22: "%s.%d: buffer_path_simplify('%s') succeeded: got '%s'\n",
! 23: __FILE__,
! 24: __LINE__,
! 25: in,
! 26: out);
! 27:
! 28: if (psrc != pdest) buffer_copy_buffer(psrc, pdest);
! 29: buffer_path_simplify(pdest, psrc);
! 30:
! 31: if (!buffer_is_equal_string(pdest, out, out_len)) {
! 32: fprintf(stderr,
! 33: "%s.%d: buffer_path_simplify('%s') failed - not idempotent: expected '%s', got '%s'\n",
! 34: __FILE__,
! 35: __LINE__,
! 36: out,
! 37: out,
! 38: pdest->ptr ? pdest->ptr : "");
! 39: fflush(stderr);
! 40: abort();
! 41: }
! 42: }
! 43: }
! 44:
! 45: static void test_buffer_path_simplify_with(buffer *psrc, buffer *pdest) {
! 46: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN(""), CONST_STR_LEN(""));
! 47: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN(" "), CONST_STR_LEN("/"));
! 48: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("/"), CONST_STR_LEN("/"));
! 49: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("//"), CONST_STR_LEN("/"));
! 50: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("abc"), CONST_STR_LEN("/abc"));
! 51: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("abc//"), CONST_STR_LEN("/abc/"));
! 52: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("abc/./xyz"), CONST_STR_LEN("/abc/xyz"));
! 53: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("abc/.//xyz"), CONST_STR_LEN("/abc/xyz"));
! 54: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("abc/../xyz"), CONST_STR_LEN("/xyz"));
! 55: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("/abc/./xyz"), CONST_STR_LEN("/abc/xyz"));
! 56: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("/abc//./xyz"), CONST_STR_LEN("/abc/xyz"));
! 57: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("/abc/../xyz"), CONST_STR_LEN("/xyz"));
! 58: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("abc/../xyz/."), CONST_STR_LEN("/xyz/"));
! 59: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("/abc/../xyz/."), CONST_STR_LEN("/xyz/"));
! 60: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("abc/./xyz/.."), CONST_STR_LEN("/abc/"));
! 61: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("/abc/./xyz/.."), CONST_STR_LEN("/abc/"));
! 62: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("./xyz/.."), CONST_STR_LEN("/"));
! 63: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN(".//xyz/.."), CONST_STR_LEN("/"));
! 64: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("/./xyz/.."), CONST_STR_LEN("/"));
! 65: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN(".././xyz/.."), CONST_STR_LEN("/"));
! 66: run_buffer_path_simplify(psrc, pdest, CONST_STR_LEN("/.././xyz/.."), CONST_STR_LEN("/"));
! 67: }
! 68:
! 69: static void test_buffer_path_simplify() {
! 70: buffer *psrc = buffer_init();
! 71: buffer *pdest = buffer_init();
! 72:
! 73: /* test with using the same buffer and with using different buffers */
! 74: test_buffer_path_simplify_with(psrc, psrc);
! 75: test_buffer_path_simplify_with(pdest, psrc);
! 76:
! 77: buffer_free(psrc);
! 78: buffer_free(pdest);
! 79: }
! 80:
! 81: int main() {
! 82: test_buffer_path_simplify();
! 83:
! 84: return 0;
! 85: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>