ReactOS 0.4.15-dev-7953-g1f49173
files.c File Reference
#include <stdio.h>
#include <windows.h>
#include <advpub.h>
#include <fci.h>
#include "wine/test.h"
Include dependency graph for files.c:

Go to the source code of this file.

Macros

#define MEDIA_SIZE   999999999
 
#define FOLDER_THRESHOLD   900000
 

Functions

static HRESULT (WINAPI *pAddDelBackupEntry)(LPCSTR
 
static void init_function_pointers (void)
 
static void createTestFile (const CHAR *name)
 
static void create_test_files (void)
 
static void delete_test_files (void)
 
static BOOL check_ini_file_attr (LPSTR filename)
 
static void test_AddDelBackupEntry (void)
 
static void *CDECL mem_alloc (ULONG cb)
 
static void CDECL mem_free (void *memory)
 
static BOOL CDECL get_next_cabinet (PCCAB pccab, ULONG cbPrevCab, void *pv)
 
static LONG CDECL progress (UINT typeStatus, ULONG cb1, ULONG cb2, void *pv)
 
static int CDECL file_placed (PCCAB pccab, char *pszFile, LONG cbFile, BOOL fContinuation, void *pv)
 
static INT_PTR CDECL fci_open (char *pszFile, int oflag, int pmode, int *err, void *pv)
 
static UINT CDECL fci_read (INT_PTR hf, void *memory, UINT cb, int *err, void *pv)
 
static UINT CDECL fci_write (INT_PTR hf, void *memory, UINT cb, int *err, void *pv)
 
static int CDECL fci_close (INT_PTR hf, int *err, void *pv)
 
static LONG CDECL fci_seek (INT_PTR hf, LONG dist, int seektype, int *err, void *pv)
 
static int CDECL fci_delete (char *pszFile, int *err, void *pv)
 
static BOOL CDECL get_temp_file (char *pszTempName, int cbTempName, void *pv)
 
static INT_PTR CDECL get_open_info (char *pszName, USHORT *pdate, USHORT *ptime, USHORT *pattribs, int *err, void *pv)
 
static void add_file (HFCI hfci, char *file)
 
static void set_cab_parameters (PCCAB pCabParams)
 
static void create_cab_file (void)
 
static void test_ExtractFiles (void)
 
static void test_AdvInstallFile (void)
 
 START_TEST (files)
 

Variables

static HMODULE hAdvPack
 
static LPCSTR
 
static DWORD
 
static LPVOID
 
static CHAR CURR_DIR [MAX_PATH]
 

Macro Definition Documentation

◆ FOLDER_THRESHOLD

#define FOLDER_THRESHOLD   900000

Definition at line 29 of file files.c.

◆ MEDIA_SIZE

#define MEDIA_SIZE   999999999

Definition at line 28 of file files.c.

Function Documentation

◆ add_file()

static void add_file ( HFCI  hfci,
char file 
)
static

Definition at line 330 of file files.c.

331{
332 char path[MAX_PATH];
333 BOOL res;
334
336 lstrcatA(path, "\\");
338
341 ok(res, "Expected FCIAddFile to succeed\n");
342}
#define ok(value,...)
Definition: atltest.h:57
cd_progress_ptr progress
Definition: cdjpeg.h:152
#define FALSE
Definition: types.h:117
#define MAX_PATH
Definition: compat.h:34
BOOL __cdecl FCIAddFile(HFCI hfci, char *pszSourceFile, char *pszFileName, BOOL fExecute, PFNFCIGETNEXTCABINET pfnfcignc, PFNFCISTATUS pfnfcis, PFNFCIGETOPENINFO pfnfcigoi, TCOMP typeCompress)
Definition: fci.c:1397
#define tcompTYPE_MSZIP
Definition: fci.h:65
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint res
Definition: glext.h:9613
LPSTR WINAPI lstrcpyA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:100
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
static CHAR CURR_DIR[MAX_PATH]
Definition: files.c:38
static BOOL CDECL get_next_cabinet(PCCAB pccab, ULONG cbPrevCab, void *pv)
Definition: files.c:194
static INT_PTR CDECL get_open_info(char *pszName, USHORT *pdate, USHORT *ptime, USHORT *pattribs, int *err, void *pv)
Definition: files.c:304
Definition: fci.c:127

Referenced by create_cab_file().

◆ check_ini_file_attr()

static BOOL check_ini_file_attr ( LPSTR  filename)
static

Definition at line 88 of file files.c.

89{
90 BOOL ret;
93
96
97 return ret;
98}
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI SetFileAttributesA(LPCSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:776
DWORD WINAPI GetFileAttributesA(LPCSTR lpFileName)
Definition: fileinfo.c:636
unsigned long DWORD
Definition: ntddk_ex.h:95
const char * filename
Definition: ioapi.h:137
BOOL expected
Definition: store.c:2063
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
Definition: cookie.c:202
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
int ret

Referenced by test_AddDelBackupEntry().

◆ create_cab_file()

static void create_cab_file ( void  )
static

Definition at line 356 of file files.c.

357{
358 CCAB cabParams;
359 HFCI hfci;
360 ERF erf;
361 static CHAR a_txt[] = "a.txt",
362 b_txt[] = "b.txt",
363 testdir_c_txt[] = "testdir\\c.txt",
364 testdir_d_txt[] = "testdir\\d.txt";
365 BOOL res;
366
367 set_cab_parameters(&cabParams);
368
371 get_temp_file, &cabParams, NULL);
372
373 ok(hfci != NULL, "Failed to create an FCI context\n");
374
375 add_file(hfci, a_txt);
376 add_file(hfci, b_txt);
377 add_file(hfci, testdir_c_txt);
378 add_file(hfci, testdir_d_txt);
379
381 ok(res, "Failed to flush the cabinet\n");
382
383 res = FCIDestroy(hfci);
384 ok(res, "Failed to destroy the cabinet\n");
385}
#define mem_free(ptr, bsize)
Definition: types.h:124
#define NULL
Definition: types.h:112
#define mem_alloc(bsize)
Definition: types.h:123
BOOL __cdecl FCIDestroy(HFCI hfci)
Definition: fci.c:1709
HFCI __cdecl FCICreate(PERF perf, PFNFCIFILEPLACED pfnfiledest, PFNFCIALLOC pfnalloc, PFNFCIFREE pfnfree, PFNFCIOPEN pfnopen, PFNFCIREAD pfnread, PFNFCIWRITE pfnwrite, PFNFCICLOSE pfnclose, PFNFCISEEK pfnseek, PFNFCIDELETE pfndelete, PFNFCIGETTEMPFILE pfnfcigtf, PCCAB pccab, void *pv)
Definition: fci.c:998
BOOL __cdecl FCIFlushCabinet(HFCI hfci, BOOL fGetNextCab, PFNFCIGETNEXTCABINET pfnfcignc, PFNFCISTATUS pfnfcis)
Definition: fci.c:1675
double __cdecl erf(double)
static UINT CDECL fci_write(INT_PTR hf, void *memory, UINT cb, int *err, void *pv)
Definition: files.c:246
static void add_file(HFCI hfci, char *file)
Definition: files.c:330
static BOOL CDECL get_temp_file(char *pszTempName, int cbTempName, void *pv)
Definition: files.c:285
static void set_cab_parameters(PCCAB pCabParams)
Definition: files.c:344
static UINT CDECL fci_read(INT_PTR hf, void *memory, UINT cb, int *err, void *pv)
Definition: files.c:234
static INT_PTR CDECL fci_open(char *pszFile, int oflag, int pmode, int *err, void *pv)
Definition: files.c:210
static int CDECL fci_delete(char *pszFile, int *err, void *pv)
Definition: files.c:277
static int CDECL file_placed(PCCAB pccab, char *pszFile, LONG cbFile, BOOL fContinuation, void *pv)
Definition: files.c:204
static LONG CDECL fci_seek(INT_PTR hf, LONG dist, int seektype, int *err, void *pv)
Definition: files.c:266
static int CDECL fci_close(INT_PTR hf, int *err, void *pv)
Definition: files.c:258
Definition: fci.h:144
Definition: fci.h:44
char CHAR
Definition: xmlstorage.h:175

Referenced by create_cc_test_files(), create_test_files(), START_TEST(), test_adminimage(), test_cabisextracted(), test_caborder(), test_file_in_use_cab(), test_lastusedsource(), test_missingcab(), test_mixedmedia(), and test_readonlyfile_cab().

◆ create_test_files()

static void create_test_files ( void  )
static

Definition at line 66 of file files.c.

67{
68 createTestFile("a.txt");
69 createTestFile("b.txt");
70 CreateDirectoryA("testdir", NULL);
71 createTestFile("testdir\\c.txt");
72 createTestFile("testdir\\d.txt");
73 CreateDirectoryA("dest", NULL);
74}
BOOL WINAPI CreateDirectoryA(IN LPCSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:37
static void createTestFile(const CHAR *name)
Definition: files.c:54

Referenced by START_TEST().

◆ createTestFile()

static void createTestFile ( const CHAR name)
static

Definition at line 54 of file files.c.

55{
57 DWORD written;
58
60 ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
61 WriteFile(file, name, strlen(name), &written, NULL);
62 WriteFile(file, "\n", strlen("\n"), &written, NULL);
64}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define CREATE_ALWAYS
Definition: disk.h:72
#define GENERIC_WRITE
Definition: nt_native.h:90
Definition: name.c:39

Referenced by create_test_files(), and test_AdvInstallFile().

◆ delete_test_files()

static void delete_test_files ( void  )
static

Definition at line 76 of file files.c.

77{
78 DeleteFileA("a.txt");
79 DeleteFileA("b.txt");
80 DeleteFileA("testdir\\c.txt");
81 DeleteFileA("testdir\\d.txt");
82 RemoveDirectoryA("testdir");
83 RemoveDirectoryA("dest");
84
85 DeleteFileA("extract.cab");
86}
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI RemoveDirectoryA(IN LPCSTR lpPathName)
Definition: dir.c:714

Referenced by START_TEST().

◆ fci_close()

static int CDECL fci_close ( INT_PTR  hf,
int err,
void pv 
)
static

Definition at line 258 of file files.c.

259{
260 HANDLE handle = (HANDLE)hf;
261 ok(CloseHandle(handle), "Failed to CloseHandle\n");
262
263 return 0;
264}
PVOID HANDLE
Definition: typedefs.h:73

Referenced by create_cab_file().

◆ fci_delete()

static int CDECL fci_delete ( char pszFile,
int err,
void pv 
)
static

Definition at line 277 of file files.c.

278{
279 BOOL ret = DeleteFileA(pszFile);
280 ok(ret, "Failed to DeleteFile %s\n", pszFile);
281
282 return 0;
283}

Referenced by create_cab_file().

◆ fci_open()

static INT_PTR CDECL fci_open ( char pszFile,
int  oflag,
int  pmode,
int err,
void pv 
)
static

Definition at line 210 of file files.c.

211{
213 DWORD dwAccess = 0;
214 DWORD dwShareMode = 0;
215 DWORD dwCreateDisposition = OPEN_EXISTING;
216
217 dwAccess = GENERIC_READ | GENERIC_WRITE;
218 /* FILE_SHARE_DELETE is not supported by Windows Me/98/95 */
219 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
220
222 dwCreateDisposition = OPEN_EXISTING;
223 else
224 dwCreateDisposition = CREATE_NEW;
225
226 handle = CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
227 dwCreateDisposition, 0, NULL);
228
229 ok(handle != INVALID_HANDLE_VALUE, "Failed to CreateFile %s\n", pszFile);
230
231 return (INT_PTR)handle;
232}
#define OPEN_EXISTING
Definition: compat.h:775
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
#define CREATE_NEW
Definition: disk.h:69
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
int32_t INT_PTR
Definition: typedefs.h:64

Referenced by create_cab_file().

◆ fci_read()

static UINT CDECL fci_read ( INT_PTR  hf,
void memory,
UINT  cb,
int err,
void pv 
)
static

Definition at line 234 of file files.c.

235{
236 HANDLE handle = (HANDLE)hf;
237 DWORD dwRead;
238 BOOL res;
239
240 res = ReadFile(handle, memory, cb, &dwRead, NULL);
241 ok(res, "Failed to ReadFile\n");
242
243 return dwRead;
244}
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
static char memory[1024 *256]
Definition: process.c:116

Referenced by create_cab_file().

◆ fci_seek()

static LONG CDECL fci_seek ( INT_PTR  hf,
LONG  dist,
int  seektype,
int err,
void pv 
)
static

Definition at line 266 of file files.c.

267{
268 HANDLE handle = (HANDLE)hf;
269 DWORD ret;
270
271 ret = SetFilePointer(handle, dist, NULL, seektype);
272 ok(ret != INVALID_SET_FILE_POINTER, "Failed to SetFilePointer\n");
273
274 return ret;
275}
#define INVALID_SET_FILE_POINTER
Definition: compat.h:732
#define SetFilePointer
Definition: compat.h:743

Referenced by create_cab_file().

◆ fci_write()

static UINT CDECL fci_write ( INT_PTR  hf,
void memory,
UINT  cb,
int err,
void pv 
)
static

Definition at line 246 of file files.c.

247{
248 HANDLE handle = (HANDLE)hf;
249 DWORD dwWritten;
250 BOOL res;
251
252 res = WriteFile(handle, memory, cb, &dwWritten, NULL);
253 ok(res, "Failed to WriteFile\n");
254
255 return dwWritten;
256}

Referenced by create_cab_file().

◆ file_placed()

static int CDECL file_placed ( PCCAB  pccab,
char pszFile,
LONG  cbFile,
BOOL  fContinuation,
void pv 
)
static

Definition at line 204 of file files.c.

206{
207 return 0;
208}

Referenced by create_cab_file().

◆ get_next_cabinet()

static BOOL CDECL get_next_cabinet ( PCCAB  pccab,
ULONG  cbPrevCab,
void pv 
)
static

Definition at line 194 of file files.c.

195{
196 return TRUE;
197}
#define TRUE
Definition: types.h:120

Referenced by add_file(), and create_cab_file().

◆ get_open_info()

static INT_PTR CDECL get_open_info ( char pszName,
USHORT pdate,
USHORT ptime,
USHORT pattribs,
int err,
void pv 
)
static

Definition at line 304 of file files.c.

306{
310 DWORD attrs;
311 BOOL res;
312
315
316 ok(handle != INVALID_HANDLE_VALUE, "Failed to CreateFile %s\n", pszName);
317
319 ok(res, "Expected GetFileInformationByHandle to succeed\n");
320
322 FileTimeToDosDateTime(&filetime, pdate, ptime);
323
324 attrs = GetFileAttributesA(pszName);
325 ok(attrs != INVALID_FILE_ATTRIBUTES, "Failed to GetFileAttributes\n");
326
327 return (INT_PTR)handle;
328}
BOOL WINAPI GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
Definition: fileinfo.c:458
BOOL WINAPI FileTimeToLocalFileTime(IN CONST FILETIME *lpFileTime, OUT LPFILETIME lpLocalFileTime)
Definition: time.c:221
BOOL WINAPI FileTimeToDosDateTime(IN CONST FILETIME *lpFileTime, OUT LPWORD lpFatDate, OUT LPWORD lpFatTime)
Definition: time.c:37
#define FILE_FLAG_SEQUENTIAL_SCAN
Definition: disk.h:43

Referenced by add_file(), and add_file_data().

◆ get_temp_file()

static BOOL CDECL get_temp_file ( char pszTempName,
int  cbTempName,
void pv 
)
static

Definition at line 285 of file files.c.

286{
287 LPSTR tempname;
288
289 tempname = HeapAlloc(GetProcessHeap(), 0, MAX_PATH);
290 GetTempFileNameA(".", "xx", 0, tempname);
291
292 if (tempname && (strlen(tempname) < (unsigned)cbTempName))
293 {
294 lstrcpyA(pszTempName, tempname);
295 HeapFree(GetProcessHeap(), 0, tempname);
296 return TRUE;
297 }
298
299 HeapFree(GetProcessHeap(), 0, tempname);
300
301 return FALSE;
302}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
Definition: filename.c:26
char * LPSTR
Definition: xmlstorage.h:182

Referenced by create_cab_file().

◆ HRESULT()

static HRESULT ( WINAPI pAddDelBackupEntry)
static

◆ init_function_pointers()

static void init_function_pointers ( void  )
static

Definition at line 40 of file files.c.

41{
42 hAdvPack = LoadLibraryA("advpack.dll");
43
44 if (hAdvPack)
45 {
46 pAddDelBackupEntry = (void *)GetProcAddress(hAdvPack, "AddDelBackupEntry");
47 pExtractFiles = (void *)GetProcAddress(hAdvPack, "ExtractFiles");
48 pExtractFilesW = (void *)GetProcAddress(hAdvPack, "ExtractFilesW");
49 pAdvInstallFile = (void*)GetProcAddress(hAdvPack, "AdvInstallFile");
50 }
51}
#define GetProcAddress(x, y)
Definition: compat.h:753
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
static HMODULE hAdvPack
Definition: files.c:32

Referenced by START_TEST().

◆ mem_alloc()

static void *CDECL mem_alloc ( ULONG  cb)
static

Definition at line 184 of file files.c.

185{
186 return HeapAlloc(GetProcessHeap(), 0, cb);
187}

◆ mem_free()

static void CDECL mem_free ( void memory)
static

Definition at line 189 of file files.c.

190{
192}

◆ progress()

static LONG CDECL progress ( UINT  typeStatus,
ULONG  cb1,
ULONG  cb2,
void pv 
)
static

Definition at line 199 of file files.c.

200{
201 return 0;
202}

◆ set_cab_parameters()

static void set_cab_parameters ( PCCAB  pCabParams)
static

Definition at line 344 of file files.c.

345{
346 ZeroMemory(pCabParams, sizeof(CCAB));
347
348 pCabParams->cb = MEDIA_SIZE;
349 pCabParams->cbFolderThresh = FOLDER_THRESHOLD;
350 pCabParams->setID = 0xbeef;
351 lstrcpyA(pCabParams->szCabPath, CURR_DIR);
352 lstrcatA(pCabParams->szCabPath, "\\");
353 lstrcpyA(pCabParams->szCab, "extract.cab");
354}
#define MEDIA_SIZE
Definition: files.c:28
#define FOLDER_THRESHOLD
Definition: files.c:29
ULONG cbFolderThresh
Definition: fci.h:146
USHORT setID
Definition: fci.h:157
char szCabPath[CB_MAX_CAB_PATH]
Definition: fci.h:161
ULONG cb
Definition: fci.h:145
char szCab[CB_MAX_CABINET_NAME]
Definition: fci.h:160
#define ZeroMemory
Definition: winbase.h:1712

Referenced by create_cab_file().

◆ START_TEST()

START_TEST ( files  )

Definition at line 546 of file files.c.

547{
548 DWORD len;
549 char temp_path[MAX_PATH], prev_path[MAX_PATH];
550
552
553 GetCurrentDirectoryA(MAX_PATH, prev_path);
556
559
560 if(len && (CURR_DIR[len - 1] == '\\'))
561 CURR_DIR[len - 1] = 0;
562
565
569
571
573 SetCurrentDirectoryA(prev_path);
574}
#define FreeLibrary(x)
Definition: compat.h:748
DWORD WINAPI GetCurrentDirectoryA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2146
BOOL WINAPI SetCurrentDirectoryA(IN LPCSTR lpPathName)
Definition: path.c:2206
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2054
GLenum GLsizei len
Definition: glext.h:6722
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
static void test_ExtractFiles(void)
Definition: files.c:387
static void delete_test_files(void)
Definition: files.c:76
static void init_function_pointers(void)
Definition: files.c:40
static void create_test_files(void)
Definition: files.c:66
static void test_AddDelBackupEntry(void)
Definition: files.c:100
static void test_AdvInstallFile(void)
Definition: files.c:492
static void create_cab_file(void)
Definition: files.c:356
char temp_path[MAX_PATH]
Definition: mspatcha.c:123

◆ test_AddDelBackupEntry()

static void test_AddDelBackupEntry ( void  )
static

Definition at line 100 of file files.c.

101{
102 BOOL ret;
103 HRESULT res;
105 CHAR windir[MAX_PATH];
106
108 lstrcatA(path, "\\backup\\basename.INI");
109
110 /* native AddDelBackupEntry crashes if lpcszBaseName is NULL */
111
112 /* try a NULL file list */
113 res = pAddDelBackupEntry(NULL, "backup", "basename", AADBE_ADD_ENTRY);
114 ok(res == S_OK, "Expected S_OK, got %d\n", res);
115 ok(!DeleteFileA(path), "Expected path to not exist\n");
116
118 lstrcatA(path, "\\backup\\.INI");
119
120 /* try an empty base name */
121 res = pAddDelBackupEntry("one\0two\0three\0", "backup", "", AADBE_ADD_ENTRY);
122 ok(res == S_OK, "Expected S_OK, got %d\n", res);
123 ok(!DeleteFileA(path), "Expected path to not exist\n");
124
126 lstrcatA(path, "\\basename.INI");
127
128 /* try an invalid flag */
129 res = pAddDelBackupEntry("one\0two\0three\0", NULL, "basename", 0);
130 ok(res == S_OK, "Expected S_OK, got %d\n", res);
131 ok(!DeleteFileA(path), "Expected path to not exist\n");
132
133 lstrcpyA(path, "c:\\basename.INI");
134
135 /* create the INF file */
136 res = pAddDelBackupEntry("one\0two\0three\0", "c:\\", "basename", AADBE_ADD_ENTRY);
137 ok(res == S_OK, "Expected S_OK, got %d\n", res);
139 {
140 ok(check_ini_file_attr(path), "Expected ini file to be hidden\n");
141 ok(DeleteFileA(path), "Expected path to exist\n");
142 }
143 else
144 win_skip("Test file could not be created\n");
145
147 lstrcatA(path, "\\backup\\basename.INI");
148
149 /* try to create the INI file in a nonexistent directory */
150 RemoveDirectoryA("backup");
151 res = pAddDelBackupEntry("one\0two\0three\0", "backup", "basename", AADBE_ADD_ENTRY);
152 ok(res == S_OK, "Expected S_OK, got %d\n", res);
153 ok(!check_ini_file_attr(path), "Expected ini file to not be hidden\n");
154 ok(!DeleteFileA(path), "Expected path to not exist\n");
155
156 /* try an existent, relative backup directory */
157 CreateDirectoryA("backup", NULL);
158 res = pAddDelBackupEntry("one\0two\0three\0", "backup", "basename", AADBE_ADD_ENTRY);
159 ok(res == S_OK, "Expected S_OK, got %d\n", res);
160 ok(check_ini_file_attr(path), "Expected ini file to be hidden\n");
161 ok(DeleteFileA(path), "Expected path to exist\n");
162 RemoveDirectoryA("backup");
163
164 GetWindowsDirectoryA(windir, sizeof(windir));
165 sprintf(path, "%s\\basename.INI", windir);
166
167 /* try a NULL backup dir, INI is created in the windows directory */
168 res = pAddDelBackupEntry("one\0two\0three\0", NULL, "basename", AADBE_ADD_ENTRY);
169 ok(res == S_OK, "Expected S_OK, got %d\n", res);
170
171 /* remove the entries with AADBE_DEL_ENTRY */
173 res = pAddDelBackupEntry("one\0three\0", NULL, "basename", AADBE_DEL_ENTRY);
175 ok(res == S_OK, "Expected S_OK, got %d\n", res);
177 ok(ret == TRUE ||
178 broken(ret == FALSE), /* win98 */
179 "Expected path to exist\n");
180}
#define broken(x)
Definition: _sntprintf.h:21
#define AADBE_DEL_ENTRY
Definition: advpub.h:116
#define AADBE_ADD_ENTRY
Definition: advpub.h:115
UINT WINAPI GetWindowsDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2337
#define S_OK
Definition: intsafe.h:52
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static BOOL check_ini_file_attr(LPSTR filename)
Definition: files.c:88
#define win_skip
Definition: test.h:160

Referenced by START_TEST().

◆ test_AdvInstallFile()

static void test_AdvInstallFile ( void  )
static

Definition at line 492 of file files.c.

493{
494 HRESULT hr;
496 char destFolder[MAX_PATH];
497
498 hmod = LoadLibraryA("setupapi.dll");
499 if (!hmod)
500 {
501 skip("setupapi.dll not present\n");
502 return;
503 }
504
506
507 lstrcpyA(destFolder, CURR_DIR);
508 lstrcatA(destFolder, "\\");
509 lstrcatA(destFolder, "dest");
510
511 createTestFile("source.txt");
512
513 /* try invalid source directory */
514 hr = pAdvInstallFile(NULL, NULL, "source.txt", destFolder, "destination.txt", 0, 0);
515 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
516 ok(!DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to not exist\n");
517
518 /* try invalid source file */
519 hr = pAdvInstallFile(NULL, CURR_DIR, NULL, destFolder, "destination.txt", 0, 0);
520 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
521 ok(!DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to not exist\n");
522
523 /* try invalid destination directory */
524 hr = pAdvInstallFile(NULL, CURR_DIR, "source.txt", NULL, "destination.txt", 0, 0);
525 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
526 ok(!DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to not exist\n");
527
528 /* try copying to nonexistent destination directory */
529 hr = pAdvInstallFile(NULL, CURR_DIR, "source.txt", destFolder, "destination.txt", 0, 0);
530 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
531 ok(DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to exist\n");
532
533 /* native windows screws up if the source file doesn't exist */
534
535 /* test AIF_NOOVERWRITE behavior, asks the user to overwrite if AIF_QUIET is not specified */
536 createTestFile("dest\\destination.txt");
537 hr = pAdvInstallFile(NULL, CURR_DIR, "source.txt", destFolder,
538 "destination.txt", AIF_NOOVERWRITE | AIF_QUIET, 0);
539 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
540 ok(DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to exist\n");
541 ok(RemoveDirectoryA("dest"), "Expected dest to exist\n");
542
543 DeleteFileA("source.txt");
544}
#define AIF_QUIET
Definition: advpub.h:127
#define AIF_NOOVERWRITE
Definition: advpub.h:123
#define skip(...)
Definition: atltest.h:64
#define E_INVALIDARG
Definition: ddrawi.h:101
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:143
HRESULT hr
Definition: shlfolder.c:183

Referenced by START_TEST().

◆ test_ExtractFiles()

static void test_ExtractFiles ( void  )
static

Definition at line 387 of file files.c.

388{
389 HRESULT hr;
390 char destFolder[MAX_PATH];
391
392 lstrcpyA(destFolder, CURR_DIR);
393 lstrcatA(destFolder, "\\");
394 lstrcatA(destFolder, "dest");
395
396 /* try NULL cab file */
397 hr = pExtractFiles(NULL, destFolder, 0, NULL, NULL, 0);
398 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
399 ok(RemoveDirectoryA("dest"), "Expected dest to exist\n");
400
401 /* try NULL destination */
402 hr = pExtractFiles("extract.cab", NULL, 0, NULL, NULL, 0);
403 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
404 ok(!RemoveDirectoryA("dest"), "Expected dest to not exist\n");
405
406 /* extract all files in the cab to nonexistent destination directory */
407 hr = pExtractFiles("extract.cab", destFolder, 0, NULL, NULL, 0);
409 hr == E_FAIL, /* win95 */
410 "Expected %08x or %08x, got %08x\n", E_FAIL,
412 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
413 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
414 ok(!RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to not exist\n");
415 ok(!RemoveDirectoryA("dest"), "Expected dest to not exist\n");
416
417 /* extract all files in the cab to the destination directory */
418 CreateDirectoryA("dest", NULL);
419 hr = pExtractFiles("extract.cab", destFolder, 0, NULL, NULL, 0);
420 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
421 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
422 ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
423 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
424 ok(DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n");
425 ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
426
427 /* extract all files to a relative destination directory */
428 hr = pExtractFiles("extract.cab", "dest", 0, NULL, NULL, 0);
429 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
430 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
431 ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
432 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
433 ok(DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n");
434 ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
435
436 /* only extract two of the files from the cab */
437 hr = pExtractFiles("extract.cab", "dest", 0, "a.txt:testdir\\c.txt", NULL, 0);
438 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
439 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
440 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
441 ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
442 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
443 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
444
445 /* use valid chars before and after file list */
446 hr = pExtractFiles("extract.cab", "dest", 0, " :\t: a.txt:testdir\\c.txt \t:", NULL, 0);
447 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
448 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
449 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
450 ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
451 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
452 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
453
454 /* use invalid chars before and after file list */
455 hr = pExtractFiles("extract.cab", "dest", 0, " +-\\ a.txt:testdir\\c.txt a_:", NULL, 0);
456 ok(hr == E_FAIL, "Expected E_FAIL, got %d\n", hr);
457 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
458 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
459 ok(!RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to not exist\n");
460
461 /* try an empty file list */
462 hr = pExtractFiles("extract.cab", "dest", 0, "", NULL, 0);
463 ok(hr == E_FAIL, "Expected E_FAIL, got %d\n", hr);
464 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
465 ok(!RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to not exist\n");
466
467 /* try a nonexistent file in the file list */
468 hr = pExtractFiles("extract.cab", "dest", 0, "a.txt:idontexist:testdir\\c.txt", NULL, 0);
469 ok(hr == E_FAIL, "Expected E_FAIL, got %d\n", hr);
470 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
471 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
472 ok(!RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to not exist\n");
473
474 if(pExtractFilesW) {
475 static const WCHAR extract_cabW[] = {'e','x','t','r','a','c','t','.','c','a','b',0};
476 static const WCHAR destW[] = {'d','e','s','t',0};
477 static const WCHAR file_listW[] =
478 {'a','.','t','x','t',':','t','e','s','t','d','i','r','\\','c','.','t','x','t',0};
479
480 hr = pExtractFilesW(extract_cabW, destW, 0, file_listW, NULL, 0);
481 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
482 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
483 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
484 ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
485 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
486 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
487 }else {
488 win_skip("ExtractFilesW not available\n");
489 }
490}
#define E_FAIL
Definition: ddrawi.h:102
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

Variable Documentation

◆ CURR_DIR

◆ DWORD

Definition at line 33 of file files.c.

◆ hAdvPack

HMODULE hAdvPack
static

Definition at line 32 of file files.c.

Referenced by init_function_pointers(), and START_TEST().

◆ LPCSTR

Definition at line 33 of file files.c.

◆ LPVOID

Definition at line 34 of file files.c.