wine/dlls/msvcr70/tests/msvcr70.c
Shaun Ren 6d2a9af43b msvcrt: Fix strncmp return value.
Some programs, such as Final Fantasy IV (3D remake), expect strncmp
to return exactly +/-1 when the strings are not equal.

Signed-off-by: Shaun Ren <sren@codeweavers.com>
2022-09-19 20:12:32 +02:00

87 lines
2.7 KiB
C

/*
* Copyright 2022 Shaun Ren for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <windef.h>
#include <winbase.h>
#include <errno.h>
#include "wine/test.h"
static int (__cdecl *p_strcmp)(const char *, const char *);
static int (__cdecl *p_strncmp)(const char *, const char *, size_t);
#define SETNOFAIL(x,y) x = (void*)GetProcAddress(hcrt,y)
#define SET(x,y) do { SETNOFAIL(x,y); ok(x != NULL, "Export '%s' not found\n", y); } while(0)
static BOOL init(void)
{
HMODULE hcrt;
SetLastError(0xdeadbeef);
hcrt = LoadLibraryA("msvcr70.dll");
if (!hcrt) {
win_skip("msvcr70.dll not installed (got %ld)\n", GetLastError());
return FALSE;
}
SET(p_strcmp, "strcmp");
SET(p_strncmp, "strncmp");
return TRUE;
}
static void test_strcmp(void)
{
int ret = p_strcmp( "abc", "abcd" );
ok( ret == -1, "wrong ret %d\n", ret );
ret = p_strcmp( "", "abc" );
ok( ret == -1, "wrong ret %d\n", ret );
ret = p_strcmp( "abc", "ab\xa0" );
ok( ret == -1, "wrong ret %d\n", ret );
ret = p_strcmp( "ab\xb0", "ab\xa0" );
ok( ret == 1, "wrong ret %d\n", ret );
ret = p_strcmp( "ab\xc2", "ab\xc2" );
ok( ret == 0, "wrong ret %d\n", ret );
ret = p_strncmp( "abc", "abcd", 3 );
ok( ret == 0, "wrong ret %d\n", ret );
ret = p_strncmp( "", "abc", 3 );
ok( ret == -1, "wrong ret %d\n", ret );
ret = p_strncmp( "abc", "ab\xa0", 4 );
ok( ret == -1, "wrong ret %d\n", ret );
ret = p_strncmp( "ab\xb0", "ab\xa0", 3 );
ok( ret == 1, "wrong ret %d\n", ret );
ret = p_strncmp( "ab\xb0", "ab\xa0", 2 );
ok( ret == 0, "wrong ret %d\n", ret );
ret = p_strncmp( "ab\xc2", "ab\xc2", 3 );
ok( ret == 0, "wrong ret %d\n", ret );
ret = p_strncmp( "abc", "abd", 0 );
ok( ret == 0, "wrong ret %d\n", ret );
ret = p_strncmp( "abc", "abc", 12 );
ok( ret == 0, "wrong ret %d\n", ret );
}
START_TEST(msvcr70)
{
if(!init())
return;
test_strcmp();
}