comparison tests/unistr/test-u-strtok.h @ 18052:20a313c1ef00

unistr/uN-strtok-tests: avoid a trivial leak * tests/unistr/test-u-strtok.h (test_u_strtok): Untabify. Free input and delim after the multibyte delimiter tests.
author Daiki Ueno <ueno@gnu.org>
date Tue, 07 Jul 2015 15:12:52 +0900
parents 6ff81241d5b7
children
comparison
equal deleted inserted replaced
18051:07dbc84077fc 18052:20a313c1ef00
26 } 26 }
27 27
28 { 28 {
29 UNIT input[] = 29 UNIT input[] =
30 { 'A', 'B', 'C', ' ', 'A', 'B', 'C', 'D', 'A', 'B', ' ', '\t', 30 { 'A', 'B', 'C', ' ', 'A', 'B', 'C', 'D', 'A', 'B', ' ', '\t',
31 'A', 'B', 'C', 'D', 'A', 'B', 'C', 'D', 'A', 'B', 'D', 'E', 0 31 'A', 'B', 'C', 'D', 'A', 'B', 'C', 'D', 'A', 'B', 'D', 'E', 0
32 }; 32 };
33 const UNIT delim[] = { ' ', '\t', 0 }; 33 const UNIT delim[] = { ' ', '\t', 0 };
34 UNIT *state; 34 UNIT *state;
35 const UNIT *result; 35 const UNIT *result;
36 result = U_STRTOK (input, delim, &state); 36 result = U_STRTOK (input, delim, &state);
45 45
46 /* Check for multibyte delimiters. */ 46 /* Check for multibyte delimiters. */
47 { 47 {
48 ucs4_t u_input[] = 48 ucs4_t u_input[] =
49 { 'A', 'B', 'C', 0x3000, 'A', 'B', 'C', 'D', 'A', 'B', 0x3000, 0x3001, 49 { 'A', 'B', 'C', 0x3000, 'A', 'B', 'C', 'D', 'A', 'B', 0x3000, 0x3001,
50 'A', 'B', 'C', 'D', 'A', 'B', 'C', 'D', 'A', 'B', 'D', 'E', 0 50 'A', 'B', 'C', 'D', 'A', 'B', 'C', 'D', 'A', 'B', 'D', 'E', 0
51 }; 51 };
52 ucs4_t u_delim[] = { 0x3000, 0x3001, 0 }; 52 ucs4_t u_delim[] = { 0x3000, 0x3001, 0 };
53 size_t input_len = 6 * SIZEOF (u_input); 53 size_t input_len = 6 * SIZEOF (u_input);
54 UNIT *input = (UNIT *) malloc (input_len); 54 UNIT *input = (UNIT *) malloc (input_len);
55 size_t delim_len = 6 * SIZEOF (u_delim); 55 size_t delim_len = 6 * SIZEOF (u_delim);
58 const UNIT *result; 58 const UNIT *result;
59 UNIT *ptr, *first_ptr, *second_ptr; 59 UNIT *ptr, *first_ptr, *second_ptr;
60 size_t i; 60 size_t i;
61 for (i = 0, ptr = input; i < SIZEOF (u_input) && u_input[i] != 0; i++) 61 for (i = 0, ptr = input; i < SIZEOF (u_input) && u_input[i] != 0; i++)
62 { 62 {
63 int ret = U_UCTOMB (ptr, u_input[i], input_len - (ptr - input)); 63 int ret = U_UCTOMB (ptr, u_input[i], input_len - (ptr - input));
64 if (i == 4) 64 if (i == 4)
65 first_ptr = ptr; 65 first_ptr = ptr;
66 if (i == 12) 66 if (i == 12)
67 second_ptr = ptr; 67 second_ptr = ptr;
68 ptr += ret; 68 ptr += ret;
69 } 69 }
70 *ptr = 0; 70 *ptr = 0;
71 for (i = 0, ptr = delim; i < SIZEOF (u_delim) && u_delim[i] != 0; i++) 71 for (i = 0, ptr = delim; i < SIZEOF (u_delim) && u_delim[i] != 0; i++)
72 { 72 {
73 int ret = U_UCTOMB (ptr, u_delim[i], delim_len - (ptr - delim)); 73 int ret = U_UCTOMB (ptr, u_delim[i], delim_len - (ptr - delim));
74 ptr += ret; 74 ptr += ret;
75 } 75 }
76 *ptr = 0; 76 *ptr = 0;
77 result = U_STRTOK (input, delim, &state); 77 result = U_STRTOK (input, delim, &state);
78 ASSERT (result == input); 78 ASSERT (result == input);
79 result = U_STRTOK (NULL, delim, &state); 79 result = U_STRTOK (NULL, delim, &state);
80 ASSERT (result == first_ptr); 80 ASSERT (result == first_ptr);
81 result = U_STRTOK (NULL, delim, &state); 81 result = U_STRTOK (NULL, delim, &state);
82 ASSERT (result == second_ptr); 82 ASSERT (result == second_ptr);
83 result = U_STRTOK (NULL, delim, &state); 83 result = U_STRTOK (NULL, delim, &state);
84 ASSERT (result == NULL); 84 ASSERT (result == NULL);
85 free (input);
86 free (delim);
85 } 87 }
86 } 88 }