1 /* 2 * Copyright 2017 Giannis Adamopoulos 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 17 */ 18 19 #include <stdarg.h> 20 #include <stdio.h> 21 22 #include "wine/test.h" 23 #include "windef.h" 24 #include "winbase.h" 25 #include "winerror.h" 26 27 HANDLE _CreateActCtxFromFile(LPCWSTR FileName, int line); 28 VOID _ActivateCtx(HANDLE h, ULONG_PTR *cookie, int line); 29 VOID _DeactivateCtx(ULONG_PTR cookie, int line); 30 31 typedef DWORD (WINAPI *LPGETVERSION)(); 32 33 VOID _TestVesion(HANDLE dll, DWORD ExpectedVersion, int line) 34 { 35 LPGETVERSION proc = (LPGETVERSION)GetProcAddress(dll, "GetVersion"); 36 DWORD version = proc(); 37 ok_(__FILE__, line)(version == ExpectedVersion, "Got version %lu, expected %lu\n", version, ExpectedVersion); 38 } 39 40 VOID TestDllRedirection() 41 { 42 HANDLE dll1, dll2, h; 43 ULONG_PTR cookie; 44 45 /* Try to load the libraries without sxs */ 46 dll1 = LoadLibraryExW(L"kernel32test_versioned.dll",0 , 0); 47 ok (dll1 != NULL, "LoadLibraryExW failed\n"); 48 dll2 = LoadLibraryExW(L"testdata\\kernel32test_versioned.dll",0 , 0); 49 ok (dll2 != NULL, "LoadLibraryExW failed\n"); 50 51 ok (dll1 != dll2, "\n"); 52 _TestVesion(dll1, 1, __LINE__); 53 _TestVesion(dll2, 2, __LINE__); 54 55 FreeLibrary(dll1); 56 FreeLibrary(dll2); 57 58 dll1 = LoadLibraryExW(L"kernel32test_versioned.dll",0 , 0); 59 ok (dll1 != NULL, "LoadLibraryExW failed\n"); 60 61 /* redir2dep.manifest defines an assembly with nothing but a dependency on redirtest2 assembly */ 62 /* redirtest2.manifest defines an assembly that contains kernel32test_versioned.dll */ 63 /* In win10 it is enought to load and activate redirtest2 */ 64 /* In win2k3 however the only way to trigger the redirection is to load and activate redir2dep */ 65 h = _CreateActCtxFromFile(L"testdata\\redir2dep.manifest", __LINE__); 66 _ActivateCtx(h, &cookie, __LINE__); 67 dll2 = LoadLibraryExW(L"kernel32test_versioned.dll",0 , 0); 68 _DeactivateCtx(cookie, __LINE__); 69 ok (dll2 != NULL, "LoadLibraryExW failed\n"); 70 71 ok (dll1 != dll2, "\n"); 72 _TestVesion(dll1, 1, __LINE__); 73 _TestVesion(dll2, 2, __LINE__); 74 75 FreeLibrary(dll1); 76 FreeLibrary(dll2); 77 78 dll1 = LoadLibraryExW(L"comctl32.dll",0 ,0); 79 ok (dll1 != NULL, "LoadLibraryExW failed\n"); 80 81 h = _CreateActCtxFromFile(L"comctl32dep.manifest", __LINE__); 82 _ActivateCtx(h, &cookie, __LINE__); 83 dll2 = LoadLibraryExW(L"comctl32.dll",0 , 0); 84 _DeactivateCtx(cookie, __LINE__); 85 ok (dll2 != NULL, "LoadLibraryExW failed\n"); 86 87 ok (dll1 != dll2, "\n"); 88 89 } 90 91 START_TEST(LoadLibraryExW) 92 { 93 TestDllRedirection(); 94 }