[PATCH v2 2/3] wcsmbs: Add test-wcsstr
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Fri Mar 1 17:07:05 GMT 2024
On 01/03/24 12:52, Adhemerval Zanella Netto wrote:
>
>
> On 28/02/24 21:45, DJ Delorie wrote:
>> Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
>>> Parametrize test-strstr.c so it can be used to check wcsstr.
>>
>> LGTM although I suggest renaming one of the variables to more accurately
>> reflect its new role. Also a question about error() formatting, but you
>> could commit this as-is if you want.
>>
>> Reviewed-by: DJ Delorie <dj@redhat.com>
>>
>>> diff --git a/string/test-strstr.c b/string/test-strstr.c
>>> index 05d0b7c98c..f82aeb2cfa 100644
>>> --- a/string/test-strstr.c
>>> +++ b/string/test-strstr.c
>>> @@ -17,16 +17,44 @@
>>> <https://www.gnu.org/licenses/>. */
>>>
>>> #define TEST_MAIN
>>> -#define TEST_NAME "strstr"
>>> -#include "test-string.h"
>>> +#ifndef WIDE
>>> +# define TEST_NAME "strstr"
>>> +#else
>>> +# define TEST_NAME "wcsstr"
>>> +#endif
>>
>> Ok.
>>
>>> +#ifndef WIDE
>>> +# define CHAR char
>>> +# define STRLEN strlen
>>> +# define STRSTR strstr
>>> +# define STRCPY strcpy
>>> +# define MEMCPY memcpy
>>> +# define MEMSET memset
>>> +# define MEMPCPY mempcpy
>>> +# define L(s) s
>>> +#else
>>> +# include <wchar.h>
>>> +# define CHAR wchar_t
>>> +# define STRLEN wcslen
>>> +# define STRCPY wcscpy
>>> +# define STRSTR wcsstr
>>> +# define MEMCPY wmemcpy
>>> +# define MEMSET wmemset
>>> +# define MEMPCPY wmempcpy
>>> +# define L(s) L ## s
>>> +/* The test requires up to 8191 charateres, so allocate at least 32Kb
>>> + (considering 4kb page size). */
>>> +# define BUF1PAGES 4
>>> +#endif
>>>
>>> +#include "test-string.h"
>>
>> Ok.
>>
>>> /* Naive implementation to verify results. */
>>> -static char *
>>> -simple_strstr (const char *s1, const char *s2)
>>> +static CHAR *
>>> +simple_strstr (const CHAR *s1, const CHAR *s2)
>>> {
>>> - ssize_t s1len = strlen (s1);
>>> - ssize_t s2len = strlen (s2);
>>> + ssize_t s1len = STRLEN (s1);
>>> + ssize_t s2len = STRLEN (s2);
>>>
>>> if (s2len > s1len)
>>> return NULL;
>>> @@ -38,28 +66,27 @@ simple_strstr (const char *s1, const char *s2)
>>> if (s1[i + j] != s2[j])
>>> break;
>>> if (j == s2len)
>>> - return (char *) s1 + i;
>>> + return (CHAR *) s1 + i;
>>> }
>>>
>>> return NULL;
>>> }
>>
>> Ok.
>>
>>
>>> -typedef char *(*proto_t) (const char *, const char *);
>>> +typedef CHAR *(*proto_t) (const CHAR *, const CHAR *);
>>>
>>> -IMPL (strstr, 1)
>>> +IMPL (STRSTR, 1)
>>
>> Ok.
>>
>>> static int
>>> -check_result (impl_t *impl, const char *s1, const char *s2,
>>> - char *exp_result)
>>> +check_result (impl_t *impl, const CHAR *s1, const CHAR *s2,
>>> + CHAR *exp_result)
>>
>> Ok.
>>
>>> {
>>> - char *result = CALL (impl, s1, s2);
>>> + CHAR *result = CALL (impl, s1, s2);
>>
>> Ok.
>>
>>> if (result != exp_result)
>>> {
>>> - error (0, 0, "Wrong result in function %s %s %s", impl->name,
>>> - (result == NULL) ? "(null)" : result,
>>> - (exp_result == NULL) ? "(null)" : exp_result);
>>> + error (0, 0, "Wrong result in function %p %p %p", impl->name,
>>> + result, exp_result);
>>
>> Ok... but do we not have a way to printf() wide character strings?
>
> Indeed, I think we can use "%Ls" here. I think I have used %p just to avoid
> adding another parametrized macro. I will fix it.
In fact I think I will keep '%p', the others tests functions also only print
the address (I think to avoid polluting the console/log file with gibberish).
More information about the Libc-alpha
mailing list