Paul Vriens : crypt32: Add tests for CryptSIPRetrieveSubjectGuid.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Sep 26 15:04:46 CDT 2006


Module: wine
Branch: master
Commit: 3863939168459e5346cebd207920c4b8aad4cff7
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=3863939168459e5346cebd207920c4b8aad4cff7

Author: Paul Vriens <Paul.Vriens at xs4all.nl>
Date:   Tue Sep 26 16:11:08 2006 +0200

crypt32: Add tests for CryptSIPRetrieveSubjectGuid.

---

 dlls/crypt32/tests/sip.c |  167 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 167 insertions(+), 0 deletions(-)

diff --git a/dlls/crypt32/tests/sip.c b/dlls/crypt32/tests/sip.c
index 1a4db2d..04d2990 100644
--- a/dlls/crypt32/tests/sip.c
+++ b/dlls/crypt32/tests/sip.c
@@ -23,11 +23,25 @@ #include <stdarg.h>
 #include <windef.h>
 #include <winbase.h>
 #include <winerror.h>
+#include <winnls.h>
 #include <wincrypt.h>
 #include <mssip.h>
 
 #include "wine/test.h"
 
+static char *show_guid(const GUID *guid)
+{
+    static char guidstring[39];
+
+    sprintf(guidstring,
+        "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
+        guid->Data1, guid->Data2, guid->Data3,
+        guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
+        guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
+
+    return guidstring;
+}
+
 static void test_AddRemoveProvider(void)
 {
     BOOL ret;
@@ -104,6 +118,158 @@ static void test_AddRemoveProvider(void)
      GetLastError());
 }
 
+static void test_SIPRetrieveSubjectGUID(void)
+{
+    BOOL ret;
+    GUID subject;
+    HANDLE file;
+    static const CHAR windir[] = "windir";
+    static const CHAR regeditExe[] = "regedit.exe";
+    static const GUID nullSubject  = { 0x0, 0x0, 0x0, { 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 }};
+    static const WCHAR deadbeef[]  = { 'c',':','\\','d','e','a','d','b','e','e','f','.','d','b','f',0 };
+    /* Couldn't find a name for this GUID, it's the one used for 95% of the files */
+    static const GUID unknownGUID = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
+    static CHAR  regeditPath[MAX_PATH];
+    static WCHAR regeditPathW[MAX_PATH];
+    static CHAR path[MAX_PATH];
+    static CHAR tempfile[MAX_PATH];
+    static WCHAR tempfileW[MAX_PATH];
+    DWORD written;
+
+    /* NULL check */
+    SetLastError(0xdeadbeef);
+    ret = CryptSIPRetrieveSubjectGuid(NULL, NULL, NULL);
+    ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
+    todo_wine
+        ok (GetLastError() == ERROR_INVALID_PARAMETER,
+            "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
+
+    /* Test with a non-existent file (hopefully) */
+    SetLastError(0xdeadbeef);
+    /* Set subject to something other than zero's */
+    memset(&subject, 1, sizeof(GUID));
+    ret = CryptSIPRetrieveSubjectGuid(deadbeef, NULL, &subject);
+    ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
+    todo_wine
+    {
+        ok (GetLastError() == ERROR_FILE_NOT_FOUND,
+            "Expected ERROR_FILE_NOT_FOUND, got %ld.\n", GetLastError());
+        ok ( !memcmp(&subject, &nullSubject, sizeof(GUID)),
+            "Expected a NULL GUID for c:\\deadbeef.dbf, not %s\n", show_guid(&subject));
+    }
+
+    /* Now with an executable that should exist
+     *
+     * Use A-functions where possible as that should be available on all platforms
+     */
+    GetEnvironmentVariableA(windir, regeditPath, MAX_PATH);
+    sprintf(regeditPath, "%s\\%s", regeditPath, regeditExe);
+    MultiByteToWideChar( CP_ACP, 0, regeditPath,
+                         strlen(regeditPath)+1, regeditPathW,
+                         sizeof(regeditPathW)/sizeof(regeditPathW[0]) );
+
+    SetLastError(0xdeadbeef);
+    memset(&subject, 1, sizeof(GUID));
+    ret = CryptSIPRetrieveSubjectGuid(regeditPathW, NULL, &subject);
+    todo_wine
+    {
+        ok ( ret, "Expected CryptSIPRetrieveSubjectGuid to succeed\n");
+        ok ( GetLastError() == ERROR_SUCCESS,
+            "Expected ERROR_SUCCESS, got 0x%08lx\n", GetLastError());
+        ok ( !memcmp(&subject, &unknownGUID, sizeof(GUID)),
+            "Expected (%s), got (%s).\n", show_guid(&unknownGUID), show_guid(&subject));
+    }
+
+    /* The same thing but now with a handle instead of a filename */
+    file = CreateFileA(regeditPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
+    SetLastError(0xdeadbeef);
+    memset(&subject, 1, sizeof(GUID));
+    ret = CryptSIPRetrieveSubjectGuid(NULL, file, &subject);
+    todo_wine
+    {
+        ok ( ret, "Expected CryptSIPRetrieveSubjectGuid to succeed\n");
+        ok ( GetLastError() == ERROR_SUCCESS,
+            "Expected ERROR_SUCCESS, got 0x%08lx\n", GetLastError());
+        ok ( !memcmp(&subject, &unknownGUID, sizeof(GUID)),
+            "Expected (%s), got (%s).\n", show_guid(&unknownGUID), show_guid(&subject));
+    }
+    CloseHandle(file);
+
+    /* And both */
+    file = CreateFileA(regeditPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
+    SetLastError(0xdeadbeef);
+    memset(&subject, 1, sizeof(GUID));
+    ret = CryptSIPRetrieveSubjectGuid(regeditPathW, file, &subject);
+    todo_wine
+    {
+        ok ( ret, "Expected CryptSIPRetrieveSubjectGuid to succeed\n");
+        ok ( GetLastError() == ERROR_SUCCESS,
+            "Expected ERROR_SUCCESS, got 0x%08lx\n", GetLastError());
+        ok ( !memcmp(&subject, &unknownGUID, sizeof(GUID)),
+            "Expected (%s), got (%s).\n", show_guid(&unknownGUID), show_guid(&subject));
+    }
+    CloseHandle(file);
+
+    /* Now with an empty file */
+    GetTempPathA(sizeof(path), path);
+    GetTempFileNameA(path, "sip", 0 , tempfile);
+    MultiByteToWideChar( CP_ACP, 0, tempfile,
+                         strlen(tempfile)+1, tempfileW,
+                         sizeof(tempfileW)/sizeof(tempfileW[0]) );
+
+    SetLastError(0xdeadbeef);
+    memset(&subject, 1, sizeof(GUID));
+    ret = CryptSIPRetrieveSubjectGuid(tempfileW, NULL, &subject);
+    ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
+    todo_wine
+    {
+        ok ( GetLastError() == ERROR_FILE_INVALID ||
+             GetLastError() == S_OK /* Win98 */,
+            "Expected ERROR_FILE_INVALID or S_OK, got 0x%08lx\n", GetLastError());
+        ok ( !memcmp(&subject, &nullSubject, sizeof(GUID)),
+            "Expected a NULL GUID for empty file %s, not %s\n", tempfile, show_guid(&subject));
+    }
+
+    /* Use a file with a size of 3 (at least < 4) */
+    file = CreateFileA(tempfile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
+    WriteFile(file, "123", 3, &written, NULL);
+    CloseHandle(file);
+
+    SetLastError(0xdeadbeef);
+    memset(&subject, 1, sizeof(GUID));
+    ret = CryptSIPRetrieveSubjectGuid(tempfileW, NULL, &subject);
+    ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
+    todo_wine
+    {
+        ok ( GetLastError() == ERROR_INVALID_PARAMETER ||
+             GetLastError() == S_OK /* Win98 */,
+            "Expected ERROR_INVALID_PARAMETER or S_OK, got 0x%08lx\n", GetLastError());
+        ok ( !memcmp(&subject, &nullSubject, sizeof(GUID)),
+            "Expected a NULL GUID for empty file %s, not %s\n", tempfile, show_guid(&subject));
+    }
+
+    /* And now >= 4 */
+    file = CreateFileA(tempfile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
+    WriteFile(file, "1234", 4, &written, NULL);
+    CloseHandle(file);
+
+    SetLastError(0xdeadbeef);
+    memset(&subject, 1, sizeof(GUID));
+    ret = CryptSIPRetrieveSubjectGuid(tempfileW, NULL, &subject);
+    ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
+    todo_wine
+    {
+        ok ( GetLastError() == TRUST_E_SUBJECT_FORM_UNKNOWN ||
+             GetLastError() == S_OK /* Win98 */,
+            "Expected TRUST_E_SUBJECT_FORM_UNKNOWN or S_OK, got 0x%08lx\n", GetLastError());
+        ok ( !memcmp(&subject, &nullSubject, sizeof(GUID)),
+            "Expected a NULL GUID for empty file %s, not %s\n", tempfile, show_guid(&subject));
+    }
+
+    /* Clean up */
+    DeleteFileA(tempfile);
+}
+
 static void test_SIPLoad(void)
 {
     BOOL ret;
@@ -182,5 +348,6 @@ static void test_SIPLoad(void)
 START_TEST(sip)
 {
     test_AddRemoveProvider();
+    test_SIPRetrieveSubjectGUID();
     test_SIPLoad();
 }




More information about the wine-cvs mailing list