Release 1.1.37.
[wine/gsoc-2012-control.git] / dlls / mapi32 / tests / util.c
bloba638cff88d94c9d4dec07ccb7146b8ac00856ee3
1 /*
2 * Unit test suite for MAPI utility functions
4 * Copyright 2004 Jon Griffiths
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 #include "wine/test.h"
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winuser.h"
25 #include "winerror.h"
26 #include "winnt.h"
27 #include "mapiutil.h"
28 #include "mapitags.h"
29 #include "mapi32_test.h"
31 static HMODULE hMapi32 = 0;
33 static SCODE (WINAPI *pScInitMapiUtil)(ULONG);
34 static void (WINAPI *pSwapPword)(PUSHORT,ULONG);
35 static void (WINAPI *pSwapPlong)(PULONG,ULONG);
36 static void (WINAPI *pHexFromBin)(LPBYTE,int,LPWSTR);
37 static void (WINAPI *pFBinFromHex)(LPWSTR,LPBYTE);
38 static UINT (WINAPI *pUFromSz)(LPCSTR);
39 static ULONG (WINAPI *pUlFromSzHex)(LPCSTR);
40 static ULONG (WINAPI *pCbOfEncoded)(LPCSTR);
41 static BOOL (WINAPI *pIsBadBoundedStringPtr)(LPCSTR,ULONG);
43 static void test_SwapPword(void)
45 USHORT shorts[3];
47 pSwapPword = (void*)GetProcAddress(hMapi32, "SwapPword@8");
48 if (!pSwapPword)
50 win_skip("SwapPword is not available\n");
51 return;
54 shorts[0] = 0xff01;
55 shorts[1] = 0x10ff;
56 shorts[2] = 0x2001;
57 pSwapPword(shorts, 2);
58 ok((shorts[0] == 0x01ff && shorts[1] == 0xff10 && shorts[2] == 0x2001),
59 "Expected {0x01ff,0xff10,0x2001}, got {0x%04x,0x%04x,0x%04x}\n",
60 shorts[0], shorts[1], shorts[2]);
63 static void test_SwapPlong(void)
65 ULONG longs[3];
67 pSwapPlong = (void*)GetProcAddress(hMapi32, "SwapPlong@8");
68 if (!pSwapPlong)
70 win_skip("SwapPlong is not available\n");
71 return;
74 longs[0] = 0xffff0001;
75 longs[1] = 0x1000ffff;
76 longs[2] = 0x20000001;
77 pSwapPlong(longs, 2);
78 ok((longs[0] == 0x0100ffff && longs[1] == 0xffff0010 && longs[2] == 0x20000001),
79 "Expected {0x0100ffff,0xffff0010,0x20000001}, got {0x%08x,0x%08x,0x%08x}\n",
80 longs[0], longs[1], longs[2]);
83 static void test_HexFromBin(void)
85 static char res[] = { "000102030405060708090A0B0C0D0E0F101112131415161"
86 "718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B"
87 "3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F6"
88 "06162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F8081828384"
89 "85868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A"
90 "9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCD"
91 "CECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F"
92 "2F3F4F5F6F7F8F9FAFBFCFDFE\0X" };
93 BYTE data[255];
94 WCHAR strw[256];
95 BOOL bOk;
96 int i;
98 pHexFromBin = (void*)GetProcAddress(hMapi32, "HexFromBin@12");
99 pFBinFromHex = (void*)GetProcAddress(hMapi32, "FBinFromHex@8");
100 if (!pHexFromBin || !pFBinFromHex)
102 win_skip("Hexadecimal conversion functions are not available\n");
103 return;
106 for (i = 0; i < 255; i++)
107 data[i] = i;
108 memset(strw, 'X', sizeof(strw));
109 pHexFromBin(data, sizeof(data), strw);
111 ok(memcmp(strw, res, sizeof(res) - 1) == 0, "HexFromBin: Result differs\n");
113 memset(data, 0, sizeof(data));
114 pFBinFromHex((LPWSTR)res, data);
115 bOk = TRUE;
116 for (i = 0; i < 255; i++)
117 if (data[i] != i)
118 bOk = FALSE;
119 ok(bOk == TRUE, "FBinFromHex: Result differs\n");
122 static void test_UFromSz(void)
124 pUFromSz = (void*)GetProcAddress(hMapi32, "UFromSz@4");
125 if (!pUFromSz)
127 win_skip("UFromSz is not available\n");
128 return;
131 ok(pUFromSz("105679") == 105679u,
132 "UFromSz: expected 105679, got %d\n", pUFromSz("105679"));
134 ok(pUFromSz(" 4") == 0, "UFromSz: exected 0. got %d\n",
135 pUFromSz(" 4"));
138 static void test_UlFromSzHex(void)
140 pUlFromSzHex = (void*)GetProcAddress(hMapi32, "UlFromSzHex@4");
141 if (!pUlFromSzHex)
143 win_skip("UlFromSzHex is not available\n");
144 return;
147 ok(pUlFromSzHex("fF") == 0xffu,
148 "UlFromSzHex: expected 0xff, got 0x%x\n", pUlFromSzHex("fF"));
150 ok(pUlFromSzHex(" c") == 0, "UlFromSzHex: exected 0x0. got 0x%x\n",
151 pUlFromSzHex(" c"));
154 static void test_CbOfEncoded(void)
156 char buff[129];
157 unsigned int i;
159 pCbOfEncoded = (void*)GetProcAddress(hMapi32, "CbOfEncoded@4");
160 if (!pCbOfEncoded)
162 win_skip("CbOfEncoded is not available\n");
163 return;
166 for (i = 0; i < sizeof(buff) - 1; i++)
168 ULONG ulRet, ulExpected = (((i | 3) >> 2) + 1) * 3;
170 memset(buff, '\0', sizeof(buff));
171 memset(buff, '?', i);
172 ulRet = pCbOfEncoded(buff);
173 ok(ulRet == ulExpected,
174 "CbOfEncoded(length %d): expected %d, got %d\n",
175 i, ulExpected, ulRet);
179 static void test_IsBadBoundedStringPtr(void)
181 pIsBadBoundedStringPtr = (void*)GetProcAddress(hMapi32, "IsBadBoundedStringPtr@8");
182 if (!pIsBadBoundedStringPtr)
184 win_skip("IsBadBoundedStringPtr is not available\n");
185 return;
188 ok(pIsBadBoundedStringPtr(NULL, 0) == TRUE, "IsBadBoundedStringPtr: expected TRUE\n");
189 ok(pIsBadBoundedStringPtr("TEST", 4) == TRUE, "IsBadBoundedStringPtr: expected TRUE\n");
190 ok(pIsBadBoundedStringPtr("TEST", 5) == FALSE, "IsBadBoundedStringPtr: expected FALSE\n");
193 START_TEST(util)
195 SCODE ret;
197 if (!HaveDefaultMailClient())
199 win_skip("No default mail client installed\n");
200 return;
203 hMapi32 = LoadLibraryA("mapi32.dll");
205 pScInitMapiUtil = (void*)GetProcAddress(hMapi32, "ScInitMapiUtil@4");
207 if (!pScInitMapiUtil)
209 win_skip("ScInitMapiUtil is not available\n");
210 FreeLibrary(hMapi32);
211 return;
214 SetLastError(0xdeadbeef);
215 ret = pScInitMapiUtil(0);
216 if ((ret != S_OK) && (GetLastError() == ERROR_PROC_NOT_FOUND))
218 win_skip("ScInitMapiUtil is not implemented\n");
219 FreeLibrary(hMapi32);
220 return;
222 else if ((ret == E_FAIL) && (GetLastError() == ERROR_INVALID_HANDLE))
224 win_skip("ScInitMapiUtil doesn't work on some Win98 and WinME systems\n");
225 FreeLibrary(hMapi32);
226 return;
229 test_SwapPword();
230 test_SwapPlong();
231 test_HexFromBin();
232 test_UFromSz();
233 test_UlFromSzHex();
234 test_CbOfEncoded();
235 test_IsBadBoundedStringPtr();
237 FreeLibrary(hMapi32);