comctl32: A couple fixes for tab icon offsets.
[wine] / dlls / oleaut32 / tests / usrmarshal.c
1 /*
2  * Marshaling Tests
3  *
4  * Copyright 2004 Robert Shearman
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "objbase.h"
26 #include "propidl.h" /* for LPSAFEARRAY_User* routines */
27
28 #include "wine/test.h"
29
30 /* doesn't work on Windows due to needing more of the
31  * MIDL_STUB_MESSAGE structure to be filled out */
32 #define LPSAFEARRAY_UNMARSHAL_WORKS 0
33
34 static void test_marshal_LPSAFEARRAY(void)
35 {
36     unsigned char *buffer;
37     unsigned long size;
38     LPSAFEARRAY lpsa;
39     LPSAFEARRAY lpsa2 = NULL;
40     unsigned char *wiresa;
41     SAFEARRAYBOUND sab;
42     MIDL_STUB_MESSAGE stubMsg = { 0 };
43     USER_MARSHAL_CB umcb = { 0 };
44
45     umcb.Flags = MAKELONG(MSHCTX_DIFFERENTMACHINE, NDR_LOCAL_DATA_REPRESENTATION);
46     umcb.pReserve = NULL;
47     umcb.pStubMsg = &stubMsg;
48
49     sab.lLbound = 5;
50     sab.cElements = 10;
51
52     lpsa = SafeArrayCreate(VT_I2, 1, &sab);
53     *(DWORD *)lpsa->pvData = 0xcafebabe;
54
55     lpsa->cLocks = 7;
56     size = LPSAFEARRAY_UserSize(&umcb.Flags, 0, &lpsa);
57     ok(size == 64, "size should be 64 bytes, not %ld\n", size);
58     buffer = (unsigned char *)HeapAlloc(GetProcessHeap(), 0, size);
59     LPSAFEARRAY_UserMarshal(&umcb.Flags, buffer, &lpsa);
60     wiresa = buffer;
61     ok(*(DWORD *)wiresa == TRUE, "wiresa + 0x0 should be TRUE instead of 0x%08lx\n", *(DWORD *)wiresa);
62     wiresa += sizeof(DWORD);
63     ok(*(DWORD *)wiresa == lpsa->cDims, "wiresa + 0x4 should be lpsa->cDims instead of 0x%08lx\n", *(DWORD *)wiresa);
64     wiresa += sizeof(DWORD);
65     ok(*(WORD *)wiresa == lpsa->cDims, "wiresa + 0x8 should be lpsa->cDims instead of 0x%04x\n", *(WORD *)wiresa);
66     wiresa += sizeof(WORD);
67     ok(*(WORD *)wiresa == lpsa->fFeatures, "wiresa + 0xc should be lpsa->fFeatures instead of 0x%08x\n", *(WORD *)wiresa);
68     wiresa += sizeof(WORD);
69     ok(*(DWORD *)wiresa == lpsa->cbElements, "wiresa + 0x10 should be lpsa->cbElements instead of 0x%08lx\n", *(DWORD *)wiresa);
70     wiresa += sizeof(DWORD);
71     ok(*(WORD *)wiresa == lpsa->cLocks, "wiresa + 0x16 should be lpsa->cLocks instead of 0x%04x\n", *(WORD *)wiresa);
72     wiresa += sizeof(WORD);
73     ok(*(WORD *)wiresa == VT_I2, "wiresa + 0x14 should be VT_I2 instead of 0x%04x\n", *(WORD *)wiresa);
74     wiresa += sizeof(WORD);
75     ok(*(DWORD *)wiresa == VT_I2, "wiresa + 0x18 should be VT_I2 instead of 0x%08lx\n", *(DWORD *)wiresa);
76     wiresa += sizeof(DWORD);
77     ok(*(DWORD *)wiresa == sab.cElements, "wiresa + 0x1c should be sab.cElements instead of %lu\n", *(DWORD *)wiresa);
78     wiresa += sizeof(DWORD);
79     ok(*(DWORD_PTR *)wiresa == (DWORD_PTR)lpsa->pvData, "wirestgm + 0x20 should be lpsa->pvData instead of 0x%08lx\n", *(DWORD_PTR *)wiresa);
80     wiresa += sizeof(DWORD_PTR);
81     ok(*(DWORD *)wiresa == sab.cElements, "wiresa + 0x24 should be sab.cElements instead of %lu\n", *(DWORD *)wiresa);
82     wiresa += sizeof(DWORD);
83     ok(*(LONG *)wiresa == sab.lLbound, "wiresa + 0x28 should be sab.clLbound instead of %ld\n", *(LONG *)wiresa);
84     wiresa += sizeof(LONG);
85     ok(*(DWORD *)wiresa == sab.cElements, "wiresa + 0x2c should be sab.cElements instead of %lu\n", *(DWORD *)wiresa);
86     wiresa += sizeof(DWORD);
87     /* elements are now pointed to by wiresa */
88
89     if (LPSAFEARRAY_UNMARSHAL_WORKS)
90     {
91         LPSAFEARRAY_UserUnmarshal(&umcb.Flags, buffer, &lpsa2);
92         ok(lpsa2 != NULL, "LPSAFEARRAY didn't unmarshal\n");
93         LPSAFEARRAY_UserFree(&umcb.Flags, &lpsa2);
94     }
95     HeapFree(GetProcessHeap(), 0, buffer);
96     SafeArrayDestroy(lpsa);
97
98     /* test NULL safe array */
99     lpsa = NULL;
100
101     size = LPSAFEARRAY_UserSize(&umcb.Flags, 0, &lpsa);
102     ok(size == 4, "size should be 4 bytes, not %ld\n", size);
103     buffer = (unsigned char *)HeapAlloc(GetProcessHeap(), 0, size);
104     LPSAFEARRAY_UserMarshal(&umcb.Flags, buffer, &lpsa);
105     wiresa = buffer;
106     ok(*(DWORD *)wiresa == FALSE, "wiresa + 0x0 should be FALSE instead of 0x%08lx\n", *(DWORD *)wiresa);
107     wiresa += sizeof(DWORD);
108
109     if (LPSAFEARRAY_UNMARSHAL_WORKS)
110     {
111         LPSAFEARRAY_UserUnmarshal(&umcb.Flags, buffer, &lpsa2);
112         ok(lpsa2 == NULL, "NULL LPSAFEARRAY didn't unmarshal\n");
113         LPSAFEARRAY_UserFree(&umcb.Flags, &lpsa2);
114     }
115     HeapFree(GetProcessHeap(), 0, buffer);
116 }
117
118 START_TEST(usrmarshal)
119 {
120     CoInitialize(NULL);
121
122     test_marshal_LPSAFEARRAY();
123
124     CoUninitialize();
125 }