Fix version tests on NT, 2K and XP, make some errors more verbose.
[wine] / dlls / version / tests / install.c
1 /*
2  * Copyright (C) 2005 Stefan Leichter
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 #include "winver.h"
27
28 static void test_find_file(void)
29 {
30     DWORD ret;
31     UINT dwCur, dwOut ;
32     char appdir[MAX_PATH];
33     char curdir[MAX_PATH];
34     char filename[MAX_PATH];
35     char outBuf[MAX_PATH];
36     char windir[MAX_PATH];
37
38     memset(appdir, 0, MAX_PATH);
39     memset(windir, 0, MAX_PATH);
40
41     dwCur=MAX_PATH;
42     dwOut=MAX_PATH;
43     memset(curdir, 0, MAX_PATH);
44     memset(outBuf, 0, MAX_PATH);
45     ret = VerFindFileA(0, "regedit", "", "", curdir, &dwCur, outBuf, &dwOut);
46     ok(!ret, "Wrong return value got %lx expected 0\n", ret);
47     ok(dwCur == 1, "Wrong length of buffer for current location: "
48        "got %d(%s) expected 1\n", dwCur, curdir);
49     ok(dwOut == 1, "Wrong length of buffer for the recommended installation location: "
50        "got %d(%s) expected 1\n", dwOut, outBuf);
51
52     if(!GetWindowsDirectoryA(windir, MAX_PATH))
53         trace("GetWindowsDirectoryA failed\n");
54     else {
55         sprintf(appdir, "%s\\regedit.exe", windir);
56         if(INVALID_FILE_ATTRIBUTES == GetFileAttributesA(appdir))
57             trace("GetFileAttributesA(%s) failed\n", appdir);
58         else {
59             dwCur=MAX_PATH;
60             dwOut=MAX_PATH;
61             memset(curdir, 0, MAX_PATH);
62             memset(outBuf, 0, MAX_PATH);
63             ret = VerFindFileA(0, "regedit.exe", "", "", curdir, &dwCur, outBuf, &dwOut);
64             todo_wine ok(VFF_CURNEDEST == ret, "Wrong return value got %lx expected VFF_CURNEDEST\n", ret);
65             todo_wine ok(dwCur == 1 + strlen(windir), "Wrong length of buffer for current location: "
66                "got %d(%s) expected %d\n", dwCur, curdir, strlen(windir)+1);
67             ok(dwOut == 1, "Wrong length of buffer for the recommended installation location: "
68                "got %d(%s) expected 1\n", dwOut, outBuf);
69
70             dwCur=MAX_PATH;
71             dwOut=MAX_PATH;
72             memset(curdir, 0, MAX_PATH);
73             memset(outBuf, 0, MAX_PATH);
74             ret = VerFindFileA(0, "regedit.exe", NULL, NULL, curdir, &dwCur, outBuf, &dwOut);
75             todo_wine ok(VFF_CURNEDEST == ret, "Wrong return value got %lx expected VFF_CURNEDEST\n", ret);
76             todo_wine ok(dwCur == 1 + strlen(windir), "Wrong length of buffer for current location: "
77                "got %d(%s) expected %d\n", dwCur, curdir, strlen(windir)+1);
78             ok(dwOut == 1, "Wrong length of buffer for the recommended installation location: "
79                "got %d(%s) expected 1\n", dwOut, outBuf);
80         }
81     }
82     if(!GetModuleFileNameA(NULL, filename, MAX_PATH) ||
83        !GetSystemDirectoryA(windir, MAX_PATH) ||
84        !GetTempPathA(MAX_PATH, appdir))
85         trace("GetModuleFileNameA, GetSystemDirectoryA or GetTempPathA failed\n");
86     else {
87         char *p = strrchr(filename, '\\');
88         if(p) {
89             *(p++) ='\0';
90             SetCurrentDirectoryA(filename);
91             memmove(filename, p, 1 + strlen(p));
92         }
93
94         dwCur=MAX_PATH;
95         dwOut=MAX_PATH;
96         memset(outBuf, 0, MAX_PATH);
97         memset(curdir, 0, MAX_PATH);
98         ret = VerFindFileA(0, filename, NULL, NULL, curdir, &dwCur, outBuf, &dwOut);
99         todo_wine ok(VFF_CURNEDEST == ret, "Wrong return value got %lx expected VFF_CURNEDEST\n", ret);
100         ok(dwOut == 1, "Wrong length of buffer for the recommended installation location"
101            "got %d(%s) expected 1\n", dwOut, outBuf);
102
103         dwCur=MAX_PATH;
104         dwOut=MAX_PATH;
105         memset(outBuf, 0, MAX_PATH);
106         memset(curdir, 0, MAX_PATH);
107         ret = VerFindFileA(VFFF_ISSHAREDFILE, filename, NULL, appdir, curdir, &dwCur, outBuf, &dwOut);
108         todo_wine ok(VFF_CURNEDEST == ret, "Wrong return value got %lx expected VFF_CURNEDEST\n", ret);
109         ok(dwOut == 1 + strlen(windir), "Wrong length of buffer for current location: "
110            "got %d(%s) expected %d\n", dwOut, outBuf, strlen(windir)+1);
111
112         dwCur=MAX_PATH;
113         dwOut=MAX_PATH;
114         memset(outBuf, 0, MAX_PATH);
115         memset(curdir, 0, MAX_PATH);
116         ret = VerFindFileA(0, filename, NULL, appdir, curdir, &dwCur, outBuf, &dwOut);
117         todo_wine ok(VFF_CURNEDEST == ret, "Wrong return value got %lx expected VFF_CURNEDEST\n", ret);
118         ok(dwOut == 1 + strlen(appdir), "Wrong length of buffer for current location: "
119            "got %d(%s) expected %d\n", dwOut, outBuf, strlen(appdir)+1);
120     }
121 }
122
123 START_TEST(install)
124 {
125     test_find_file();
126 }