Release 1.5.29.
[wine] / dlls / ole32 / tests / errorinfo.c
1 /*
2  * Error Info Tests
3  *
4  * Copyright 2007 Robert Shearman
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * 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 #define COBJMACROS
22 #define CONST_VTABLE
23
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "objbase.h"
29
30 #include "wine/test.h"
31
32 #define ok_ole_success(hr, func) ok(hr == S_OK, func " failed with error 0x%08x\n", hr)
33
34 static const CLSID CLSID_WineTest =
35 { /* 9474ba1a-258b-490b-bc13-516e9239ace0 */
36     0x9474ba1a,
37     0x258b,
38     0x490b,
39     {0xbc, 0x13, 0x51, 0x6e, 0x92, 0x39, 0xac, 0xe0}
40 };
41
42 static void test_error_info(void)
43 {
44     HRESULT hr;
45     ICreateErrorInfo *pCreateErrorInfo;
46     IErrorInfo *pErrorInfo;
47     static WCHAR wszDescription[] = {'F','a','i','l','e','d',' ','S','p','r','o','c','k','e','t',0};
48     static WCHAR wszHelpFile[] = {'s','p','r','o','c','k','e','t','.','h','l','p',0};
49     static WCHAR wszSource[] = {'s','p','r','o','c','k','e','t',0};
50     IUnknown *unk;
51
52     hr = CreateErrorInfo(&pCreateErrorInfo);
53     ok_ole_success(hr, "CreateErrorInfo");
54
55     hr = ICreateErrorInfo_QueryInterface(pCreateErrorInfo, &IID_IUnknown, (void**)&unk);
56     ok_ole_success(hr, "QI");
57     IUnknown_Release(unk);
58
59     hr = ICreateErrorInfo_SetDescription(pCreateErrorInfo, NULL);
60     ok_ole_success(hr, "ICreateErrorInfo_SetDescription");
61
62     hr = ICreateErrorInfo_SetDescription(pCreateErrorInfo, wszDescription);
63     ok_ole_success(hr, "ICreateErrorInfo_SetDescription");
64
65     hr = ICreateErrorInfo_SetGUID(pCreateErrorInfo, &CLSID_WineTest);
66     ok_ole_success(hr, "ICreateErrorInfo_SetGUID");
67
68     hr = ICreateErrorInfo_SetHelpContext(pCreateErrorInfo, 0xdeadbeef);
69     ok_ole_success(hr, "ICreateErrorInfo_SetHelpContext");
70
71     hr = ICreateErrorInfo_SetHelpFile(pCreateErrorInfo, NULL);
72     ok_ole_success(hr, "ICreateErrorInfo_SetHelpFile");
73
74     hr = ICreateErrorInfo_SetHelpFile(pCreateErrorInfo, wszHelpFile);
75     ok_ole_success(hr, "ICreateErrorInfo_SetHelpFile");
76
77     hr = ICreateErrorInfo_SetSource(pCreateErrorInfo, NULL);
78     ok_ole_success(hr, "ICreateErrorInfo_SetSource");
79
80     hr = ICreateErrorInfo_SetSource(pCreateErrorInfo, wszSource);
81     ok_ole_success(hr, "ICreateErrorInfo_SetSource");
82
83     hr = ICreateErrorInfo_QueryInterface(pCreateErrorInfo, &IID_IErrorInfo, (void **)&pErrorInfo);
84     ok_ole_success(hr, "ICreateErrorInfo_QueryInterface");
85
86     hr = IErrorInfo_QueryInterface(pErrorInfo, &IID_IUnknown, (void**)&unk);
87     ok_ole_success(hr, "QI");
88     IUnknown_Release(unk);
89
90     ICreateErrorInfo_Release(pCreateErrorInfo);
91
92     hr = SetErrorInfo(0, pErrorInfo);
93     ok_ole_success(hr, "SetErrorInfo");
94
95     IErrorInfo_Release(pErrorInfo);
96     pErrorInfo = NULL;
97
98     hr = GetErrorInfo(0, &pErrorInfo);
99     ok_ole_success(hr, "GetErrorInfo");
100
101     IErrorInfo_Release(pErrorInfo);
102
103     hr = GetErrorInfo(0, &pErrorInfo);
104     ok(hr == S_FALSE, "GetErrorInfo should have returned S_FALSE instead of 0x%08x\n", hr);
105     ok(!pErrorInfo, "pErrorInfo should be set to NULL\n");
106
107     hr = SetErrorInfo(0, NULL);
108     ok_ole_success(hr, "SetErrorInfo");
109
110     hr = GetErrorInfo(0xdeadbeef, &pErrorInfo);
111     ok(hr == E_INVALIDARG, "GetErrorInfo should have returned E_INVALIDARG instead of 0x%08x\n", hr);
112
113     hr = SetErrorInfo(0xdeadbeef, NULL);
114     ok(hr == E_INVALIDARG, "SetErrorInfo should have returned E_INVALIDARG instead of 0x%08x\n", hr);
115 }
116
117 START_TEST(errorinfo)
118 {
119     test_error_info();
120 }