propsys/tests: Add tests for PSStringFromPropertyKey.

This commit is contained in:
Andrew Nguyen 2010-07-25 21:57:59 -05:00 committed by Alexandre Julliard
parent c50177b1c1
commit c20908bf56
4 changed files with 153 additions and 0 deletions

1
configure vendored
View File

@ -14665,6 +14665,7 @@ wine_fn_config_dll pidgen enable_pidgen
wine_fn_config_dll powrprof enable_powrprof powrprof
wine_fn_config_dll printui enable_printui
wine_fn_config_dll propsys enable_propsys propsys
wine_fn_config_test dlls/propsys/tests propsys_test
wine_fn_config_dll psapi enable_psapi psapi
wine_fn_config_test dlls/psapi/tests psapi_test
wine_fn_config_dll pstorec enable_pstorec

View File

@ -2534,6 +2534,7 @@ WINE_CONFIG_DLL(pidgen)
WINE_CONFIG_DLL(powrprof,,[powrprof])
WINE_CONFIG_DLL(printui)
WINE_CONFIG_DLL(propsys,,[propsys])
WINE_CONFIG_TEST(dlls/propsys/tests)
WINE_CONFIG_DLL(psapi,,[psapi])
WINE_CONFIG_TEST(dlls/psapi/tests)
WINE_CONFIG_DLL(pstorec)

View File

@ -0,0 +1,11 @@
TOPSRCDIR = @top_srcdir@
TOPOBJDIR = ../../..
SRCDIR = @srcdir@
VPATH = @srcdir@
TESTDLL = propsys.dll
IMPORTS = propsys
C_SRCS = \
propsys.c
@MAKE_TEST_RULES@

View File

@ -0,0 +1,140 @@
/*
* Unit tests for Windows property system
*
* Copyright 2010 Andrew Nguyen
*
* 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
*/
#define COBJMACROS
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "objbase.h"
#include "propsys.h"
#include "initguid.h"
#include "wine/test.h"
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
static void test_PSStringFromPropertyKey(void)
{
static const WCHAR fillerW[] = {'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X',
'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X',
'X','X','X','X','X','X','X','X','X','X'};
static const WCHAR zero_fillerW[] = {'\0','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X',
'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X',
'X','X','X','X','X','X','X','X','X','X','X','X','X','X'};
static const WCHAR zero_truncatedW[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0',
'0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0',
'0','0','0','}',' ','\0','9','X','X','X','X','X','X','X','X','X'};
static const WCHAR zero_truncated2W[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0',
'0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0',
'0','0','0','}',' ','\0','9','2','7','6','9','4','9','2','X','X'};
static const WCHAR zero_truncated3W[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0',
'0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0',
'0','0','0','}',' ','\0','9','2','7','6','9','4','9','2','4','X'};
static const WCHAR zero_truncated4W[] = {'\0','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0',
'0','0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0',
'0','0','0','}',' ','\0','7','X','X','X','X','X','X','X','X','X'};
static const WCHAR truncatedW[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
'0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
'0','}',' ','\0','9','X','X','X','X','X','X','X','X','X'};
static const WCHAR truncated2W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
'0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
'0','}',' ','\0','9','2','7','6','9','4','9','2','X','X'};
static const WCHAR truncated3W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
'0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
'0','}',' ','\0','9','2','7','6','9','4','9','2','4','X'};
static const WCHAR truncated4W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
'0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
'0','}',' ','\0','7','X','X','X','X','X','X','X','X','X'};
static const WCHAR expectedW[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
'0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
'0','}',' ','4','2','9','4','9','6','7','2','9','5',0};
static const WCHAR expected2W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
'0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
'0','}',' ','1','3','5','7','9','\0','X','X','X','X','X'};
static const WCHAR expected3W[] = {'{','0','0','0','0','0','0','0','0','-','0','0','0','0','-','0','0','0',
'0','-','0','0','0','0','-','0','0','0','0','0','0','0','0','0','0','0',
'0','}',' ','0','\0','X','X','X','X','X','X','X','X','X'};
PROPERTYKEY prop = {GUID_NULL, ~0U};
PROPERTYKEY prop2 = {GUID_NULL, 13579};
PROPERTYKEY prop3 = {GUID_NULL, 0};
WCHAR out[PKEYSTR_MAX];
HRESULT ret;
const struct
{
REFPROPERTYKEY pkey;
LPWSTR psz;
UINT cch;
HRESULT hr_expect;
const WCHAR *buf_expect;
int hr_broken;
HRESULT hr2;
int buf_broken;
const WCHAR *buf2;
} testcases[] =
{
{NULL, NULL, 0, E_POINTER},
{&prop, NULL, 0, E_POINTER},
{&prop, NULL, PKEYSTR_MAX, E_POINTER},
{NULL, out, 0, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
{NULL, out, PKEYSTR_MAX, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_fillerW, 0, 0, 1, fillerW},
{&prop, out, 0, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
{&prop, out, GUIDSTRING_MAX, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
{&prop, out, GUIDSTRING_MAX + 1, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
{&prop, out, GUIDSTRING_MAX + 2, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_truncatedW, 1, S_OK, 1, truncatedW},
{&prop, out, PKEYSTR_MAX - 2, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_truncated2W, 1, S_OK, 1, truncated2W},
{&prop, out, PKEYSTR_MAX - 1, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_truncated3W, 1, S_OK, 1, truncated3W},
{&prop, out, PKEYSTR_MAX, S_OK, expectedW},
{&prop2, out, GUIDSTRING_MAX + 2, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), zero_truncated4W, 1, S_OK, 1, truncated4W},
{&prop2, out, GUIDSTRING_MAX + 6, S_OK, expected2W},
{&prop2, out, PKEYSTR_MAX, S_OK, expected2W},
{&prop3, out, GUIDSTRING_MAX + 1, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), fillerW},
{&prop3, out, GUIDSTRING_MAX + 2, S_OK, expected3W},
{&prop3, out, PKEYSTR_MAX, S_OK, expected3W},
};
int i;
for (i = 0; i < sizeof(testcases)/sizeof(testcases[0]); i++)
{
if (testcases[i].psz)
memcpy(testcases[i].psz, fillerW, PKEYSTR_MAX * sizeof(WCHAR));
ret = PSStringFromPropertyKey(testcases[i].pkey,
testcases[i].psz,
testcases[i].cch);
ok(ret == testcases[i].hr_expect ||
broken(testcases[i].hr_broken && ret == testcases[i].hr2), /* Vista/Win2k8 */
"[%d] Expected PSStringFromPropertyKey to return 0x%08x, got 0x%08x\n",
i, testcases[i].hr_expect, ret);
if (testcases[i].psz)
ok(!memcmp(testcases[i].psz, testcases[i].buf_expect, PKEYSTR_MAX * sizeof(WCHAR)) ||
broken(testcases[i].buf_broken &&
!memcmp(testcases[i].psz, testcases[i].buf2, PKEYSTR_MAX * sizeof(WCHAR))), /* Vista/Win2k8 */
"[%d] Unexpected output contents\n", i);
}
}
START_TEST(propsys)
{
test_PSStringFromPropertyKey();
}