From 25b97799b4b36f1af133100d16f5c9cc5758ae8a Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Tue, 22 Apr 2014 11:40:41 +0000 Subject: [PATCH] [CABINET_WINETEST] * Sync with Wine 1.7.17. CORE-8080 svn path=/trunk/; revision=62875 --- rostests/winetests/cabinet/CMakeLists.txt | 3 +- rostests/winetests/cabinet/extract.c | 10 +- rostests/winetests/cabinet/fdi.c | 251 +++++++++++++++++++++- 3 files changed, 253 insertions(+), 11 deletions(-) diff --git a/rostests/winetests/cabinet/CMakeLists.txt b/rostests/winetests/cabinet/CMakeLists.txt index 1afec1771a7..faab5d8fd6d 100644 --- a/rostests/winetests/cabinet/CMakeLists.txt +++ b/rostests/winetests/cabinet/CMakeLists.txt @@ -1,7 +1,6 @@ add_definitions(-DUSE_WINE_TODOS) add_executable(cabinet_winetest extract.c fdi.c testlist.c) -target_link_libraries(cabinet_winetest wine) set_module_type(cabinet_winetest win32cui) -add_importlibs(cabinet_winetest cabinet msvcrt kernel32 ntdll) +add_importlibs(cabinet_winetest cabinet msvcrt kernel32) add_cd_file(TARGET cabinet_winetest DESTINATION reactos/bin FOR all) diff --git a/rostests/winetests/cabinet/extract.c b/rostests/winetests/cabinet/extract.c index 45387be85fe..c790af8baa2 100644 --- a/rostests/winetests/cabinet/extract.c +++ b/rostests/winetests/cabinet/extract.c @@ -240,8 +240,8 @@ static INT_PTR CDECL get_open_info(char *pszName, USHORT *pdate, USHORT *ptime, DWORD attrs; BOOL res; - handle = CreateFile(pszName, GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); + handle = CreateFileA(pszName, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); ok(handle != INVALID_HANDLE_VALUE, "Failed to CreateFile %s\n", pszName); @@ -251,7 +251,7 @@ static INT_PTR CDECL get_open_info(char *pszName, USHORT *pdate, USHORT *ptime, FileTimeToLocalFileTime(&finfo.ftLastWriteTime, &filetime); FileTimeToDosDateTime(&filetime, pdate, ptime); - attrs = GetFileAttributes(pszName); + attrs = GetFileAttributesA(pszName); ok(attrs != INVALID_FILE_ATTRIBUTES, "Failed to GetFileAttributes\n"); return (INT_PTR)handle; @@ -623,7 +623,7 @@ static void test_Extract(void) /* first file exists */ createTestFile("dest\\a.txt"); - SetFileAttributes("dest\\a.txt", FILE_ATTRIBUTE_READONLY); + SetFileAttributesA("dest\\a.txt", FILE_ATTRIBUTE_READONLY); ZeroMemory(&session, sizeof(SESSION)); lstrcpyA(session.Destination, "dest"); session.Operation = EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES; @@ -665,7 +665,7 @@ static void test_Extract(void) /* third file exists */ createTestFile("dest\\testdir\\c.txt"); - SetFileAttributes("dest\\testdir\\c.txt", FILE_ATTRIBUTE_READONLY); + SetFileAttributesA("dest\\testdir\\c.txt", FILE_ATTRIBUTE_READONLY); ZeroMemory(&session, sizeof(SESSION)); lstrcpyA(session.Destination, "dest"); session.Operation = EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES; diff --git a/rostests/winetests/cabinet/fdi.c b/rostests/winetests/cabinet/fdi.c index 507d9c19a54..2c0d78ccd3a 100644 --- a/rostests/winetests/cabinet/fdi.c +++ b/rostests/winetests/cabinet/fdi.c @@ -2,6 +2,7 @@ * Unit tests for the File Decompression Interface * * Copyright (C) 2006 James Hawkins + * Copyright (C) 2013 Dmitry Timoshkov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -18,7 +19,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -//#include +#include //#include #include #include @@ -30,6 +31,105 @@ static CHAR CURR_DIR[MAX_PATH]; +/* avoid including CRT headers */ +#ifndef _O_BINARY +# define _O_BINARY 0x8000 +#endif + +#ifndef _S_IREAD +# define _S_IREAD 0x0100 +# define _S_IWRITE 0x0080 +#endif + +#include + +struct CFHEADER +{ + UCHAR signature[4]; /* file signature */ + ULONG reserved1; /* reserved */ + ULONG cbCabinet; /* size of this cabinet file in bytes */ + ULONG reserved2; /* reserved */ + ULONG coffFiles; /* offset of the first CFFILE entry */ + ULONG reserved3; /* reserved */ + UCHAR versionMinor; /* cabinet file format version, minor */ + UCHAR versionMajor; /* cabinet file format version, major */ + USHORT cFolders; /* number of CFFOLDER entries in this cabinet */ + USHORT cFiles; /* number of CFFILE entries in this cabinet */ + USHORT flags; /* cabinet file option indicators */ + USHORT setID; /* must be the same for all cabinets in a set */ + USHORT iCabinet; /* number of this cabinet file in a set */ +#if 0 + USHORT cbCFHeader; /* (optional) size of per-cabinet reserved area */ + UCHAR cbCFFolder; /* (optional) size of per-folder reserved area */ + UCHAR cbCFData; /* (optional) size of per-datablock reserved area */ + UCHAR abReserve; /* (optional) per-cabinet reserved area */ + UCHAR szCabinetPrev; /* (optional) name of previous cabinet file */ + UCHAR szDiskPrev; /* (optional) name of previous disk */ + UCHAR szCabinetNext; /* (optional) name of next cabinet file */ + UCHAR szDiskNext; /* (optional) name of next disk */ +#endif +}; + +struct CFFOLDER +{ + ULONG coffCabStart; /* offset of the first CFDATA block in this folder */ + USHORT cCFData; /* number of CFDATA blocks in this folder */ + USHORT typeCompress; /* compression type indicator */ +#if 0 + UCHAR abReserve[]; /* (optional) per-folder reserved area */ +#endif +}; + +struct CFFILE +{ + ULONG cbFile; /* uncompressed size of this file in bytes */ + ULONG uoffFolderStart; /* uncompressed offset of this file in the folder */ + USHORT iFolder; /* index into the CFFOLDER area */ + USHORT date; /* date stamp for this file */ + USHORT time; /* time stamp for this file */ + USHORT attribs; /* attribute flags for this file */ +#if 0 + UCHAR szName[]; /* name of this file */ +#endif +}; + +struct CFDATA +{ + ULONG csum; /* checksum of this CFDATA entry */ + USHORT cbData; /* number of compressed bytes in this block */ + USHORT cbUncomp; /* number of uncompressed bytes in this block */ +#if 0 + UCHAR abReserve[]; /* (optional) per-datablock reserved area */ + UCHAR ab[cbData]; /* compressed data bytes */ +#endif +}; + +static const struct +{ + struct CFHEADER header; + struct CFFOLDER folder; + struct CFFILE file; + UCHAR szName[sizeof("file.dat")]; + struct CFDATA data; + UCHAR ab[sizeof("Hello World!")-1]; +} cab_data = +{ + { {'M','S','C','F'}, 0, 0x59, 0, sizeof(struct CFHEADER) + sizeof(struct CFFOLDER), 0, 3,1, 1, 1, 0, 0x1225, 0x2013 }, + { sizeof(struct CFHEADER) + sizeof(struct CFFOLDER) + sizeof(struct CFFILE) + sizeof("file.dat"), 1, tcompTYPE_NONE }, + { sizeof("Hello World!")-1, 0, 0, 0x1225, 0x2013, 0xa114 }, + { 'f','i','l','e','.','d','a','t',0 }, + { 0, sizeof("Hello World!")-1, sizeof("Hello World!")-1 }, + { 'H','e','l','l','o',' ','W','o','r','l','d','!' } +}; + +#include + +struct mem_data +{ + const char *base; + LONG size, pos; +}; + /* FDI callbacks */ static void * CDECL fdi_alloc(ULONG cb) @@ -440,8 +540,8 @@ static INT_PTR CDECL get_open_info(char *pszName, USHORT *pdate, USHORT *ptime, DWORD attrs; BOOL res; - handle = CreateFile(pszName, GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); + handle = CreateFileA(pszName, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); ok(handle != INVALID_HANDLE_VALUE, "Failed to CreateFile %s\n", pszName); @@ -451,7 +551,7 @@ static INT_PTR CDECL get_open_info(char *pszName, USHORT *pdate, USHORT *ptime, FileTimeToLocalFileTime(&finfo.ftLastWriteTime, &filetime); FileTimeToDosDateTime(&filetime, pdate, ptime); - attrs = GetFileAttributes(pszName); + attrs = GetFileAttributesA(pszName); ok(attrs != INVALID_FILE_ATTRIBUTES, "Failed to GetFileAttributes\n"); /* fixme: should convert attrs to *pattribs, make sure * have a test that catches the fact that we don't? @@ -592,6 +692,120 @@ static INT_PTR __cdecl CopyProgress(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION return 0; } +static INT_PTR CDECL fdi_mem_open(char *name, int oflag, int pmode) +{ + static const char expected[] = "memory\\block"; + struct mem_data *data; + + ok(!strcmp(name, expected), "expected %s, got %s\n", expected, name); + ok(oflag == _O_BINARY, "expected _O_BINARY, got %x\n", oflag); + ok(pmode == (_S_IREAD | _S_IWRITE), "expected _S_IREAD | _S_IWRITE, got %x\n", pmode); + + data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data)); + if (!data) return -1; + + data->base = (const char *)&cab_data; + data->size = sizeof(cab_data); + data->pos = 0; + + trace("mem_open(%s,%x,%x) => %p\n", name, oflag, pmode, data); + return (INT_PTR)data; +} + +static UINT CDECL fdi_mem_read(INT_PTR hf, void *pv, UINT cb) +{ + struct mem_data *data = (struct mem_data *)hf; + UINT available, cb_read; + + available = data->size - data->pos; + cb_read = (available >= cb) ? cb : available; + + memcpy(pv, data->base + data->pos, cb_read); + data->pos += cb_read; + + /*trace("mem_read(%p,%p,%u) => %u\n", hf, pv, cb, cb_read);*/ + return cb_read; +} + +static UINT CDECL fdi_mem_write(INT_PTR hf, void *pv, UINT cb) +{ + static const char expected[12] = "Hello World!"; + + trace("mem_write(%#lx,%p,%u)\n", hf, pv, cb); + + ok(hf == 0x12345678, "expected 0x12345678, got %#lx\n", hf); + ok(cb == 12, "expected 12, got %u\n", cb); + ok(!memcmp(pv, expected, 12), "expected %s, got %s\n", expected, (const char *)pv); + + return cb; +} + +static int CDECL fdi_mem_close(INT_PTR hf) +{ + HeapFree(GetProcessHeap(), 0, (void *)hf); + return 0; +} + +static LONG CDECL fdi_mem_seek(INT_PTR hf, LONG dist, int seektype) +{ + struct mem_data *data = (struct mem_data *)hf; + + switch (seektype) + { + case SEEK_SET: + data->pos = dist; + break; + + case SEEK_CUR: + data->pos += dist; + break; + + case SEEK_END: + default: + ok(0, "seek: not expected type %d\n", seektype); + return -1; + } + + if (data->pos < 0) data->pos = 0; + if (data->pos > data->size) data->pos = data->size; + + /*mem_seek(%p,%d,%d) => %u\n", hf, dist, seektype, data->pos);*/ + return data->pos; +} + +static INT_PTR CDECL fdi_mem_notify(FDINOTIFICATIONTYPE fdint, FDINOTIFICATION *info) +{ + static const char expected[9] = "file.dat\0"; + + switch (fdint) + { + case fdintCLOSE_FILE_INFO: + trace("mem_notify: CLOSE_FILE_INFO %s, handle %#lx\n", info->psz1, info->hf); + + ok(!strcmp(info->psz1, expected), "expected %s, got %s\n", expected, info->psz1); + ok(info->date == 0x1225, "expected 0x1225, got %#x\n", info->date); + ok(info->time == 0x2013, "expected 0x2013, got %#x\n", info->time); + ok(info->attribs == 0xa114, "expected 0xa114, got %#x\n", info->attribs); + ok(info->iFolder == 0, "expected 0, got %#x\n", info->iFolder); + return 1; + + case fdintCOPY_FILE: + { + trace("mem_notify: COPY_FILE %s, %d bytes\n", info->psz1, info->cb); + + ok(info->cb == 12, "expected 12, got %u\n", info->cb); + ok(!strcmp(info->psz1, expected), "expected %s, got %s\n", expected, info->psz1); + return 0x12345678; /* call write() callback */ + } + + default: + trace("mem_notify(%d,%p)\n", fdint, info); + return 0; + } + + return 0; +} + static void test_FDICopy(void) { CCAB cabParams; @@ -601,6 +815,11 @@ static void test_FDICopy(void) BOOL ret; char name[] = "extract.cab"; char path[MAX_PATH + 1]; + char memory_block[] = "memory\\block"; + char memory[] = "memory\\"; + char block[] = "block"; + FDICABINETINFO info; + INT_PTR fd; set_cab_parameters(&cabParams); @@ -648,6 +867,30 @@ static void test_FDICopy(void) FDIDestroy(hfdi); DeleteFileA(name); + + /* test extracting from a memory block */ + hfdi = FDICreate(fdi_alloc, fdi_free, fdi_mem_open, fdi_mem_read, + fdi_mem_write, fdi_mem_close, fdi_mem_seek, cpuUNKNOWN, &erf); + ok(hfdi != NULL, "FDICreate error %d\n", erf.erfOper); + + fd = fdi_mem_open(memory_block, _O_BINARY, _S_IREAD | _S_IWRITE); + ok(fd != -1, "fdi_open failed\n"); + + memset(&info, 0, sizeof(info)); + ret = FDIIsCabinet(hfdi, fd, &info); + ok(ret, "FDIIsCabinet error %d\n", erf.erfOper); + ok(info.cbCabinet == 0x59, "expected 0x59, got %#x\n", info.cbCabinet); + ok(info.cFiles == 1, "expected 1, got %d\n", info.cFiles); + ok(info.cFolders == 1, "expected 1, got %d\n", info.cFolders); + ok(info.setID == 0x1225, "expected 0x1225, got %#x\n", info.setID); + ok(info.iCabinet == 0x2013, "expected 0x2013, got %#x\n", info.iCabinet); + + fdi_mem_close(fd); + + ret = FDICopy(hfdi, block, memory, 0, fdi_mem_notify, NULL, 0); + ok(ret, "FDICopy error %d\n", erf.erfOper); + + FDIDestroy(hfdi); } -- 2.17.1