Ejemplo n.º 1
0
static void expect_band_content_(int line, HWND hRebar, UINT uBand, INT fStyle, COLORREF clrFore,
    COLORREF clrBack, LPCSTR lpText, int iImage, HWND hwndChild,
    INT cxMinChild, INT cyMinChild, INT cx, HBITMAP hbmBack, INT wID,
    INT cyChild, INT cyMaxChild, INT cyIntegral, INT cxIdeal, LPARAM lParam,
    UINT cxHeader, UINT cxHeader_broken)
{
    CHAR buf[MAX_PATH] = "abc";
    REBARBANDINFOA rb;

    memset(&rb, 0xdd, sizeof(rb));
    rb.cbSize = REBARBANDINFOA_V6_SIZE;
    rb.fMask = RBBIM_BACKGROUND | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_COLORS
        | RBBIM_HEADERSIZE | RBBIM_ID | RBBIM_IDEALSIZE | RBBIM_IMAGE | RBBIM_LPARAM
        | RBBIM_SIZE | RBBIM_STYLE | RBBIM_TEXT;
    rb.lpText = buf;
    rb.cch = MAX_PATH;
    ok(SendMessageA(hRebar, RB_GETBANDINFOA, uBand, (LPARAM)&rb), "RB_GETBANDINFOA failed from line %d\n", line);
    expect_eq(line, rb.fStyle, fStyle, int, "%x");
    expect_eq(line, rb.clrFore, clrFore, COLORREF, "%x");
    expect_eq(line, rb.clrBack, clrBack, COLORREF, "%x");
    expect_eq(line, strcmp(rb.lpText, lpText), 0, int, "%d");
    expect_eq(line, rb.iImage, iImage, int, "%x");
    expect_eq(line, rb.hwndChild, hwndChild, HWND, "%p");
    expect_eq(line, rb.cxMinChild, cxMinChild, int, "%d");
    expect_eq(line, rb.cyMinChild, cyMinChild, int, "%d");
    expect_eq(line, rb.cx, cx, int, "%d");
    expect_eq(line, rb.hbmBack, hbmBack, HBITMAP, "%p");
    expect_eq(line, rb.wID, wID, int, "%d");
    /* the values of cyChild, cyMaxChild and cyIntegral can't be read unless the band is RBBS_VARIABLEHEIGHT */
    expect_eq(line, rb.cyChild, cyChild, int, "%x");
    expect_eq(line, rb.cyMaxChild, cyMaxChild, int, "%x");
    expect_eq(line, rb.cyIntegral, cyIntegral, int, "%x");
    expect_eq(line, rb.cxIdeal, cxIdeal, int, "%d");
    expect_eq(line, rb.lParam, lParam, LPARAM, "%ld");
    ok(rb.cxHeader == cxHeader || rb.cxHeader == cxHeader + 1 || broken(rb.cxHeader == cxHeader_broken),
        "expected %d for %d from line %d\n", cxHeader, rb.cxHeader, line);
}
Ejemplo n.º 2
0
static void test_StrXXX_overflows(void)
{
    CHAR str1[2*MAX_PATH+1], buf[2*MAX_PATH];
    WCHAR wstr1[2*MAX_PATH+1], wbuf[2*MAX_PATH];
    const WCHAR fmt[] = {'%','s',0};
    STRRET strret;
    int ret;
    int i;

    for (i=0; i<2*MAX_PATH; i++)
    {
        str1[i] = '0'+(i%10);
        wstr1[i] = '0'+(i%10);
    }
    str1[2*MAX_PATH] = 0;
    wstr1[2*MAX_PATH] = 0;

    memset(buf, 0xbf, sizeof(buf));
    expect_eq(StrCpyNA(buf, str1, 10), buf, PCHAR, "%p");
    expect_eq(buf[9], 0, CHAR, "%x");
    expect_eq(buf[10], '\xbf', CHAR, "%x");

    if (pStrCatBuffA)
    {
        expect_eq(pStrCatBuffA(buf, str1, 100), buf, PCHAR, "%p");
        expect_eq(buf[99], 0, CHAR, "%x");
        expect_eq(buf[100], '\xbf', CHAR, "%x");
    }
    else
        win_skip("StrCatBuffA() is not available\n");

if (0)
{
    /* crashes on XP */
    StrCpyNW(wbuf, (LPCWSTR)0x1, 10);
    StrCpyNW((LPWSTR)0x1, wstr1, 10);
}

    memset(wbuf, 0xbf, sizeof(wbuf));
    expect_eq(StrCpyNW(wbuf, (LPCWSTR)0x1, 1), wbuf, PWCHAR, "%p");
    expect_eq(wbuf[0], 0, WCHAR, "%x");
    expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");

    memset(wbuf, 0xbf, sizeof(wbuf));
    expect_eq(StrCpyNW(wbuf, 0, 10), wbuf, PWCHAR, "%p");
    expect_eq(wbuf[0], 0, WCHAR, "%x");
    expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");

    memset(wbuf, 0xbf, sizeof(wbuf));
    expect_eq(StrCpyNW(wbuf, 0, 0), wbuf, PWCHAR, "%p");
    expect_eq(wbuf[0], (WCHAR)0xbfbf, WCHAR, "%x");
    expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");

    memset(wbuf, 0xbf, sizeof(wbuf));
    expect_eq(StrCpyNW(wbuf, wstr1, 0), wbuf, PWCHAR, "%p");
    expect_eq(wbuf[0], (WCHAR)0xbfbf, WCHAR, "%x");
    expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");

    memset(wbuf, 0xbf, sizeof(wbuf));
    expect_eq(StrCpyNW(wbuf, wstr1, 10), wbuf, PWCHAR, "%p");
    expect_eq(wbuf[9], 0, WCHAR, "%x");
    expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");

    if (pStrCatBuffW)
    {
        expect_eq(pStrCatBuffW(wbuf, wstr1, 100), wbuf, PWCHAR, "%p");
        expect_eq(wbuf[99], 0, WCHAR, "%x");
        expect_eq(wbuf[100], (WCHAR)0xbfbf, WCHAR, "%x");
    }
    else
        win_skip("StrCatBuffW() is not available\n");

    if (pStrRetToBufW)
    {
        memset(wbuf, 0xbf, sizeof(wbuf));
        strret.uType = STRRET_WSTR;
        U(strret).pOleStr = StrDupW(wstr1);
        expect_eq2(pStrRetToBufW(&strret, NULL, wbuf, 10), S_OK, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) /* Vista */, HRESULT, "%x");
        expect_eq(wbuf[9], 0, WCHAR, "%x");
        expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
    }
    else
        win_skip("StrRetToBufW() is not available\n");

    if (pStrRetToBufA)
    {
        memset(buf, 0xbf, sizeof(buf));
        strret.uType = STRRET_CSTR;
        StrCpyN(U(strret).cStr, str1, MAX_PATH);
        expect_eq2(pStrRetToBufA(&strret, NULL, buf, 10), S_OK, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) /* Vista */, HRESULT, "%x");
        expect_eq(buf[9], 0, CHAR, "%x");
        expect_eq(buf[10], (CHAR)0xbf, CHAR, "%x");
    }
    else
        win_skip("StrRetToBufA() is not available\n");

    if (pwnsprintfA)
    {
        memset(buf, 0xbf, sizeof(buf));
        ret = pwnsprintfA(buf, 10, "%s", str1);
        ok(broken(ret == 9) || ret == -1 /* Vista */, "Unexpected wnsprintfA return %d, expected 9 or -1\n", ret);
        expect_eq(buf[9], 0, CHAR, "%x");
        expect_eq(buf[10], (CHAR)0xbf, CHAR, "%x");
    }
    else
        win_skip("wnsprintfA() is not available\n");

    if (pwnsprintfW)
    {
        memset(wbuf, 0xbf, sizeof(wbuf));
        ret = pwnsprintfW(wbuf, 10, fmt, wstr1);
        ok(broken(ret == 9) || ret == -1 /* Vista */, "Unexpected wnsprintfW return %d, expected 9 or -1\n", ret);
        expect_eq(wbuf[9], 0, WCHAR, "%x");
        expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x");
    }
    else
        win_skip("wnsprintfW() is not available\n");
}
Ejemplo n.º 3
0
static void test_dump_typelib(const char *name)
{
    WCHAR wszName[MAX_PATH];
    ITypeLib *typelib;
    int ifcount = sizeof(info)/sizeof(info[0]);
    int iface, func;

    MultiByteToWideChar(CP_UTF8, 0, name, -1, wszName, MAX_PATH);
    ole_check(LoadTypeLibEx(wszName, REGKIND_NONE, &typelib));
    expect_eq(ITypeLib_GetTypeInfoCount(typelib), ifcount, UINT, "%d");
    for (iface = 0; iface < ifcount; iface++)
    {
        const interface_info *if_info = &info[iface];
        ITypeInfo *typeinfo;
        TYPEATTR *typeattr;
        BSTR bstrIfName;

        trace("Interface %s\n", if_info->name);
        ole_check(ITypeLib_GetTypeInfo(typelib, iface, &typeinfo));
        ole_check(ITypeLib_GetDocumentation(typelib, iface, &bstrIfName, NULL, NULL, NULL));
        expect_wstr_utf8val(bstrIfName, if_info->name);
        SysFreeString(bstrIfName);

        ole_check(ITypeInfo_GetTypeAttr(typeinfo, &typeattr));
        expect_int(typeattr->typekind, if_info->type);
        expect_hex(typeattr->wTypeFlags, if_info->wTypeFlags);
        expect_int(typeattr->cbAlignment, if_info->cbAlignment);
        expect_int(typeattr->cbSizeInstance, if_info->cbSizeInstance);
        expect_int(typeattr->cbSizeVft, if_info->cbSizeVft);
        expect_int(typeattr->cFuncs, if_info->cFuncs);

        for (func = 0; func < typeattr->cFuncs; func++)
        {
            function_info *fn_info = (function_info *)&if_info->funcs[func];
            FUNCDESC *desc;
            BSTR namesTab[256];
            UINT cNames;
            int i;

            trace("Function %s\n", fn_info->names[0]);
            ole_check(ITypeInfo_GetFuncDesc(typeinfo, func, &desc));
            expect_int(desc->memid, fn_info->memid);
            expect_int(desc->funckind, fn_info->funckind);
            expect_int(desc->invkind, fn_info->invkind);
            expect_int(desc->callconv, fn_info->callconv);
            expect_int(desc->cParams, fn_info->cParams);
            expect_int(desc->cParamsOpt, fn_info->cParamsOpt);
            expect_int(desc->oVft, fn_info->oVft);
            expect_int(desc->cScodes, fn_info->cScodes);
            expect_int(desc->wFuncFlags, fn_info->wFuncFlags);
            ole_check(ITypeInfo_GetNames(typeinfo, desc->memid, namesTab, 256, &cNames));
            for (i = 0; i < cNames; i++)
            {
                expect_wstr_utf8val(namesTab[i], fn_info->names[i]);
                SysFreeString(namesTab[i]);
            }
            expect_null(fn_info->names[cNames]);

            check_type(&desc->elemdescFunc, &fn_info->ret_type);
            for (i = 0 ; i < desc->cParams; i++)
            {
                check_type(&desc->lprgelemdescParam[i], &fn_info->params[i]);
            }
            expect_int(fn_info->params[desc->cParams].vt, (VARTYPE)-1);

            ITypeInfo_ReleaseFuncDesc(typeinfo, desc);
        }

        ITypeInfo_ReleaseTypeAttr(typeinfo, typeattr);
        ITypeInfo_Release(typeinfo);
    }
    ITypeLib_Release(typelib);
}