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 ...@@ -566,43 +566,51 @@ static BOOL FindProvTypesRegVals(DWORD dwIndex, DWORD *pdwProvType, LPSTR *pszTy
HKEY hKey; HKEY hKey;
HKEY hSubKey; HKEY hSubKey;
PSTR ch; PSTR ch;
LPSTR szName;
DWORD cbName;
BOOL ret = FALSE;
if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\Defaults\\Provider Types", &hKey)) if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\Defaults\\Provider Types", &hKey))
return FALSE; 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)) NULL, NULL, NULL, NULL, NULL))
return FALSE; goto cleanup;
(*pcbTypeName)++; cbName++;
if (!(*pszTypeName = ((LPSTR)LocalAlloc(LMEM_ZEROINIT, *pcbTypeName)))) if (!(szName = LocalAlloc(LMEM_ZEROINIT, cbName)))
return FALSE; goto cleanup;
if (RegEnumKeyEx(hKey, dwIndex, *pszTypeName, pcbTypeName, NULL, NULL, NULL, NULL)) if (RegEnumKeyEx(hKey, dwIndex, szName, &cbName, NULL, NULL, NULL, NULL))
return FALSE; goto cleanup;
(*pcbTypeName)++; cbName++;
ch = *pszTypeName + strlen(*pszTypeName); ch = szName + strlen(szName);
/* Convert "Type 000" to 0, etc/ */ /* Convert "Type 000" to 0, etc/ */
*pdwProvType = *(--ch) - '0'; *pdwProvType = *(--ch) - '0';
*pdwProvType += (*(--ch) - '0') * 10; *pdwProvType += (*(--ch) - '0') * 10;
*pdwProvType += (*(--ch) - '0') * 100; *pdwProvType += (*(--ch) - '0') * 100;
if (RegOpenKey(hKey, *pszTypeName, &hSubKey)) if (RegOpenKey(hKey, szName, &hSubKey))
return FALSE; goto cleanup;
if (RegQueryValueEx(hSubKey, "TypeName", NULL, NULL, NULL, pcbTypeName)) if (RegQueryValueEx(hSubKey, "TypeName", NULL, NULL, NULL, pcbTypeName))
return FALSE; goto cleanup;
if (!(*pszTypeName = LocalAlloc(LMEM_ZEROINIT, *pcbTypeName)))
goto cleanup;
if (!RegQueryValueEx(hSubKey, "TypeName", NULL, NULL, (LPBYTE)*pszTypeName, pcbTypeName))
ret = TRUE;
cleanup:
if (!ret)
LocalFree(*pszTypeName);
LocalFree(szName);
if (!(*pszTypeName = ((LPSTR)LocalAlloc(LMEM_ZEROINIT, *pcbTypeName))))
return FALSE;
if (RegQueryValueEx(hSubKey, "TypeName", NULL, NULL, (LPBYTE)*pszTypeName, pcbTypeName))
return FALSE;
RegCloseKey(hSubKey); RegCloseKey(hSubKey);
RegCloseKey(hKey); RegCloseKey(hKey);
return TRUE; return ret;
} }
static void test_enum_provider_types(void) static void test_enum_provider_types(void)
...@@ -612,7 +620,7 @@ static void test_enum_provider_types(void) ...@@ -612,7 +620,7 @@ static void test_enum_provider_types(void)
LPSTR pszTypeName = NULL; LPSTR pszTypeName = NULL;
DWORD cbTypeName; DWORD cbTypeName;
DWORD dwTypeCount; DWORD dwTypeCount;
/* actual values */ /* actual values */
DWORD index = 0; DWORD index = 0;
DWORD provType; DWORD provType;
...@@ -622,45 +630,47 @@ static void test_enum_provider_types(void) ...@@ -622,45 +630,47 @@ static void test_enum_provider_types(void)
DWORD result; DWORD result;
DWORD notNull = 5; DWORD notNull = 5;
DWORD notZeroFlags = 5; DWORD notZeroFlags = 5;
if(!pCryptEnumProviderTypesA) if(!pCryptEnumProviderTypesA)
{ {
skip("CryptEnumProviderTypesA is not available\n"); skip("CryptEnumProviderTypesA is not available\n");
return; return;
} }
if (!FindProvTypesRegVals(index, &dwProvType, &pszTypeName, &cbTypeName, &dwTypeCount)) if (!FindProvTypesRegVals(index, &dwProvType, &pszTypeName, &cbTypeName, &dwTypeCount))
{ {
skip("Could not find provider types in registry\n"); skip("Could not find provider types in registry\n");
return; return;
} }
/* check pdwReserved for NULL */ /* check pdwReserved for NULL */
result = pCryptEnumProviderTypesA(index, &notNull, 0, &provType, typeName, &typeNameSize); result = pCryptEnumProviderTypesA(index, &notNull, 0, &provType, typeName, &typeNameSize);
ok(!result && GetLastError()==ERROR_INVALID_PARAMETER, "expected %i, got %d\n", ok(!result && GetLastError()==ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n",
ERROR_INVALID_PARAMETER, GetLastError()); GetLastError());
/* check dwFlags == zero */ /* check dwFlags == zero */
result = pCryptEnumProviderTypesA(index, NULL, notZeroFlags, &provType, typeName, &typeNameSize); result = pCryptEnumProviderTypesA(index, NULL, notZeroFlags, &provType, typeName, &typeNameSize);
ok(!result && GetLastError()==NTE_BAD_FLAGS, "expected %i, got %d\n", ok(!result && GetLastError()==NTE_BAD_FLAGS, "expected ERROR_INVALID_PARAMETER, got %d\n",
ERROR_INVALID_PARAMETER, GetLastError()); GetLastError());
/* alloc provider type to half the size required
* cbTypeName holds the size required */
typeNameSize = cbTypeName / 2;
if (!(typeName = ((LPSTR)LocalAlloc(LMEM_ZEROINIT, typeNameSize))))
return;
/* This test fails under Win2k SP4: /* This test fails under Win2k SP4:
result = TRUE, GetLastError() == 0xdeadbeef * result = TRUE, GetLastError() == 0xdeadbeef */
SetLastError(0xdeadbeef); if (0)
result = pCryptEnumProviderTypesA(index, NULL, 0, &provType, typeName, &typeNameSize); {
ok(!result && GetLastError()==ERROR_MORE_DATA, "expected 0/ERROR_MORE_DATA, got %d/%08lx\n", /* alloc provider type to half the size required
result, GetLastError()); * cbTypeName holds the size required */
*/ typeNameSize = cbTypeName / 2;
if (!(typeName = ((LPSTR)LocalAlloc(LMEM_ZEROINIT, typeNameSize))))
LocalFree(typeName); goto cleanup;
SetLastError(0xdeadbeef);
result = pCryptEnumProviderTypesA(index, NULL, 0, &provType, typeName, &typeNameSize);
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 /* loop through the provider types to get the number of provider types
* after loop ends, count should be dwTypeCount + 1 so subtract 1 * after loop ends, count should be dwTypeCount + 1 so subtract 1
* to get actual number of provider types */ * to get actual number of provider types */
...@@ -669,30 +679,31 @@ static void test_enum_provider_types(void) ...@@ -669,30 +679,31 @@ static void test_enum_provider_types(void)
; ;
typeCount--; typeCount--;
ok(typeCount==dwTypeCount, "expected %d, got %d\n", dwTypeCount, typeCount); ok(typeCount==dwTypeCount, "expected %d, got %d\n", dwTypeCount, typeCount);
/* loop past the actual number of provider types to get the error /* loop past the actual number of provider types to get the error
* ERROR_NO_MORE_ITEMS */ * ERROR_NO_MORE_ITEMS */
for (typeCount = 0; typeCount < dwTypeCount + 1; typeCount++) for (typeCount = 0; typeCount < dwTypeCount + 1; typeCount++)
result = pCryptEnumProviderTypesA(typeCount, NULL, 0, &provType, NULL, &typeNameSize); result = pCryptEnumProviderTypesA(typeCount, NULL, 0, &provType, NULL, &typeNameSize);
ok(!result && GetLastError()==ERROR_NO_MORE_ITEMS, "expected %i, got %d\n", ok(!result && GetLastError()==ERROR_NO_MORE_ITEMS, "expected ERROR_NO_MORE_ITEMS, got %d\n",
ERROR_NO_MORE_ITEMS, GetLastError()); GetLastError());
/* check expected versus actual values returned */ /* check expected versus actual values returned */
result = pCryptEnumProviderTypesA(index, NULL, 0, &provType, NULL, &typeNameSize); result = pCryptEnumProviderTypesA(index, NULL, 0, &provType, NULL, &typeNameSize);
ok(result && typeNameSize==cbTypeName, "expected %d, got %d\n", cbTypeName, typeNameSize); ok(result && typeNameSize==cbTypeName, "expected %d, got %d\n", cbTypeName, typeNameSize);
if (!(typeName = ((LPSTR)LocalAlloc(LMEM_ZEROINIT, typeNameSize)))) if (!(typeName = ((LPSTR)LocalAlloc(LMEM_ZEROINIT, typeNameSize))))
return; goto cleanup;
typeNameSize = 0xdeadbeef; typeNameSize = 0xdeadbeef;
result = pCryptEnumProviderTypesA(index, NULL, 0, &provType, typeName, &typeNameSize); result = pCryptEnumProviderTypesA(index, NULL, 0, &provType, typeName, &typeNameSize);
ok(result, "expected TRUE, got %d\n", result); ok(result, "expected TRUE, got %d\n", result);
ok(provType==dwProvType, "expected %d, got %d\n", dwProvType, provType); ok(provType==dwProvType, "expected %d, got %d\n", dwProvType, provType);
if (pszTypeName) if (pszTypeName)
ok(!strcmp(pszTypeName, typeName), "expected %s, got %s\n", pszTypeName, typeName); ok(!strcmp(pszTypeName, typeName), "expected %s, got %s\n", pszTypeName, typeName);
ok(typeNameSize==cbTypeName, "expected %d, got %d\n", cbTypeName, typeNameSize); ok(typeNameSize==cbTypeName, "expected %d, got %d\n", cbTypeName, typeNameSize);
LocalFree(typeName); LocalFree(typeName);
cleanup:
LocalFree(pszTypeName);
} }
static BOOL FindDfltProvRegVals(DWORD dwProvType, DWORD dwFlags, LPSTR *pszProvName, DWORD *pcbProvName) 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