4 * Copyright 2004 Robert Shearman
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
26 #include "propidl.h" /* for LPSAFEARRAY_User* routines */
28 #include "wine/test.h"
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 #define BSTR_UNMARSHAL_WORKS 0
35 static void test_marshal_LPSAFEARRAY(void)
37 unsigned char *buffer;
40 LPSAFEARRAY lpsa2 = NULL;
41 unsigned char *wiresa;
43 MIDL_STUB_MESSAGE stubMsg = { 0 };
44 USER_MARSHAL_CB umcb = { 0 };
46 umcb.Flags = MAKELONG(MSHCTX_DIFFERENTMACHINE, NDR_LOCAL_DATA_REPRESENTATION);
48 umcb.pStubMsg = &stubMsg;
53 lpsa = SafeArrayCreate(VT_I2, 1, &sab);
54 *(DWORD *)lpsa->pvData = 0xcafebabe;
57 size = LPSAFEARRAY_UserSize(&umcb.Flags, 0, &lpsa);
58 ok(size == 64, "size should be 64 bytes, not %ld\n", size);
59 buffer = (unsigned char *)HeapAlloc(GetProcessHeap(), 0, size);
60 LPSAFEARRAY_UserMarshal(&umcb.Flags, buffer, &lpsa);
62 ok(*(DWORD *)wiresa == TRUE, "wiresa + 0x0 should be TRUE instead of 0x%08lx\n", *(DWORD *)wiresa);
63 wiresa += sizeof(DWORD);
64 ok(*(DWORD *)wiresa == lpsa->cDims, "wiresa + 0x4 should be lpsa->cDims instead of 0x%08lx\n", *(DWORD *)wiresa);
65 wiresa += sizeof(DWORD);
66 ok(*(WORD *)wiresa == lpsa->cDims, "wiresa + 0x8 should be lpsa->cDims instead of 0x%04x\n", *(WORD *)wiresa);
67 wiresa += sizeof(WORD);
68 ok(*(WORD *)wiresa == lpsa->fFeatures, "wiresa + 0xc should be lpsa->fFeatures instead of 0x%08x\n", *(WORD *)wiresa);
69 wiresa += sizeof(WORD);
70 ok(*(DWORD *)wiresa == lpsa->cbElements, "wiresa + 0x10 should be lpsa->cbElements instead of 0x%08lx\n", *(DWORD *)wiresa);
71 wiresa += sizeof(DWORD);
72 ok(*(WORD *)wiresa == lpsa->cLocks, "wiresa + 0x16 should be lpsa->cLocks instead of 0x%04x\n", *(WORD *)wiresa);
73 wiresa += sizeof(WORD);
74 ok(*(WORD *)wiresa == VT_I2, "wiresa + 0x14 should be VT_I2 instead of 0x%04x\n", *(WORD *)wiresa);
75 wiresa += sizeof(WORD);
76 ok(*(DWORD *)wiresa == VT_I2, "wiresa + 0x18 should be VT_I2 instead of 0x%08lx\n", *(DWORD *)wiresa);
77 wiresa += sizeof(DWORD);
78 ok(*(DWORD *)wiresa == sab.cElements, "wiresa + 0x1c should be sab.cElements instead of %lu\n", *(DWORD *)wiresa);
79 wiresa += sizeof(DWORD);
80 ok(*(DWORD_PTR *)wiresa == (DWORD_PTR)lpsa->pvData, "wirestgm + 0x20 should be lpsa->pvData instead of 0x%08lx\n", *(DWORD_PTR *)wiresa);
81 wiresa += sizeof(DWORD_PTR);
82 ok(*(DWORD *)wiresa == sab.cElements, "wiresa + 0x24 should be sab.cElements instead of %lu\n", *(DWORD *)wiresa);
83 wiresa += sizeof(DWORD);
84 ok(*(LONG *)wiresa == sab.lLbound, "wiresa + 0x28 should be sab.clLbound instead of %ld\n", *(LONG *)wiresa);
85 wiresa += sizeof(LONG);
86 ok(*(DWORD *)wiresa == sab.cElements, "wiresa + 0x2c should be sab.cElements instead of %lu\n", *(DWORD *)wiresa);
87 wiresa += sizeof(DWORD);
88 /* elements are now pointed to by wiresa */
90 if (LPSAFEARRAY_UNMARSHAL_WORKS)
92 LPSAFEARRAY_UserUnmarshal(&umcb.Flags, buffer, &lpsa2);
93 ok(lpsa2 != NULL, "LPSAFEARRAY didn't unmarshal\n");
94 LPSAFEARRAY_UserFree(&umcb.Flags, &lpsa2);
96 HeapFree(GetProcessHeap(), 0, buffer);
97 SafeArrayDestroy(lpsa);
99 /* test NULL safe array */
102 size = LPSAFEARRAY_UserSize(&umcb.Flags, 0, &lpsa);
103 ok(size == 4, "size should be 4 bytes, not %ld\n", size);
104 buffer = (unsigned char *)HeapAlloc(GetProcessHeap(), 0, size);
105 LPSAFEARRAY_UserMarshal(&umcb.Flags, buffer, &lpsa);
107 ok(*(DWORD *)wiresa == FALSE, "wiresa + 0x0 should be FALSE instead of 0x%08lx\n", *(DWORD *)wiresa);
108 wiresa += sizeof(DWORD);
110 if (LPSAFEARRAY_UNMARSHAL_WORKS)
112 LPSAFEARRAY_UserUnmarshal(&umcb.Flags, buffer, &lpsa2);
113 ok(lpsa2 == NULL, "NULL LPSAFEARRAY didn't unmarshal\n");
114 LPSAFEARRAY_UserFree(&umcb.Flags, &lpsa2);
116 HeapFree(GetProcessHeap(), 0, buffer);
119 static void test_marshal_BSTR(void)
122 MIDL_STUB_MESSAGE stubMsg = { 0 };
123 USER_MARSHAL_CB umcb = { 0 };
124 unsigned char *buffer;
126 WCHAR str[] = {'m','a','r','s','h','a','l',' ','t','e','s','t','1',0};
129 umcb.Flags = MAKELONG(MSHCTX_DIFFERENTMACHINE, NDR_LOCAL_DATA_REPRESENTATION);
130 umcb.pReserve = NULL;
131 umcb.pStubMsg = &stubMsg;
133 b = SysAllocString(str);
134 len = SysStringLen(b);
135 ok(len == 13, "get %ld\n", len);
137 /* BSTRs are DWORD aligned */
138 size = BSTR_UserSize(&umcb.Flags, 1, &b);
139 ok(size == 42, "size %ld\n", size);
141 size = BSTR_UserSize(&umcb.Flags, 0, &b);
142 ok(size == 38, "size %ld\n", size);
144 buffer = HeapAlloc(GetProcessHeap(), 0, size);
145 BSTR_UserMarshal(&umcb.Flags, buffer, &b);
146 wireb = (DWORD*)buffer;
148 ok(*wireb == len, "wv[0] %08lx\n", *wireb);
150 ok(*wireb == len * 2, "wv[1] %08lx\n", *wireb);
152 ok(*wireb == len, "wv[2] %08lx\n", *wireb);
154 ok(!memcmp(wireb, str, len * 2), "strings differ\n");
156 if (BSTR_UNMARSHAL_WORKS)
159 BSTR_UserUnmarshal(&umcb.Flags, buffer, &b2);
160 ok(b2 != NULL, "NULL LPSAFEARRAY didn't unmarshal\n");
161 ok(!memcmp(b, b2, (len + 1) * 2), "strings differ\n");
162 BSTR_UserFree(&umcb.Flags, &b2);
165 HeapFree(GetProcessHeap(), 0, buffer);
169 size = BSTR_UserSize(&umcb.Flags, 0, &b);
170 ok(size == 12, "size %ld\n", size);
172 buffer = HeapAlloc(GetProcessHeap(), 0, size);
173 BSTR_UserMarshal(&umcb.Flags, buffer, &b);
174 wireb = (DWORD*)buffer;
175 ok(*wireb == 0, "wv[0] %08lx\n", *wireb);
177 ok(*wireb == 0xffffffff, "wv[1] %08lx\n", *wireb);
179 ok(*wireb == 0, "wv[2] %08lx\n", *wireb);
181 HeapFree(GetProcessHeap(), 0, buffer);
185 START_TEST(usrmarshal)
189 test_marshal_LPSAFEARRAY();