2004-06-25 04:55:37 +02:00
|
|
|
/*
|
|
|
|
* Unit test suite for clipboard functions.
|
|
|
|
*
|
|
|
|
* Copyright 2002 Dmitry Timoshkov
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-06-25 04:55:37 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
2009-04-17 15:46:06 +02:00
|
|
|
#include "wingdi.h"
|
2004-06-25 04:55:37 +02:00
|
|
|
#include "winuser.h"
|
|
|
|
|
|
|
|
static BOOL is_win9x = FALSE;
|
|
|
|
|
|
|
|
#define test_last_error(expected_error) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if (!is_win9x) \
|
|
|
|
ok(GetLastError() == expected_error, \
|
2006-10-07 21:45:11 +02:00
|
|
|
"Last error should be set to %d, not %d\n", \
|
2004-06-25 04:55:37 +02:00
|
|
|
expected_error, GetLastError()); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
static void test_ClipboardOwner(void)
|
|
|
|
{
|
|
|
|
HWND hWnd1, hWnd2;
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL ret;
|
2004-06-25 04:55:37 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!GetClipboardOwner() && GetLastError() == 0xdeadbeef,
|
|
|
|
"could not perform clipboard test: clipboard already owned\n");
|
|
|
|
|
|
|
|
hWnd1 = CreateWindowExA(0, "static", NULL, WS_POPUP,
|
|
|
|
0, 0, 10, 10, 0, 0, 0, NULL);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok(hWnd1 != 0, "CreateWindowExA error %d\n", GetLastError());
|
2004-06-25 04:55:37 +02:00
|
|
|
trace("hWnd1 = %p\n", hWnd1);
|
|
|
|
|
|
|
|
hWnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
|
|
|
|
0, 0, 10, 10, 0, 0, 0, NULL);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok(hWnd2 != 0, "CreateWindowExA error %d\n", GetLastError());
|
2004-06-25 04:55:37 +02:00
|
|
|
trace("hWnd2 = %p\n", hWnd2);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!CloseClipboard(), "CloseClipboard should fail if clipboard wasn't open\n");
|
2009-12-23 12:13:44 +01:00
|
|
|
ok(GetLastError() == ERROR_CLIPBOARD_NOT_OPEN || broken(GetLastError() == 0xdeadbeef), /* wow64 */
|
|
|
|
"wrong error %u\n", GetLastError());
|
2004-06-25 04:55:37 +02:00
|
|
|
|
|
|
|
ok(OpenClipboard(0), "OpenClipboard failed\n");
|
|
|
|
ok(!GetClipboardOwner(), "clipboard should still be not owned\n");
|
|
|
|
ok(!OpenClipboard(hWnd1), "OpenClipboard should fail since clipboard already opened\n");
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = CloseClipboard();
|
2006-10-07 21:45:11 +02:00
|
|
|
ok( ret, "CloseClipboard error %d\n", GetLastError());
|
2004-06-25 04:55:37 +02:00
|
|
|
|
|
|
|
ok(OpenClipboard(hWnd1), "OpenClipboard failed\n");
|
2012-07-06 02:25:18 +02:00
|
|
|
todo_wine ok(OpenClipboard(hWnd1), "OpenClipboard second time in the same hwnd failed\n");
|
2004-06-25 04:55:37 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2011-01-04 22:58:35 +01:00
|
|
|
ret = OpenClipboard(hWnd2);
|
|
|
|
ok(!ret && (GetLastError() == 0xdeadbeef || GetLastError() == ERROR_ACCESS_DENIED),
|
2008-01-24 00:32:52 +01:00
|
|
|
"OpenClipboard should fail without setting last error value, or with ERROR_ACCESS_DENIED, got error %d\n", GetLastError());
|
2004-06-25 04:55:37 +02:00
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!GetClipboardOwner() && GetLastError() == 0xdeadbeef, "clipboard should still be not owned\n");
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = EmptyClipboard();
|
2006-10-07 21:45:11 +02:00
|
|
|
ok( ret, "EmptyClipboard error %d\n", GetLastError());
|
2004-06-25 04:55:37 +02:00
|
|
|
ok(GetClipboardOwner() == hWnd1, "clipboard should be owned by %p, not by %p\n", hWnd1, GetClipboardOwner());
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2011-01-04 22:58:35 +01:00
|
|
|
ret = OpenClipboard(hWnd2);
|
|
|
|
ok(!ret && (GetLastError() == 0xdeadbeef || GetLastError() == ERROR_ACCESS_DENIED),
|
2011-08-03 23:50:18 +02:00
|
|
|
"OpenClipboard should fail without setting last error value, or with ERROR_ACCESS_DENIED, got error %d\n", GetLastError());
|
2004-06-25 04:55:37 +02:00
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = CloseClipboard();
|
2006-10-07 21:45:11 +02:00
|
|
|
ok( ret, "CloseClipboard error %d\n", GetLastError());
|
2004-06-25 04:55:37 +02:00
|
|
|
ok(GetClipboardOwner() == hWnd1, "clipboard should still be owned\n");
|
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DestroyWindow(hWnd1);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok( ret, "DestroyWindow error %d\n", GetLastError());
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = DestroyWindow(hWnd2);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok( ret, "DestroyWindow error %d\n", GetLastError());
|
2004-06-25 04:55:37 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!GetClipboardOwner() && GetLastError() == 0xdeadbeef, "clipboard should not be owned\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_RegisterClipboardFormatA(void)
|
|
|
|
{
|
|
|
|
ATOM atom_id;
|
|
|
|
UINT format_id, format_id2;
|
|
|
|
char buf[256];
|
|
|
|
int len;
|
2004-12-27 18:26:37 +01:00
|
|
|
BOOL ret;
|
2004-06-25 04:55:37 +02:00
|
|
|
|
|
|
|
format_id = RegisterClipboardFormatA("my_cool_clipboard_format");
|
|
|
|
ok(format_id > 0xc000 && format_id < 0xffff, "invalid clipboard format id %04x\n", format_id);
|
|
|
|
|
|
|
|
format_id2 = RegisterClipboardFormatA("MY_COOL_CLIPBOARD_FORMAT");
|
|
|
|
ok(format_id2 == format_id, "invalid clipboard format id %04x\n", format_id2);
|
|
|
|
|
|
|
|
len = GetClipboardFormatNameA(format_id, buf, 256);
|
|
|
|
ok(len == lstrlenA("my_cool_clipboard_format"), "wrong format name length %d\n", len);
|
|
|
|
ok(!lstrcmpA(buf, "my_cool_clipboard_format"), "wrong format name \"%s\"\n", buf);
|
|
|
|
|
|
|
|
lstrcpyA(buf, "foo");
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
len = GetAtomNameA((ATOM)format_id, buf, 256);
|
|
|
|
ok(len == 0, "GetAtomNameA should fail\n");
|
|
|
|
test_last_error(ERROR_INVALID_HANDLE);
|
|
|
|
|
|
|
|
todo_wine
|
|
|
|
{
|
|
|
|
lstrcpyA(buf, "foo");
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
len = GlobalGetAtomNameA((ATOM)format_id, buf, 256);
|
|
|
|
ok(len == 0, "GlobalGetAtomNameA should fail\n");
|
|
|
|
test_last_error(ERROR_INVALID_HANDLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
atom_id = FindAtomA("my_cool_clipboard_format");
|
|
|
|
ok(atom_id == 0, "FindAtomA should fail\n");
|
|
|
|
test_last_error(ERROR_FILE_NOT_FOUND);
|
|
|
|
|
2006-12-14 18:10:47 +01:00
|
|
|
if (0)
|
|
|
|
{
|
2004-06-25 04:55:37 +02:00
|
|
|
/* this relies on the clipboard and global atom table being different */
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
atom_id = GlobalFindAtomA("my_cool_clipboard_format");
|
|
|
|
ok(atom_id == 0, "GlobalFindAtomA should fail\n");
|
|
|
|
test_last_error(ERROR_FILE_NOT_FOUND);
|
2011-03-03 21:51:29 +01:00
|
|
|
}
|
2004-06-25 04:55:37 +02:00
|
|
|
|
|
|
|
for (format_id = 0; format_id < 0xffff; format_id++)
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
len = GetClipboardFormatNameA(format_id, buf, 256);
|
|
|
|
|
|
|
|
if (format_id < 0xc000)
|
|
|
|
ok(!len, "GetClipboardFormatNameA should fail, but it returned %d (%s)\n", len, buf);
|
|
|
|
else
|
2011-03-03 21:51:29 +01:00
|
|
|
if (len) trace("%04x: %s\n", format_id, len ? buf : "");
|
2006-12-14 18:10:47 +01:00
|
|
|
}
|
2004-06-25 04:55:37 +02:00
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = OpenClipboard(0);
|
2006-10-07 21:45:11 +02:00
|
|
|
ok( ret, "OpenClipboard error %d\n", GetLastError());
|
2004-06-25 04:55:37 +02:00
|
|
|
|
|
|
|
trace("# of formats available: %d\n", CountClipboardFormats());
|
|
|
|
|
|
|
|
format_id = 0;
|
|
|
|
while ((format_id = EnumClipboardFormats(format_id)))
|
|
|
|
{
|
|
|
|
ok(IsClipboardFormatAvailable(format_id), "format %04x was listed as available\n", format_id);
|
|
|
|
len = GetClipboardFormatNameA(format_id, buf, 256);
|
|
|
|
trace("%04x: %s\n", format_id, len ? buf : "");
|
|
|
|
}
|
|
|
|
|
2004-12-27 18:26:37 +01:00
|
|
|
ret = EmptyClipboard();
|
2006-10-07 21:45:11 +02:00
|
|
|
ok( ret, "EmptyClipboard error %d\n", GetLastError());
|
2004-12-27 18:26:37 +01:00
|
|
|
ret =CloseClipboard();
|
2006-10-07 21:45:11 +02:00
|
|
|
ok( ret, "CloseClipboard error %d\n", GetLastError());
|
2004-06-25 04:55:37 +02:00
|
|
|
|
|
|
|
if (CountClipboardFormats())
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!EnumClipboardFormats(0), "EnumClipboardFormats should fail if clipboard wasn't open\n");
|
|
|
|
ok(GetLastError() == ERROR_CLIPBOARD_NOT_OPEN,
|
2006-10-07 21:45:11 +02:00
|
|
|
"Last error should be set to ERROR_CLIPBOARD_NOT_OPEN, not %d\n", GetLastError());
|
2004-06-25 04:55:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ok(!EmptyClipboard(), "EmptyClipboard should fail if clipboard wasn't open\n");
|
2009-12-23 12:13:44 +01:00
|
|
|
ok(GetLastError() == ERROR_CLIPBOARD_NOT_OPEN || broken(GetLastError() == 0xdeadbeef), /* wow64 */
|
|
|
|
"Wrong error %u\n", GetLastError());
|
2011-03-07 17:05:32 +01:00
|
|
|
|
|
|
|
format_id = RegisterClipboardFormatA("#1234");
|
|
|
|
ok(format_id == 1234, "invalid clipboard format id %04x\n", format_id);
|
2004-06-25 04:55:37 +02:00
|
|
|
}
|
|
|
|
|
2009-04-17 15:46:06 +02:00
|
|
|
static HGLOBAL create_text(void)
|
|
|
|
{
|
|
|
|
HGLOBAL h = GlobalAlloc(GMEM_DDESHARE|GMEM_MOVEABLE, 5);
|
|
|
|
char *p = GlobalLock(h);
|
|
|
|
strcpy(p, "test");
|
|
|
|
GlobalUnlock(h);
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HENHMETAFILE create_emf(void)
|
|
|
|
{
|
|
|
|
const RECT rect = {0, 0, 100, 100};
|
|
|
|
HDC hdc = CreateEnhMetaFileA(NULL, NULL, &rect, "HENHMETAFILE Ole Clipboard Test\0Test\0\0");
|
|
|
|
ExtTextOutA(hdc, 0, 0, ETO_OPAQUE, &rect, "Test String", strlen("Test String"), NULL);
|
|
|
|
return CloseEnhMetaFile(hdc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_synthesized(void)
|
|
|
|
{
|
|
|
|
HGLOBAL h, htext;
|
|
|
|
HENHMETAFILE emf;
|
|
|
|
BOOL r;
|
|
|
|
UINT cf;
|
2011-01-28 14:05:29 +01:00
|
|
|
HANDLE data;
|
2009-04-17 15:46:06 +02:00
|
|
|
|
|
|
|
htext = create_text();
|
|
|
|
emf = create_emf();
|
|
|
|
|
|
|
|
r = OpenClipboard(NULL);
|
|
|
|
ok(r, "gle %d\n", GetLastError());
|
|
|
|
r = EmptyClipboard();
|
|
|
|
ok(r, "gle %d\n", GetLastError());
|
|
|
|
h = SetClipboardData(CF_TEXT, htext);
|
|
|
|
ok(h == htext, "got %p\n", h);
|
|
|
|
h = SetClipboardData(CF_ENHMETAFILE, emf);
|
|
|
|
ok(h == emf, "got %p\n", h);
|
|
|
|
r = CloseClipboard();
|
|
|
|
ok(r, "gle %d\n", GetLastError());
|
|
|
|
|
|
|
|
r = OpenClipboard(NULL);
|
|
|
|
ok(r, "gle %d\n", GetLastError());
|
|
|
|
cf = EnumClipboardFormats(0);
|
|
|
|
ok(cf == CF_TEXT, "cf %08x\n", cf);
|
2011-01-28 14:05:29 +01:00
|
|
|
data = GetClipboardData(cf);
|
|
|
|
ok(data != NULL, "couldn't get data, cf %08x\n", cf);
|
2009-04-17 15:46:06 +02:00
|
|
|
|
|
|
|
cf = EnumClipboardFormats(cf);
|
|
|
|
ok(cf == CF_ENHMETAFILE, "cf %08x\n", cf);
|
2011-01-28 14:05:29 +01:00
|
|
|
data = GetClipboardData(cf);
|
|
|
|
ok(data != NULL, "couldn't get data, cf %08x\n", cf);
|
2009-04-17 15:46:06 +02:00
|
|
|
|
|
|
|
cf = EnumClipboardFormats(cf);
|
|
|
|
todo_wine ok(cf == CF_LOCALE, "cf %08x\n", cf);
|
|
|
|
if(cf == CF_LOCALE)
|
|
|
|
cf = EnumClipboardFormats(cf);
|
|
|
|
ok(cf == CF_OEMTEXT, "cf %08x\n", cf);
|
2011-01-28 14:05:29 +01:00
|
|
|
data = GetClipboardData(cf);
|
|
|
|
ok(data != NULL, "couldn't get data, cf %08x\n", cf);
|
2009-04-17 15:46:06 +02:00
|
|
|
|
|
|
|
cf = EnumClipboardFormats(cf);
|
2009-04-21 11:38:52 +02:00
|
|
|
ok(cf == CF_UNICODETEXT ||
|
|
|
|
broken(cf == CF_METAFILEPICT), /* win9x and winME has no CF_UNICODETEXT */
|
|
|
|
"cf %08x\n", cf);
|
2009-04-17 15:46:06 +02:00
|
|
|
|
2009-04-21 11:38:52 +02:00
|
|
|
if(cf == CF_UNICODETEXT)
|
|
|
|
cf = EnumClipboardFormats(cf);
|
2009-04-17 15:49:29 +02:00
|
|
|
ok(cf == CF_METAFILEPICT, "cf %08x\n", cf);
|
2011-01-28 14:05:29 +01:00
|
|
|
data = GetClipboardData(cf);
|
|
|
|
todo_wine ok(data != NULL, "couldn't get data, cf %08x\n", cf);
|
2009-04-17 15:46:06 +02:00
|
|
|
|
2009-04-17 15:49:29 +02:00
|
|
|
cf = EnumClipboardFormats(cf);
|
2009-04-17 15:46:06 +02:00
|
|
|
ok(cf == 0, "cf %08x\n", cf);
|
|
|
|
|
|
|
|
r = EmptyClipboard();
|
|
|
|
ok(r, "gle %d\n", GetLastError());
|
|
|
|
|
|
|
|
r = CloseClipboard();
|
|
|
|
ok(r, "gle %d\n", GetLastError());
|
|
|
|
}
|
|
|
|
|
2004-06-25 04:55:37 +02:00
|
|
|
START_TEST(clipboard)
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
FindAtomW(NULL);
|
|
|
|
if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) is_win9x = TRUE;
|
|
|
|
|
|
|
|
test_RegisterClipboardFormatA();
|
|
|
|
test_ClipboardOwner();
|
2009-04-17 15:46:06 +02:00
|
|
|
test_synthesized();
|
2004-06-25 04:55:37 +02:00
|
|
|
}
|