Paul Vriens : setupapi/tests: Add a test for installing a driver service via an INF file.

Alexandre Julliard julliard at winehq.org
Fri Mar 21 07:46:52 CDT 2008


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

Author: Paul Vriens <paul.vriens.wine at gmail.com>
Date:   Thu Mar 20 20:00:46 2008 +0100

setupapi/tests: Add a test for installing a driver service via an INF file.

---

 dlls/setupapi/tests/install.c |   94 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 89 insertions(+), 5 deletions(-)

diff --git a/dlls/setupapi/tests/install.c b/dlls/setupapi/tests/install.c
index 3145ae4..77c74f8 100644
--- a/dlls/setupapi/tests/install.c
+++ b/dlls/setupapi/tests/install.c
@@ -28,6 +28,7 @@
 #include "winnls.h"
 #include "winuser.h"
 #include "winreg.h"
+#include "winsvc.h"
 #include "setupapi.h"
 
 #include "wine/test.h"
@@ -83,10 +84,9 @@ static const char *cmdline_inf = "[Version]\n"
     "[Add.Settings]\n"
     "HKCU,Software\\Wine\\setupapitest,,\n";
 
-static void ok_cmdline(LPCSTR section, int mode, LPCSTR path, BOOL expectsuccess)
+static void run_cmdline(LPCSTR section, int mode, LPCSTR path)
 {
     CHAR cmdline[MAX_PATH * 2];
-    LONG ret;
 
     sprintf(cmdline, "%s %d %s", section, mode, path);
     if (pInstallHinfSectionA) pInstallHinfSectionA(NULL, NULL, cmdline, 0);
@@ -96,6 +96,11 @@ static void ok_cmdline(LPCSTR section, int mode, LPCSTR path, BOOL expectsuccess
         MultiByteToWideChar(CP_ACP, 0, cmdline, -1, cmdlinew, MAX_PATH*2);
         pInstallHinfSectionW(NULL, NULL, cmdlinew, 0);
     }
+}
+
+static void ok_registry(BOOL expectsuccess)
+{
+    LONG ret;
 
     /* Functional tests for success of install and clean up */
     ret = RegDeleteKey(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest");
@@ -114,21 +119,99 @@ static void test_cmdline(void)
 
     create_inf_file(inffile, cmdline_inf);
     sprintf(path, "%s\\%s", CURR_DIR, inffile);
-    ok_cmdline("DefaultInstall", 128, path, TRUE);
+    run_cmdline("DefaultInstall", 128, path);
+    ok_registry(TRUE);
     ok(DeleteFile(inffile), "Expected source inf to exist, last error was %d\n", GetLastError());
 
     /* Test handling of spaces in path, unquoted and quoted */
     create_inf_file(infwithspaces, cmdline_inf);
 
     sprintf(path, "%s\\%s", CURR_DIR, infwithspaces);
-    ok_cmdline("DefaultInstall", 128, path, TRUE);
+    run_cmdline("DefaultInstall", 128, path);
+    ok_registry(TRUE);
 
     sprintf(path, "\"%s\\%s\"", CURR_DIR, infwithspaces);
-    ok_cmdline("DefaultInstall", 128, path, FALSE);
+    run_cmdline("DefaultInstall", 128, path);
+    ok_registry(FALSE);
 
     ok(DeleteFile(infwithspaces), "Expected source inf to exist, last error was %d\n", GetLastError());
 }
 
+static void test_driver_install(void)
+{
+    HANDLE handle;
+    SC_HANDLE scm_handle, svc_handle;
+    BOOL ret;
+    char path[MAX_PATH], windir[MAX_PATH], driver[MAX_PATH];
+    DWORD attrs;
+    /* Minimal stuff needed */
+    static const char *inf =
+        "[Version]\n"
+        "Signature=\"$Chicago$\"\n"
+        "[DestinationDirs]\n"
+        "Winetest.DriverFiles=12\n"
+        "[DefaultInstall]\n"
+        "CopyFiles=Winetest.DriverFiles\n"
+        "[DefaultInstall.Services]\n"
+        "AddService=Winetest,,Winetest.Service\n"
+        "[Winetest.Service]\n"
+        "ServiceBinary=%12%\\winetest.sys\n"
+        "ServiceType=1\n"
+        "StartType=4\n"
+        "ErrorControl=1\n"
+        "[Winetest.DriverFiles]\n"
+        "winetest.sys";
+
+    /* Bail out if we are on win98 */
+    SetLastError(0xdeadbeef);
+    scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
+
+    if (!scm_handle && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
+    {
+        skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
+        return;
+    }
+    CloseServiceHandle(scm_handle);
+
+    /* Place where we expect the driver to be installed */
+    GetWindowsDirectoryA(windir, MAX_PATH);
+    lstrcpyA(driver, windir);
+    lstrcatA(driver, "\\system32\\drivers\\winetest.sys");
+
+    /* Create a dummy driver file */
+    handle = CreateFileA("winetest.sys", GENERIC_WRITE, 0, NULL,
+                           CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+    CloseHandle(handle);
+
+    create_inf_file(inffile, inf);
+    sprintf(path, "%s\\%s", CURR_DIR, inffile);
+    run_cmdline("DefaultInstall", 128, path);
+
+    /* Driver should have been installed */
+    attrs = GetFileAttributes(driver);
+    ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected driver to exist\n");
+
+    scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
+
+    /* Open the service to see if it's really there */
+    svc_handle = OpenServiceA(scm_handle, "Winetest", DELETE);
+    todo_wine
+    ok(svc_handle != NULL, "Service was not created\n");
+
+    SetLastError(0xdeadbeef);
+    ret = DeleteService(svc_handle);
+    todo_wine
+    ok(ret, "Service could not be deleted : %d\n", GetLastError());
+
+    CloseServiceHandle(svc_handle);
+    CloseServiceHandle(scm_handle);
+
+    /* File cleanup */
+    DeleteFile(inffile);
+    DeleteFile("winetest.sys");
+    DeleteFile(driver);
+}
+
 START_TEST(install)
 {
     HMODULE hsetupapi = GetModuleHandle("setupapi.dll");
@@ -171,6 +254,7 @@ START_TEST(install)
         assert(hhook != 0);
 
         test_cmdline();
+        test_driver_install();
 
         UnhookWindowsHookEx(hhook);
     }




More information about the wine-cvs mailing list