2 * Tests for recycle bin functions
4 * Copyright 2011 Jay Yang
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.
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.
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
21 #define WIN32_LEAN_AND_MEAN
26 #include "wine/test.h"
28 static int (WINAPI
*pSHQueryRecycleBinA
)(LPCSTR
,LPSHQUERYRBINFO
);
29 static int (WINAPI
*pSHFileOperationA
)(LPSHFILEOPSTRUCTA
);
31 static char int64_buffer
[65];
32 /* Note: This function uses a single buffer for the return value.*/
33 static const char* str_from_int64(__int64 ll
)
36 if (sizeof(ll
) > sizeof(unsigned long) && ll
>> 32)
37 sprintf(int64_buffer
,"%lx%08lx",(unsigned long)(ll
>> 32),(unsigned long)ll
);
39 sprintf(int64_buffer
,"%lx",(unsigned long)ll
);
43 static void setup_pointers(void)
45 HMODULE hshell32
= GetModuleHandleA("shell32.dll");
46 pSHQueryRecycleBinA
= (void*)GetProcAddress(hshell32
, "SHQueryRecycleBinA");
47 pSHFileOperationA
= (void*)GetProcAddress(hshell32
, "SHFileOperationA");
50 static void test_query_recyclebin(void)
52 SHQUERYRBINFO info1
={sizeof(info1
),0xdeadbeef,0xdeadbeef};
53 SHQUERYRBINFO info2
={sizeof(info2
),0xdeadbeef,0xdeadbeef};
58 const CHAR
*name
="test.txt";
59 CHAR buf
[MAX_PATH
+strlen(name
)+2];
60 if(!pSHQueryRecycleBinA
)
62 skip("SHQueryRecycleBinA does not exist");
65 if(!pSHFileOperationA
)
67 skip("SHFileOperationA does not exist");
70 GetCurrentDirectoryA(MAX_PATH
, buf
);
73 buf
[strlen(buf
) + 1] = '\0';
74 hr
= pSHQueryRecycleBinA(buf
,&info1
);
75 ok(hr
== S_OK
, "SHQueryRecycleBinA failed with error 0x%x\n", hr
);
76 ok(info1
.i64Size
!=0xdeadbeef,"i64Size not set\n");
77 ok(info1
.i64NumItems
!=0xdeadbeef,"i64NumItems not set\n");
78 /*create and send a file to the recycle bin*/
79 file
= CreateFileA(name
,GENERIC_WRITE
,0,NULL
,CREATE_ALWAYS
,0,NULL
);
80 ok(file
!= INVALID_HANDLE_VALUE
, "Failure to open file %s\n",name
);
81 WriteFile(file
,name
,strlen(name
),&written
,NULL
);
84 shfo
.wFunc
= FO_DELETE
;
87 shfo
.fFlags
= FOF_FILESONLY
| FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_ALLOWUNDO
;
88 shfo
.hNameMappings
= NULL
;
89 shfo
.lpszProgressTitle
= NULL
;
90 ok(!pSHFileOperationA(&shfo
), "Deletion was not successful\n");
91 hr
= pSHQueryRecycleBinA(buf
,&info2
);
92 ok(hr
== S_OK
, "SHQueryRecycleBinW failed with error 0x%x\n", hr
);
93 ok(info2
.i64Size
==info1
.i64Size
+written
,"Expected recycle bin to have 0x%s bytes\n",str_from_int64(info1
.i64Size
+written
));
94 ok(info2
.i64NumItems
==info1
.i64NumItems
+1,"Expected recycle bin to have 0x%s items\n",str_from_int64(info1
.i64NumItems
+1));
98 START_TEST(recyclebin
)
101 test_query_recyclebin();