Removed W->A from DEFWND_ImmIsUIMessageW.
[wine] / dlls / mapi32 / tests / util.c
1 /*
2  * Unit test suite for MAPI utility functions
3  *
4  * Copyright 2004 Jon Griffiths
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 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
23 #include "wine/test.h"
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "winerror.h"
28 #include "winnt.h"
29 #include "mapiutil.h"
30 #include "mapitags.h"
31
32 static HMODULE hMapi32 = 0;
33
34 static SCODE (WINAPI *pScInitMapiUtil)(ULONG);
35 static void  (WINAPI *pSwapPword)(PUSHORT,ULONG);
36 static void  (WINAPI *pSwapPlong)(PULONG,ULONG);
37 static void  (WINAPI *pHexFromBin)(LPBYTE,int,LPWSTR);
38 static void  (WINAPI *pFBinFromHex)(LPWSTR,LPBYTE);
39
40 static void test_SwapPword(void)
41 {
42     USHORT shorts[3];
43
44     pSwapPword = (void*)GetProcAddress(hMapi32, "SwapPword@8");
45     if (!pSwapPword)
46         return;
47
48     shorts[0] = 0xff01;
49     shorts[1] = 0x10ff;
50     shorts[2] = 0x2001;
51     pSwapPword(shorts, 2);
52     ok(shorts[0] == 0x01ff && shorts[1] == 0xff10 && shorts[2] == 0x2001,
53        "Expected {0x01ff,0xff10,0x2001}, got {0x%04x,0x%04x,0x%04x}\n",
54        shorts[0], shorts[1], shorts[2]);
55 }
56
57 static void test_SwapPlong(void)
58 {
59     ULONG longs[3];
60
61     pSwapPlong = (void*)GetProcAddress(hMapi32, "SwapPlong@8");
62     if (!pSwapPlong)
63         return;
64
65     longs[0] = 0xffff0001;
66     longs[1] = 0x1000ffff;
67     longs[2] = 0x20000001;
68     pSwapPlong(longs, 2);
69     ok(longs[0] == 0x0100ffff && longs[1] == 0xffff0010 && longs[2] == 0x20000001,
70        "Expected {0x0100ffff,0xffff0010,0x20000001}, got {0x%08lx,0x%08lx,0x%08lx}\n",
71        longs[0], longs[1], longs[2]);
72 }
73
74 static void test_HexFromBin(void)
75 {
76     static const char res[] = { "000102030405060708090A0B0C0D0E0F101112131415161"
77       "718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B"
78       "3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F6"
79       "06162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F8081828384"
80       "85868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A"
81       "9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCD"
82       "CECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F"
83       "2F3F4F5F6F7F8F9FAFBFCFDFE\0X" };
84     BYTE data[255];
85     WCHAR strw[256];
86     BOOL bOk;
87     int i;
88
89     pHexFromBin = (void*)GetProcAddress(hMapi32, "HexFromBin@12");
90     pFBinFromHex = (void*)GetProcAddress(hMapi32, "FBinFromHex@8");
91     if (!pHexFromBin || !pFBinFromHex)
92         return;
93
94     for (i = 0; i < 255; i++)
95         data[i] = i;
96     memset(strw, 'X', sizeof(strw));
97     pHexFromBin(data, sizeof(data), strw);
98
99     ok(memcmp(strw, res, sizeof(res) - 1) == 0, "HexFromBin: Result differs\n");
100
101     memset(data, 0, sizeof(data));
102     pFBinFromHex((LPWSTR)res, data);
103     bOk = TRUE;
104     for (i = 0; i < 255; i++)
105         if (data[i] != i)
106             bOk = FALSE;
107     ok(bOk == TRUE, "FBinFromHex: Result differs\n");
108 }
109
110
111 START_TEST(util)
112 {
113     hMapi32 = LoadLibraryA("mapi32.dll");
114
115     pScInitMapiUtil = (void*)GetProcAddress(hMapi32, "ScInitMapiUtil@4");
116     if (!pScInitMapiUtil)
117         return;
118     pScInitMapiUtil(0);
119
120     test_SwapPword();
121     test_SwapPlong();
122     test_HexFromBin();
123 }