static void test_invalid_callbackA(void) { BOOL ret; char source[MAX_PATH], temp[MAX_PATH]; GetTempPathA(sizeof(temp), temp); GetTempFileNameA(temp, "doc", 0, source); create_source_fileA(source, comp_cab_zip_multi, sizeof(comp_cab_zip_multi)); SetLastError(0xdeadbeef); ret = SetupIterateCabinetA(source, 0, NULL, NULL); ok(!ret, "Expected SetupIterateCabinetA to return 0, got %d\n", ret); ok(GetLastError() == ERROR_INVALID_DATA, "Expected GetLastError() to return ERROR_INVALID_DATA, got %u\n", GetLastError()); SetLastError(0xdeadbeef); ret = SetupIterateCabinetA(source, 0, crash_callbackA, NULL); ok(!ret, "Expected SetupIterateCabinetA to return 0, got %d\n", ret); ok(GetLastError() == ERROR_INVALID_DATA, "Expected GetLastError() to return ERROR_INVALID_DATA, got %u\n", GetLastError()); DeleteFileA(source); }
static void test_simple_enumerationA(void) { BOOL ret; char source[MAX_PATH], temp[MAX_PATH]; int enum_count = 0; GetTempPathA(sizeof(temp), temp); GetTempFileNameA(temp, "doc", 0, source); create_source_fileA(source, comp_cab_zip_multi, sizeof(comp_cab_zip_multi)); ret = SetupIterateCabinetA(source, 0, simple_callbackA, &enum_count); ok(ret == 1, "Expected SetupIterateCabinetA to return 1, got %d\n", ret); ok(enum_count == sizeof(expected_files)/sizeof(char *), "Unexpectedly enumerated %d files\n", enum_count); DeleteFileA(source); }
static void test_invalid_parametersA(void) { BOOL ret; char source[MAX_PATH], temp[MAX_PATH]; int i; const struct { PCSTR CabinetFile; PSP_FILE_CALLBACK_A MsgHandler; DWORD expected_lasterror; int todo_lasterror; } invalid_parameters[] = { {NULL, NULL, ERROR_INVALID_PARAMETER}, {NULL, dummy_callbackA, ERROR_INVALID_PARAMETER}, {"c:\\nonexistent.cab", NULL, ERROR_FILE_NOT_FOUND}, {"c:\\nonexistent.cab", dummy_callbackA, ERROR_FILE_NOT_FOUND}, {source, NULL, ERROR_INVALID_DATA, 1}, {source, dummy_callbackA, ERROR_INVALID_DATA, 1}, }; GetTempPathA(sizeof(temp), temp); GetTempFileNameA(temp, "doc", 0, source); create_source_fileA(source, NULL, 0); for (i = 0; i < sizeof(invalid_parameters)/sizeof(invalid_parameters[0]); i++) { SetLastError(0xdeadbeef); ret = SetupIterateCabinetA(invalid_parameters[i].CabinetFile, 0, invalid_parameters[i].MsgHandler, NULL); ok(!ret, "[%d] Expected SetupIterateCabinetA to return 0, got %d\n", i, ret); if (invalid_parameters[i].todo_lasterror) { todo_wine ok(GetLastError() == invalid_parameters[i].expected_lasterror, "[%d] Expected GetLastError() to return %u, got %u\n", i, invalid_parameters[i].expected_lasterror, GetLastError()); } else { ok(GetLastError() == invalid_parameters[i].expected_lasterror, "[%d] Expected GetLastError() to return %u, got %u\n", i, invalid_parameters[i].expected_lasterror, GetLastError()); } } SetLastError(0xdeadbeef); ret = SetupIterateCabinetA("", 0, NULL, NULL); ok(!ret, "Expected SetupIterateCabinetA to return 0, got %d\n", ret); ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY || GetLastError() == ERROR_FILE_NOT_FOUND, /* Win9x/NT4/Win2k */ "Expected GetLastError() to return ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError()); SetLastError(0xdeadbeef); ret = SetupIterateCabinetA("", 0, dummy_callbackA, NULL); ok(!ret, "Expected SetupIterateCabinetA to return 0, got %d\n", ret); ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY || GetLastError() == ERROR_FILE_NOT_FOUND, /* Win9x/NT4/Win2k */ "Expected GetLastError() to return ERROR_NOT_ENOUGH_MEMORY, got %u\n", GetLastError()); DeleteFileA(source); }
int main(int argc, char *argv[]) { int ret = 0; char infile[MAX_PATH], outfile[MAX_PATH], actual_name[MAX_PATH]; char outfile_basename[MAX_PATH], *basename_index; UINT comp; if (argc < 3) { myprintf( "Usage:\n" ); myprintf( "\t%s infile outfile\n", argv[0] ); myprintf( "\t%s /r infile\n", argv[0] ); return 1; } if (argc == 3 && (option_equal(argv[1], "R") || option_equal(argv[1], "r"))) GetFullPathNameA( argv[2], sizeof(infile), infile, NULL ); else GetFullPathNameA( argv[1], sizeof(infile), infile, NULL ); if (!SetupGetFileCompressionInfoExA( infile, actual_name, sizeof(actual_name), NULL, NULL, NULL, &comp )) { myprintf( "%s: can't open input file %s\n", argv[0], infile ); return 1; } if (argc == 3 && (option_equal(argv[1], "R") || option_equal(argv[1], "r"))) { switch (comp) { case FILE_COMPRESSION_MSZIP: outfile_basename[0] = 0; if (!SetupIterateCabinetA( infile, 0, set_outfile, outfile_basename )) { myprintf( "%s: can't determine original name\n", argv[0] ); return 1; } GetFullPathNameA( infile, sizeof(outfile), outfile, &basename_index ); *basename_index = 0; strcat( outfile, outfile_basename ); break; case FILE_COMPRESSION_WINLZA: GetExpandedNameA( infile, outfile_basename ); break; default: myprintf( "%s: can't determine original\n", argv[0] ); return 1; } } else GetFullPathNameA( argv[2], sizeof(outfile), outfile, NULL ); if (!lstrcmpiA( infile, outfile )) { myprintf( "%s: can't expand file to itself\n", argv[0] ); return 1; } switch (comp) { case FILE_COMPRESSION_MSZIP: if (!SetupIterateCabinetA( infile, 0, extract_callback, outfile )) { myprintf( "%s: cabinet extraction failed\n", argv[0] ); return 1; } break; case FILE_COMPRESSION_WINLZA: { INT hin, hout; OFSTRUCT ofin, ofout; LONG error; if ((hin = LZOpenFileA( infile, &ofin, OF_READ )) < 0) { myprintf( "%s: can't open input file %s\n", argv[0], infile ); return 1; } if ((hout = LZOpenFileA( outfile, &ofout, OF_CREATE | OF_WRITE )) < 0) { LZClose( hin ); myprintf( "%s: can't open output file %s\n", argv[0], outfile ); return 1; } error = LZCopy( hin, hout ); LZClose( hin ); LZClose( hout ); if (error < 0) { myprintf( "%s: LZCopy failed, error is %d\n", argv[0], error ); return 1; } break; } default: if (!CopyFileA( infile, outfile, FALSE )) { myprintf( "%s: CopyFileA failed\n", argv[0] ); return 1; } break; } return ret; }