[PATCH] kernel32/tests: Add tests for NormalizeString API function.

Huw Davies huw at codeweavers.com
Mon Apr 9 04:24:14 CDT 2018


On Sun, Apr 08, 2018 at 04:14:25PM -0500, Sergio Gómez Del Real wrote:
> Signed-off-by: Sergio Gómez Del Real <sdelreal at codeweavers.com>
> ---
>  dlls/kernel32/tests/locale.c | 333 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 333 insertions(+)
> 
> diff --git a/dlls/kernel32/tests/locale.c b/dlls/kernel32/tests/locale.c
> index a99763db92..21f3fc5e4c 100644
> --- a/dlls/kernel32/tests/locale.c
> +++ b/dlls/kernel32/tests/locale.c
> @@ -106,6 +106,7 @@ static INT (WINAPI *pGetNumberFormatEx)(LPCWSTR, DWORD, LPCWSTR, const NUMBERFMT
>  static INT (WINAPI *pFindNLSStringEx)(LPCWSTR, DWORD, LPCWSTR, INT, LPCWSTR, INT, LPINT, LPNLSVERSIONINFO, LPVOID, LPARAM);
>  static LANGID (WINAPI *pSetThreadUILanguage)(LANGID);
>  static LANGID (WINAPI *pGetThreadUILanguage)(VOID);
> +static INT (WINAPI *pNormalizeString)(NORM_FORM, LPCWSTR, INT, LPWSTR, INT);
>  
>  static void InitFunctionPointers(void)
>  {
> @@ -141,6 +142,7 @@ static void InitFunctionPointers(void)
>    X(FindNLSStringEx);
>    X(SetThreadUILanguage);
>    X(GetThreadUILanguage);
> +  X(NormalizeString);
>  
>    mod = GetModuleHandleA("ntdll");
>    X(RtlUpcaseUnicodeChar);
> @@ -5470,6 +5472,336 @@ static void test_SetThreadUILanguage(void)
>      "expected %d got %d\n", MAKELANGID(LANG_DUTCH, SUBLANG_DUTCH_BELGIAN), res);
>  }
>  
> +static void test_NormalizeString(void)
> +{
> +    /* part 0: specific cases */
> +    /* LATIN CAPITAL LETTER D WITH DOT ABOVE */
> +    static WCHAR part0_str1[] = {0x1e0a,0};

static const WCHAR

> +    static WCHAR *part0_nfc1 = part0_str1;
> +    static WCHAR part0_nfd1[] = {0x0044,0x0307,0};
> +    static WCHAR *part0_nfkc1 = part0_str1;
> +    static WCHAR *part0_nfkd1 = part0_nfd1;


I would get rid of the pointers, and simply enter the strings into test_arr[]

e.g.
     static const struct test_data_normal test_arr[] =
     {
         { part0_str1, part0_str1, part0_nfd1, part0_str1, part0_nfd1 },


...

> +    struct test_data_normal {
> +        WCHAR *str;
> +        WCHAR *nfc;
> +        WCHAR *nfd;
> +        WCHAR *nfkc;
> +        WCHAR *nfkd;

These are consts.

> +    };
> +    struct test_data_normal test_arr[] =

static const

> +    {
> +        { part0_str1, part0_nfc1, part0_nfd1, part0_nfkc1, part0_nfkd1 },
> +        { part0_str2, part0_nfc2, part0_nfd2, part0_nfkc2, part0_nfkd2 },
> +        { part0_str3, part0_nfc3, part0_nfd3, part0_nfkc3, part0_nfkd3 },
> +        { part0_str4, part0_nfc4, part0_nfd4, part0_nfkc4, part0_nfkd4 },
> +        { part0_str5, part0_nfc5, part0_nfd5, part0_nfkc5, part0_nfkd5 },
> +        { part0_str6, part0_nfc6, part0_nfd6, part0_nfkc6, part0_nfkd6 },
> +        { part0_str8, part0_nfc8, part0_nfd8, part0_nfkc8, part0_nfkd8 },
> +        { part0_str9, part0_nfc9, part0_nfd9, part0_nfkc9, part0_nfkd9 },
> +        { part0_str10, part0_nfc10, part0_nfd10, part0_nfkc10, part0_nfkd10 },
> +        { part0_str11, part0_nfc11, part0_nfd11, part0_nfkc11, part0_nfkd11 },
> +        { part0_str12, part0_nfc12, part0_nfd12, part0_nfkc12, part0_nfkd12 },
> +        { part1_str1, part1_nfc1, part1_nfd1, part1_nfkc1, part1_nfkd1 },
> +        { part1_str2, part1_nfc2, part1_nfd2, part1_nfkc2, part1_nfkd2 },
> +        { part1_str3, part1_nfc3, part1_nfd3, part1_nfkc3, part1_nfkd3 },
> +        { part1_str4, part1_nfc4, part1_nfd4, part1_nfkc4, part1_nfkd4 },
> +        { part1_str5, part1_nfc5, part1_nfd5, part1_nfkc5, part1_nfkd5 },
> +        { part1_str6, part1_nfc6, part1_nfd6, part1_nfkc6, part1_nfkd6 },
> +        { part1_str7, part1_nfc7, part1_nfd7, part1_nfkc7, part1_nfkd7 },
> +        { part1_str8, part1_nfc8, part1_nfd8, part1_nfkc8, part1_nfkd8 },
> +        { part1_str9, part1_nfc9, part1_nfd9, part1_nfkc9, part1_nfkd9 },
> +        { part1_str10, part1_nfc10, part1_nfd10, part1_nfkc10, part1_nfkd10 },
> +        { part1_str11, part1_nfc11, part1_nfd11, part1_nfkc11, part1_nfkd11 },
> +        { 0 }
> +    };
> +    struct test_data_normal *ptest = test_arr;
> +    int dstlen;
> +    WCHAR *dst;
> +
> +    if (!pFindNLSStringEx)

pNormalizeString!  Also check that there are versions of Windows on testbot
that don't have NormalizeString.

> +    {
> +        win_skip("NormalizeString is not available.\n");
> +        return;
> +    }
> +
> +    todo_wine {
> +        dstlen = pNormalizeString( NormalizationD, ptest->str, -1, NULL, 0 );
> +        dst = HeapAlloc( GetProcessHeap(), 0, dstlen );
> +        dstlen = pNormalizeString( NormalizationD, ptest->str, -1, dst, 1 );
> +        ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Should have failed with ERROR_INSUFFICIENT_BUFFER");

Let's just use an array for dst, WHCAR dst[80]; should be enough for anyone, both here
(where you leak dst anyway) and for the loop below.

> +    }
> +
> +    /* 
         ^ trailing whitespace.

> +     * For each string, first test passing -1 as srclen to NormalizeString,
> +     * thereby assuming a null-terminating string in src, and then test passing
> +     * explicitly the string length.
> +     * Do that for all 4 normalization forms.
> +     */
> +    while (ptest->str)
> +    {
> +        int str_cmp;

It might be worth trying to loop through the four forms rather than
duplicate the same code four (or really eight) times.

> +
> +        todo_wine {
> +            dstlen = pNormalizeString( NormalizationD, ptest->str, -1, NULL, 0 );
> +            if (dstlen)
> +            {
> +                dst = HeapAlloc( GetProcessHeap(), 0, dstlen * sizeof(WCHAR) );
> +                dstlen = pNormalizeString( NormalizationD, ptest->str, -1, dst, dstlen );
> +                ok(dstlen == strlenW( ptest->nfd )+1, "Copied length differed: was %d, should be %d\n",
> +                   dstlen, strlenW( ptest->nfd )+1);
> +                str_cmp = strncmpW( ptest->nfd, dst, dstlen+1 );
> +                ok( str_cmp == 0, "NFD test failed: returned value was %d\n", str_cmp );
> +                HeapFree( GetProcessHeap(), 0, dst );
> +            }
> +
> +            dstlen = pNormalizeString( NormalizationD, ptest->str, strlenW(ptest->str), NULL, 0 );
> +            if (dstlen)
> +            {
> +                dst = HeapAlloc( GetProcessHeap(), 0, dstlen * sizeof(WCHAR) );
> +                dstlen = pNormalizeString( NormalizationD, ptest->str, strlenW(ptest->str), dst, dstlen );
> +                ok(dstlen == strlenW( ptest->nfd ) ||
> +                   broken( dstlen == -6 ), // Vista, 7, 8, 10, 2008. Only part1_str9.

I'd be tempted to leave part1_str9 out as it seems be the broken
everywhere.  If you really want to keep this in, add a broken flag to
the test struct.

Also note c++ comments are out.

> +                   "Copied length differed: was %d, should be %d\n",
> +                   dstlen, strlenW( ptest->nfd ));
> +                str_cmp = strncmpW( ptest->nfd, dst, dstlen );
> +                ok( str_cmp == 0, "NFD test failed: returned value was %d\n", str_cmp );
> +                HeapFree( GetProcessHeap(), 0, dst );
> +            }
> +




More information about the wine-devel mailing list