wbemdisp.c 11.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * Copyright 2015 Hans Leidekker for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#define COBJMACROS

#include <stdio.h>
#include "windows.h"
#include "initguid.h"
#include "objidl.h"
#include "wbemdisp.h"
#include "wine/test.h"

DEFINE_GUID(CLSID_WINMGMTS,0x172bddf8,0xceea,0x11d1,0x8b,0x05,0x00,0x60,0x08,0x06,0xd9,0xb6);
29
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
30 31 32

static void test_ParseDisplayName(void)
{
33
    static const WCHAR biosW[] = {'W','i','n','3','2','_','B','i','o','s',0};
34 35 36
    static const WCHAR manufacturerW[] = {'M','a','n','u','f','a','c','t','u','r','e','r',0};
    static const WCHAR versionW[] = {'v','e','r','s','i','o','n',0};
    static const WCHAR nosuchW[] = {'N','o','S','u','c','h',0};
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    static const WCHAR name1[] =
        {'w','i','n','m','g','m','t','s',':',0};
    static const WCHAR name2[] =
        {'w','i','n','m','g','m','t','s',':','\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',0};
    static const WCHAR name3[] =
        {'w','i','n','m','g','m','t','s',':','\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',':',
         'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k','.',
         'D','e','v','i','c','e','I','D','=','\'','C',':','\'',0};
    static const WCHAR name4[] =
        {'w','i','n','m','g','m','t','s',':','\\','\\','.','\\','r','o','o','t','\\','c','i','m','v','2',':',
         'W','i','n','3','2','_','S','e','r','v','i','c','e',0};
    static const struct
    {
        const WCHAR *name;
        HRESULT      hr;
        REFIID       iid;
        ULONG        eaten;
    } tests[] =
    {
        { name1, S_OK, &IID_ISWbemServices, sizeof(name1)/sizeof(name1[0]) - 1 },
        { name2, S_OK, &IID_ISWbemServices, sizeof(name2)/sizeof(name2[0]) - 1 },
        { name3, S_OK, &IID_ISWbemObject, sizeof(name3)/sizeof(name3[0]) - 1 },
        { name4, S_OK, &IID_ISWbemObject, sizeof(name4)/sizeof(name4[0]) - 1 }
    };
61
    LCID english = MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT);
62 63 64 65 66
    IParseDisplayName *displayname;
    IBindCtx *ctx;
    IMoniker *moniker;
    IUnknown *obj;
    BSTR str;
67
    ULONG i, eaten, count;
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
    HRESULT hr;

    hr = CoCreateInstance( &CLSID_WINMGMTS, NULL, CLSCTX_INPROC_SERVER, &IID_IParseDisplayName, (void **)&displayname );
    if (hr != S_OK)
    {
        win_skip( "can't create instance of WINMGMTS\n" );
        return;
    }

    hr = CreateBindCtx( 0, &ctx );
    ok( hr == S_OK, "got %x\n", hr );

    for (i =0; i < sizeof(tests)/sizeof(tests[0]); i++)
    {
        str = SysAllocString( tests[i].name );
        eaten = 0xdeadbeef;
        moniker = NULL;
        hr = IParseDisplayName_ParseDisplayName( displayname, NULL, str, &eaten, &moniker );
        SysFreeString( str );
        ok( hr == tests[i].hr, "%u: got %x\n", i, hr );
        ok( eaten == tests[i].eaten, "%u: got %u\n", i, eaten );
        if (moniker)
        {
            obj = NULL;
            hr = IMoniker_BindToObject( moniker, ctx, NULL, tests[i].iid, (void **)&obj );
            ok( hr == S_OK, "%u: got %x\n", i, hr );
            if (obj) IUnknown_Release( obj );
            IMoniker_Release( moniker );
        }
    }

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
    str = SysAllocString( name1 );
    eaten = 0xdeadbeef;
    moniker = NULL;
    hr = IParseDisplayName_ParseDisplayName( displayname, NULL, str, &eaten, &moniker );
    SysFreeString( str );
    ok( hr == S_OK, "got %x\n", hr );
    ok( eaten == lstrlenW(name1), "got %u\n", eaten );
    if (moniker)
    {
        ISWbemServices *services = NULL;

        hr = IMoniker_BindToObject( moniker, ctx, NULL, &IID_IUnknown, (void **)&services );
        ok( hr == S_OK, "got %x\n", hr );
        if (services)
        {
            ISWbemObjectSet *objectset = NULL;

            str = SysAllocString( biosW );
            hr = ISWbemServices_InstancesOf( services, str, 0, NULL, &objectset );
            SysFreeString( str );
            ok( hr == S_OK, "got %x\n", hr );
            if (objectset)
            {
                hr = ISWbemObjectSet_get__NewEnum( objectset, &obj );
                ok( hr == S_OK, "got %x\n", hr );
                if (obj)
                {
                    IEnumVARIANT *enumvar = NULL;

                    hr = IUnknown_QueryInterface( obj, &IID_IEnumVARIANT, (void **)&enumvar );
                    ok( hr == S_OK, "got %x\n", hr );

                    if (enumvar)
                    {
133
                        VARIANT var, res;
134
                        ULONG fetched;
135 136
                        IDispatch *dispatch = NULL;
                        DISPID dispid;
137 138
                        DISPPARAMS params;
                        UINT arg_err;
139 140 141 142 143 144 145 146 147 148 149 150 151 152

                        fetched = 0xdeadbeef;
                        hr = IEnumVARIANT_Next( enumvar, 0, &var, &fetched );
                        ok( hr == S_OK, "got %x\n", hr );
                        ok( !fetched, "got %u\n", fetched );

                        fetched = 0xdeadbeef;
                        V_VT( &var ) = VT_ERROR;
                        V_ERROR( &var ) = 0xdeadbeef;
                        hr = IEnumVARIANT_Next( enumvar, 1, &var, &fetched );
                        ok( hr == S_OK, "got %x\n", hr );
                        ok( fetched == 1, "got %u\n", fetched );
                        ok( V_VT( &var ) == VT_DISPATCH, "got %u\n", V_VT( &var ) );
                        ok( V_DISPATCH( &var ) != (IDispatch *)0xdeadbeef, "got %u\n", V_VT( &var ) );
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187

                        dispatch = V_DISPATCH( &var );
                        count = 0;
                        hr = IDispatch_GetTypeInfoCount( dispatch, &count );
                        ok( hr == S_OK, "got %x\n", hr );
                        ok( count == 1, "got %u\n", count );

                        str = SysAllocString( manufacturerW );
                        dispid = 0xdeadbeef;
                        hr = IDispatch_GetIDsOfNames( dispatch, &IID_NULL, &str, 1, english, &dispid );
                        SysFreeString( str );
                        ok( hr == S_OK, "got %x\n", hr );
                        ok( dispid == 0x1800001 || dispid == 0x10b /* win2k */, "got %x\n", dispid );

                        str = SysAllocString( versionW );
                        dispid = 0xdeadbeef;
                        hr = IDispatch_GetIDsOfNames( dispatch, &IID_NULL, &str, 1, english, &dispid );
                        SysFreeString( str );
                        ok( hr == S_OK, "got %x\n", hr );
                        ok( dispid == 0x1800002 || dispid == 0x119 /* win2k */, "got %x\n", dispid );

                        str = SysAllocString( nosuchW );
                        dispid = 0xdeadbeef;
                        hr = IDispatch_GetIDsOfNames( dispatch, &IID_NULL, &str, 1, english, &dispid );
                        SysFreeString( str );
                        ok( hr == DISP_E_UNKNOWNNAME, "got %x\n", hr );
                        ok( dispid == DISPID_UNKNOWN, "got %x\n", dispid );

                        str = SysAllocString( manufacturerW );
                        dispid = 0xdeadbeef;
                        hr = IDispatch_GetIDsOfNames( dispatch, &IID_NULL, &str, 1, english, &dispid );
                        SysFreeString( str );
                        ok( hr == S_OK, "got %x\n", hr );
                        ok( dispid == 0x1800001 || dispid == 0x10b /* win2k */, "got %x\n", dispid );

188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
                        if (dispid == 0x1800001) /* crashes on win2k */
                        {
                            V_VT( &res ) = VT_ERROR;
                            V_BSTR( &res ) = (BSTR)0xdeadbeef;
                            params.rgvarg = (VARIANTARG *)0xdeadbeef;
                            params.rgdispidNamedArgs = (DISPID *)0xdeadbeef;
                            params.cArgs = params.cNamedArgs = 0xdeadbeef;
                            arg_err = 0xdeadbeef;
                            hr = IDispatch_Invoke( dispatch, DISPID_UNKNOWN, &IID_NULL, english,
                                                   DISPATCH_METHOD|DISPATCH_PROPERTYGET,
                                                   &params, &res, NULL, &arg_err );
                            ok( hr == DISP_E_MEMBERNOTFOUND || hr == S_OK /* winxp */, "got %x\n", hr );
                            ok( params.rgvarg == (VARIANTARG *)0xdeadbeef, "got %p\n", params.rgvarg );
                            ok( params.rgdispidNamedArgs == (DISPID *)0xdeadbeef, "got %p\n", params.rgdispidNamedArgs );
                            ok( params.cArgs == 0xdeadbeef, "got %u\n", params.cArgs );
                            ok( params.cNamedArgs == 0xdeadbeef, "got %u\n", params.cNamedArgs );
                            ok( V_VT( &res ) == VT_ERROR, "got %u\n", V_VT( &res ) );
                            ok( V_ERROR( &res ) == 0xdeadbeef, "got %u\n", V_VT( &res ) );
                            ok( arg_err == 0xdeadbeef, "got %u\n", arg_err );
                            if (hr == S_OK) VariantClear( &res );
                        }

                        V_VT( &res ) = VT_ERROR;
                        V_BSTR( &res ) = (BSTR)0xdeadbeef;
                        memset( &params, 0, sizeof(params) );
                        hr = IDispatch_Invoke( dispatch, dispid, &IID_NULL, english,
                                               DISPATCH_METHOD|DISPATCH_PROPERTYGET,
                                               &params, &res, NULL, NULL );
                        ok( hr == S_OK, "got %x\n", hr );
                        ok( params.rgvarg == NULL, "got %p\n", params.rgvarg );
                        ok( params.rgdispidNamedArgs == NULL, "got %p\n", params.rgdispidNamedArgs );
                        ok( !params.cArgs, "got %u\n", params.cArgs );
                        ok( !params.cNamedArgs, "got %u\n", params.cNamedArgs );
                        ok( V_VT( &res ) == VT_BSTR, "got %u\n", V_VT( &res ) );
                        ok( V_BSTR( &res ) != (BSTR)0xdeadbeef, "got %u\n", V_VT( &res ) );
                        VariantClear( &res );
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
                        VariantClear( &var );

                        fetched = 0xdeadbeef;
                        hr = IEnumVARIANT_Next( enumvar, 1, &var, &fetched );
                        ok( hr == S_FALSE, "got %x\n", hr );
                        ok( !fetched, "got %u\n", fetched );

                        IEnumVARIANT_Release( enumvar );
                    }
                    IUnknown_Release( obj );
                }
                ISWbemObjectSet_Release( objectset );
            }
            IUnknown_Release( services );
        }
        IMoniker_Release( moniker );
    }

242 243 244 245 246 247 248 249 250 251
    IBindCtx_Release( ctx );
    IParseDisplayName_Release( displayname );
}

START_TEST(wbemdisp)
{
    CoInitialize( NULL );
    test_ParseDisplayName();
    CoUninitialize();
}