Beispiel #1
0
static void test_QueryInterface(void)
{
    LPVOID pvObj = NULL;
    HRESULT hr;
    IFont*  font = NULL;
    LONG ref;

    hr = pOleCreateFontIndirect(NULL, &IID_IFont, NULL);
    EXPECT_HR(hr, E_POINTER);

    hr = pOleCreateFontIndirect(NULL, &IID_IFont, &pvObj);
    font = pvObj;

    EXPECT_HR(hr, S_OK);
    ok(font != NULL,"OCFI (NULL,..) returns NULL, instead of !NULL\n");

    pvObj = NULL;
    hr = IFont_QueryInterface( font, &IID_IFont, &pvObj);
    EXPECT_HR(hr, S_OK);

    /* Test if QueryInterface increments ref counter for IFONTs */
    ref = IFont_AddRef(font);
    ok(ref == 3 ||
       broken(ref == 1), /* win95 */
           "IFont_QI expected ref value 3 but instead got %d\n", ref);
    IFont_Release(font);

    ok(pvObj != NULL,"IFont_QI does return NULL, instead of a ptr\n");

    IFont_Release(font);
    IFont_Release(font);
}
Beispiel #2
0
static void test_QueryInterface(void)
{
    LPVOID pvObj = NULL;
    HRESULT hres;
    IFont*  font = NULL;
    LONG ret;

    hres = pOleCreateFontIndirect(NULL, &IID_IFont, NULL);
    ok(hres == E_POINTER, "got 0x%08x\n", hres);

    hres = pOleCreateFontIndirect(NULL, &IID_IFont, &pvObj);
    font = pvObj;

    ok(hres == S_OK,"OCFI (NULL,..) does not return 0, but 0x%08x\n",hres);
    ok(font != NULL,"OCFI (NULL,..) returns NULL, instead of !NULL\n");

    pvObj = NULL;
    hres = IFont_QueryInterface( font, &IID_IFont, &pvObj);

    /* Test if QueryInterface increments ref counter for IFONTs */
    ret = IFont_AddRef(font);
    ok(ret == 3 ||
       broken(ret == 1), /* win95 */
       "IFont_QI expected ref value 3 but instead got %d\n",ret);
    IFont_Release(font);

    ok(hres == S_OK,"IFont_QI does not return S_OK, but 0x%08x\n", hres);
    ok(pvObj != NULL,"IFont_QI does return NULL, instead of a ptr\n");

    /* Original ref and QueryInterface ref both have to be released */
    IFont_Release(font);
    IFont_Release(font);
}
Beispiel #3
0
static void test_OleCreateFontIndirect(void)
{
    FONTDESC fontdesc;
    IFont *font;
    HRESULT hr;

    fontdesc.cbSizeofstruct = sizeof(fontdesc);
    fontdesc.lpstrName = arial_font;
    fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
    fontdesc.sWeight = FW_NORMAL;
    fontdesc.sCharset = ANSI_CHARSET;
    fontdesc.fItalic = FALSE;
    fontdesc.fUnderline = FALSE;
    fontdesc.fStrikethrough = FALSE;

    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
    EXPECT_HR(hr, S_OK);
    IFont_Release(font);

    /* play with cbSizeofstruct value */
    fontdesc.cbSizeofstruct = sizeof(fontdesc)-1;
    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
    EXPECT_HR(hr, S_OK);
    IFont_Release(font);

    fontdesc.cbSizeofstruct = sizeof(fontdesc)+1;
    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
    EXPECT_HR(hr, S_OK);
    IFont_Release(font);

    fontdesc.cbSizeofstruct = 0;
    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
    EXPECT_HR(hr, S_OK);
    IFont_Release(font);
}
Beispiel #4
0
static void test_realization(void)
{
    IFont *font;
    FONTDESC fontdesc;
    HRESULT hr;
    BSTR name;
    SHORT cs;

    /* Try to create a symbol only font (marlett) with charset
       set to ANSI.  This will result in another, ANSI, font
       being selected */
    fontdesc.cbSizeofstruct = sizeof(fontdesc);
    fontdesc.lpstrName = marlett_font;
    fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
    fontdesc.sWeight = FW_NORMAL;
    fontdesc.sCharset = ANSI_CHARSET;
    fontdesc.fItalic = FALSE;
    fontdesc.fUnderline = FALSE;
    fontdesc.fStrikethrough = FALSE;

    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
    EXPECT_HR(hr, S_OK);

    hr = IFont_get_Charset(font, &cs);
    EXPECT_HR(hr, S_OK);
    ok(cs == ANSI_CHARSET, "got charset %d\n", cs);

    IFont_Release(font);

    /* Now create an ANSI font and change the name to marlett */

    fontdesc.lpstrName = arial_font;

    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
    EXPECT_HR(hr, S_OK);

    hr = IFont_get_Charset(font, &cs);
    EXPECT_HR(hr, S_OK);
    ok(cs == ANSI_CHARSET, "got charset %d\n", cs);

    name = SysAllocString(marlett_font);
    hr = IFont_put_Name(font, name);
    EXPECT_HR(hr, S_OK);
    SysFreeString(name);

    hr = IFont_get_Name(font, &name);
    EXPECT_HR(hr, S_OK);
    ok(!lstrcmpiW(name, marlett_font), "got name %s\n", wine_dbgstr_w(name));
    SysFreeString(name);

    hr = IFont_get_Charset(font, &cs);
    EXPECT_HR(hr, S_OK);
    ok(cs == SYMBOL_CHARSET, "got charset %d\n", cs);

    IFont_Release(font);
}
Beispiel #5
0
static void test_OleCreateFontIndirect(void)
{
    FONTDESC fontdesc;
    IUnknown *unk, *unk2;
    IFont *font;
    HRESULT hr;

    fontdesc.cbSizeofstruct = sizeof(fontdesc);
    fontdesc.lpstrName = arial_font;
    fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
    fontdesc.sWeight = FW_NORMAL;
    fontdesc.sCharset = ANSI_CHARSET;
    fontdesc.fItalic = FALSE;
    fontdesc.fUnderline = FALSE;
    fontdesc.fStrikethrough = FALSE;

    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
    EXPECT_HR(hr, S_OK);
    IFont_Release(font);

    /* play with cbSizeofstruct value */
    fontdesc.cbSizeofstruct = sizeof(fontdesc)-1;
    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
    EXPECT_HR(hr, S_OK);
    IFont_Release(font);

    fontdesc.cbSizeofstruct = sizeof(fontdesc)+1;
    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
    EXPECT_HR(hr, S_OK);
    IFont_Release(font);

    fontdesc.cbSizeofstruct = 0;
    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font);
    EXPECT_HR(hr, S_OK);
    IFont_Release(font);

    hr = OleInitialize(NULL);
    ok(hr == S_OK, "got 0x%08x\n", hr);

    hr = CoGetClassObject(&CLSID_StdFont, CLSCTX_INPROC_SERVER, NULL, &IID_IClassFactory, (void**)&unk);
    ok(hr == S_OK, "got 0x%08x\n", hr);

    hr = IUnknown_QueryInterface(unk, &IID_IUnknown, (void**)&unk2);
    ok(hr == S_OK, "got 0x%08x\n", hr);

    IUnknown_Release(unk);
    IUnknown_Release(unk2);

    OleUninitialize();
}
Beispiel #6
0
static void test_returns(void)
{
    IFont *pFont;
    FONTDESC fontdesc;
    HRESULT hr;

    fontdesc.cbSizeofstruct = sizeof(fontdesc);
    fontdesc.lpstrName = MSSansSerif_font;
    fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
    fontdesc.sWeight = FW_NORMAL;
    fontdesc.sCharset = 0;
    fontdesc.fItalic = FALSE;
    fontdesc.fUnderline = FALSE;
    fontdesc.fStrikethrough = FALSE;

    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
    EXPECT_HR(hr, S_OK);

    hr = IFont_put_Name(pFont, NULL);
    EXPECT_HR(hr, CTL_E_INVALIDPROPERTYVALUE);

    hr = IFont_get_Name(pFont, NULL);
    EXPECT_HR(hr, E_POINTER);

    hr = IFont_get_Size(pFont, NULL);
    EXPECT_HR(hr, E_POINTER);

    hr = IFont_get_Bold(pFont, NULL);
    EXPECT_HR(hr, E_POINTER);

    IFont_Release(pFont);
}
Beispiel #7
0
/* Various checks along the way.                         */
static void test_ifont_size(LONG lo_size, LONG hi_size,
	LONG ratio_logical, LONG ratio_himetric,
	LONG hfont_height, const char * test_name)
{
	FONTDESC fd;
	LPVOID pvObj = NULL;
	IFont* ifnt = NULL;
	HFONT hfont;
	LOGFONTA lf;
	CY psize;
	HRESULT hres;
        DWORD rtnval;

	fd.cbSizeofstruct = sizeof(FONTDESC);
	fd.lpstrName      = arial_font; /* using scalable instead of bitmap font reduces errors due to font realization */
	S(fd.cySize).Lo   = lo_size;
	S(fd.cySize).Hi   = hi_size;
	fd.sWeight        = 0;
	fd.sCharset       = 0;
        fd.fItalic        = FALSE;
        fd.fUnderline     = FALSE;
        fd.fStrikethrough = FALSE;

	/* Create font, test that it worked. */
	hres = pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
	ifnt = pvObj;
	ok(hres == S_OK,"%s: OCFI returns 0x%08x instead of S_OK.\n",
		test_name, hres);
	ok(pvObj != NULL,"%s: OCFI returns NULL.\n", test_name);

        /* Change the scaling ratio */
        hres = IFont_SetRatio(ifnt, ratio_logical, ratio_himetric);
        ok((ratio_logical && ratio_himetric) ? hres == S_OK : hres == E_FAIL,
           "%s: IFont_SetRatio unexpectedly returned 0x%08x.\n", test_name, hres);

	/* Read back size. */
	hres = IFont_get_Size(ifnt, &psize);
	ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
		test_name, hres);

        /* Check returned size - allow for errors due to rounding & font realization. */
	ok((abs(S(psize).Lo - lo_size) < 10000) && S(psize).Hi == hi_size,
		"%s: IFont_get_Size: Lo=%d, Hi=%d; expected Lo=%d, Hi=%d.\n",
		test_name, S(psize).Lo, S(psize).Hi, lo_size, hi_size);

	/* Check hFont size. */
	hres = IFont_get_hFont (ifnt, &hfont);
	ok(hres == S_OK, "%s: IFont_get_hFont returns 0x%08x instead of S_OK.\n",
		test_name, hres);
	rtnval = GetObjectA(hfont, sizeof(LOGFONTA), &lf);
        ok(rtnval > 0, "GetObject(hfont) failed\n");

        /* Since font scaling may encounter rounding errors, allow 1 pixel deviation. */
	ok(abs(lf.lfHeight - hfont_height) <= 1,
		"%s: hFont has lf.lfHeight=%d, expected %d.\n",
		test_name, lf.lfHeight, hfont_height);

	/* Free IFont. */
	IFont_Release(ifnt);
}
Beispiel #8
0
void test_QueryInterface(void)
{
        LPVOID pvObj = NULL;
        HRESULT hres;
        IFont*  font = NULL;

        hres = pOleCreateFontIndirect(NULL, &IID_IFont, &pvObj);
        font = pvObj;

        ok(hres == S_OK,"OCFI (NULL,..) does not return 0, but 0x%08lx\n",hres);
        ok(font != NULL,"OCFI (NULL,..) returns NULL, instead of !NULL\n");

        pvObj = NULL;
        hres = IFont_QueryInterface( font, &IID_IFont, &pvObj);

        ok(hres == S_OK,"IFont_QI does not return S_OK, but 0x%08lx\n", hres);
        ok(pvObj != NULL,"IFont_QI does return NULL, instead of a ptr\n");

	IFont_Release(font);
}
Beispiel #9
0
static void test_hfont_lifetime(void)
{
    IFont *font, *font2;
    FONTDESC fontdesc;
    HRESULT hr;
    HFONT hfont, first_hfont = NULL;
    CY size;
    DWORD obj_type;
    int i;

    fontdesc.cbSizeofstruct = sizeof(fontdesc);
    fontdesc.lpstrName = arial_font;
    fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
    fontdesc.sWeight = FW_NORMAL;
    fontdesc.sCharset = ANSI_CHARSET;
    fontdesc.fItalic = FALSE;
    fontdesc.fUnderline = FALSE;
    fontdesc.fStrikethrough = FALSE;

    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
    EXPECT_HR(hr, S_OK);

    hr = IFont_get_hFont(font, &hfont);
    EXPECT_HR(hr, S_OK);

    /* show that if the font is updated the old hfont is deleted when the
       new font is realized */
    for(i = 0; i < 100; i++)
    {
        HFONT last_hfont = hfont;

        size.int64 = (i + 10) * 20000;

        obj_type = GetObjectType(hfont);
        ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);

        hr = IFont_put_Size(font, size);
        EXPECT_HR(hr, S_OK);

        /* put_Size doesn't cause the new font to be realized */
        obj_type = GetObjectType(last_hfont);
        ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);

        hr = IFont_get_hFont(font, &hfont);
        EXPECT_HR(hr, S_OK);

        obj_type = GetObjectType(last_hfont);
        ok(obj_type == 0, "%d: got obj type %d\n", i, obj_type);
    }

    /* now show that if we take a reference on the hfont, it persists
       until the font object is released */
    for(i = 0; i < 100; i++)
    {
        size.int64 = (i + 10) * 20000;

        obj_type = GetObjectType(hfont);
        ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);

        hr = IFont_put_Size(font, size);
        EXPECT_HR(hr, S_OK);

        hr = IFont_get_hFont(font, &hfont);
        EXPECT_HR(hr, S_OK);

        hr = IFont_AddRefHfont(font, hfont);
        EXPECT_HR(hr, S_OK);

        if(i == 0) first_hfont = hfont;
        obj_type = GetObjectType(first_hfont);
        ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
    }

    IFont_Release(font);

    obj_type = GetObjectType(first_hfont);
    ok(obj_type == 0, "got obj type %d\n", obj_type);

    /* An AddRefHfont followed by a ReleaseHfont means the font doesn't not persist
       through re-realization */

    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
    EXPECT_HR(hr, S_OK);

    hr = IFont_get_hFont(font, &hfont);
    EXPECT_HR(hr, S_OK);

    for(i = 0; i < 100; i++)
    {
        HFONT last_hfont = hfont;

        size.int64 = (i + 10) * 20000;

        obj_type = GetObjectType(hfont);
        ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);

        hr = IFont_put_Size(font, size);
        EXPECT_HR(hr, S_OK);

        /* put_Size doesn't cause the new font to be realized */
        obj_type = GetObjectType(last_hfont);
        ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);

        hr = IFont_get_hFont(font, &hfont);
        EXPECT_HR(hr, S_OK);

        hr = IFont_AddRefHfont(font, hfont);
        EXPECT_HR(hr, S_OK);

        hr = IFont_ReleaseHfont(font, hfont);
        EXPECT_HR(hr, S_OK);

        obj_type = GetObjectType(last_hfont);
        ok(obj_type == 0, "%d: got obj type %d\n", i, obj_type);
    }

    /* Interestingly if we release a nonexistent reference on the hfont,
     * it persists until the font object is released
     */
    for(i = 0; i < 100; i++)
    {
        size.int64 = (i + 10) * 20000;

        obj_type = GetObjectType(hfont);
        ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);

        hr = IFont_put_Size(font, size);
        EXPECT_HR(hr, S_OK);

        hr = IFont_get_hFont(font, &hfont);
        EXPECT_HR(hr, S_OK);

        hr = IFont_ReleaseHfont(font, hfont);
        EXPECT_HR(hr, S_OK);

        if(i == 0) first_hfont = hfont;
        obj_type = GetObjectType(first_hfont);
        ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);
    }

    IFont_Release(font);

    obj_type = GetObjectType(first_hfont);
    ok(obj_type == 0, "got obj type %d\n", obj_type);

    /* If we take two internal references on a hfont then we can release
       it twice.  So it looks like there's a total reference count
       that includes internal and external references */

    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font);
    EXPECT_HR(hr, S_OK);
    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&font2);
    EXPECT_HR(hr, S_OK);

    hr = IFont_get_hFont(font, &hfont);
    EXPECT_HR(hr, S_OK);
    hr = IFont_get_hFont(font2, &first_hfont);
    EXPECT_HR(hr, S_OK);
todo_wine
    ok(hfont == first_hfont, "fonts differ\n");
    hr = IFont_ReleaseHfont(font, hfont);
    EXPECT_HR(hr, S_OK);
    hr = IFont_ReleaseHfont(font, hfont);
todo_wine
    EXPECT_HR(hr, S_OK);
    hr = IFont_ReleaseHfont(font, hfont);
    EXPECT_HR(hr, S_FALSE);

    obj_type = GetObjectType(hfont);
    ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);

    IFont_Release(font);

    obj_type = GetObjectType(hfont);
    ok(obj_type == OBJ_FONT, "got obj type %d\n", obj_type);

    IFont_Release(font2);

    obj_type = GetObjectType(hfont);
    ok(obj_type == 0, "got obj type %d\n", obj_type);
}
Beispiel #10
0
static void test_AddRefHfont(void)
{
    FONTDESC fd;
    IFont* ifnt1 = NULL;
    IFont* ifnt2 = NULL;
    IFont* ifnt3 = NULL;
    HFONT hfnt1 = 0;
    HFONT hfnt2 = 0;
    HFONT hfnt3 = 0;
    HRESULT hres;

    /* Basic font description */
    fd.cbSizeofstruct = sizeof(FONTDESC);
    fd.lpstrName      = system_font;
    S(fd.cySize).Lo   = 100;
    S(fd.cySize).Hi   = 100;
    fd.sWeight        = 0;
    fd.sCharset       = 0;
    fd.fItalic        = FALSE;
    fd.fUnderline     = FALSE;
    fd.fStrikethrough = FALSE;

    /* Create HFONTs and IFONTs */
    pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt1);
    IFont_get_hFont(ifnt1,&hfnt1);
    fd.lpstrName = arial_font;
    pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
    IFont_get_hFont(ifnt2,&hfnt2);

    /* Try invalid HFONT */
    hres = IFont_AddRefHfont(ifnt1,NULL);
    ok(hres == E_INVALIDARG,
        "IFont_AddRefHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
        hres);

    /* Try to add a bad HFONT */
    hres = IFont_AddRefHfont(ifnt1,(HFONT)32);
    ok(hres == S_FALSE,
        "IFont_AddRefHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
        hres);

    /* Add simple IFONT HFONT pair */
    hres = IFont_AddRefHfont(ifnt1,hfnt1);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
        hres);

    /* IFONT and HFONT do not have to be the same (always looks at HFONT) */
    hres = IFont_AddRefHfont(ifnt2,hfnt1);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
        hres);

    /* Release all hfnt1 refs */
    hres = IFont_ReleaseHfont(ifnt1,hfnt1);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
        hres);

    hres = IFont_ReleaseHfont(ifnt1,hfnt1);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
        hres);

    hres = IFont_ReleaseHfont(ifnt1,hfnt1);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
        hres);

    /* Check if hfnt1 is empty */
    hres = IFont_ReleaseHfont(ifnt1,hfnt1);
    ok(hres == S_FALSE,
        "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
        hres);

    /* Release all hfnt2 refs */
    hres = IFont_ReleaseHfont(ifnt2,hfnt2);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
        hres);

    /* Check if hfnt2 is empty */
    hres = IFont_ReleaseHfont(ifnt2,hfnt2);
    ok(hres == S_FALSE,
        "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
        hres);

    /* Show that releasing an IFONT does not always release it from the HFONT cache. */

    IFont_Release(ifnt1);

    /* Add a reference for destroyed hfnt1 */
    hres = IFont_AddRefHfont(ifnt2,hfnt1);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
        hres);

    /* Decrement reference for destroyed hfnt1 */
    hres = IFont_ReleaseHfont(ifnt2,hfnt1);
    ok(hres == S_OK ||
       hres == S_FALSE, /* <= win2k */
        "IFont_AddRefHfont: (Release ref) Expected S_OK or S_FALSE but got 0x%08x\n",
        hres);

    /* Shows that releasing all IFONT's does clear the HFONT cache. */

    IFont_Release(ifnt2);

    /* Need to make a new IFONT for testing */
    fd.fUnderline = TRUE;
    pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt3);
    IFont_get_hFont(ifnt3,&hfnt3);

    /* Add a reference for destroyed hfnt1 */
    hres = IFont_AddRefHfont(ifnt3,hfnt1);
    ok(hres == S_FALSE,
        "IFont_AddRefHfont: (Add ref) Expected S_OK but got 0x%08x\n",
        hres);

    /* Decrement reference for destroyed hfnt1 */
    hres = IFont_ReleaseHfont(ifnt3,hfnt1);
    ok(hres == S_FALSE,
        "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
        hres);

    IFont_Release(ifnt3);
}
Beispiel #11
0
static void test_ReleaseHfont(void)
{
    FONTDESC fd;
    LPVOID pvObj1 = NULL;
    LPVOID pvObj2 = NULL;
    IFont* ifnt1 = NULL;
    IFont* ifnt2 = NULL;
    HFONT hfnt1 = 0;
    HFONT hfnt2 = 0;
    HRESULT hres;

    /* Basic font description */
    fd.cbSizeofstruct = sizeof(FONTDESC);
    fd.lpstrName      = system_font;
    S(fd.cySize).Lo   = 100;
    S(fd.cySize).Hi   = 100;
    fd.sWeight        = 0;
    fd.sCharset       = 0;
    fd.fItalic        = FALSE;
    fd.fUnderline     = FALSE;
    fd.fStrikethrough = FALSE;

    /* Create HFONTs and IFONTs */
    pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj1);
    ifnt1 = pvObj1;
    IFont_get_hFont(ifnt1,&hfnt1);
    fd.lpstrName = arial_font;
    pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj2);
    ifnt2 = pvObj2;
    IFont_get_hFont(ifnt2,&hfnt2);

    /* Try invalid HFONT */
    hres = IFont_ReleaseHfont(ifnt1,NULL);
    ok(hres == E_INVALIDARG,
        "IFont_ReleaseHfont: (Bad HFONT) Expected E_INVALIDARG but got 0x%08x\n",
        hres);

    /* Try to add a bad HFONT */
    hres = IFont_ReleaseHfont(ifnt1,(HFONT)32);
    ok(hres == S_FALSE,
        "IFont_ReleaseHfont: (Bad HFONT) Expected S_FALSE but got 0x%08x\n",
        hres);

    /* Release all refs */
    hres = IFont_ReleaseHfont(ifnt1,hfnt1);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
        hres);

    hres = IFont_ReleaseHfont(ifnt2,hfnt2);
    ok(hres == S_OK,
        "IFont_AddRefHfont: (Release ref) Expected S_OK but got 0x%08x\n",
        hres);

    /* Check that both lists are empty */
    hres = IFont_ReleaseHfont(ifnt1,hfnt1);
    ok(hres == S_FALSE,
        "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
        hres);

    /* The list should be empty */
    hres = IFont_ReleaseHfont(ifnt2,hfnt2);
    ok(hres == S_FALSE,
        "IFont_AddRefHfont: (Release ref) Expected S_FALSE but got 0x%08x\n",
        hres);

    IFont_Release(ifnt1);
    IFont_Release(ifnt2);
}
Beispiel #12
0
static void test_IsEqual(void)
{
    FONTDESC fd;
    IFont* ifnt = NULL;
    IFont* ifnt2 = NULL;
    HRESULT hres;

    /* Basic font description */
    fd.cbSizeofstruct = sizeof(FONTDESC);
    fd.lpstrName      = system_font;
    S(fd.cySize).Lo   = 100;
    S(fd.cySize).Hi   = 100;
    fd.sWeight        = 0;
    fd.sCharset       = 0;
    fd.fItalic        = FALSE;
    fd.fUnderline     = FALSE;
    fd.fStrikethrough = FALSE;

    /* Create font */
    pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt);

    /* Test equal fonts */
    pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
    hres = IFont_IsEqual(ifnt,ifnt2);
    ok(hres == S_OK,
        "IFont_IsEqual: (EQUAL) Expected S_OK but got 0x%08x\n",hres);
    IFont_Release(ifnt2);

    /* Check for bad pointer */
    hres = IFont_IsEqual(ifnt,NULL);
    ok(hres == E_POINTER,
        "IFont_IsEqual: (NULL) Expected 0x80004003 but got 0x%08x\n",hres);

    /* Test strName */
    fd.lpstrName = arial_font;
    pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
    hres = IFont_IsEqual(ifnt,ifnt2);
    ok(hres == S_FALSE,
        "IFont_IsEqual: (strName) Expected S_FALSE but got 0x%08x\n",hres);
    fd.lpstrName = system_font;
    IFont_Release(ifnt2);

    /* Test lo font size */
    S(fd.cySize).Lo = 10000;
    pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
    hres = IFont_IsEqual(ifnt,ifnt2);
    ok(hres == S_FALSE,
        "IFont_IsEqual: (Lo font size) Expected S_FALSE but got 0x%08x\n",hres);
    S(fd.cySize).Lo = 100;
    IFont_Release(ifnt2);

    /* Test hi font size */
    S(fd.cySize).Hi = 10000;
    pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
    hres = IFont_IsEqual(ifnt,ifnt2);
    ok(hres == S_FALSE,
        "IFont_IsEqual: (Hi font size) Expected S_FALSE but got 0x%08x\n",hres);
    S(fd.cySize).Hi = 100;
    IFont_Release(ifnt2);

    /* Test font weight  */
    fd.sWeight = 100;
    pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
    hres = IFont_IsEqual(ifnt,ifnt2);
    ok(hres == S_FALSE,
        "IFont_IsEqual: (Weight) Expected S_FALSE but got 0x%08x\n",hres);
    fd.sWeight = 0;
    IFont_Release(ifnt2);

    /* Test charset */
    fd.sCharset = 1;
    pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
    hres = IFont_IsEqual(ifnt,ifnt2);
    ok(hres == S_FALSE,
        "IFont_IsEqual: (Charset) Expected S_FALSE but got 0x%08x\n",hres);
    fd.sCharset = 0;
    IFont_Release(ifnt2);

    /* Test italic setting */
    fd.fItalic = TRUE;
    pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
    hres = IFont_IsEqual(ifnt,ifnt2);
    ok(hres == S_FALSE,
        "IFont_IsEqual: (Italic) Expected S_FALSE but got 0x%08x\n",hres);
    fd.fItalic = FALSE;
    IFont_Release(ifnt2);

    /* Test underline setting */
    fd.fUnderline = TRUE;
    pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
    hres = IFont_IsEqual(ifnt,ifnt2);
    ok(hres == S_FALSE,
        "IFont_IsEqual: (Underline) Expected S_FALSE but got 0x%08x\n",hres);
    fd.fUnderline = FALSE;
    IFont_Release(ifnt2);

    /* Test strikethrough setting */
    fd.fStrikethrough = TRUE;
    pOleCreateFontIndirect(&fd, &IID_IFont, (void **)&ifnt2);
    hres = IFont_IsEqual(ifnt,ifnt2);
    ok(hres == S_FALSE,
        "IFont_IsEqual: (Strikethrough) Expected S_FALSE but got 0x%08x\n",hres);
    fd.fStrikethrough = FALSE;
    IFont_Release(ifnt2);

    /* Free IFont. */
    IFont_Release(ifnt);
}
Beispiel #13
0
static void test_font_events_disp(void)
{
    static const WCHAR nameW[] = {'N','a','m','e',0};
    static const WCHAR sizeW[] = {'S','i','z','e',0};
    static const WCHAR boldW[] = {'B','o','l','d',0};
    static const WCHAR italicW[] = {'I','t','a','l','i','c',0};
    static const WCHAR underlineW[] = {'U','n','d','e','r','l','i','n','e',0};
    static const WCHAR strikeW[] = {'S','t','r','i','k','e','t','h','r','o','u','g','h',0};
    static const WCHAR weightW[] = {'W','e','i','g','h','t',0};
    static const WCHAR charsetW[] = {'C','h','a','r','s','e','t',0};

    static const struct font_dispid font_dispids[] =
    {
        { DISPID_FONT_NAME, nameW },
        { DISPID_FONT_SIZE, sizeW },
        { DISPID_FONT_BOLD, boldW },
        { DISPID_FONT_ITALIC, italicW },
        { DISPID_FONT_UNDER, underlineW },
        { DISPID_FONT_STRIKE, strikeW },
        { DISPID_FONT_WEIGHT, weightW },
        { DISPID_FONT_CHARSET, charsetW }
    };

    IFont *pFont;
    IFont *pFont2;
    IConnectionPointContainer *pCPC;
    IConnectionPoint *pCP;
    FONTDESC fontdesc;
    HRESULT hr;
    DWORD dwCookie;
    IFontDisp *pFontDisp;
    DISPPARAMS dispparams;
    VARIANTARG vararg;
    INT i;

    fontdesc.cbSizeofstruct = sizeof(fontdesc);
    fontdesc.lpstrName = MSSansSerif_font;
    fontdesc.cySize.int64 = 12 * 10000; /* 12 pt */
    fontdesc.sWeight = FW_NORMAL;
    fontdesc.sCharset = 0;
    fontdesc.fItalic = FALSE;
    fontdesc.fUnderline = FALSE;
    fontdesc.fStrikethrough = FALSE;

    hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void **)&pFont);
    EXPECT_HR(hr, S_OK);

    hr = IFont_QueryInterface(pFont, &IID_IConnectionPointContainer, (void **)&pCPC);
    EXPECT_HR(hr, S_OK);

    hr = IConnectionPointContainer_FindConnectionPoint(pCPC, &IID_IFontEventsDisp, &pCP);
    EXPECT_HR(hr, S_OK);
    IConnectionPointContainer_Release(pCPC);

    hr = IConnectionPoint_Advise(pCP, (IUnknown *)&FontEventsDisp, &dwCookie);
    EXPECT_HR(hr, S_OK);
    IConnectionPoint_Release(pCP);

    fonteventsdisp_invoke_called = 0;
    fonteventsdisp_invoke_arg0 = NULL;
    hr = IFont_put_Bold(pFont, TRUE);
    EXPECT_HR(hr, S_OK);

    ok(fonteventsdisp_invoke_called == 1, "IFontEventDisp::Invoke wasn't called once\n");
    SysFreeString(fonteventsdisp_invoke_arg0);

    hr = IFont_QueryInterface(pFont, &IID_IFontDisp, (void **)&pFontDisp);
    EXPECT_HR(hr, S_OK);

    for (i = 0; i < sizeof(font_dispids)/sizeof(font_dispids[0]); i++)
    {
        switch (font_dispids[i].dispid)
        {
        case DISPID_FONT_NAME:
        {
            static const WCHAR arialW[] = {'A','r','i','a','l',0};
            V_VT(&vararg) = VT_BSTR;
            V_BSTR(&vararg) = SysAllocString(arialW);
            break;
        }
        case DISPID_FONT_SIZE:
            V_VT(&vararg) = VT_CY;
            S(V_CY(&vararg)).Lo = 25;
            S(V_CY(&vararg)).Hi = 0;
            break;
        case DISPID_FONT_BOLD:
            V_VT(&vararg) = VT_BOOL;
            V_BOOL(&vararg) = VARIANT_FALSE;
            break;
        case DISPID_FONT_ITALIC:
        case DISPID_FONT_UNDER:
        case DISPID_FONT_STRIKE:
            V_VT(&vararg) = VT_BOOL;
            V_BOOL(&vararg) = VARIANT_TRUE;
            break;
        case DISPID_FONT_WEIGHT:
            V_VT(&vararg) = VT_I2;
            V_I2(&vararg) = FW_BLACK;
            break;
        case DISPID_FONT_CHARSET:
            V_VT(&vararg) = VT_I2;
            V_I2(&vararg) = 1;
            break;
        default:
            ;
        }

        dispparams.cNamedArgs = 0;
        dispparams.rgdispidNamedArgs = NULL;
        dispparams.cArgs = 1;
        dispparams.rgvarg = &vararg;
        fonteventsdisp_invoke_called = 0;
        hr = IFontDisp_Invoke(pFontDisp, font_dispids[i].dispid, &IID_NULL, 0, DISPATCH_PROPERTYPUT, &dispparams, NULL, NULL, NULL);
        ok(hr == S_OK, "dispid=%d, got 0x%08x\n", font_dispids[i].dispid, hr);
        ok(fonteventsdisp_invoke_called == 1, "dispid=%d, DISPID_FONT_CHANGED not called, got %d\n", font_dispids[i].dispid,
            fonteventsdisp_invoke_called);
        if (hr == S_OK)
        {
            ok(!lstrcmpW(font_dispids[i].name, fonteventsdisp_invoke_arg0), "dispid=%d, got %s, expected %s\n",
                font_dispids[i].dispid, wine_dbgstr_w(fonteventsdisp_invoke_arg0), wine_dbgstr_w(font_dispids[i].name));
            SysFreeString(fonteventsdisp_invoke_arg0);
        }
        VariantClear(&vararg);
    }

    IFontDisp_Release(pFontDisp);

    hr = IFont_Clone(pFont, &pFont2);
    EXPECT_HR(hr, S_OK);
    IFont_Release(pFont);

    /* this test shows that the notification routine isn't called again */
    fonteventsdisp_invoke_called = 0;
    hr = IFont_put_Bold(pFont2, FALSE);
    EXPECT_HR(hr, S_OK);
    ok(fonteventsdisp_invoke_called == 0, "got %d\n", fonteventsdisp_invoke_called);

    IFont_Release(pFont2);
}
Beispiel #14
0
static void test_ifont_sizes(LONG lo_size, LONG hi_size,
                             LONG ratio_logical, LONG ratio_himetric,
                             LONG hfont_height, const char * test_name)
{
    FONTDESC fd;
    LPVOID pvObj = NULL;
    IFont* ifnt = NULL;
    HFONT hfont;
    LOGFONT lf;
    CY psize;
    HRESULT hres;

    fd.cbSizeofstruct = sizeof(FONTDESC);
    fd.lpstrName      = system_font;
    S(fd.cySize).Lo   = lo_size;
    S(fd.cySize).Hi   = hi_size;
    fd.sWeight        = 0;
    fd.sCharset       = 0;
    fd.fItalic        = 0;
    fd.fUnderline     = 0;
    fd.fStrikethrough = 0;

    /* Create font, test that it worked. */
    hres = pOleCreateFontIndirect(&fd, &IID_IFont, &pvObj);
    ifnt = pvObj;
    ok(hres == S_OK,"%s: OCFI returns 0x%08x instead of S_OK.\n",
       test_name, hres);
    ok(pvObj != NULL,"%s: OCFI returns NULL.\n", test_name);

    /* Read back size.  Hi part was ignored. */
    hres = IFont_get_Size(ifnt, &psize);
    ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
       test_name, hres);
    ok(S(psize).Lo == lo_size && S(psize).Hi == 0,
       "%s: get_Size: Lo=%d, Hi=%d; expected Lo=%d, Hi=0.\n",
       test_name, S(psize).Lo, S(psize).Hi, lo_size);

    /* Change ratio, check size unchanged.  Standard is 72, 2540. */
    hres = IFont_SetRatio(ifnt, ratio_logical, ratio_himetric);
    ok(hres == S_OK,"%s: IFont_SR returns 0x%08x instead of S_OK.\n",
       test_name, hres);
    hres = IFont_get_Size(ifnt, &psize);
    ok(hres == S_OK,"%s: IFont_get_size returns 0x%08x instead of S_OK.\n",
       test_name, hres);
    ok(S(psize).Lo == lo_size && S(psize).Hi == 0,
       "%s: gS after SR: Lo=%d, Hi=%d; expected Lo=%d, Hi=0.\n",
       test_name, S(psize).Lo, S(psize).Hi, lo_size);

    /* Check hFont size with this ratio.  This tests an important 	*/
    /* conversion for which MSDN is very wrong.			*/
    hres = IFont_get_hFont (ifnt, &hfont);
    ok(hres == S_OK, "%s: IFont_get_hFont returns 0x%08x instead of S_OK.\n",
       test_name, hres);
    hres = GetObject (hfont, sizeof(LOGFONT), &lf);
    ok(lf.lfHeight == hfont_height,
       "%s: hFont has lf.lfHeight=%d, expected %d.\n",
       test_name, lf.lfHeight, hfont_height);

    /* Free IFont. */
    IFont_Release(ifnt);
}