2004-04-24 01:30:00 +02:00
|
|
|
/*
|
|
|
|
* Unit test suite for MAPI utility functions
|
|
|
|
*
|
|
|
|
* Copyright 2004 Jon Griffiths
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-04-24 01:30:00 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "winnt.h"
|
|
|
|
#include "mapiutil.h"
|
|
|
|
#include "mapitags.h"
|
2001-09-17 00:00:00 +02:00
|
|
|
#include "mapi32_test.h"
|
2004-04-24 01:30:00 +02:00
|
|
|
|
|
|
|
static HMODULE hMapi32 = 0;
|
|
|
|
|
|
|
|
static SCODE (WINAPI *pScInitMapiUtil)(ULONG);
|
2010-01-31 01:58:43 +01:00
|
|
|
static void (WINAPI *pDeinitMapiUtil)(void);
|
2004-04-24 01:30:00 +02:00
|
|
|
static void (WINAPI *pSwapPword)(PUSHORT,ULONG);
|
|
|
|
static void (WINAPI *pSwapPlong)(PULONG,ULONG);
|
2004-09-13 20:09:30 +02:00
|
|
|
static void (WINAPI *pHexFromBin)(LPBYTE,int,LPWSTR);
|
2010-01-31 01:58:33 +01:00
|
|
|
static BOOL (WINAPI *pFBinFromHex)(LPWSTR,LPBYTE);
|
2004-11-30 18:38:52 +01:00
|
|
|
static UINT (WINAPI *pUFromSz)(LPCSTR);
|
|
|
|
static ULONG (WINAPI *pUlFromSzHex)(LPCSTR);
|
|
|
|
static ULONG (WINAPI *pCbOfEncoded)(LPCSTR);
|
|
|
|
static BOOL (WINAPI *pIsBadBoundedStringPtr)(LPCSTR,ULONG);
|
2010-01-31 01:58:43 +01:00
|
|
|
static SCODE (WINAPI *pMAPIInitialize)(LPVOID);
|
|
|
|
static void (WINAPI *pMAPIUninitialize)(void);
|
2004-04-24 01:30:00 +02:00
|
|
|
|
2010-01-31 01:58:24 +01:00
|
|
|
static void init_function_pointers(void)
|
|
|
|
{
|
|
|
|
hMapi32 = LoadLibraryA("mapi32.dll");
|
|
|
|
|
|
|
|
pScInitMapiUtil = (void*)GetProcAddress(hMapi32, "ScInitMapiUtil@4");
|
2010-01-31 01:58:43 +01:00
|
|
|
pDeinitMapiUtil = (void*)GetProcAddress(hMapi32, "DeinitMapiUtil@0");
|
2010-01-31 01:58:24 +01:00
|
|
|
pSwapPword = (void*)GetProcAddress(hMapi32, "SwapPword@8");
|
|
|
|
pSwapPlong = (void*)GetProcAddress(hMapi32, "SwapPlong@8");
|
|
|
|
pHexFromBin = (void*)GetProcAddress(hMapi32, "HexFromBin@12");
|
|
|
|
pFBinFromHex = (void*)GetProcAddress(hMapi32, "FBinFromHex@8");
|
|
|
|
pUFromSz = (void*)GetProcAddress(hMapi32, "UFromSz@4");
|
|
|
|
pUlFromSzHex = (void*)GetProcAddress(hMapi32, "UlFromSzHex@4");
|
|
|
|
pCbOfEncoded = (void*)GetProcAddress(hMapi32, "CbOfEncoded@4");
|
|
|
|
pIsBadBoundedStringPtr = (void*)GetProcAddress(hMapi32, "IsBadBoundedStringPtr@8");
|
2010-01-31 01:58:43 +01:00
|
|
|
pMAPIInitialize = (void*)GetProcAddress(hMapi32, "MAPIInitialize");
|
|
|
|
pMAPIUninitialize = (void*)GetProcAddress(hMapi32, "MAPIUninitialize");
|
2010-01-31 01:58:24 +01:00
|
|
|
}
|
|
|
|
|
2004-04-24 01:30:00 +02:00
|
|
|
static void test_SwapPword(void)
|
|
|
|
{
|
|
|
|
USHORT shorts[3];
|
|
|
|
|
|
|
|
if (!pSwapPword)
|
2010-01-18 13:59:49 +01:00
|
|
|
{
|
|
|
|
win_skip("SwapPword is not available\n");
|
2004-04-24 01:30:00 +02:00
|
|
|
return;
|
2010-01-18 13:59:49 +01:00
|
|
|
}
|
2004-04-24 01:30:00 +02:00
|
|
|
|
|
|
|
shorts[0] = 0xff01;
|
|
|
|
shorts[1] = 0x10ff;
|
|
|
|
shorts[2] = 0x2001;
|
|
|
|
pSwapPword(shorts, 2);
|
2009-06-19 12:30:46 +02:00
|
|
|
ok((shorts[0] == 0x01ff && shorts[1] == 0xff10 && shorts[2] == 0x2001),
|
2004-04-24 01:30:00 +02:00
|
|
|
"Expected {0x01ff,0xff10,0x2001}, got {0x%04x,0x%04x,0x%04x}\n",
|
|
|
|
shorts[0], shorts[1], shorts[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_SwapPlong(void)
|
|
|
|
{
|
|
|
|
ULONG longs[3];
|
|
|
|
|
|
|
|
if (!pSwapPlong)
|
2010-01-18 13:59:49 +01:00
|
|
|
{
|
|
|
|
win_skip("SwapPlong is not available\n");
|
2004-04-24 01:30:00 +02:00
|
|
|
return;
|
2010-01-18 13:59:49 +01:00
|
|
|
}
|
2004-04-24 01:30:00 +02:00
|
|
|
|
|
|
|
longs[0] = 0xffff0001;
|
|
|
|
longs[1] = 0x1000ffff;
|
|
|
|
longs[2] = 0x20000001;
|
|
|
|
pSwapPlong(longs, 2);
|
2009-06-19 12:30:46 +02:00
|
|
|
ok((longs[0] == 0x0100ffff && longs[1] == 0xffff0010 && longs[2] == 0x20000001),
|
2006-10-12 20:56:25 +02:00
|
|
|
"Expected {0x0100ffff,0xffff0010,0x20000001}, got {0x%08x,0x%08x,0x%08x}\n",
|
2004-04-24 01:30:00 +02:00
|
|
|
longs[0], longs[1], longs[2]);
|
|
|
|
}
|
|
|
|
|
2004-09-13 20:09:30 +02:00
|
|
|
static void test_HexFromBin(void)
|
|
|
|
{
|
2006-12-09 19:05:56 +01:00
|
|
|
static char res[] = { "000102030405060708090A0B0C0D0E0F101112131415161"
|
2004-09-13 20:09:30 +02:00
|
|
|
"718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B"
|
|
|
|
"3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F6"
|
|
|
|
"06162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F8081828384"
|
|
|
|
"85868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A"
|
|
|
|
"9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCD"
|
|
|
|
"CECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F"
|
|
|
|
"2F3F4F5F6F7F8F9FAFBFCFDFE\0X" };
|
|
|
|
BYTE data[255];
|
|
|
|
WCHAR strw[256];
|
|
|
|
BOOL bOk;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!pHexFromBin || !pFBinFromHex)
|
2010-01-18 13:59:49 +01:00
|
|
|
{
|
|
|
|
win_skip("Hexadecimal conversion functions are not available\n");
|
2004-09-13 20:09:30 +02:00
|
|
|
return;
|
2010-01-18 13:59:49 +01:00
|
|
|
}
|
2004-09-13 20:09:30 +02:00
|
|
|
|
|
|
|
for (i = 0; i < 255; i++)
|
|
|
|
data[i] = i;
|
|
|
|
memset(strw, 'X', sizeof(strw));
|
|
|
|
pHexFromBin(data, sizeof(data), strw);
|
|
|
|
|
|
|
|
ok(memcmp(strw, res, sizeof(res) - 1) == 0, "HexFromBin: Result differs\n");
|
|
|
|
|
|
|
|
memset(data, 0, sizeof(data));
|
|
|
|
pFBinFromHex((LPWSTR)res, data);
|
|
|
|
bOk = TRUE;
|
|
|
|
for (i = 0; i < 255; i++)
|
|
|
|
if (data[i] != i)
|
|
|
|
bOk = FALSE;
|
|
|
|
ok(bOk == TRUE, "FBinFromHex: Result differs\n");
|
|
|
|
}
|
|
|
|
|
2004-11-30 18:38:52 +01:00
|
|
|
static void test_UFromSz(void)
|
|
|
|
{
|
|
|
|
if (!pUFromSz)
|
2010-01-18 13:59:49 +01:00
|
|
|
{
|
|
|
|
win_skip("UFromSz is not available\n");
|
2004-11-30 18:38:52 +01:00
|
|
|
return;
|
2010-01-18 13:59:49 +01:00
|
|
|
}
|
2004-11-30 18:38:52 +01:00
|
|
|
|
|
|
|
ok(pUFromSz("105679") == 105679u,
|
|
|
|
"UFromSz: expected 105679, got %d\n", pUFromSz("105679"));
|
|
|
|
|
|
|
|
ok(pUFromSz(" 4") == 0, "UFromSz: exected 0. got %d\n",
|
|
|
|
pUFromSz(" 4"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_UlFromSzHex(void)
|
|
|
|
{
|
|
|
|
if (!pUlFromSzHex)
|
2010-01-18 13:59:49 +01:00
|
|
|
{
|
|
|
|
win_skip("UlFromSzHex is not available\n");
|
2004-11-30 18:38:52 +01:00
|
|
|
return;
|
2010-01-18 13:59:49 +01:00
|
|
|
}
|
2004-11-30 18:38:52 +01:00
|
|
|
|
|
|
|
ok(pUlFromSzHex("fF") == 0xffu,
|
2006-10-12 20:56:25 +02:00
|
|
|
"UlFromSzHex: expected 0xff, got 0x%x\n", pUlFromSzHex("fF"));
|
2004-11-30 18:38:52 +01:00
|
|
|
|
2006-10-12 20:56:25 +02:00
|
|
|
ok(pUlFromSzHex(" c") == 0, "UlFromSzHex: exected 0x0. got 0x%x\n",
|
2004-11-30 18:38:52 +01:00
|
|
|
pUlFromSzHex(" c"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_CbOfEncoded(void)
|
|
|
|
{
|
|
|
|
char buff[129];
|
2006-06-13 14:02:45 +02:00
|
|
|
unsigned int i;
|
2004-11-30 18:38:52 +01:00
|
|
|
|
|
|
|
if (!pCbOfEncoded)
|
2010-01-18 13:59:49 +01:00
|
|
|
{
|
|
|
|
win_skip("CbOfEncoded is not available\n");
|
2004-11-30 18:38:52 +01:00
|
|
|
return;
|
2010-01-18 13:59:49 +01:00
|
|
|
}
|
2004-11-30 18:38:52 +01:00
|
|
|
|
|
|
|
for (i = 0; i < sizeof(buff) - 1; i++)
|
|
|
|
{
|
|
|
|
ULONG ulRet, ulExpected = (((i | 3) >> 2) + 1) * 3;
|
|
|
|
|
|
|
|
memset(buff, '\0', sizeof(buff));
|
|
|
|
memset(buff, '?', i);
|
|
|
|
ulRet = pCbOfEncoded(buff);
|
2009-06-19 12:30:46 +02:00
|
|
|
ok(ulRet == ulExpected,
|
2009-02-02 19:20:19 +01:00
|
|
|
"CbOfEncoded(length %d): expected %d, got %d\n",
|
2004-11-30 18:38:52 +01:00
|
|
|
i, ulExpected, ulRet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_IsBadBoundedStringPtr(void)
|
|
|
|
{
|
|
|
|
if (!pIsBadBoundedStringPtr)
|
2010-01-18 13:59:49 +01:00
|
|
|
{
|
|
|
|
win_skip("IsBadBoundedStringPtr is not available\n");
|
2004-11-30 18:38:52 +01:00
|
|
|
return;
|
2010-01-18 13:59:49 +01:00
|
|
|
}
|
2004-11-30 18:38:52 +01:00
|
|
|
|
|
|
|
ok(pIsBadBoundedStringPtr(NULL, 0) == TRUE, "IsBadBoundedStringPtr: expected TRUE\n");
|
|
|
|
ok(pIsBadBoundedStringPtr("TEST", 4) == TRUE, "IsBadBoundedStringPtr: expected TRUE\n");
|
|
|
|
ok(pIsBadBoundedStringPtr("TEST", 5) == FALSE, "IsBadBoundedStringPtr: expected FALSE\n");
|
|
|
|
}
|
2004-09-13 20:09:30 +02:00
|
|
|
|
2004-04-24 01:30:00 +02:00
|
|
|
START_TEST(util)
|
|
|
|
{
|
2007-03-04 11:44:34 +01:00
|
|
|
SCODE ret;
|
|
|
|
|
2001-09-17 00:00:00 +02:00
|
|
|
if (!HaveDefaultMailClient())
|
|
|
|
{
|
|
|
|
win_skip("No default mail client installed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-31 01:58:24 +01:00
|
|
|
init_function_pointers();
|
2007-03-04 11:44:34 +01:00
|
|
|
|
2010-01-31 01:58:43 +01:00
|
|
|
if (!pScInitMapiUtil || !pDeinitMapiUtil)
|
2007-03-04 11:44:34 +01:00
|
|
|
{
|
2010-01-31 01:58:43 +01:00
|
|
|
win_skip("MAPI utility initialization functions are not available\n");
|
2007-03-04 11:44:34 +01:00
|
|
|
FreeLibrary(hMapi32);
|
2004-04-24 01:30:00 +02:00
|
|
|
return;
|
2007-03-04 11:44:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
ret = pScInitMapiUtil(0);
|
|
|
|
if ((ret != S_OK) && (GetLastError() == ERROR_PROC_NOT_FOUND))
|
|
|
|
{
|
2009-02-23 10:40:40 +01:00
|
|
|
win_skip("ScInitMapiUtil is not implemented\n");
|
2007-03-04 11:44:34 +01:00
|
|
|
FreeLibrary(hMapi32);
|
|
|
|
return;
|
|
|
|
}
|
2009-06-19 12:30:46 +02:00
|
|
|
else if ((ret == E_FAIL) && (GetLastError() == ERROR_INVALID_HANDLE))
|
|
|
|
{
|
|
|
|
win_skip("ScInitMapiUtil doesn't work on some Win98 and WinME systems\n");
|
|
|
|
FreeLibrary(hMapi32);
|
|
|
|
return;
|
|
|
|
}
|
2004-04-24 01:30:00 +02:00
|
|
|
|
|
|
|
test_SwapPword();
|
|
|
|
test_SwapPlong();
|
2010-01-31 01:58:43 +01:00
|
|
|
|
|
|
|
/* We call MAPIInitialize here for the benefit of native extended MAPI
|
|
|
|
* providers which crash in the HexFromBin tests when MAPIInitialize has
|
2010-02-01 20:47:31 +01:00
|
|
|
* not been called. Since MAPIInitialize is irrelevant for HexFromBin on
|
2010-01-31 01:58:43 +01:00
|
|
|
* Wine, we do not care whether MAPIInitialize succeeds. */
|
|
|
|
if (pMAPIInitialize)
|
|
|
|
ret = pMAPIInitialize(NULL);
|
2004-09-13 20:09:30 +02:00
|
|
|
test_HexFromBin();
|
2010-01-31 01:58:43 +01:00
|
|
|
if (pMAPIUninitialize && ret == S_OK)
|
|
|
|
pMAPIUninitialize();
|
|
|
|
|
2004-11-30 18:38:52 +01:00
|
|
|
test_UFromSz();
|
|
|
|
test_UlFromSzHex();
|
|
|
|
test_CbOfEncoded();
|
|
|
|
test_IsBadBoundedStringPtr();
|
2007-03-04 11:44:34 +01:00
|
|
|
|
2010-01-31 01:58:43 +01:00
|
|
|
pDeinitMapiUtil();
|
2007-03-04 11:44:34 +01:00
|
|
|
FreeLibrary(hMapi32);
|
2004-04-24 01:30:00 +02:00
|
|
|
}
|