1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799
|
/*
* Unit test for setupapi.dll install functions
*
* Copyright 2007 Misha Koshelev
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#include "winuser.h"
#include "winreg.h"
#include "winsvc.h"
#include "setupapi.h"
#include "shlobj.h"
#include "wine/test.h"
static const char inffile[] = "test.inf";
static const WCHAR inffileW[] = {'t','e','s','t','.','i','n','f',0};
static char CURR_DIR[MAX_PATH];
/* Notes on InstallHinfSectionA/W:
* - InstallHinfSectionA on WinXP seems to be a stub - it does not do anything
* and simply returns without displaying any error message or setting last
* error.
* - These functions do not return a value and do not always set last error to
* ERROR_SUCCESS when installation still occurs (e.g., unquoted inf file with
* spaces, registry keys are written but last error is 6).
* - On installation problems, a MessageBox() is displayed and a Beep() is
* issued. The MessageBox() is disabled with a CBT hook.
*/
/*
* Helpers
*/
static void create_inf_file(LPCSTR filename, const char *data)
{
DWORD res;
BOOL ret;
HANDLE handle = CreateFileA(filename, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
assert(handle != INVALID_HANDLE_VALUE);
ret = WriteFile(handle, data, strlen(data), &res, NULL);
assert(ret != 0);
CloseHandle(handle);
}
/* CBT hook to ensure a window (e.g., MessageBox) cannot be created */
static HHOOK hhook;
static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam)
{
return nCode == HCBT_CREATEWND ? 1: CallNextHookEx(hhook, nCode, wParam, lParam);
}
/*
* Tests
*/
static const char *cmdline_inf = "[Version]\n"
"Signature=\"$Chicago$\"\n"
"[DefaultInstall]\n"
"AddReg=Add.Settings\n"
"[Add.Settings]\n"
"HKCU,Software\\Wine\\setupapitest,,\n";
static void run_cmdline(LPCSTR section, int mode, LPCSTR path)
{
CHAR cmdline[MAX_PATH * 2];
WCHAR cmdlinew[MAX_PATH * 2];
sprintf(cmdline, "%s %d %s", section, mode, path);
MultiByteToWideChar(CP_ACP, 0, cmdline, -1, cmdlinew, MAX_PATH*2);
InstallHinfSectionW(NULL, NULL, cmdlinew, 0);
}
static void ok_registry(BOOL expectsuccess)
{
LONG ret;
/* Functional tests for success of install and clean up */
ret = RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest");
ok((expectsuccess && ret == ERROR_SUCCESS) ||
(!expectsuccess && ret == ERROR_FILE_NOT_FOUND),
"Expected registry key Software\\Wine\\setupapitest to %s, RegDeleteKey returned %d\n",
expectsuccess ? "exist" : "not exist",
ret);
}
/* Test command line processing */
static void test_cmdline(void)
{
static const char infwithspaces[] = "test file.inf";
char path[MAX_PATH];
BOOL ret;
create_inf_file(inffile, cmdline_inf);
sprintf(path, "%s\\%s", CURR_DIR, inffile);
run_cmdline("DefaultInstall", 128, path);
ok_registry(TRUE);
ret = DeleteFileA(inffile);
ok(ret, "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);
run_cmdline("DefaultInstall", 128, path);
ok_registry(TRUE);
sprintf(path, "\"%s\\%s\"", CURR_DIR, infwithspaces);
run_cmdline("DefaultInstall", 128, path);
ok_registry(FALSE);
ret = DeleteFileA(infwithspaces);
ok(ret, "Expected source inf to exist, last error was %d\n", GetLastError());
}
static const char *cmdline_inf_reg = "[Version]\n"
"Signature=\"$Chicago$\"\n"
"[DefaultInstall]\n"
"DelReg=Del.Settings\n"
"[Del.Settings]\n"
"HKCU,Software\\Wine\\setupapitest\n";
static void test_registry(void)
{
HKEY key;
LONG res;
char path[MAX_PATH];
BOOL ret;
/* First create a registry structure we would like to be deleted */
ok(!RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest", &key),
"Expected RegCreateKeyA to succeed\n");
/* Doublecheck if the registry key is present */
ok(!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest", &key),
"Expected registry key to exist\n");
create_inf_file(inffile, cmdline_inf_reg);
sprintf(path, "%s\\%s", CURR_DIR, inffile);
run_cmdline("DefaultInstall", 128, path);
/* Check if the registry key is recursively deleted */
res = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest", &key);
ok(res == ERROR_FILE_NOT_FOUND, "Didn't expect the registry key to exist\n");
/* Just in case */
if (res == ERROR_SUCCESS)
{
RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest");
RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest");
}
ret = DeleteFileA(inffile);
ok(ret, "Expected source inf to exist, last error was %d\n", GetLastError());
}
static void test_install_from(void)
{
char path[MAX_PATH];
HINF infhandle;
HKEY key;
LONG res;
BOOL ret;
/* First create a registry structure we would like to be deleted */
ok(!RegCreateKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest", &key),
"Expected RegCreateKeyA to succeed\n");
/* Doublecheck if the registry key is present */
ok(!RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest", &key),
"Expected registry key to exist\n");
create_inf_file(inffile, cmdline_inf_reg);
sprintf(path, "%s\\%s", CURR_DIR, inffile);
infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
SetLastError(0xdeadbeef);
ret = SetupInstallFromInfSectionA(NULL, infhandle, "DefaultInstall", SPINST_REGISTRY, key,
"A:\\", 0, NULL, NULL, NULL, NULL);
ok(ret, "Unexpected failure\n");
ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
/* Check if the registry key is recursively deleted */
res = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest", &key);
ok(res == ERROR_FILE_NOT_FOUND, "Didn't expect the registry key to exist\n");
/* Just in case */
if (res == ERROR_SUCCESS)
{
RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest\\setupapitest");
RegDeleteKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest");
}
SetupCloseInfFile(infhandle);
DeleteFileA(inffile);
}
static void test_install_svc_from(void)
{
char inf[2048];
char path[MAX_PATH];
HINF infhandle;
BOOL ret;
SC_HANDLE scm_handle, svc_handle;
/* Basic inf file to satisfy SetupOpenInfFileA */
strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n");
create_inf_file(inffile, inf);
sprintf(path, "%s\\%s", CURR_DIR, inffile);
infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
/* Nothing but the Version section */
SetLastError(0xdeadbeef);
ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
ok(!ret, "Expected failure\n");
ok(GetLastError() == ERROR_SECTION_NOT_FOUND,
"Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
SetupCloseInfFile(infhandle);
DeleteFileA(inffile);
/* Add the section */
strcat(inf, "[Winetest.Services]\n");
create_inf_file(inffile, inf);
infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
SetLastError(0xdeadbeef);
ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
ok(!ret, "Expected failure\n");
ok(GetLastError() == ERROR_SECTION_NOT_FOUND,
"Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
SetupCloseInfFile(infhandle);
DeleteFileA(inffile);
/* Add a reference */
strcat(inf, "AddService=Winetest,,Winetest.Service\n");
create_inf_file(inffile, inf);
infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
SetLastError(0xdeadbeef);
ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
ok(!ret, "Expected failure\n");
ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
"Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
SetupCloseInfFile(infhandle);
DeleteFileA(inffile);
/* Add the section */
strcat(inf, "[Winetest.Service]\n");
create_inf_file(inffile, inf);
infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
SetLastError(0xdeadbeef);
ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
ok(!ret, "Expected failure\n");
ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
"Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
SetupCloseInfFile(infhandle);
DeleteFileA(inffile);
/* Just the ServiceBinary */
strcat(inf, "ServiceBinary=%12%\\winetest.sys\n");
create_inf_file(inffile, inf);
infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
SetLastError(0xdeadbeef);
ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
ok(!ret, "Expected failure\n");
ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
"Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
SetupCloseInfFile(infhandle);
DeleteFileA(inffile);
/* Add the ServiceType */
strcat(inf, "ServiceType=1\n");
create_inf_file(inffile, inf);
infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
SetLastError(0xdeadbeef);
ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
ok(!ret, "Expected failure\n");
ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
"Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
SetupCloseInfFile(infhandle);
DeleteFileA(inffile);
/* Add the StartType */
strcat(inf, "StartType=4\n");
create_inf_file(inffile, inf);
infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
SetLastError(0xdeadbeef);
ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
ok(!ret, "Expected failure\n");
ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
"Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
SetupCloseInfFile(infhandle);
DeleteFileA(inffile);
/* This should be it, the minimal entries to install a service */
strcat(inf, "ErrorControl=1");
create_inf_file(inffile, inf);
infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
SetLastError(0xdeadbeef);
ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
{
skip("Not enough rights to install the service\n");
SetupCloseInfFile(infhandle);
DeleteFileA(inffile);
return;
}
ok(ret, "Expected success\n");
ok(GetLastError() == ERROR_SUCCESS,
"Expected ERROR_SUCCESS, got %08x\n", GetLastError());
SetupCloseInfFile(infhandle);
DeleteFileA(inffile);
scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
/* Open the service to see if it's really there */
svc_handle = OpenServiceA(scm_handle, "Winetest", DELETE);
ok(svc_handle != NULL, "Service was not created\n");
SetLastError(0xdeadbeef);
ret = DeleteService(svc_handle);
ok(ret, "Service could not be deleted : %d\n", GetLastError());
CloseServiceHandle(svc_handle);
CloseServiceHandle(scm_handle);
strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n");
strcat(inf, "[XSP.InstallPerVer]\n");
strcat(inf, "AddReg=AspEventlogMsg.Reg,Perf.Reg,AspVersions.Reg,FreeADO.Reg,IndexServer.Reg\n");
create_inf_file(inffile, inf);
sprintf(path, "%s\\%s", CURR_DIR, inffile);
infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
SetLastError(0xdeadbeef);
ret = SetupInstallServicesFromInfSectionA(infhandle, "XSP.InstallPerVer", 0);
ok(ret, "Expected success\n");
ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
SetupCloseInfFile(infhandle);
DeleteFileA(inffile);
/* TODO: Test the Flags */
}
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 don't have enough rights */
SetLastError(0xdeadbeef);
scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);
if (!scm_handle && (GetLastError() == ERROR_ACCESS_DENIED))
{
skip("Not enough rights to install the service\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 = GetFileAttributesA(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);
ok(svc_handle != NULL, "Service was not created\n");
SetLastError(0xdeadbeef);
ret = DeleteService(svc_handle);
ok(ret, "Service could not be deleted : %d\n", GetLastError());
CloseServiceHandle(svc_handle);
CloseServiceHandle(scm_handle);
/* File cleanup */
DeleteFileA(inffile);
DeleteFileA("winetest.sys");
DeleteFileA(driver);
}
static void test_profile_items(void)
{
char path[MAX_PATH], commonprogs[MAX_PATH];
static const char *inf =
"[Version]\n"
"Signature=\"$Chicago$\"\n"
"[DefaultInstall]\n"
"ProfileItems=TestItem,TestItem2,TestGroup\n"
"[TestItem]\n"
"Name=TestItem\n"
"CmdLine=11,,notepad.exe\n"
"[TestItem2]\n"
"Name=TestItem2\n"
"CmdLine=11,,notepad.exe\n"
"SubDir=TestDir\n"
"[TestGroup]\n"
"Name=TestGroup,4\n"
;
if (S_OK != SHGetFolderPathA(NULL, CSIDL_COMMON_PROGRAMS, NULL, SHGFP_TYPE_CURRENT, commonprogs))
{
skip("No common program files directory exists\n");
goto cleanup;
}
snprintf(path, MAX_PATH, "%s\\TestDir", commonprogs);
if (!CreateDirectoryA(path, NULL) && GetLastError() == ERROR_ACCESS_DENIED)
{
skip("need admin rights\n");
return;
}
RemoveDirectoryA(path);
create_inf_file(inffile, inf);
sprintf(path, "%s\\%s", CURR_DIR, inffile);
run_cmdline("DefaultInstall", 128, path);
snprintf(path, MAX_PATH, "%s\\TestItem.lnk", commonprogs);
snprintf(path, MAX_PATH, "%s\\TestDir", commonprogs);
ok(INVALID_FILE_ATTRIBUTES != GetFileAttributesA(path), "directory not created\n");
snprintf(path, MAX_PATH, "%s\\TestDir\\TestItem2.lnk", commonprogs);
ok(INVALID_FILE_ATTRIBUTES != GetFileAttributesA(path), "link not created\n");
snprintf(path, MAX_PATH, "%s\\TestGroup", commonprogs);
ok(INVALID_FILE_ATTRIBUTES != GetFileAttributesA(path), "group not created\n");
snprintf(path, MAX_PATH, "%s\\TestItem.lnk", commonprogs);
DeleteFileA(path);
snprintf(path, MAX_PATH, "%s\\TestDir\\TestItem2.lnk", commonprogs);
DeleteFileA(path);
snprintf(path, MAX_PATH, "%s\\TestItem2.lnk", commonprogs);
DeleteFileA(path);
snprintf(path, MAX_PATH, "%s\\TestDir", commonprogs);
RemoveDirectoryA(path);
snprintf(path, MAX_PATH, "%s\\TestGroup", commonprogs);
RemoveDirectoryA(path);
cleanup:
DeleteFileA(inffile);
}
static void test_inffilelistA(void)
{
static const char inffile2[] = "test2.inf";
static const char *inf =
"[Version]\n"
"Signature=\"$Chicago$\"";
char buffer[MAX_PATH] = { 0 };
char dir[MAX_PATH], *p;
DWORD expected, outsize;
BOOL ret;
/* create a private directory, the temp directory may contain some
* inf files left over from old installations
*/
if (!GetTempFileNameA(CURR_DIR, "inftest", 1, dir))
{
win_skip("GetTempFileNameA failed with error %d\n", GetLastError());
return;
}
if (!CreateDirectoryA(dir, NULL ))
{
win_skip("CreateDirectoryA(%s) failed with error %d\n", dir, GetLastError());
return;
}
if (!SetCurrentDirectoryA(dir))
{
win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError());
RemoveDirectoryA(dir);
return;
}
create_inf_file(inffile, inf);
create_inf_file(inffile2, inf);
/* mixed style
*/
expected = 3 + strlen(inffile) + strlen(inffile2);
ret = SetupGetInfFileListA(dir, INF_STYLE_OLDNT | INF_STYLE_WIN4, buffer,
MAX_PATH, &outsize);
ok(ret, "expected SetupGetInfFileListA to succeed!\n");
ok(expected == outsize, "expected required buffersize to be %d, got %d\n",
expected, outsize);
for(p = buffer; lstrlenA(p) && (outsize > (p - buffer)); p+=lstrlenA(p) + 1)
ok(!lstrcmpA(p,inffile2) || !lstrcmpA(p,inffile),
"unexpected filename %s\n",p);
DeleteFileA(inffile);
DeleteFileA(inffile2);
SetCurrentDirectoryA(CURR_DIR);
RemoveDirectoryA(dir);
}
static void test_inffilelist(void)
{
static const char inffile2[] = "test2.inf";
static const WCHAR inffile2W[] = {'t','e','s','t','2','.','i','n','f',0};
static const char invalid_inf[] = "invalid.inf";
static const WCHAR invalid_infW[] = {'i','n','v','a','l','i','d','.','i','n','f',0};
static const char *inf =
"[Version]\n"
"Signature=\"$Chicago$\"";
static const char *inf2 =
"[Version]\n"
"Signature=\"$CHICAGO$\"";
static const char *infNT =
"[Version]\n"
"Signature=\"$WINDOWS NT$\"";
WCHAR *p, *ptr;
char dirA[MAX_PATH];
WCHAR dir[MAX_PATH] = { 0 };
WCHAR buffer[MAX_PATH] = { 0 };
DWORD expected, outsize;
BOOL ret;
/* NULL means %windir%\\inf
* get the value as reference
*/
expected = 0;
SetLastError(0xdeadbeef);
ret = SetupGetInfFileListW(NULL, INF_STYLE_WIN4, NULL, 0, &expected);
ok(ret, "expected SetupGetInfFileListW to succeed! Error: %d\n", GetLastError());
ok(expected > 0, "expected required buffersize to be at least 1\n");
/* check if an empty string doesn't behaves like NULL */
outsize = 0;
SetLastError(0xdeadbeef);
ret = SetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
ok(!ret, "expected SetupGetInfFileListW to fail!\n");
/* create a private directory, the temp directory may contain some
* inf files left over from old installations
*/
if (!GetTempFileNameA(CURR_DIR, "inftest", 1, dirA))
{
win_skip("GetTempFileNameA failed with error %d\n", GetLastError());
return;
}
if (!CreateDirectoryA(dirA, NULL ))
{
win_skip("CreateDirectoryA(%s) failed with error %d\n", dirA, GetLastError());
return;
}
if (!SetCurrentDirectoryA(dirA))
{
win_skip("SetCurrentDirectoryA failed with error %d\n", GetLastError());
RemoveDirectoryA(dirA);
return;
}
MultiByteToWideChar(CP_ACP, 0, dirA, -1, dir, MAX_PATH);
/* check a not existing directory
*/
ptr = dir + lstrlenW(dir);
MultiByteToWideChar(CP_ACP, 0, "\\not_existent", -1, ptr, MAX_PATH - lstrlenW(dir));
outsize = 0xffffffff;
SetLastError(0xdeadbeef);
ret = SetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
ok(ret, "expected SetupGetInfFileListW to succeed!\n");
ok(outsize == 1, "expected required buffersize to be 1, got %d\n", outsize);
ok(ERROR_PATH_NOT_FOUND == GetLastError(),
"expected error ERROR_PATH_NOT_FOUND, got %d\n", GetLastError());
create_inf_file(inffile, inf);
create_inf_file(inffile2, inf);
create_inf_file(invalid_inf, "This content does not match the inf file format");
/* pass a filename instead of a directory
*/
*ptr = '\\';
MultiByteToWideChar(CP_ACP, 0, invalid_inf, -1, ptr+1, MAX_PATH - lstrlenW(dir));
outsize = 0xffffffff;
SetLastError(0xdeadbeef);
ret = SetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
ok(!ret, "expected SetupGetInfFileListW to fail!\n");
ok(ERROR_DIRECTORY == GetLastError(),
"expected error ERROR_DIRECTORY, got %d\n", GetLastError());
/* make the filename look like directory
*/
dir[1 + lstrlenW(dir)] = 0;
dir[lstrlenW(dir)] = '\\';
SetLastError(0xdeadbeef);
ret = SetupGetInfFileListW(dir, INF_STYLE_WIN4, NULL, 0, &outsize);
ok(!ret, "expected SetupGetInfFileListW to fail!\n");
ok(ERROR_DIRECTORY == GetLastError(),
"expected error ERROR_DIRECTORY, got %d\n", GetLastError());
/* now check the buffer contents of a valid call
*/
*ptr = 0;
expected = 3 + strlen(inffile) + strlen(inffile2);
ret = SetupGetInfFileListW(dir, INF_STYLE_WIN4, buffer, MAX_PATH, &outsize);
ok(ret, "expected SetupGetInfFileListW to succeed!\n");
ok(expected == outsize, "expected required buffersize to be %d, got %d\n",
expected, outsize);
for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1)
ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW),
"unexpected filename %s\n",wine_dbgstr_w(p));
/* upper case value
*/
create_inf_file(inffile2, inf2);
ret = SetupGetInfFileListW(dir, INF_STYLE_WIN4, buffer, MAX_PATH, &outsize);
ok(ret, "expected SetupGetInfFileListW to succeed!\n");
ok(expected == outsize, "expected required buffersize to be %d, got %d\n",
expected, outsize);
for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1)
ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW),
"unexpected filename %s\n",wine_dbgstr_w(p));
/* signature Windows NT is also inf style win4
*/
create_inf_file(inffile2, infNT);
expected = 3 + strlen(inffile) + strlen(inffile2);
ret = SetupGetInfFileListW(dir, INF_STYLE_WIN4, buffer, MAX_PATH, &outsize);
ok(ret, "expected SetupGetInfFileListW to succeed!\n");
ok(expected == outsize, "expected required buffersize to be %d, got %d\n",
expected, outsize);
for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1)
ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW),
"unexpected filename %s\n",wine_dbgstr_w(p));
/* old style
*/
expected = 2 + strlen(invalid_inf);
ret = SetupGetInfFileListW(dir, INF_STYLE_OLDNT, buffer, MAX_PATH, &outsize);
ok(ret, "expected SetupGetInfFileListW to succeed!\n");
ok(expected == outsize, "expected required buffersize to be %d, got %d\n",
expected, outsize);
for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1)
ok(!lstrcmpW(p,invalid_infW), "unexpected filename %s\n",wine_dbgstr_w(p));
/* mixed style
*/
expected = 4 + strlen(inffile) + strlen(inffile2) + strlen(invalid_inf);
ret = SetupGetInfFileListW(dir, INF_STYLE_OLDNT | INF_STYLE_WIN4, buffer,
MAX_PATH, &outsize);
ok(ret, "expected SetupGetInfFileListW to succeed!\n");
ok(expected == outsize, "expected required buffersize to be %d, got %d\n",
expected, outsize);
for(p = buffer; lstrlenW(p) && (outsize > (p - buffer)); p+=lstrlenW(p) + 1)
ok(!lstrcmpW(p,inffile2W) || !lstrcmpW(p,inffileW) || !lstrcmpW(p,invalid_infW),
"unexpected filename %s\n",wine_dbgstr_w(p));
DeleteFileA(inffile);
DeleteFileA(inffile2);
DeleteFileA(invalid_inf);
SetCurrentDirectoryA(CURR_DIR);
RemoveDirectoryA(dirA);
}
static const char dirid_inf[] = "[Version]\n"
"Signature=\"$Chicago$\"\n"
"[DefaultInstall]\n"
"AddReg=Add.Settings\n"
"[Add.Settings]\n"
"HKCU,Software\\Wine\\setupapitest,dirid,,%%%i%%\n";
static void check_dirid(int dirid, LPCSTR expected)
{
char buffer[sizeof(dirid_inf)+11];
char path[MAX_PATH], actual[MAX_PATH];
LONG ret;
DWORD size, type;
HKEY key;
sprintf(buffer, dirid_inf, dirid);
create_inf_file(inffile, buffer);
sprintf(path, "%s\\%s", CURR_DIR, inffile);
run_cmdline("DefaultInstall", 128, path);
size = sizeof(actual);
actual[0] = '\0';
ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\setupapitest", &key);
if (ret == ERROR_SUCCESS)
{
ret = RegQueryValueExA(key, "dirid", NULL, &type, (BYTE*)&actual, &size);
RegCloseKey(key);
if (type != REG_SZ)
ret = ERROR_FILE_NOT_FOUND;
}
ok(ret == ERROR_SUCCESS, "Failed getting value for dirid %i, err=%d\n", dirid, ret);
ok(!strcmp(actual, expected), "Expected path for dirid %i was \"%s\", got \"%s\"\n", dirid, expected, actual);
ok_registry(TRUE);
ret = DeleteFileA(inffile);
ok(ret, "Expected source inf to exist, last error was %d\n", GetLastError());
}
/* Test dirid values */
static void test_dirid(void)
{
char expected[MAX_PATH];
check_dirid(DIRID_NULL, "");
GetWindowsDirectoryA(expected, MAX_PATH);
check_dirid(DIRID_WINDOWS, expected);
GetSystemDirectoryA(expected, MAX_PATH);
check_dirid(DIRID_SYSTEM, expected);
strcat(expected, "\\unknown");
check_dirid(40, expected);
}
START_TEST(install)
{
char temp_path[MAX_PATH], prev_path[MAX_PATH];
DWORD len;
GetCurrentDirectoryA(MAX_PATH, prev_path);
GetTempPathA(MAX_PATH, temp_path);
SetCurrentDirectoryA(temp_path);
strcpy(CURR_DIR, temp_path);
len = strlen(CURR_DIR);
if(len && (CURR_DIR[len - 1] == '\\'))
CURR_DIR[len - 1] = 0;
/* Set CBT hook to disallow MessageBox creation in current thread */
hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
assert(hhook != 0);
test_cmdline();
test_registry();
test_install_from();
test_install_svc_from();
test_driver_install();
test_dirid();
UnhookWindowsHookEx(hhook);
/* We have to run this test after the CBT hook is disabled because
ProfileItems needs to create a window on Windows XP. */
test_profile_items();
test_inffilelist();
test_inffilelistA();
SetCurrentDirectoryA(prev_path);
}
|