1 /* 2 * Tests for recycle bin functions 3 * 4 * Copyright 2011 Jay Yang 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 */ 20 21 #include "precomp.h" 22 23 static int (WINAPI *pSHQueryRecycleBinA)(LPCSTR,LPSHQUERYRBINFO); 24 static int (WINAPI *pSHFileOperationA)(LPSHFILEOPSTRUCTA); 25 26 static void setup_pointers(void) 27 { 28 HMODULE hshell32 = GetModuleHandleA("shell32.dll"); 29 pSHQueryRecycleBinA = (void*)GetProcAddress(hshell32, "SHQueryRecycleBinA"); 30 pSHFileOperationA = (void*)GetProcAddress(hshell32, "SHFileOperationA"); 31 } 32 33 static void test_query_recyclebin(void) 34 { 35 SHQUERYRBINFO info1={sizeof(info1),0xdeadbeef,0xdeadbeef}; 36 SHQUERYRBINFO info2={sizeof(info2),0xdeadbeef,0xdeadbeef}; 37 UINT written; 38 HRESULT hr; 39 HANDLE file; 40 SHFILEOPSTRUCTA shfo; 41 CHAR temp_path[MAX_PATH-14], buf[MAX_PATH+1]; 42 if(!pSHQueryRecycleBinA) 43 { 44 skip("SHQueryRecycleBinA does not exist\n"); 45 return; 46 } 47 if(!pSHFileOperationA) 48 { 49 skip("SHFileOperationA does not exist\n"); 50 return; 51 } 52 ok(GetTempPathA(sizeof(temp_path), temp_path), "GetTempPath failed\n"); 53 ok(GetTempFileNameA(temp_path, "trash", 0, buf), "GetTempFileName failed\n"); 54 buf[strlen(buf) + 1] = '\0'; 55 hr = pSHQueryRecycleBinA(buf,&info1); 56 ok(hr == S_OK, "SHQueryRecycleBinA failed with error 0x%x\n", hr); 57 ok(info1.i64Size!=0xdeadbeef,"i64Size not set\n"); 58 ok(info1.i64NumItems!=0xdeadbeef,"i64NumItems not set\n"); 59 /*create and send a file to the recycle bin*/ 60 file = CreateFileA(buf,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0,NULL); 61 ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n",buf); 62 WriteFile(file,buf,strlen(buf),&written,NULL); 63 CloseHandle(file); 64 shfo.hwnd = NULL; 65 shfo.wFunc = FO_DELETE; 66 shfo.pFrom = buf; 67 shfo.pTo = NULL; 68 shfo.fFlags = FOF_FILESONLY | FOF_NOCONFIRMATION | FOF_SILENT | FOF_ALLOWUNDO; 69 shfo.hNameMappings = NULL; 70 shfo.lpszProgressTitle = NULL; 71 ok(!pSHFileOperationA(&shfo), "Deletion was not successful\n"); 72 hr = pSHQueryRecycleBinA(buf,&info2); 73 ok(hr == S_OK, "SHQueryRecycleBinA failed with error 0x%x\n", hr); 74 ok(info2.i64Size==info1.i64Size+written,"Expected recycle bin to have 0x%s bytes\n",wine_dbgstr_longlong(info1.i64Size+written)); 75 ok(info2.i64NumItems==info1.i64NumItems+1,"Expected recycle bin to have 0x%s items\n",wine_dbgstr_longlong(info1.i64NumItems+1)); 76 } 77 78 79 START_TEST(recyclebin) 80 { 81 setup_pointers(); 82 test_query_recyclebin(); 83 } 84