Added tests.
[wine] / dlls / mshtml / tests / htmldoc.c
1 /*
2  * Copyright 2005 Jacek Caban
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #define COBJMACROS
20
21 #include <wine/test.h>
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "ole2.h"
27 #include "mshtml.h"
28
29 static void test_Persist(IUnknown *punk)
30 {
31     IPersistMoniker *persist_mon;
32     IPersistFile *persist_file;
33     GUID guid;
34     HRESULT hres;
35
36     hres = IUnknown_QueryInterface(punk, &IID_IPersistFile, (void**)&persist_file);
37     ok(hres == S_OK, "QueryInterface(IID_IPersist) failed: %08lx\n", hres);
38     if(SUCCEEDED(hres)) {
39         hres = IPersist_GetClassID(persist_file, NULL);
40         ok(hres == E_INVALIDARG, "GetClassID returned: %08lx, expected E_INVALIDARG\n", hres);
41
42         hres = IPersist_GetClassID(persist_file, &guid);
43         ok(hres == S_OK, "GetClassID failed: %08lx\n", hres);
44         ok(IsEqualGUID(&CLSID_HTMLDocument, &guid), "guid != CLSID_HTMLDocument\n");
45
46         IPersist_Release(persist_file);
47     }
48
49     hres = IUnknown_QueryInterface(punk, &IID_IPersistMoniker, (void**)&persist_mon);
50     ok(hres == S_OK, "QueryInterface(IID_IPersistMoniker) failed: %08lx\n", hres);
51     if(SUCCEEDED(hres)) {
52         hres = IPersistMoniker_GetClassID(persist_mon, NULL);
53         ok(hres == E_INVALIDARG, "GetClassID returned: %08lx, expected E_INVALIDARG\n", hres);
54
55         hres = IPersistMoniker_GetClassID(persist_mon, &guid);
56         ok(hres == S_OK, "GetClassID failed: %08lx\n", hres);
57         ok(IsEqualGUID(&CLSID_HTMLDocument, &guid), "guid != CLSID_HTMLDocument\n");
58
59         IPersistMoniker_Release(persist_mon);
60     }
61 }
62
63 static void test_OleObj(IUnknown *punk)
64 {
65     IOleObject *oleobj;
66     HRESULT hres;
67     GUID guid;
68
69     hres = IUnknown_QueryInterface(punk, &IID_IOleObject, (void**)&oleobj);
70     ok(hres == S_OK, "QueryInterface(IID_IOleObject) failed: %08lx\n", hres);
71     if(SUCCEEDED(hres)) {
72         hres = IOleObject_GetUserClassID(oleobj, NULL);
73         ok(hres == E_INVALIDARG, "GetUserClassID returned: %08lx, expected E_INVALIDARG\n", hres);
74
75         hres = IOleObject_GetUserClassID(oleobj, &guid);
76         ok(hres == S_OK, "GetUserClassID failed: %08lx\n", hres);
77         ok(IsEqualGUID(&guid, &CLSID_HTMLDocument), "guid != CLSID_HTMLDocument\n");
78
79         IOleObject_Release(oleobj);
80     }
81 }
82
83 static void test_HTMLDocument()
84 {
85     IUnknown *htmldoc_unk = NULL;
86     HRESULT hres;
87
88     hres = CoCreateInstance(&CLSID_HTMLDocument, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
89             &IID_IUnknown, (void**)&htmldoc_unk);
90     ok(hres == S_OK, "CoCreateInstance failed: %08lx\n", hres);
91     if(FAILED(hres))
92         return;
93
94     test_Persist(htmldoc_unk);
95     test_OleObj(htmldoc_unk);
96     
97     IUnknown_Release(htmldoc_unk);
98 }
99
100 START_TEST(htmldoc)
101 {
102     CoInitialize(NULL);
103
104     test_HTMLDocument();
105
106     CoUninitialize();
107 }