tests: Don't depend on the static uuid libraries in the tests.
[wine] / dlls / jscript / tests / jscript.c
1 /*
2  * Copyright 2008 Jacek Caban for CodeWeavers
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #define COBJMACROS
20
21 #include <initguid.h>
22 #include <ole2.h>
23 #include <activscp.h>
24 #include <objsafe.h>
25
26 #include "wine/test.h"
27
28 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
29
30 static const CLSID CLSID_JScript =
31     {0xf414c260,0x6ac0,0x11cf,{0xb6,0xd1,0x00,0xaa,0x00,0xbb,0xbb,0x58}};
32
33 static void test_safety(IUnknown *unk)
34 {
35     IObjectSafety *safety;
36     DWORD supported, enabled;
37     HRESULT hres;
38
39     hres = IUnknown_QueryInterface(unk, &IID_IObjectSafety, (void**)&safety);
40     ok(hres == S_OK, "Could not get IObjectSafety: %08x\n", hres);
41     if(FAILED(hres))
42         return;
43
44     hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, &supported, NULL);
45     ok(hres == E_POINTER, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres);
46     hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, NULL, &enabled);
47     ok(hres == E_POINTER, "GetInterfaceSafetyOptions failed: %08x, expected E_POINTER\n", hres);
48
49     supported = enabled = 0xdeadbeef;
50     hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_NULL, &supported, &enabled);
51     ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
52     ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
53        "supported=%x\n", supported);
54     ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
55
56     supported = enabled = 0xdeadbeef;
57     hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScript, &supported, &enabled);
58     ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
59     ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
60        "supported=%x\n", supported);
61     ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
62
63     supported = enabled = 0xdeadbeef;
64     hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
65     ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
66     ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
67        "supported=%x\n", supported);
68     ok(enabled == INTERFACE_USES_DISPEX, "enabled=%x\n", enabled);
69
70     hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
71             INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER
72                 |INTERFACESAFE_FOR_UNTRUSTED_CALLER,
73             INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
74     ok(hres == E_FAIL, "SetInterfaceSafetyOptions failed: %08x, expected E_FAIL\n", hres);
75
76     hres = IObjectSafety_SetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse,
77             INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER,
78             INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER);
79     ok(hres == S_OK, "SetInterfaceSafetyOptions failed: %08x\n", hres);
80
81     supported = enabled = 0xdeadbeef;
82     hres = IObjectSafety_GetInterfaceSafetyOptions(safety, &IID_IActiveScriptParse, &supported, &enabled);
83     ok(hres == S_OK, "GetInterfaceSafetyOptions failed: %08x\n", hres);
84     ok(supported == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
85        "supported=%x\n", supported);
86     ok(enabled == (INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_DISPEX|INTERFACE_USES_SECURITY_MANAGER),
87        "enabled=%x\n", enabled);
88
89     IObjectSafety_Release(safety);
90 }
91
92 static void test_jscript(void)
93 {
94     IActiveScriptParse *parse;
95     IActiveScript *script;
96     IUnknown *unk;
97     HRESULT hres;
98
99     hres = CoCreateInstance(&CLSID_JScript, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
100             &IID_IUnknown, (void**)&unk);
101     ok(hres == S_OK, "CoCreateInstance failed: %08x\n", hres);
102     if(FAILED(hres))
103         return;
104
105     hres = IUnknown_QueryInterface(unk, &IID_IActiveScript, (void**)&script);
106     ok(hres == S_OK, "Could not get IActiveScript: %08x\n", hres);
107
108     hres = IUnknown_QueryInterface(unk, &IID_IActiveScriptParse, (void**)&parse);
109     ok(hres == S_OK, "Could not get IActiveScriptParse: %08x\n", hres);
110
111     test_safety(unk);
112
113     IActiveScriptParse_Release(parse);
114     IActiveScript_Release(script);
115     IUnknown_Release(unk);
116 }
117
118 START_TEST(jscript)
119 {
120     CoInitialize(NULL);
121
122     test_jscript();
123
124     CoUninitialize();
125 }