mscoree/tests: Add some tests for GetRequestedRuntimeInfo.
[wine] / dlls / mscoree / tests / mscoree.c
1 /*
2  * Copyright 2010 Louis Lenders
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 "corerror.h"
20 #include "mscoree.h"
21 #include "wine/test.h"
22
23 static HMODULE hmscoree;
24
25 static HRESULT (WINAPI *pGetCORVersion)(LPWSTR, DWORD, DWORD*);
26 static HRESULT (WINAPI *pGetCORSystemDirectory)(LPWSTR, DWORD, DWORD*);
27 static HRESULT (WINAPI *pGetRequestedRuntimeInfo)(LPCWSTR, LPCWSTR, LPCWSTR, DWORD, DWORD, LPWSTR, DWORD, DWORD*, LPWSTR, DWORD, DWORD*);
28
29 static BOOL init_functionpointers(void)
30 {
31     hmscoree = LoadLibraryA("mscoree.dll");
32
33     if (!hmscoree)
34     {
35         win_skip("mscoree.dll not available\n");
36         return FALSE;
37     }
38
39     pGetCORVersion = (void *)GetProcAddress(hmscoree, "GetCORVersion");
40     pGetCORSystemDirectory = (void *)GetProcAddress(hmscoree, "GetCORSystemDirectory");
41     pGetRequestedRuntimeInfo = (void *)GetProcAddress(hmscoree, "GetRequestedRuntimeInfo");
42
43     if (!pGetCORVersion || !pGetCORSystemDirectory || !pGetRequestedRuntimeInfo)
44     {
45         win_skip("functions not available\n");
46         FreeLibrary(hmscoree);
47         return FALSE;
48     }
49
50     return TRUE;
51 }
52
53 static void test_versioninfo(void)
54 {
55     const WCHAR v2_0[] = {'v','2','.','0','.','5','0','7','2','7',0};
56     const WCHAR v1_1[] = {'v','1','.','1','.','4','3','2','2',0};
57
58     WCHAR version[MAX_PATH];
59     WCHAR path[MAX_PATH];
60     DWORD size, path_len;
61     HRESULT hr;
62
63     hr =  pGetCORVersion(NULL, MAX_PATH, &size);
64     ok(hr == E_POINTER,"GetCORVersion returned %08x\n", hr);
65
66     hr =  pGetCORVersion(version, 1, &size);
67     ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER),"GetCORVersion returned %08x\n", hr);
68
69     hr =  pGetCORVersion(version, MAX_PATH, &size);
70     ok(hr == S_OK,"GetCORVersion returned %08x\n", hr);
71
72     trace("latest installed .net runtime: %s\n", wine_dbgstr_w(version));
73
74     hr = pGetCORSystemDirectory(path, MAX_PATH , &size);
75     ok(hr == S_OK, "GetCORSystemDirectory returned %08x\n", hr);
76     /* size includes terminating null-character */
77     ok(size == (lstrlenW(path) + 1),"size is %d instead of %d\n", size, (lstrlenW(path) + 1));
78
79     path_len = size;
80
81     hr = pGetCORSystemDirectory(path, path_len-1 , &size);
82     ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), "GetCORSystemDirectory returned %08x\n", hr);
83
84     hr = pGetCORSystemDirectory(NULL, MAX_PATH , &size);
85     ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), "GetCORSystemDirectory returned %08x\n", hr);
86
87     hr = pGetCORSystemDirectory(path, MAX_PATH , NULL);
88     ok(hr == E_POINTER,"GetCORSystemDirectory returned %08x\n", hr);
89
90     trace("latest installed .net installed in directory: %s\n", wine_dbgstr_w(path));
91
92     /* test GetRequestedRuntimeInfo, first get info about different versions of runtime */
93     hr = pGetRequestedRuntimeInfo( NULL, v2_0, NULL, 0, 0, path, MAX_PATH, &path_len, version, MAX_PATH, &size);
94
95     if(hr == CLR_E_SHIM_RUNTIME) return; /* skipping rest of tests on win2k as .net 2.0 not installed */
96
97     ok(hr == S_OK, "GetRequestedRuntimeInfo returned %08x\n", hr);
98     trace(" installed in directory %s is .net version %s \n", wine_dbgstr_w(path), wine_dbgstr_w(version));
99
100     hr = pGetRequestedRuntimeInfo( NULL, v1_1, NULL, 0, 0, path, MAX_PATH, &path_len, version, MAX_PATH, &size);
101     ok(hr == S_OK || CLR_E_SHIM_RUNTIME /*v1_1 not installed*/, "GetRequestedRuntimeInfo returned %08x\n", hr);
102     if(hr == S_OK)
103         trace(" installed in directory %s is .net version %s \n", wine_dbgstr_w(path), wine_dbgstr_w(version));
104     /* version number NULL not allowed without RUNTIME_INFO_UPGRADE_VERSION flag */
105     hr = pGetRequestedRuntimeInfo( NULL, NULL, NULL, 0, 0, path, MAX_PATH, &path_len, version, MAX_PATH, &size);
106     todo_wine ok(hr == CLR_E_SHIM_RUNTIME, "GetRequestedRuntimeInfo returned %08x\n", hr);
107     /* with RUNTIME_INFO_UPGRADE_VERSION flag and version number NULL, latest installed version is returned */
108     hr = pGetRequestedRuntimeInfo( NULL, NULL, NULL, 0, RUNTIME_INFO_UPGRADE_VERSION, path, MAX_PATH, &path_len, version, MAX_PATH, &size);
109     ok(hr == S_OK, "GetRequestedRuntimeInfo returned %08x\n", hr);
110
111     hr = pGetRequestedRuntimeInfo( NULL, v2_0, NULL, 0, 0, path, 1, &path_len, version, MAX_PATH, &size);
112     todo_wine ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), "GetRequestedRuntimeInfo returned %08x\n", hr);
113
114     /* if one of the buffers is NULL, the other one is still happily filled */
115     memset(version, 0, sizeof(version));
116     hr = pGetRequestedRuntimeInfo( NULL, v2_0, NULL, 0, 0, NULL, MAX_PATH, &path_len, version, MAX_PATH, &size);
117     ok(hr == S_OK, "GetRequestedRuntimeInfo returned %08x\n", hr);
118     ok(!lstrcmpW(version, v2_0), "version is %s , expected %s\n", wine_dbgstr_w(version), wine_dbgstr_w(v2_0));
119     /* With NULL-pointer for bufferlength, the buffer itsself still gets filled with correct string */
120     memset(version, 0, sizeof(version));
121     hr = pGetRequestedRuntimeInfo( NULL, v2_0, NULL, 0, 0, path, MAX_PATH, &path_len, version, MAX_PATH, NULL);
122     todo_wine ok(hr == S_OK, "GetRequestedRuntimeInfo returned %08x\n", hr);
123     todo_wine ok(!lstrcmpW(version, v2_0), "version is %s , expected %s\n", wine_dbgstr_w(version), wine_dbgstr_w(v2_0));
124 }
125
126 START_TEST(mscoree)
127 {
128     if (!init_functionpointers())
129         return;
130
131     test_versioninfo();
132
133     FreeLibrary(hmscoree);
134 }