prop.c 49.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Unit test suite for MAPI property 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22 23 24 25 26
 */

#include "wine/test.h"
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "winerror.h"
#include "winnt.h"
27
#include "initguid.h"
28 29
#include "mapiutil.h"
#include "mapitags.h"
30
#include "mapi32_test.h"
31 32 33 34

static HMODULE hMapi32 = 0;

static SCODE        (WINAPI *pScInitMapiUtil)(ULONG);
35
static void         (WINAPI *pDeinitMapiUtil)(void);
36 37 38 39 40 41 42
static SCODE        (WINAPI *pPropCopyMore)(LPSPropValue,LPSPropValue,ALLOCATEMORE*,LPVOID);
static ULONG        (WINAPI *pUlPropSize)(LPSPropValue);
static BOOL         (WINAPI *pFPropContainsProp)(LPSPropValue,LPSPropValue,ULONG);
static BOOL         (WINAPI *pFPropCompareProp)(LPSPropValue,ULONG,LPSPropValue);
static LONG         (WINAPI *pLPropCompareProp)(LPSPropValue,LPSPropValue);
static LPSPropValue (WINAPI *pPpropFindProp)(LPSPropValue,ULONG,ULONG);
static SCODE        (WINAPI *pScCountProps)(INT,LPSPropValue,ULONG*);
43 44
static SCODE        (WINAPI *pScCopyProps)(int,LPSPropValue,LPVOID,ULONG*);
static SCODE        (WINAPI *pScRelocProps)(int,LPSPropValue,LPVOID,LPVOID,ULONG*);
45 46 47 48 49 50 51 52
static LPSPropValue (WINAPI *pLpValFindProp)(ULONG,ULONG,LPSPropValue);
static BOOL         (WINAPI *pFBadRglpszA)(LPSTR*,ULONG);
static BOOL         (WINAPI *pFBadRglpszW)(LPWSTR*,ULONG);
static BOOL         (WINAPI *pFBadRowSet)(LPSRowSet);
static ULONG        (WINAPI *pFBadPropTag)(ULONG);
static ULONG        (WINAPI *pFBadRow)(LPSRow);
static ULONG        (WINAPI *pFBadProp)(LPSPropValue);
static ULONG        (WINAPI *pFBadColumnSet)(LPSPropTagArray);
53 54
static SCODE        (WINAPI *pCreateIProp)(LPCIID,ALLOCATEBUFFER*,ALLOCATEMORE*,
                                           FREEBUFFER*,LPVOID,LPPROPDATA*);
55 56
static SCODE        (WINAPI *pMAPIAllocateBuffer)(ULONG, LPVOID);
static SCODE        (WINAPI *pMAPIAllocateMore)(ULONG, LPVOID, LPVOID);
57
static SCODE        (WINAPI *pMAPIInitialize)(LPVOID);
58
static SCODE        (WINAPI *pMAPIFreeBuffer)(LPVOID);
59
static void         (WINAPI *pMAPIUninitialize)(void);
60 61 62 63 64

static BOOL InitFuncPtrs(void)
{
    hMapi32 = LoadLibraryA("mapi32.dll");

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    pPropCopyMore = (void*)GetProcAddress(hMapi32, "PropCopyMore@16");
    pUlPropSize = (void*)GetProcAddress(hMapi32, "UlPropSize@4");
    pFPropContainsProp = (void*)GetProcAddress(hMapi32, "FPropContainsProp@12");
    pFPropCompareProp = (void*)GetProcAddress(hMapi32, "FPropCompareProp@12");
    pLPropCompareProp = (void*)GetProcAddress(hMapi32, "LPropCompareProp@8");
    pPpropFindProp = (void*)GetProcAddress(hMapi32, "PpropFindProp@12");
    pScCountProps = (void*)GetProcAddress(hMapi32, "ScCountProps@12");
    pScCopyProps = (void*)GetProcAddress(hMapi32, "ScCopyProps@16");
    pScRelocProps = (void*)GetProcAddress(hMapi32, "ScRelocProps@20");
    pLpValFindProp = (void*)GetProcAddress(hMapi32, "LpValFindProp@12");
    pFBadRglpszA = (void*)GetProcAddress(hMapi32, "FBadRglpszA@8");
    pFBadRglpszW = (void*)GetProcAddress(hMapi32, "FBadRglpszW@8");
    pFBadRowSet = (void*)GetProcAddress(hMapi32, "FBadRowSet@4");
    pFBadPropTag = (void*)GetProcAddress(hMapi32, "FBadPropTag@4");
    pFBadRow = (void*)GetProcAddress(hMapi32, "FBadRow@4");
    pFBadProp = (void*)GetProcAddress(hMapi32, "FBadProp@4");
    pFBadColumnSet = (void*)GetProcAddress(hMapi32, "FBadColumnSet@4");
    pCreateIProp = (void*)GetProcAddress(hMapi32, "CreateIProp@24");

84
    pScInitMapiUtil = (void*)GetProcAddress(hMapi32, "ScInitMapiUtil@4");
85
    pDeinitMapiUtil = (void*)GetProcAddress(hMapi32, "DeinitMapiUtil@0");
86 87 88
    pMAPIAllocateBuffer = (void*)GetProcAddress(hMapi32, "MAPIAllocateBuffer");
    pMAPIAllocateMore = (void*)GetProcAddress(hMapi32, "MAPIAllocateMore");
    pMAPIFreeBuffer = (void*)GetProcAddress(hMapi32, "MAPIFreeBuffer");
89 90 91 92 93
    pMAPIInitialize = (void*)GetProcAddress(hMapi32, "MAPIInitialize");
    pMAPIUninitialize = (void*)GetProcAddress(hMapi32, "MAPIUninitialize");

    return pMAPIAllocateBuffer && pMAPIAllocateMore && pMAPIFreeBuffer &&
           pScInitMapiUtil && pDeinitMapiUtil;
94
}
95

96 97
/* FIXME: Test PT_I2, PT_I4, PT_R4, PT_R8, PT_CURRENCY, PT_APPTIME, PT_SYSTIME,
 * PT_ERROR, PT_BOOLEAN, PT_I8, and PT_CLSID. */
98
static ULONG ptTypes[] = {
99
    PT_STRING8, PT_BINARY, PT_UNICODE
100 101 102 103 104 105 106 107 108 109
};

static inline int strcmpW(const WCHAR *str1, const WCHAR *str2)
{
    while (*str1 && (*str1 == *str2)) { str1++; str2++; }
    return *str1 - *str2;
}

static void test_PropCopyMore(void)
{
110 111
    static char szHiA[] = "Hi!";
    static WCHAR szHiW[] = { 'H', 'i', '!', '\0' };
112 113 114
    SPropValue *lpDest = NULL, *lpSrc = NULL;
    ULONG i;
    SCODE scode;
115

116
    if (!pPropCopyMore)
117 118
    {
        win_skip("PropCopyMore is not available\n");
119
        return;
120
    }
121

122
    scode = pMAPIAllocateBuffer(sizeof(SPropValue), &lpDest);
123
    ok(scode == S_OK, "Expected MAPIAllocateBuffer to return S_OK, got 0x%x\n", scode);
124
    if (FAILED(scode))
125 126
    {
        skip("MAPIAllocateBuffer failed\n");
127
        return;
128
    }
129

130
    scode = pMAPIAllocateMore(sizeof(SPropValue), lpDest, &lpSrc);
131
    ok(scode == S_OK, "Expected MAPIAllocateMore to return S_OK, got 0x%x\n", scode);
132
    if (FAILED(scode))
133 134
    {
        skip("MAPIAllocateMore failed\n");
135
        return;
136
    }
137

138
    for (i = 0; i < ARRAY_SIZE(ptTypes); i++)
139 140
    {
        lpSrc->ulPropTag = ptTypes[i];
141

142 143 144
        switch (ptTypes[i])
        {
        case PT_STRING8:
145
            lpSrc->Value.lpszA = szHiA;
146 147
            break;
        case PT_UNICODE:
148
            lpSrc->Value.lpszW = szHiW;
149 150 151 152 153 154 155 156
            break;
        case PT_BINARY:
            lpSrc->Value.bin.cb = 4;
            lpSrc->Value.bin.lpb = (LPBYTE)szHiA;
            break;
        }

        memset(lpDest, 0xff, sizeof(SPropValue));
157

158
        scode = pPropCopyMore(lpDest, lpSrc, (ALLOCATEMORE*)pMAPIAllocateMore, lpDest);
159
        ok(!scode && lpDest->ulPropTag == lpSrc->ulPropTag,
160
           "PropCopyMore: Expected 0x0,%d, got 0x%08x,%d\n",
161 162 163 164 165 166 167 168 169 170 171 172 173 174
           lpSrc->ulPropTag, scode, lpDest->ulPropTag);
        if (SUCCEEDED(scode))
        {
            switch (ptTypes[i])
            {
            case PT_STRING8:
                ok(lstrcmpA(lpDest->Value.lpszA, lpSrc->Value.lpszA) == 0,
                   "PropCopyMore: Ascii string differs\n");
                break;
            case PT_UNICODE:
                ok(strcmpW(lpDest->Value.lpszW, lpSrc->Value.lpszW) == 0,
                   "PropCopyMore: Unicode string differs\n");
                break;
            case PT_BINARY:
175
                ok(lpDest->Value.bin.cb == 4 &&
176 177 178 179 180 181
                   !memcmp(lpSrc->Value.bin.lpb, lpDest->Value.bin.lpb, 4),
                   "PropCopyMore: Binary array  differs\n");
                break;
            }
        }
    }
182

183
    /* Since all allocations are linked, freeing lpDest frees everything */
184 185
    scode = pMAPIFreeBuffer(lpDest);
    ok(scode == S_OK, "Expected MAPIFreeBuffer to return S_OK, got 0x%x\n", scode);
186 187 188 189
}

static void test_UlPropSize(void)
{
190 191
    static char szHiA[] = "Hi!";
    static WCHAR szHiW[] = { 'H', 'i', '!', '\0' };
192 193 194 195 196 197
    LPSTR  buffa[2];
    LPWSTR buffw[2];
    SBinary buffbin[2];
    ULONG pt, exp, res;

    if (!pUlPropSize)
198 199
    {
        win_skip("UlPropSize is not available\n");
200
        return;
201
    }
202 203 204 205 206 207 208

    for (pt = 0; pt < PROP_ID_INVALID; pt++)
    {
        SPropValue pv;

        memset(&pv, 0 ,sizeof(pv));
        pv.ulPropTag = pt;
209

210
        exp = 1u; /* Default to one item for non-MV properties */
211

212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
        switch (PROP_TYPE(pt))
        {
        case PT_MV_I2:       pv.Value.MVi.cValues = exp = 2;
        case PT_I2:          exp *= sizeof(USHORT); break;
        case PT_MV_I4:       pv.Value.MVl.cValues = exp = 2;
        case PT_I4:          exp *= sizeof(LONG); break;
        case PT_MV_R4:       pv.Value.MVflt.cValues = exp = 2;
        case PT_R4:          exp *= sizeof(float); break;
        case PT_MV_DOUBLE:   pv.Value.MVdbl.cValues = exp = 2;
        case PT_R8:          exp *= sizeof(double); break;
        case PT_MV_CURRENCY: pv.Value.MVcur.cValues = exp = 2;
        case PT_CURRENCY:    exp *= sizeof(CY); break;
        case PT_MV_APPTIME:  pv.Value.MVat.cValues = exp = 2;
        case PT_APPTIME:     exp *= sizeof(double); break;
        case PT_MV_SYSTIME:  pv.Value.MVft.cValues = exp = 2;
        case PT_SYSTIME:     exp *= sizeof(FILETIME); break;
        case PT_ERROR:       exp = sizeof(SCODE); break;
        case PT_BOOLEAN:     exp = sizeof(USHORT); break;
        case PT_OBJECT:      exp = 0; break;
        case PT_MV_I8:       pv.Value.MVli.cValues = exp = 2;
        case PT_I8:          exp *= sizeof(LONG64); break;
233
#if 0
234
        /* My version of native mapi returns 0 for PT_MV_CLSID even if a valid
235
         * array is given. This _has_ to be a bug, so Wine does
236 237 238 239 240 241
         * the right thing(tm) and we don't test it here.
         */
        case PT_MV_CLSID:    pv.Value.MVguid.cValues = exp = 2;
#endif
        case PT_CLSID:       exp *= sizeof(GUID); break;
        case PT_STRING8:
242
            pv.Value.lpszA = szHiA;
243 244 245
            exp = 4;
            break;
        case PT_UNICODE:
246
            pv.Value.lpszW = szHiW;
247 248 249 250 251 252 253 254
            exp = 4 * sizeof(WCHAR);
            break;
        case PT_BINARY:
            pv.Value.bin.cb = exp = 19;
            break;
        case PT_MV_STRING8:
            pv.Value.MVszA.cValues = 2;
            pv.Value.MVszA.lppszA = buffa;
255 256
            buffa[0] = szHiA;
            buffa[1] = szHiA;
257 258 259 260 261
            exp = 8;
            break;
        case PT_MV_UNICODE:
            pv.Value.MVszW.cValues = 2;
            pv.Value.MVszW.lppszW = buffw;
262 263
            buffw[0] = szHiW;
            buffw[1] = szHiW;
264 265 266 267 268 269 270 271 272 273 274 275 276 277
            exp = 8 * sizeof(WCHAR);
            break;
        case PT_MV_BINARY:
            pv.Value.MVbin.cValues = 2;
            pv.Value.MVbin.lpbin = buffbin;
            buffbin[0].cb = 19;
            buffbin[1].cb = 1;
            exp = 20;
            break;
        default:
            exp = 0;
        }

        res = pUlPropSize(&pv);
278
        ok(res == exp,
279
           "pt= %d: Expected %d, got %d\n", pt, exp, res);
280 281 282 283 284
    }
}

static void test_FPropContainsProp(void)
{
285 286 287 288 289 290
    static char szFull[] = "Full String";
    static char szFullLower[] = "full string";
    static char szPrefix[] = "Full";
    static char szPrefixLower[] = "full";
    static char szSubstring[] = "ll St";
    static char szSubstringLower[] = "ll st";
291 292 293 294 295
    SPropValue pvLeft, pvRight;
    ULONG pt;
    BOOL bRet;

    if (!pFPropContainsProp)
296 297
    {
        win_skip("FPropContainsProp is not available\n");
298
        return;
299
    }
300 301 302 303 304 305 306 307 308 309 310 311

    /* Ensure that only PT_STRING8 and PT_BINARY are handled */
    for (pt = 0; pt < PROP_ID_INVALID; pt++)
    {
        if (pt == PT_STRING8 || pt == PT_BINARY)
            continue; /* test these later */

        memset(&pvLeft, 0 ,sizeof(pvLeft));
        memset(&pvRight, 0 ,sizeof(pvRight));
        pvLeft.ulPropTag = pvRight.ulPropTag = pt;

        bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_FULLSTRING);
312
        ok(bRet == FALSE, "pt= %d: Expected FALSE, got %d\n", pt, bRet);
313 314 315 316
    }

    /* test the various flag combinations */
    pvLeft.ulPropTag = pvRight.ulPropTag = PT_STRING8;
317 318
    pvLeft.Value.lpszA = szFull;
    pvRight.Value.lpszA = szFull;
319 320

    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_FULLSTRING);
321
    ok(bRet == TRUE, "(full,full)[] match failed\n");
322
    pvRight.Value.lpszA = szPrefix;
323 324 325 326 327
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_FULLSTRING);
    ok(bRet == FALSE, "(full,prefix)[] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_PREFIX);
    ok(bRet == TRUE, "(full,prefix)[PREFIX] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_SUBSTRING);
328
    ok(bRet == TRUE, "(full,prefix)[SUBSTRING] match failed\n");
329
    pvRight.Value.lpszA = szPrefixLower;
330 331 332 333 334
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_PREFIX);
    ok(bRet == FALSE, "(full,prefixlow)[PREFIX] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_SUBSTRING);
    ok(bRet == FALSE, "(full,prefixlow)[SUBSTRING] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_PREFIX|FL_IGNORECASE);
335
    ok(bRet == TRUE, "(full,prefixlow)[PREFIX|IGNORECASE] match failed\n");
336
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_SUBSTRING|FL_IGNORECASE);
337
    ok(bRet == TRUE, "(full,prefixlow)[SUBSTRING|IGNORECASE] match failed\n");
338
    pvRight.Value.lpszA = szSubstring;
339 340 341 342 343
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_FULLSTRING);
    ok(bRet == FALSE, "(full,substr)[] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_PREFIX);
    ok(bRet == FALSE, "(full,substr)[PREFIX] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_SUBSTRING);
344
    ok(bRet == TRUE, "(full,substr)[SUBSTRING] match failed\n");
345
    pvRight.Value.lpszA = szSubstringLower;
346 347 348 349 350 351 352
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_PREFIX);
    ok(bRet == FALSE, "(full,substrlow)[PREFIX] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_SUBSTRING);
    ok(bRet == FALSE, "(full,substrlow)[SUBSTRING] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_PREFIX|FL_IGNORECASE);
    ok(bRet == FALSE, "(full,substrlow)[PREFIX|IGNORECASE] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_SUBSTRING|FL_IGNORECASE);
353
    ok(bRet == TRUE, "(full,substrlow)[SUBSTRING|IGNORECASE] match failed\n");
354
    pvRight.Value.lpszA = szFullLower;
355
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_FULLSTRING|FL_IGNORECASE);
356
    ok(bRet == TRUE, "(full,fulllow)[IGNORECASE] match failed\n");
357 358 359 360 361 362 363

    pvLeft.ulPropTag = pvRight.ulPropTag = PT_BINARY;
    pvLeft.Value.bin.lpb = (LPBYTE)szFull;
    pvRight.Value.bin.lpb = (LPBYTE)szFull;
    pvLeft.Value.bin.cb = pvRight.Value.bin.cb = strlen(szFull);

    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_FULLSTRING);
364
    ok(bRet == TRUE, "bin(full,full)[] match failed\n");
365 366 367 368 369
    pvRight.Value.bin.lpb = (LPBYTE)szPrefix;
    pvRight.Value.bin.cb = strlen(szPrefix);
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_FULLSTRING);
    ok(bRet == FALSE, "bin(full,prefix)[] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_PREFIX);
370
    ok(bRet == TRUE, "bin(full,prefix)[PREFIX] match failed\n");
371
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_SUBSTRING);
372
    ok(bRet == TRUE, "bin(full,prefix)[SUBSTRING] match failed\n");
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
    pvRight.Value.bin.lpb = (LPBYTE)szPrefixLower;
    pvRight.Value.bin.cb = strlen(szPrefixLower);
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_PREFIX);
    ok(bRet == FALSE, "bin(full,prefixlow)[PREFIX] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_SUBSTRING);
    ok(bRet == FALSE, "bin(full,prefixlow)[SUBSTRING] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_PREFIX|FL_IGNORECASE);
    ok(bRet == FALSE, "bin(full,prefixlow)[PREFIX|IGNORECASE] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_SUBSTRING|FL_IGNORECASE);
    ok(bRet == FALSE, "bin(full,prefixlow)[SUBSTRING|IGNORECASE] match failed\n");
    pvRight.Value.bin.lpb = (LPBYTE)szSubstring;
    pvRight.Value.bin.cb = strlen(szSubstring);
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_FULLSTRING);
    ok(bRet == FALSE, "bin(full,substr)[] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_PREFIX);
    ok(bRet == FALSE, "bin(full,substr)[PREFIX] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_SUBSTRING);
390
    ok(bRet == TRUE, "bin(full,substr)[SUBSTRING] match failed\n");
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
    pvRight.Value.bin.lpb = (LPBYTE)szSubstringLower;
    pvRight.Value.bin.cb = strlen(szSubstringLower);
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_PREFIX);
    ok(bRet == FALSE, "bin(full,substrlow)[PREFIX] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_SUBSTRING);
    ok(bRet == FALSE, "bin(full,substrlow)[SUBSTRING] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_PREFIX|FL_IGNORECASE);
    ok(bRet == FALSE, "bin(full,substrlow)[PREFIX|IGNORECASE] match failed\n");
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_SUBSTRING|FL_IGNORECASE);
    ok(bRet == FALSE, "bin(full,substrlow)[SUBSTRING|IGNORECASE] match failed\n");
    pvRight.Value.bin.lpb = (LPBYTE)szFullLower;
    pvRight.Value.bin.cb = strlen(szFullLower);
    bRet = pFPropContainsProp(&pvLeft, &pvRight, FL_FULLSTRING|FL_IGNORECASE);
    ok(bRet == FALSE, "bin(full,fulllow)[IGNORECASE] match failed\n");
}

typedef struct tagFPropCompareProp_Result
{
    SHORT lVal;
    SHORT rVal;
    ULONG relOp;
    BOOL  bRet;
} FPropCompareProp_Result;

static const FPropCompareProp_Result FPCProp_Results[] =
{
    { 1, 2, RELOP_LT, TRUE },
    { 1, 1, RELOP_LT, FALSE },
    { 2, 1, RELOP_LT, FALSE },
    { 1, 2, RELOP_LE, TRUE },
    { 1, 1, RELOP_LE, TRUE },
    { 2, 1, RELOP_LE, FALSE },
    { 1, 2, RELOP_GT, FALSE },
    { 1, 1, RELOP_GT, FALSE },
    { 2, 1, RELOP_GT, TRUE },
    { 1, 2, RELOP_GE, FALSE },
    { 1, 1, RELOP_GE, TRUE },
    { 2, 1, RELOP_GE, TRUE },
    { 1, 2, RELOP_EQ, FALSE },
    { 1, 1, RELOP_EQ, TRUE },
    { 2, 1, RELOP_EQ, FALSE }
};

static const char *relops[] = { "RELOP_LT", "RELOP_LE", "RELOP_GT", "RELOP_GE", "RELOP_EQ" };

static void test_FPropCompareProp(void)
{
    SPropValue pvLeft, pvRight;
    GUID lguid, rguid;
    char lbuffa[2], rbuffa[2];
    WCHAR lbuffw[2], rbuffw[2];
    ULONG i, j;
    BOOL bRet, bExp;

    if (!pFPropCompareProp)
446 447
    {
        win_skip("FPropCompareProp is not available\n");
448
        return;
449
    }
450 451 452 453 454 455

    lbuffa[1] = '\0';
    rbuffa[1] = '\0';
    lbuffw[1] = '\0';
    rbuffw[1] = '\0';

456
    for (i = 0; i < ARRAY_SIZE(ptTypes); i++)
457 458 459
    {
        pvLeft.ulPropTag = pvRight.ulPropTag = ptTypes[i];

460
        for (j = 0; j < ARRAY_SIZE(FPCProp_Results); j++)
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
        {
            SHORT lVal = FPCProp_Results[j].lVal;
            SHORT rVal = FPCProp_Results[j].rVal;

            bExp = FPCProp_Results[j].bRet;

            switch (ptTypes[i])
            {
            case PT_BOOLEAN:
                /* Boolean values have no concept of less or greater than, only equality */
                if ((lVal == 1 && rVal == 2 && FPCProp_Results[j].relOp == RELOP_LT) ||
                    (lVal == 2 && rVal == 1 && FPCProp_Results[j].relOp == RELOP_LE)||
                    (lVal == 2 && rVal == 1 && FPCProp_Results[j].relOp == RELOP_GT)||
                    (lVal == 1 && rVal == 2 && FPCProp_Results[j].relOp == RELOP_GE)||
                    (lVal == 1 && rVal == 2 && FPCProp_Results[j].relOp == RELOP_EQ)||
                    (lVal == 2 && rVal == 1 && FPCProp_Results[j].relOp == RELOP_EQ))
                    bExp = !bExp;
                    /* Fall through ... */
            case PT_I2:
                pvLeft.Value.i = lVal;
                pvRight.Value.i = rVal;
                break;
            case PT_ERROR:
            case PT_I4:
                pvLeft.Value.l = lVal;
                pvRight.Value.l = rVal;
                break;
            case PT_R4:
                pvLeft.Value.flt = lVal;
                pvRight.Value.flt = rVal;
                break;
            case PT_APPTIME:
            case PT_R8:
                pvLeft.Value.dbl = lVal;
                pvRight.Value.dbl = rVal;
                break;
            case PT_CURRENCY:
                pvLeft.Value.cur.int64 = lVal;
                pvRight.Value.cur.int64 = rVal;
                break;
            case PT_SYSTIME:
                pvLeft.Value.ft.dwLowDateTime = lVal;
                pvLeft.Value.ft.dwHighDateTime = 0;
                pvRight.Value.ft.dwLowDateTime = rVal;
                pvRight.Value.ft.dwHighDateTime = 0;
                break;
            case PT_I8:
                pvLeft.Value.li.u.LowPart = lVal;
                pvLeft.Value.li.u.HighPart = 0;
                pvRight.Value.li.u.LowPart = rVal;
                pvRight.Value.li.u.HighPart = 0;
                break;
            case PT_CLSID:
                memset(&lguid, 0, sizeof(GUID));
                memset(&rguid, 0, sizeof(GUID));
                lguid.Data4[7] = lVal;
                rguid.Data4[7] = rVal;
                pvLeft.Value.lpguid = &lguid;
                pvRight.Value.lpguid = &rguid;
                break;
            case PT_STRING8:
                pvLeft.Value.lpszA = lbuffa;
                pvRight.Value.lpszA = rbuffa;
                lbuffa[0] = '0' + lVal;
                rbuffa[0] = '0' + rVal;
                break;
            case PT_UNICODE:
                pvLeft.Value.lpszW = lbuffw;
                pvRight.Value.lpszW = rbuffw;
                lbuffw[0] = '0' + lVal;
                rbuffw[0] = '0' + rVal;
                break;
            case PT_BINARY:
                pvLeft.Value.bin.cb = 1;
                pvRight.Value.bin.cb = 1;
Mike McCormack's avatar
Mike McCormack committed
536 537
                pvLeft.Value.bin.lpb = (LPBYTE)lbuffa;
                pvRight.Value.bin.lpb = (LPBYTE)rbuffa;
538 539 540 541 542 543
                lbuffa[0] = lVal;
                rbuffa[0] = rVal;
                break;
            }

            bRet = pFPropCompareProp(&pvLeft, FPCProp_Results[j].relOp, &pvRight);
544
            ok(bRet == bExp,
545
               "pt %d (%d,%d,%s): expected %d, got %d\n", ptTypes[i],
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575
               FPCProp_Results[j].lVal, FPCProp_Results[j].rVal,
               relops[FPCProp_Results[j].relOp], bExp, bRet);
        }
    }
}

typedef struct tagLPropCompareProp_Result
{
    SHORT lVal;
    SHORT rVal;
    INT   iRet;
} LPropCompareProp_Result;

static const LPropCompareProp_Result LPCProp_Results[] =
{
    { 1, 2, -1 },
    { 1, 1, 0 },
    { 2, 1, 1 },
};

static void test_LPropCompareProp(void)
{
    SPropValue pvLeft, pvRight;
    GUID lguid, rguid;
    char lbuffa[2], rbuffa[2];
    WCHAR lbuffw[2], rbuffw[2];
    ULONG i, j;
    INT iRet, iExp;

    if (!pLPropCompareProp)
576 577
    {
        win_skip("LPropCompareProp is not available\n");
578
        return;
579
    }
580 581 582 583 584 585

    lbuffa[1] = '\0';
    rbuffa[1] = '\0';
    lbuffw[1] = '\0';
    rbuffw[1] = '\0';

586
    for (i = 0; i < ARRAY_SIZE(ptTypes); i++)
587 588 589
    {
        pvLeft.ulPropTag = pvRight.ulPropTag = ptTypes[i];

590
        for (j = 0; j < ARRAY_SIZE(LPCProp_Results); j++)
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
        {
            SHORT lVal = LPCProp_Results[j].lVal;
            SHORT rVal = LPCProp_Results[j].rVal;

            iExp = LPCProp_Results[j].iRet;

            switch (ptTypes[i])
            {
            case PT_BOOLEAN:
                /* Boolean values have no concept of less or greater than, only equality */
                if (lVal && rVal)
                    iExp = 0;
                    /* Fall through ... */
            case PT_I2:
                pvLeft.Value.i = lVal;
                pvRight.Value.i = rVal;
                break;
            case PT_ERROR:
            case PT_I4:
                pvLeft.Value.l = lVal;
                pvRight.Value.l = rVal;
                break;
            case PT_R4:
                pvLeft.Value.flt = lVal;
                pvRight.Value.flt = rVal;
                break;
            case PT_APPTIME:
            case PT_R8:
                pvLeft.Value.dbl = lVal;
                pvRight.Value.dbl = rVal;
                break;
            case PT_CURRENCY:
                pvLeft.Value.cur.int64 = lVal;
                pvRight.Value.cur.int64 = rVal;
                break;
            case PT_SYSTIME:
                pvLeft.Value.ft.dwLowDateTime = lVal;
                pvLeft.Value.ft.dwHighDateTime = 0;
                pvRight.Value.ft.dwLowDateTime = rVal;
                pvRight.Value.ft.dwHighDateTime = 0;
                break;
            case PT_I8:
                pvLeft.Value.li.u.LowPart = lVal;
                pvLeft.Value.li.u.HighPart = 0;
                pvRight.Value.li.u.LowPart = rVal;
                pvRight.Value.li.u.HighPart = 0;
                break;
            case PT_CLSID:
                memset(&lguid, 0, sizeof(GUID));
                memset(&rguid, 0, sizeof(GUID));
                lguid.Data4[7] = lVal;
                rguid.Data4[7] = rVal;
                pvLeft.Value.lpguid = &lguid;
                pvRight.Value.lpguid = &rguid;
                break;
            case PT_STRING8:
                pvLeft.Value.lpszA = lbuffa;
                pvRight.Value.lpszA = rbuffa;
                lbuffa[0] = '0' + lVal;
                rbuffa[0] = '0' + rVal;
                break;
            case PT_UNICODE:
                pvLeft.Value.lpszW = lbuffw;
                pvRight.Value.lpszW = rbuffw;
                lbuffw[0] = '0' + lVal;
                rbuffw[0] = '0' + rVal;
                break;
            case PT_BINARY:
                pvLeft.Value.bin.cb = 1;
                pvRight.Value.bin.cb = 1;
Mike McCormack's avatar
Mike McCormack committed
661 662
                pvLeft.Value.bin.lpb = (LPBYTE)lbuffa;
                pvRight.Value.bin.lpb = (LPBYTE)rbuffa;
663 664 665 666 667 668
                lbuffa[0] = lVal;
                rbuffa[0] = rVal;
                break;
            }

            iRet = pLPropCompareProp(&pvLeft, &pvRight);
669
            ok(iRet == iExp,
670
               "pt %d (%d,%d): expected %d, got %d\n", ptTypes[i],
671 672 673 674 675 676 677 678 679 680 681
               LPCProp_Results[j].lVal, LPCProp_Results[j].rVal, iExp, iRet);
        }
    }
}

static void test_PpropFindProp(void)
{
    SPropValue pvProp, *pRet;
    ULONG i;

    if (!pPpropFindProp)
682 683
    {
        win_skip("PpropFindProp is not available\n");
684
        return;
685
    }
686

687
    for (i = 0; i < ARRAY_SIZE(ptTypes); i++)
688 689 690 691
    {
        pvProp.ulPropTag = ptTypes[i];

        pRet = pPpropFindProp(&pvProp, 1u, ptTypes[i]);
692
        ok(pRet == &pvProp,
693
           "PpropFindProp[%d]: Didn't find existing property\n",
694 695 696
           ptTypes[i]);

        pRet = pPpropFindProp(&pvProp, 1u, i ? ptTypes[i-1] : ptTypes[i+1]);
697
        ok(pRet == NULL, "PpropFindProp[%d]: Found nonexistent property\n",
698 699 700 701 702 703 704 705 706 707 708 709
           ptTypes[i]);
    }

    pvProp.ulPropTag = PROP_TAG(PT_I2, 1u);
    pRet = pPpropFindProp(&pvProp, 1u, PROP_TAG(PT_UNSPECIFIED, 0u));
    ok(pRet == NULL, "PpropFindProp[UNSPECIFIED]: Matched on different id\n");
    pRet = pPpropFindProp(&pvProp, 1u, PROP_TAG(PT_UNSPECIFIED, 1u));
    ok(pRet == &pvProp, "PpropFindProp[UNSPECIFIED]: Didn't match id\n");
}

static void test_ScCountProps(void)
{
710 711
    static char szHiA[] = "Hi!";
    static WCHAR szHiW[] = { 'H', 'i', '!', '\0' };
712 713 714 715 716 717 718
    static const ULONG ULHILEN = 4; /* chars in szHiA/W incl. NUL */
    LPSTR  buffa[3];
    LPWSTR buffw[3];
    SBinary buffbin[3];
    GUID iids[4], *iid = iids;
    SCODE res;
    ULONG pt, exp, ulRet;
719
    BOOL success = TRUE;
720 721

    if (!pScCountProps)
722 723
    {
        win_skip("ScCountProps is not available\n");
724
        return;
725
    }
726

727
    for (pt = 0; pt < PROP_ID_INVALID && success; pt++)
728 729 730 731 732 733 734 735
    {
        SPropValue pv;

        memset(&pv, 0 ,sizeof(pv));
        pv.ulPropTag = PROP_TAG(pt, 1u);

        switch (PROP_TYPE(pt))
        {
736 737 738 739 740 741 742 743 744 745 746
        case PT_I2:
        case PT_I4:
        case PT_R4:
        case PT_R8:
        case PT_CURRENCY:
        case PT_APPTIME:
        case PT_SYSTIME:
        case PT_ERROR:
        case PT_BOOLEAN:
        case PT_OBJECT:
        case PT_I8:
747 748 749 750 751 752 753
            exp = sizeof(pv);
            break;
        case PT_CLSID:
            pv.Value.lpguid = iid;
            exp = sizeof(GUID) + sizeof(pv);
            break;
        case PT_STRING8:
754
            pv.Value.lpszA = szHiA;
755 756 757
            exp = 4 + sizeof(pv);
            break;
        case PT_UNICODE:
758
            pv.Value.lpszW = szHiW;
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804
            exp = 4 * sizeof(WCHAR) + sizeof(pv);
            break;
        case PT_BINARY:
            pv.Value.bin.cb = 2;
            pv.Value.bin.lpb = (LPBYTE)iid;
            exp = 2 + sizeof(pv);
            break;
        case PT_MV_I2:
            pv.Value.MVi.cValues = 3;
            pv.Value.MVi.lpi = (SHORT*)iid;
            exp = 3 * sizeof(SHORT) + sizeof(pv);
            break;
        case PT_MV_I4:
            pv.Value.MVl.cValues = 3;
            pv.Value.MVl.lpl = (LONG*)iid;
            exp = 3 * sizeof(LONG) + sizeof(pv);
            break;
        case PT_MV_I8:
            pv.Value.MVli.cValues = 3;
            pv.Value.MVli.lpli = (LARGE_INTEGER*)iid;
            exp = 3 * sizeof(LARGE_INTEGER) + sizeof(pv);
            break;
        case PT_MV_R4:
            pv.Value.MVflt.cValues = 3;
            pv.Value.MVflt.lpflt = (float*)iid;
            exp = 3 * sizeof(float) + sizeof(pv);
            break;
        case PT_MV_APPTIME:
        case PT_MV_R8:
            pv.Value.MVdbl.cValues = 3;
            pv.Value.MVdbl.lpdbl = (double*)iid;
            exp = 3 * sizeof(double) + sizeof(pv);
            break;
        case PT_MV_CURRENCY:
            pv.Value.MVcur.cValues = 3;
            pv.Value.MVcur.lpcur = (CY*)iid;
            exp = 3 * sizeof(CY) + sizeof(pv);
            break;
        case PT_MV_SYSTIME:
            pv.Value.MVft.cValues = 3;
            pv.Value.MVft.lpft = (FILETIME*)iid;
            exp = 3 * sizeof(CY) + sizeof(pv);
            break;
        case PT_MV_STRING8:
            pv.Value.MVszA.cValues = 3;
            pv.Value.MVszA.lppszA = buffa;
805 806 807
            buffa[0] = szHiA;
            buffa[1] = szHiA;
            buffa[2] = szHiA;
808 809 810 811 812
            exp = ULHILEN * 3 + 3 * sizeof(char*) + sizeof(pv);
            break;
        case PT_MV_UNICODE:
            pv.Value.MVszW.cValues = 3;
            pv.Value.MVszW.lppszW = buffw;
813 814 815
            buffw[0] = szHiW;
            buffw[1] = szHiW;
            buffw[2] = szHiW;
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
            exp = ULHILEN * 3 * sizeof(WCHAR) + 3 * sizeof(WCHAR*) + sizeof(pv);
            break;
        case PT_MV_BINARY:
            pv.Value.MVbin.cValues = 3;
            pv.Value.MVbin.lpbin = buffbin;
            buffbin[0].cb = 17;
            buffbin[0].lpb = (LPBYTE)&iid;
            buffbin[1].cb = 2;
            buffbin[1].lpb = (LPBYTE)&iid;
            buffbin[2].cb = 1;
            buffbin[2].lpb = (LPBYTE)&iid;
            exp = 20 + sizeof(pv) + sizeof(SBinary) * 3;
            break;
        default:
            exp = 0;
        }

        ulRet = 0xffffffff;
        res = pScCountProps(1, &pv, &ulRet);
835 836
        if (!exp) {
            success = res == MAPI_E_INVALID_PARAMETER && ulRet == 0xffffffff;
837
            ok(success, "pt= %d: Expected failure, got %d, ret=0x%08X\n",
838 839 840 841
               pt, ulRet, res);
        }
        else {
            success = res == S_OK && ulRet == exp;
842
            ok(success, "pt= %d: Expected %d, got %d, ret=0x%08X\n",
843
               pt, exp, ulRet, res);
844
        }
845 846 847 848
    }

}

849 850
static void test_ScCopyRelocProps(void)
{
851
    static char szTestA[] = "Test";
852 853 854 855
    char buffer[512], buffer2[512], *lppszA[1];
    SPropValue pvProp, *lpResProp = (LPSPropValue)buffer;
    ULONG ulCount;
    SCODE sc;
856

857
    if (!pScCopyProps || !pScRelocProps)
858 859
    {
        win_skip("SPropValue copy functions are not available\n");
860
        return;
861
    }
862 863

    pvProp.ulPropTag = PROP_TAG(PT_MV_STRING8, 1u);
864

865
    lppszA[0] = szTestA;
866 867 868
    pvProp.Value.MVszA.cValues = 1;
    pvProp.Value.MVszA.lppszA = lppszA;
    ulCount = 0;
869 870

    sc = pScCopyProps(1, &pvProp, buffer, &ulCount);
871
    ok(sc == S_OK, "wrong ret %d\n", sc);
872 873 874 875 876 877 878 879 880 881
    if(sc == S_OK)
    {
        ok(lpResProp->ulPropTag == pvProp.ulPropTag, "wrong tag %x\n",lpResProp->ulPropTag);
        ok(lpResProp->Value.MVszA.cValues == 1, "wrong cValues %d\n", lpResProp->Value.MVszA.cValues);
        ok(lpResProp->Value.MVszA.lppszA[0] == buffer + sizeof(SPropValue) + sizeof(char*),
           "wrong lppszA[0] %p\n",lpResProp->Value.MVszA.lppszA[0]);
        ok(ulCount == sizeof(SPropValue) + sizeof(char*) + 5, "wrong count %d\n", ulCount);
        ok(!strcmp(lpResProp->Value.MVszA.lppszA[0], szTestA),
           "wrong string '%s'\n", lpResProp->Value.MVszA.lppszA[0]);
    }
882 883

    memcpy(buffer2, buffer, sizeof(buffer));
884

885 886 887 888 889 890
    /* Clear the data in the source buffer. Since pointers in the copied buffer
     * refer to the source buffer, this proves that native always assumes that
     * the copied buffers pointers are bad (needing to be relocated first).
     */
    memset(buffer, 0, sizeof(buffer));
    ulCount = 0;
891

892 893
    sc = pScRelocProps(1, (LPSPropValue)buffer2, buffer, buffer2, &ulCount);
    lpResProp = (LPSPropValue)buffer2;
894

895
    ok(sc == S_OK, "wrong ret %d\n", sc);
896 897 898 899 900 901 902 903 904 905 906 907 908 909 910
    if(sc == S_OK)
    {
        ok(lpResProp->ulPropTag == pvProp.ulPropTag, "wrong tag %x\n",lpResProp->ulPropTag);
        ok(lpResProp->Value.MVszA.cValues == 1, "wrong cValues %d\n", lpResProp->Value.MVszA.cValues);
        ok(lpResProp->Value.MVszA.lppszA[0] == buffer2 + sizeof(SPropValue) + sizeof(char*),
           "wrong lppszA[0] %p\n",lpResProp->Value.MVszA.lppszA[0]);
        /* Native has a bug whereby it calculates the size correctly when copying
         * but when relocating does not (presumably it uses UlPropSize() which
         * ignores multivalue pointers). Wine returns the correct value.
         */
        ok(ulCount == sizeof(SPropValue) + sizeof(char*) + 5 || ulCount == sizeof(SPropValue) + 5,
           "wrong count %d\n", ulCount);
        ok(!strcmp(lpResProp->Value.MVszA.lppszA[0], szTestA),
           "wrong string '%s'\n", lpResProp->Value.MVszA.lppszA[0]);
    }
911

912
    /* Native crashes with lpNew or lpOld set to NULL so skip testing this */
913 914
}

915 916 917 918 919 920
static void test_LpValFindProp(void)
{
    SPropValue pvProp, *pRet;
    ULONG i;

    if (!pLpValFindProp)
921 922
    {
        win_skip("LpValFindProp is not available\n");
923
        return;
924
    }
925

926
    for (i = 0; i < ARRAY_SIZE(ptTypes); i++)
927 928 929 930
    {
        pvProp.ulPropTag = PROP_TAG(ptTypes[i], 1u);

        pRet = pLpValFindProp(PROP_TAG(ptTypes[i], 1u), 1u, &pvProp);
931
        ok(pRet == &pvProp,
932
           "LpValFindProp[%d]: Didn't find existing property id/type\n",
933 934 935
           ptTypes[i]);

        pRet = pLpValFindProp(PROP_TAG(ptTypes[i], 0u), 1u, &pvProp);
936
        ok(pRet == NULL, "LpValFindProp[%d]: Found nonexistent property id\n",
937
           ptTypes[i]);
938

939
        pRet = pLpValFindProp(PROP_TAG(PT_NULL, 0u), 1u, &pvProp);
940
        ok(pRet == NULL, "LpValFindProp[%d]: Found nonexistent property id/type\n",
941
           ptTypes[i]);
942

943
        pRet = pLpValFindProp(PROP_TAG(PT_NULL, 1u), 1u, &pvProp);
944
        ok(pRet == &pvProp,
945
           "LpValFindProp[%d]: Didn't find existing property id\n",
946 947 948 949 950 951 952
           ptTypes[i]);
    }
}

static void test_FBadRglpszA(void)
{
    LPSTR lpStrs[4];
953
    static CHAR szString[] = "A String";
954
    BOOL bRet;
955

956
    if (!pFBadRglpszA)
957 958
    {
        win_skip("FBadRglpszA is not available\n");
959
        return;
960
    }
961

962
    bRet = pFBadRglpszA(NULL, 10);
963 964
    ok(bRet == TRUE, "FBadRglpszA(Null): expected TRUE, got FALSE\n");

965 966
    lpStrs[0] = lpStrs[1] = lpStrs[2] = lpStrs[3] = NULL;
    bRet = pFBadRglpszA(lpStrs, 4);
967
    ok(bRet == TRUE, "FBadRglpszA(Nulls): expected TRUE, got FALSE\n");
968 969 970

    lpStrs[0] = lpStrs[1] = lpStrs[2] = szString;
    bRet = pFBadRglpszA(lpStrs, 3);
971 972
    ok(bRet == FALSE, "FBadRglpszA(valid): expected FALSE, got TRUE\n");

973
    bRet = pFBadRglpszA(lpStrs, 4);
974
    ok(bRet == TRUE, "FBadRglpszA(1 invalid): expected TRUE, got FALSE\n");
975 976 977 978 979
}

static void test_FBadRglpszW(void)
{
    LPWSTR lpStrs[4];
980
    static WCHAR szString[] = { 'A',' ','S','t','r','i','n','g','\0' };
981
    BOOL bRet;
982

983
    if (!pFBadRglpszW)
984 985
    {
        win_skip("FBadRglpszW is not available\n");
986
        return;
987
    }
988

989
    bRet = pFBadRglpszW(NULL, 10);
990 991
    ok(bRet == TRUE, "FBadRglpszW(Null): expected TRUE, got FALSE\n");

992 993
    lpStrs[0] = lpStrs[1] = lpStrs[2] = lpStrs[3] = NULL;
    bRet = pFBadRglpszW(lpStrs, 4);
994
    ok(bRet == TRUE, "FBadRglpszW(Nulls): expected TRUE, got FALSE\n");
995 996 997

    lpStrs[0] = lpStrs[1] = lpStrs[2] = szString;
    bRet = pFBadRglpszW(lpStrs, 3);
998 999
    ok(bRet == FALSE, "FBadRglpszW(valid): expected FALSE, got TRUE\n");

1000
    bRet = pFBadRglpszW(lpStrs, 4);
1001
    ok(bRet == TRUE, "FBadRglpszW(1 invalid): expected TRUE, got FALSE\n");
1002 1003 1004 1005 1006
}

static void test_FBadRowSet(void)
{
    ULONG ulRet;
1007

1008
    if (!pFBadRowSet)
1009 1010
    {
        win_skip("FBadRowSet is not available\n");
1011
        return;
1012
    }
1013

1014 1015
    ulRet = pFBadRowSet(NULL);
    ok(ulRet != 0, "FBadRow(null): Expected non-zero, got 0\n");
1016

1017 1018 1019 1020 1021 1022 1023 1024
    /* FIXME */
}

static void test_FBadPropTag(void)
{
    ULONG pt, res;

    if (!pFBadPropTag)
1025 1026
    {
        win_skip("FBadPropTag is not available\n");
1027
        return;
1028
    }
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046

    for (pt = 0; pt < PROP_ID_INVALID; pt++)
    {
        BOOL bBad = TRUE;

        switch (pt & (~MV_FLAG & PROP_TYPE_MASK))
        {
        case PT_UNSPECIFIED:
        case PT_NULL: case PT_I2: case PT_I4: case PT_R4:
        case PT_R8: case PT_CURRENCY: case PT_APPTIME:
        case PT_ERROR: case PT_BOOLEAN: case PT_OBJECT:
        case PT_I8: case PT_STRING8: case PT_UNICODE:
        case PT_SYSTIME: case PT_CLSID: case PT_BINARY:
            bBad = FALSE;
        }

        res = pFBadPropTag(pt);
        if (bBad)
1047
            ok(res != 0, "pt= %d: Expected non-zero, got 0\n", pt);
1048
        else
1049
            ok(res == 0,
1050
               "pt= %d: Expected zero, got %d\n", pt, res);
1051 1052 1053 1054 1055 1056
    }
}

static void test_FBadRow(void)
{
    ULONG ulRet;
1057

1058
    if (!pFBadRow)
1059 1060
    {
        win_skip("FBadRow is not available\n");
1061
        return;
1062
    }
1063

1064 1065 1066 1067 1068 1069 1070 1071
    ulRet = pFBadRow(NULL);
    ok(ulRet != 0, "FBadRow(null): Expected non-zero, got 0\n");

    /* FIXME */
}

static void test_FBadProp(void)
{
1072
    static WCHAR szEmpty[] = { '\0' };
1073 1074 1075
    GUID iid;
    ULONG pt, res;
    SPropValue pv;
1076

1077
    if (!pFBadProp)
1078 1079
    {
        win_skip("FBadProp is not available\n");
1080
        return;
1081
    }
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091

    for (pt = 0; pt < PROP_ID_INVALID; pt++)
    {
        BOOL bBad = TRUE;

        memset(&pv, 0, sizeof(pv));
        pv.ulPropTag = pt;

        /* Note that MV values are valid below because their array count is 0,
         * so no pointers are validated.
1092
         */
1093 1094 1095 1096
        switch (PROP_TYPE(pt))
        {
        case (MV_FLAG|PT_UNSPECIFIED):
        case PT_UNSPECIFIED:
1097 1098
        case (MV_FLAG|PT_NULL):
        case PT_NULL:
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140
        case PT_MV_I2:
        case PT_I2:
        case PT_MV_I4:
        case PT_I4:
        case PT_MV_I8:
        case PT_I8:
        case PT_MV_R4:
        case PT_R4:
        case PT_MV_R8:
        case PT_R8:
        case PT_MV_CURRENCY:
        case PT_CURRENCY:
        case PT_MV_APPTIME:
        case PT_APPTIME:
        case (MV_FLAG|PT_ERROR):
        case PT_ERROR:
        case (MV_FLAG|PT_BOOLEAN):
        case PT_BOOLEAN:
        case (MV_FLAG|PT_OBJECT):
        case PT_OBJECT:
        case PT_MV_STRING8:
        case PT_MV_UNICODE:
        case PT_MV_SYSTIME:
        case PT_SYSTIME:
        case PT_MV_BINARY:
        case PT_BINARY:
        case PT_MV_CLSID:
            bBad = FALSE;
            break;
        case PT_STRING8:
        case PT_UNICODE:
            pv.Value.lpszW = szEmpty;
            bBad = FALSE;
            break;
        case PT_CLSID:
            pv.Value.lpguid = &iid;
            bBad = FALSE;
            break;
        }

        res = pFBadProp(&pv);
        if (bBad)
1141
            ok(res != 0, "pt= %d: Expected non-zero, got 0\n", pt);
1142
        else
1143
            ok(res == 0,
1144
               "pt= %d: Expected zero, got %d\n", pt, res);
1145 1146 1147 1148 1149 1150 1151 1152 1153
    }
}

static void test_FBadColumnSet(void)
{
    SPropTagArray pta;
    ULONG pt, res;

    if (!pFBadColumnSet)
1154 1155
    {
        win_skip("FBadColumnSet is not available\n");
1156
        return;
1157
    }
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194

    res = pFBadColumnSet(NULL);
    ok(res != 0, "(null): Expected non-zero, got 0\n");

    pta.cValues = 1;

    for (pt = 0; pt < PROP_ID_INVALID; pt++)
    {
        BOOL bBad = TRUE;

        pta.aulPropTag[0] = pt;

        switch (pt & (~MV_FLAG & PROP_TYPE_MASK))
        {
        case PT_UNSPECIFIED:
        case PT_NULL:
        case PT_I2:
        case PT_I4:
        case PT_R4:
        case PT_R8:
        case PT_CURRENCY:
        case PT_APPTIME:
        case PT_BOOLEAN:
        case PT_OBJECT:
        case PT_I8:
        case PT_STRING8:
        case PT_UNICODE:
        case PT_SYSTIME:
        case PT_CLSID:
        case PT_BINARY:
            bBad = FALSE;
        }
        if (pt == (MV_FLAG|PT_ERROR))
            bBad = FALSE;

        res = pFBadColumnSet(&pta);
        if (bBad)
1195
            ok(res != 0, "pt= %d: Expected non-zero, got 0\n", pt);
1196
        else
1197
            ok(res == 0,
1198
               "pt= %d: Expected zero, got %d\n", pt, res);
1199 1200 1201
    }
}

1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215

static void test_IProp(void)
{
    IPropData *lpIProp;
    LPMAPIERROR lpError;
    LPSPropProblemArray lpProbs;
    LPSPropValue lpProps;
    LPSPropTagArray lpTags;
    SPropValue pvs[2];
    SizedSPropTagArray(2,tags);
    ULONG access[2], count;
    SCODE sc;

    if (!pCreateIProp)
1216 1217
    {
        win_skip("CreateIProp is not available\n");
1218
        return;
1219
    }
1220 1221 1222 1223 1224

    memset(&tags, 0 , sizeof(tags));

    /* Create the object */
    lpIProp = NULL;
1225 1226
    sc = pCreateIProp(&IID_IMAPIPropData, (ALLOCATEBUFFER *)pMAPIAllocateBuffer, (ALLOCATEMORE*)pMAPIAllocateMore,
                      (FREEBUFFER *)pMAPIFreeBuffer, NULL, &lpIProp);
1227
    ok(sc == S_OK && lpIProp,
1228
       "CreateIProp: expected S_OK, non-null, got 0x%08X,%p\n", sc, lpIProp);
1229 1230 1231 1232 1233 1234

    if (sc != S_OK || !lpIProp)
        return;

    /* GetLastError - No errors set */
    lpError = NULL;
1235
    sc = IPropData_GetLastError(lpIProp, E_INVALIDARG, 0, &lpError);
1236
    ok(sc == S_OK && !lpError,
1237
       "GetLastError: Expected S_OK, null, got 0x%08X,%p\n", sc, lpError);
1238 1239 1240 1241 1242

    /* Get prop tags - succeeds returning 0 items */
    lpTags = NULL;
    sc = IPropData_GetPropList(lpIProp, 0, &lpTags);
    ok(sc == S_OK && lpTags && lpTags->cValues == 0,
1243
       "GetPropList(empty): Expected S_OK, non-null, 0, got 0x%08X,%p,%d\n",
1244 1245
        sc, lpTags, lpTags ? lpTags->cValues : 0);
    if (lpTags)
1246
        pMAPIFreeBuffer(lpTags);
1247 1248 1249 1250 1251 1252 1253 1254

    /* Get props - succeeds returning 0 items */
    lpProps = NULL;
    count = 0;
    tags.cValues = 1;
    tags.aulPropTag[0] = PR_IMPORTANCE;
    sc = IPropData_GetProps(lpIProp, (LPSPropTagArray)&tags, 0, &count, &lpProps);
    ok(sc == MAPI_W_ERRORS_RETURNED && lpProps && count == 1,
1255
       "GetProps(empty): Expected ERRORS_RETURNED, non-null, 1, got 0x%08X,%p,%d\n",
1256 1257 1258 1259
       sc, lpProps, count);
    if (lpProps && count > 0)
    {
        ok(lpProps[0].ulPropTag == CHANGE_PROP_TYPE(PR_IMPORTANCE,PT_ERROR),
1260
           "GetProps(empty): Expected %x, got %x\n",
1261 1262
           CHANGE_PROP_TYPE(PR_IMPORTANCE,PT_ERROR), lpProps[0].ulPropTag);

1263
        pMAPIFreeBuffer(lpProps);
1264 1265
    }

1266
    /* Add (NULL) - Can't add NULLs */
1267 1268 1269 1270
    lpProbs = NULL;
    pvs[0].ulPropTag = PROP_TAG(PT_NULL,0x01);
    sc = IPropData_SetProps(lpIProp, 1, pvs, &lpProbs);
    ok(sc == MAPI_E_INVALID_PARAMETER && !lpProbs,
1271
       "SetProps(): Expected INVALID_PARAMETER, null, got 0x%08X,%p\n",
1272 1273
       sc, lpProbs);

1274
    /* Add (OBJECT) - Can't add OBJECTs */
1275 1276 1277 1278
    lpProbs = NULL;
    pvs[0].ulPropTag = PROP_TAG(PT_OBJECT,0x01);
    sc = IPropData_SetProps(lpIProp, 1, pvs, &lpProbs);
    ok(sc == MAPI_E_INVALID_PARAMETER && !lpProbs,
1279
       "SetProps(OBJECT): Expected INVALID_PARAMETER, null, got 0x%08X,%p\n",
1280 1281 1282 1283 1284 1285 1286
       sc, lpProbs);

    /* Add - Adds value */
    lpProbs = NULL;
    pvs[0].ulPropTag = PR_IMPORTANCE;
    sc = IPropData_SetProps(lpIProp, 1, pvs, &lpProbs);
    ok(sc == S_OK && !lpProbs,
1287
       "SetProps(ERROR): Expected S_OK, null, got 0x%08X,%p\n", sc, lpProbs);
1288 1289 1290 1291 1292

    /* Get prop list - returns 1 item */
    lpTags = NULL;
    IPropData_GetPropList(lpIProp, 0, &lpTags);
    ok(sc == S_OK && lpTags && lpTags->cValues == 1,
1293
       "GetPropList: Expected S_OK, non-null, 1, got 0x%08X,%p,%d\n",
1294 1295 1296 1297
        sc, lpTags, lpTags ? lpTags->cValues : 0);
    if (lpTags && lpTags->cValues > 0)
    {
        ok(lpTags->aulPropTag[0] == PR_IMPORTANCE,
1298
           "GetPropList: Expected %x, got %x\n",
1299
           PR_IMPORTANCE, lpTags->aulPropTag[0]);
1300
        pMAPIFreeBuffer(lpTags);
1301 1302 1303 1304
    }

    /* Set access to read and write */
    sc = IPropData_HrSetObjAccess(lpIProp, IPROP_READWRITE);
1305
    ok(sc == S_OK, "SetObjAccess(WRITE): Expected S_OK got 0x%08X\n", sc);
1306 1307 1308 1309 1310 1311 1312 1313

    tags.cValues = 1;
    tags.aulPropTag[0] = PR_IMPORTANCE;

    /* Set item access (bad access) - Fails */
    access[0] = 0;
    sc = IPropData_HrSetPropAccess(lpIProp, (LPSPropTagArray)&tags, access);
    ok(sc == MAPI_E_INVALID_PARAMETER,
1314
       "SetPropAccess(0): Expected INVALID_PARAMETER got 0x%08X\n",sc);
1315 1316 1317
    access[0] = IPROP_READWRITE;
    sc = IPropData_HrSetPropAccess(lpIProp, (LPSPropTagArray)&tags, access);
    ok(sc == MAPI_E_INVALID_PARAMETER,
1318
       "SetPropAccess(RW): Expected INVALID_PARAMETER got 0x%08X\n",sc);
1319 1320 1321
    access[0] = IPROP_CLEAN;
    sc = IPropData_HrSetPropAccess(lpIProp, (LPSPropTagArray)&tags, access);
    ok(sc == MAPI_E_INVALID_PARAMETER,
1322
       "SetPropAccess(C): Expected INVALID_PARAMETER got 0x%08X\n",sc);
1323 1324 1325 1326 1327 1328

    /* Set item access to read/write/clean */
    tags.cValues = 1;
    tags.aulPropTag[0] = PR_IMPORTANCE;
    access[0] = IPROP_READWRITE|IPROP_CLEAN;
    sc = IPropData_HrSetPropAccess(lpIProp, (LPSPropTagArray)&tags, access);
1329
    ok(sc == S_OK, "SetPropAccess(RW/C): Expected S_OK got 0x%08X\n",sc);
1330 1331 1332

    /* Set object access to read only */
    sc = IPropData_HrSetObjAccess(lpIProp, IPROP_READONLY);
1333
    ok(sc == S_OK, "SetObjAccess(READ): Expected S_OK got 0x%08X\n", sc);
1334 1335 1336 1337

    /* Set item access to read/write/dirty - doesn't care about RO object */
    access[0] = IPROP_READONLY|IPROP_DIRTY;
    sc = IPropData_HrSetPropAccess(lpIProp, (LPSPropTagArray)&tags, access);
1338
    ok(sc == S_OK, "SetPropAccess(WRITE): Expected S_OK got 0x%08X\n", sc);
1339 1340 1341 1342 1343 1344

    /* Delete any item when set to read only - Error */
    lpProbs = NULL;
    tags.aulPropTag[0] = PR_RESPONSE_REQUESTED;
    sc = IPropData_DeleteProps(lpIProp, (LPSPropTagArray)&tags, &lpProbs);
    ok(sc == E_ACCESSDENIED && !lpProbs,
1345
       "DeleteProps(nonexistent): Expected E_ACCESSDENIED null got 0x%08X %p\n",
1346 1347 1348 1349
       sc, lpProbs);

    /* Set access to read and write */
    sc = IPropData_HrSetObjAccess(lpIProp, IPROP_READWRITE);
1350
    ok(sc == S_OK, "SetObjAccess(WRITE): Expected S_OK got 0x%08X\n", sc);
1351

1352
    /* Delete nonexistent item - No error */
1353 1354 1355 1356
    lpProbs = NULL;
    tags.aulPropTag[0] = PR_RESPONSE_REQUESTED;
    sc = IPropData_DeleteProps(lpIProp, (LPSPropTagArray)&tags, &lpProbs);
    ok(sc == S_OK && !lpProbs,
1357
       "DeleteProps(nonexistent): Expected S_OK null got 0x%08X %p\n",
1358 1359
       sc, lpProbs);

1360
    /* Delete existing item (r/o) - No error, but lpProbs populated */
1361 1362 1363 1364
    lpProbs = NULL;
    tags.aulPropTag[0] = PR_IMPORTANCE;
    sc = IPropData_DeleteProps(lpIProp, (LPSPropTagArray)&tags, &lpProbs);
    ok(sc == S_OK && lpProbs,
1365
       "DeleteProps(RO): Expected S_OK non-null got 0x%08X %p\n", sc, lpProbs);
1366 1367 1368 1369 1370 1371 1372

    if (lpProbs && lpProbs->cProblem > 0)
    {
        ok(lpProbs->cProblem == 1 &&
           lpProbs->aProblem[0].ulIndex == 0 &&
           lpProbs->aProblem[0].ulPropTag == PR_IMPORTANCE &&
           lpProbs->aProblem[0].scode == E_ACCESSDENIED,
1373
           "DeleteProps(RO): Expected (1,0,%x,%x) got (%d,%x,%x)\n",
1374 1375 1376
            PR_IMPORTANCE, E_ACCESSDENIED,
            lpProbs->aProblem[0].ulIndex, lpProbs->aProblem[0].ulPropTag,
            lpProbs->aProblem[0].scode);
1377
        pMAPIFreeBuffer(lpProbs);
1378 1379 1380 1381 1382 1383 1384
    }

    lpProbs = NULL;
    tags.cValues = 1;
    tags.aulPropTag[0] = PR_RESPONSE_REQUESTED;
    IPropData_HrAddObjProps(lpIProp, (LPSPropTagArray)&tags, &lpProbs);
    ok(sc == S_OK && !lpProbs,
1385
       "AddObjProps(RO): Expected S_OK null got 0x%08X %p\n", sc, lpProbs);
1386 1387 1388 1389 1390

    /* Get prop list - returns 1 item */
    lpTags = NULL;
    IPropData_GetPropList(lpIProp, 0, &lpTags);
    ok(sc == S_OK && lpTags && lpTags->cValues == 1,
1391
       "GetPropList: Expected S_OK, non-null, 1, got 0x%08X,%p,%d\n",
1392 1393 1394 1395
        sc, lpTags, lpTags ? lpTags->cValues : 0);
    if (lpTags && lpTags->cValues > 0)
    {
        ok(lpTags->aulPropTag[0] == PR_IMPORTANCE,
1396
           "GetPropList: Expected %x, got %x\n",
1397
           PR_IMPORTANCE, lpTags->aulPropTag[0]);
1398
        pMAPIFreeBuffer(lpTags);
1399 1400 1401 1402 1403
    }

    /* Set item to r/w again */
    access[0] = IPROP_READWRITE|IPROP_DIRTY;
    sc = IPropData_HrSetPropAccess(lpIProp, (LPSPropTagArray)&tags, access);
1404
    ok(sc == S_OK, "SetPropAccess(WRITE): Expected S_OK got 0x%08X\n", sc);
1405

1406
    /* Delete existing item (r/w) - No error, no problems */
1407 1408 1409
    lpProbs = NULL;
    sc = IPropData_DeleteProps(lpIProp, (LPSPropTagArray)&tags, &lpProbs);
    ok(sc == S_OK && !lpProbs,
1410
       "DeleteProps(RO): Expected S_OK null got 0x%08X %p\n", sc, lpProbs);
1411 1412 1413 1414 1415

    /* Free the list */
    IPropData_Release(lpIProp);
}

1416
START_TEST(prop)
1417
{
1418 1419
    SCODE ret;

1420 1421 1422 1423 1424 1425
    if (!HaveDefaultMailClient())
    {
        win_skip("No default mail client installed\n");
        return;
    }

1426
    if(!InitFuncPtrs())
1427
    {
1428
        win_skip("Needed functions are not available\n");
1429
        return;
1430
    }
1431

1432 1433 1434 1435
    SetLastError(0xdeadbeef);
    ret = pScInitMapiUtil(0);
    if ((ret != S_OK) && (GetLastError() == ERROR_PROC_NOT_FOUND))
    {
1436
        win_skip("ScInitMapiUtil is not implemented\n");
1437 1438 1439
        FreeLibrary(hMapi32);
        return;
    }
1440 1441 1442 1443 1444 1445
    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;
    }
1446 1447 1448

    test_PropCopyMore();
    test_UlPropSize();
1449 1450 1451 1452 1453 1454 1455

    /* We call MAPIInitialize here for the benefit of native extended MAPI
     * providers which crash in the FPropContainsProp tests when MAPIInitialize
     * has not been called. Since MAPIInitialize is irrelevant for FPropContainsProp
     * on Wine, we do not care whether MAPIInitialize succeeds. */
    if (pMAPIInitialize)
        ret = pMAPIInitialize(NULL);
1456
    test_FPropContainsProp();
1457 1458 1459
    if (pMAPIUninitialize && ret == S_OK)
        pMAPIUninitialize();

1460 1461 1462 1463
    test_FPropCompareProp();
    test_LPropCompareProp();
    test_PpropFindProp();
    test_ScCountProps();
1464
    test_ScCopyRelocProps();
1465 1466 1467 1468 1469 1470 1471 1472
    test_LpValFindProp();
    test_FBadRglpszA();
    test_FBadRglpszW();
    test_FBadRowSet();
    test_FBadPropTag();
    test_FBadRow();
    test_FBadProp();
    test_FBadColumnSet();
1473 1474

    test_IProp();
1475 1476

    pDeinitMapiUtil();
1477
    FreeLibrary(hMapi32);
1478
}