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
);
8 buffer_path_simplify(pdest
, psrc
);
10 if (!buffer_is_equal_string(pdest
, out
, out_len
)) {
12 "%s.%d: buffer_path_simplify('%s') failed: expected '%s', got '%s'\n",
17 pdest
->ptr
? pdest
->ptr
: "");
22 "%s.%d: buffer_path_simplify('%s') succeeded: got '%s'\n",
28 if (psrc
!= pdest
) buffer_copy_buffer(psrc
, pdest
);
29 buffer_path_simplify(pdest
, psrc
);
31 if (!buffer_is_equal_string(pdest
, out
, out_len
)) {
33 "%s.%d: buffer_path_simplify('%s') failed - not idempotent: expected '%s', got '%s'\n",
38 pdest
->ptr
? pdest
->ptr
: "");
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("/"));
69 static void test_buffer_path_simplify() {
70 buffer
*psrc
= buffer_init();
71 buffer
*pdest
= buffer_init();
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
);
82 test_buffer_path_simplify();