Correct cases where arguments of ok() calls depend on the order in
[wine/gsoc_dplay.git] / dlls / user / tests / clipboard.c
blob5f90e7b0ff2ececa205183dc48cfa081393bf8f1
1 /*
2 * Unit test suite for clipboard functions.
4 * Copyright 2002 Dmitry Timoshkov
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "wine/test.h"
22 #include "winbase.h"
23 #include "winerror.h"
24 #include "winuser.h"
26 static BOOL is_win9x = FALSE;
28 #define test_last_error(expected_error) \
29 do \
30 { \
31 if (!is_win9x) \
32 ok(GetLastError() == expected_error, \
33 "Last error should be set to %d, not %ld\n", \
34 expected_error, GetLastError()); \
35 } while (0)
37 static void test_ClipboardOwner(void)
39 HWND hWnd1, hWnd2;
40 BOOL ret;
42 SetLastError(0xdeadbeef);
43 ok(!GetClipboardOwner() && GetLastError() == 0xdeadbeef,
44 "could not perform clipboard test: clipboard already owned\n");
46 hWnd1 = CreateWindowExA(0, "static", NULL, WS_POPUP,
47 0, 0, 10, 10, 0, 0, 0, NULL);
48 ok(hWnd1 != 0, "CreateWindowExA error %ld\n", GetLastError());
49 trace("hWnd1 = %p\n", hWnd1);
51 hWnd2 = CreateWindowExA(0, "static", NULL, WS_POPUP,
52 0, 0, 10, 10, 0, 0, 0, NULL);
53 ok(hWnd2 != 0, "CreateWindowExA error %ld\n", GetLastError());
54 trace("hWnd2 = %p\n", hWnd2);
56 SetLastError(0xdeadbeef);
57 ok(!CloseClipboard(), "CloseClipboard should fail if clipboard wasn't open\n");
58 test_last_error(ERROR_CLIPBOARD_NOT_OPEN);
60 ok(OpenClipboard(0), "OpenClipboard failed\n");
61 ok(!GetClipboardOwner(), "clipboard should still be not owned\n");
62 ok(!OpenClipboard(hWnd1), "OpenClipboard should fail since clipboard already opened\n");
63 ret = CloseClipboard();
64 ok( ret, "CloseClipboard error %ld\n", GetLastError());
66 ok(OpenClipboard(hWnd1), "OpenClipboard failed\n");
68 SetLastError(0xdeadbeef);
69 ok(!OpenClipboard(hWnd2) && GetLastError() == 0xdeadbeef,
70 "OpenClipboard should fail without setting last error value\n");
72 SetLastError(0xdeadbeef);
73 ok(!GetClipboardOwner() && GetLastError() == 0xdeadbeef, "clipboard should still be not owned\n");
74 ret = EmptyClipboard();
75 ok( ret, "EmptyClipboard error %ld\n", GetLastError());
76 ok(GetClipboardOwner() == hWnd1, "clipboard should be owned by %p, not by %p\n", hWnd1, GetClipboardOwner());
78 SetLastError(0xdeadbeef);
79 ok(!OpenClipboard(hWnd2) && GetLastError() == 0xdeadbeef,
80 "OpenClipboard should fail without setting last error value\n");
82 ret = CloseClipboard();
83 ok( ret, "CloseClipboard error %ld\n", GetLastError());
84 ok(GetClipboardOwner() == hWnd1, "clipboard should still be owned\n");
86 ret = DestroyWindow(hWnd1);
87 ok( ret, "DestroyWindow error %ld\n", GetLastError());
88 ret = DestroyWindow(hWnd2);
89 ok( ret, "DestroyWindow error %ld\n", GetLastError());
90 SetLastError(0xdeadbeef);
91 ok(!GetClipboardOwner() && GetLastError() == 0xdeadbeef, "clipboard should not be owned\n");
94 static void test_RegisterClipboardFormatA(void)
96 ATOM atom_id;
97 UINT format_id, format_id2;
98 char buf[256];
99 int len;
100 BOOL ret;
102 format_id = RegisterClipboardFormatA("my_cool_clipboard_format");
103 ok(format_id > 0xc000 && format_id < 0xffff, "invalid clipboard format id %04x\n", format_id);
105 format_id2 = RegisterClipboardFormatA("MY_COOL_CLIPBOARD_FORMAT");
106 ok(format_id2 == format_id, "invalid clipboard format id %04x\n", format_id2);
108 len = GetClipboardFormatNameA(format_id, buf, 256);
109 ok(len == lstrlenA("my_cool_clipboard_format"), "wrong format name length %d\n", len);
110 ok(!lstrcmpA(buf, "my_cool_clipboard_format"), "wrong format name \"%s\"\n", buf);
112 lstrcpyA(buf, "foo");
113 SetLastError(0xdeadbeef);
114 len = GetAtomNameA((ATOM)format_id, buf, 256);
115 ok(len == 0, "GetAtomNameA should fail\n");
116 test_last_error(ERROR_INVALID_HANDLE);
118 todo_wine
120 lstrcpyA(buf, "foo");
121 SetLastError(0xdeadbeef);
122 len = GlobalGetAtomNameA((ATOM)format_id, buf, 256);
123 ok(len == 0, "GlobalGetAtomNameA should fail\n");
124 test_last_error(ERROR_INVALID_HANDLE);
127 SetLastError(0xdeadbeef);
128 atom_id = FindAtomA("my_cool_clipboard_format");
129 ok(atom_id == 0, "FindAtomA should fail\n");
130 test_last_error(ERROR_FILE_NOT_FOUND);
132 #if 0
133 /* this relies on the clipboard and global atom table being different */
134 SetLastError(0xdeadbeef);
135 atom_id = GlobalFindAtomA("my_cool_clipboard_format");
136 ok(atom_id == 0, "GlobalFindAtomA should fail\n");
137 test_last_error(ERROR_FILE_NOT_FOUND);
139 for (format_id = 0; format_id < 0xffff; format_id++)
141 SetLastError(0xdeadbeef);
142 len = GetClipboardFormatNameA(format_id, buf, 256);
144 if (format_id < 0xc000)
146 ok(!len, "GetClipboardFormatNameA should fail, but it returned %d (%s)\n", len, buf);
147 test_last_error(ERROR_INVALID_PARAMETER);
149 else
151 if (len)
152 trace("%04x: %s\n", format_id, len ? buf : "");
153 else
154 test_last_error(ERROR_INVALID_HANDLE);
157 #endif
159 ret = OpenClipboard(0);
160 ok( ret, "OpenClipboard error %ld\n", GetLastError());
162 trace("# of formats available: %d\n", CountClipboardFormats());
164 format_id = 0;
165 while ((format_id = EnumClipboardFormats(format_id)))
167 ok(IsClipboardFormatAvailable(format_id), "format %04x was listed as available\n", format_id);
168 len = GetClipboardFormatNameA(format_id, buf, 256);
169 trace("%04x: %s\n", format_id, len ? buf : "");
172 ret = EmptyClipboard();
173 ok( ret, "EmptyClipboard error %ld\n", GetLastError());
174 ret =CloseClipboard();
175 ok( ret, "CloseClipboard error %ld\n", GetLastError());
177 if (CountClipboardFormats())
179 SetLastError(0xdeadbeef);
180 ok(!EnumClipboardFormats(0), "EnumClipboardFormats should fail if clipboard wasn't open\n");
181 ok(GetLastError() == ERROR_CLIPBOARD_NOT_OPEN,
182 "Last error should be set to ERROR_CLIPBOARD_NOT_OPEN, not %ld\n", GetLastError());
185 SetLastError(0xdeadbeef);
186 ok(!EmptyClipboard(), "EmptyClipboard should fail if clipboard wasn't open\n");
187 test_last_error(ERROR_CLIPBOARD_NOT_OPEN);
190 START_TEST(clipboard)
192 SetLastError(0xdeadbeef);
193 FindAtomW(NULL);
194 if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) is_win9x = TRUE;
196 test_RegisterClipboardFormatA();
197 test_ClipboardOwner();