James Hawkins : msi: Test the file access and share modes of MsiOpenDatabase.

Alexandre Julliard julliard at winehq.org
Tue Aug 19 08:46:49 CDT 2008


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

Author: James Hawkins <jhawkins at codeweavers.com>
Date:   Mon Aug 18 23:04:16 2008 -0500

msi: Test the file access and share modes of MsiOpenDatabase.

---

 dlls/msi/tests/package.c |  171 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 171 insertions(+), 0 deletions(-)

diff --git a/dlls/msi/tests/package.c b/dlls/msi/tests/package.c
index 3eca228..1755d9b 100644
--- a/dlls/msi/tests/package.c
+++ b/dlls/msi/tests/package.c
@@ -6358,6 +6358,176 @@ static void test_sourcedir(void)
     DeleteFileA(msifile);
 }
 
+struct access_res
+{
+    BOOL gothandle;
+    DWORD lasterr;
+    BOOL todo;
+};
+
+struct access_res create[16] =
+{
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { TRUE, ERROR_SUCCESS, TRUE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { TRUE, ERROR_SUCCESS, TRUE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { TRUE, ERROR_SUCCESS, TRUE }
+};
+
+struct access_res create_commit[16] =
+{
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { TRUE, ERROR_SUCCESS, TRUE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { TRUE, ERROR_SUCCESS, TRUE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { FALSE, ERROR_SHARING_VIOLATION, FALSE },
+    { TRUE, ERROR_SUCCESS, TRUE }
+};
+
+struct access_res create_close[16] =
+{
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE },
+    { TRUE, ERROR_SUCCESS, FALSE }
+};
+
+static void _test_file_access(LPCSTR file, struct access_res *ares, DWORD line)
+{
+    DWORD access = 0, share = 0;
+    DWORD lasterr;
+    HANDLE hfile;
+    int i, j, idx = 0;
+
+    for (i = 0; i < 4; i++)
+    {
+        if (i == 0) access = 0;
+        if (i == 1) access = GENERIC_READ;
+        if (i == 2) access = GENERIC_WRITE;
+        if (i == 3) access = GENERIC_READ | GENERIC_WRITE;
+
+        for (j = 0; j < 4; j++)
+        {
+            if (j == 0) share = 0;
+            if (j == 1) share = FILE_SHARE_READ;
+            if (j == 2) share = FILE_SHARE_WRITE;
+            if (j == 3) share = FILE_SHARE_READ | FILE_SHARE_WRITE;
+
+            SetLastError(0xdeadbeef);
+            hfile = CreateFileA(file, access, share, NULL, OPEN_EXISTING,
+                                FILE_ATTRIBUTE_NORMAL, 0);
+            lasterr = GetLastError();
+            if (ares[idx].todo)
+            {
+                todo_wine
+                {
+                    ok((hfile != INVALID_HANDLE_VALUE) == ares[idx].gothandle,
+                       "(%d, handle, %d): Expected %d, got %d\n",
+                       line, idx, ares[idx].gothandle,
+                       (hfile != INVALID_HANDLE_VALUE));
+                }
+            }
+            else
+                ok((hfile != INVALID_HANDLE_VALUE) == ares[idx].gothandle,
+                   "(%d, handle, %d): Expected %d, got %d\n",
+                   line, idx, ares[idx].gothandle,
+                   (hfile != INVALID_HANDLE_VALUE));
+
+            if (ares[idx].todo)
+            {
+                todo_wine
+                {
+                    ok(lasterr == ares[idx].lasterr,
+                       "(%d, lasterr, %d): Expected %d, got %d\n",
+                       line, idx, ares[idx].lasterr, lasterr);
+                }
+            }
+            else
+            {
+                ok(lasterr == ares[idx].lasterr,
+                   "(%d, lasterr, %d): Expected %d, got %d\n",
+                   line, idx, ares[idx].lasterr, lasterr);
+            }
+
+            CloseHandle(hfile);
+            idx++;
+        }
+    }
+}
+
+#define test_file_access(file, ares) _test_file_access(file, ares, __LINE__)
+
+static void test_access(void)
+{
+    MSIHANDLE hdb;
+    UINT r;
+
+    r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATE, &hdb);
+    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
+
+    test_file_access(msifile, create);
+
+    r = MsiDatabaseCommit(hdb);
+    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
+
+    test_file_access(msifile, create_commit);
+
+    MsiCloseHandle(hdb);
+
+    test_file_access(msifile, create_close);
+
+    DeleteFileA(msifile);
+
+    r = MsiOpenDatabaseA(msifile, MSIDBOPEN_CREATEDIRECT, &hdb);
+    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
+
+    test_file_access(msifile, create);
+
+    r = MsiDatabaseCommit(hdb);
+    ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", r);
+
+    test_file_access(msifile, create_commit);
+
+    MsiCloseHandle(hdb);
+
+    test_file_access(msifile, create_close);
+
+    DeleteFileA(msifile);
+}
+
 START_TEST(package)
 {
     GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
@@ -6383,4 +6553,5 @@ START_TEST(package)
     test_MsiGetSourcePath();
     test_shortlongsource();
     test_sourcedir();
+    test_access();
 }




More information about the wine-cvs mailing list