Commit f714cf4b authored by Nicolas Le Cam's avatar Nicolas Le Cam Committed by Alexandre Julliard

advapi32/tests: test_enum_provider_types test cleanup.

parent 30a6f54d
......@@ -566,43 +566,51 @@ static BOOL FindProvTypesRegVals(DWORD dwIndex, DWORD *pdwProvType, LPSTR *pszTy
HKEY hKey;
HKEY hSubKey;
PSTR ch;
LPSTR szName;
DWORD cbName;
BOOL ret = FALSE;
if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\Defaults\\Provider Types", &hKey))
return FALSE;
if (RegQueryInfoKey(hKey, NULL, NULL, NULL, pdwTypeCount, pcbTypeName, NULL,
if (RegQueryInfoKey(hKey, NULL, NULL, NULL, pdwTypeCount, &cbName, NULL,
NULL, NULL, NULL, NULL, NULL))
return FALSE;
(*pcbTypeName)++;
goto cleanup;
cbName++;
if (!(*pszTypeName = ((LPSTR)LocalAlloc(LMEM_ZEROINIT, *pcbTypeName))))
return FALSE;
if (!(szName = LocalAlloc(LMEM_ZEROINIT, cbName)))
goto cleanup;
if (RegEnumKeyEx(hKey, dwIndex, *pszTypeName, pcbTypeName, NULL, NULL, NULL, NULL))
return FALSE;
(*pcbTypeName)++;
ch = *pszTypeName + strlen(*pszTypeName);
if (RegEnumKeyEx(hKey, dwIndex, szName, &cbName, NULL, NULL, NULL, NULL))
goto cleanup;
cbName++;
ch = szName + strlen(szName);
/* Convert "Type 000" to 0, etc/ */
*pdwProvType = *(--ch) - '0';
*pdwProvType += (*(--ch) - '0') * 10;
*pdwProvType += (*(--ch) - '0') * 100;
if (RegOpenKey(hKey, *pszTypeName, &hSubKey))
return FALSE;
if (RegOpenKey(hKey, szName, &hSubKey))
goto cleanup;
if (RegQueryValueEx(hSubKey, "TypeName", NULL, NULL, NULL, pcbTypeName))
return FALSE;
goto cleanup;
if (!(*pszTypeName = ((LPSTR)LocalAlloc(LMEM_ZEROINIT, *pcbTypeName))))
return FALSE;
if (!(*pszTypeName = LocalAlloc(LMEM_ZEROINIT, *pcbTypeName)))
goto cleanup;
if (RegQueryValueEx(hSubKey, "TypeName", NULL, NULL, (LPBYTE)*pszTypeName, pcbTypeName))
return FALSE;
if (!RegQueryValueEx(hSubKey, "TypeName", NULL, NULL, (LPBYTE)*pszTypeName, pcbTypeName))
ret = TRUE;
cleanup:
if (!ret)
LocalFree(*pszTypeName);
LocalFree(szName);
RegCloseKey(hSubKey);
RegCloseKey(hKey);
return TRUE;
return ret;
}
static void test_enum_provider_types(void)
......@@ -637,29 +645,31 @@ static void test_enum_provider_types(void)
/* check pdwReserved for NULL */
result = pCryptEnumProviderTypesA(index, &notNull, 0, &provType, typeName, &typeNameSize);
ok(!result && GetLastError()==ERROR_INVALID_PARAMETER, "expected %i, got %d\n",
ERROR_INVALID_PARAMETER, GetLastError());
ok(!result && GetLastError()==ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n",
GetLastError());
/* check dwFlags == zero */
result = pCryptEnumProviderTypesA(index, NULL, notZeroFlags, &provType, typeName, &typeNameSize);
ok(!result && GetLastError()==NTE_BAD_FLAGS, "expected %i, got %d\n",
ERROR_INVALID_PARAMETER, GetLastError());
ok(!result && GetLastError()==NTE_BAD_FLAGS, "expected ERROR_INVALID_PARAMETER, got %d\n",
GetLastError());
/* This test fails under Win2k SP4:
* result = TRUE, GetLastError() == 0xdeadbeef */
if (0)
{
/* alloc provider type to half the size required
* cbTypeName holds the size required */
typeNameSize = cbTypeName / 2;
if (!(typeName = ((LPSTR)LocalAlloc(LMEM_ZEROINIT, typeNameSize))))
return;
goto cleanup;
/* This test fails under Win2k SP4:
result = TRUE, GetLastError() == 0xdeadbeef
SetLastError(0xdeadbeef);
result = pCryptEnumProviderTypesA(index, NULL, 0, &provType, typeName, &typeNameSize);
ok(!result && GetLastError()==ERROR_MORE_DATA, "expected 0/ERROR_MORE_DATA, got %d/%08lx\n",
ok(!result && GetLastError()==ERROR_MORE_DATA, "expected 0/ERROR_MORE_DATA, got %d/%d\n",
result, GetLastError());
*/
LocalFree(typeName);
}
/* loop through the provider types to get the number of provider types
* after loop ends, count should be dwTypeCount + 1 so subtract 1
......@@ -674,15 +684,14 @@ static void test_enum_provider_types(void)
* ERROR_NO_MORE_ITEMS */
for (typeCount = 0; typeCount < dwTypeCount + 1; typeCount++)
result = pCryptEnumProviderTypesA(typeCount, NULL, 0, &provType, NULL, &typeNameSize);
ok(!result && GetLastError()==ERROR_NO_MORE_ITEMS, "expected %i, got %d\n",
ERROR_NO_MORE_ITEMS, GetLastError());
ok(!result && GetLastError()==ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n",
GetLastError());
/* check expected versus actual values returned */
result = pCryptEnumProviderTypesA(index, NULL, 0, &provType, NULL, &typeNameSize);
ok(result && typeNameSize==cbTypeName, "expected %d, got %d\n", cbTypeName, typeNameSize);
if (!(typeName = ((LPSTR)LocalAlloc(LMEM_ZEROINIT, typeNameSize))))
return;
goto cleanup;
typeNameSize = 0xdeadbeef;
result = pCryptEnumProviderTypesA(index, NULL, 0, &provType, typeName, &typeNameSize);
......@@ -693,6 +702,8 @@ static void test_enum_provider_types(void)
ok(typeNameSize==cbTypeName, "expected %d, got %d\n", cbTypeName, typeNameSize);
LocalFree(typeName);
cleanup:
LocalFree(pszTypeName);
}
static BOOL FindDfltProvRegVals(DWORD dwProvType, DWORD dwFlags, LPSTR *pszProvName, DWORD *pcbProvName)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment