From 94caa05d075efcc9a3b1204e0b8c796f52c77748 Mon Sep 17 00:00:00 2001 From: Mike McCormack Date: Mon, 31 Oct 2005 14:07:20 +0000 Subject: [PATCH] Improve MsiUseFeatureEx and MsiGetFeatureState a little, add some simple test cases. --- dlls/msi/msi.c | 61 +++++++++++++++--------------- dlls/msi/tests/.cvsignore | 1 + dlls/msi/tests/Makefile.in | 1 + dlls/msi/tests/msi.c | 76 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 29 deletions(-) create mode 100644 dlls/msi/tests/msi.c diff --git a/dlls/msi/msi.c b/dlls/msi/msi.c index f792e78773f..59e6fcbb4cb 100644 --- a/dlls/msi/msi.c +++ b/dlls/msi/msi.c @@ -1076,29 +1076,20 @@ end: */ INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature) { - INSTALLSTATE rc; - LPWSTR szwProduct= NULL; - LPWSTR szwFeature= NULL; + LPWSTR szwProduct = NULL, szwFeature= NULL; + INSTALLSTATE rc = INSTALLSTATE_UNKNOWN; - if( szProduct ) - { - szwProduct = strdupAtoW( szProduct ); - if( !szwProduct) - return ERROR_OUTOFMEMORY; - } + szwProduct = strdupAtoW( szProduct ); + if ( szProduct && !szwProduct ) + goto end; - if( szFeature ) - { - szwFeature = strdupAtoW( szFeature ); - if( !szwFeature) - { - msi_free( szwProduct); - return ERROR_OUTOFMEMORY; - } - } + szwFeature = strdupAtoW( szFeature ); + if ( szFeature && !szwFeature ) + goto end; rc = MsiQueryFeatureStateW(szwProduct, szwFeature); +end: msi_free( szwProduct); msi_free( szwFeature); @@ -1114,12 +1105,19 @@ INSTALLSTATE WINAPI MsiQueryFeatureStateA(LPCSTR szProduct, LPCSTR szFeature) */ INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature) { + WCHAR squishProduct[GUID_SIZE]; UINT rc; DWORD sz = 0; HKEY hkey; TRACE("%s %s\n", debugstr_w(szProduct), debugstr_w(szFeature)); + if (!szProduct || !szFeature) + return INSTALLSTATE_INVALIDARG; + + if (!squash_guid( szProduct, squishProduct )) + return INSTALLSTATE_INVALIDARG; + rc = MSIREG_OpenFeaturesKey(szProduct, &hkey, FALSE); if (rc != ERROR_SUCCESS) return INSTALLSTATE_UNKNOWN; @@ -1129,8 +1127,8 @@ INSTALLSTATE WINAPI MsiQueryFeatureStateW(LPCWSTR szProduct, LPCWSTR szFeature) if (rc == ERROR_SUCCESS) return INSTALLSTATE_LOCAL; - else - return INSTALLSTATE_ABSENT; + + return INSTALLSTATE_UNKNOWN; } /****************************************************************** @@ -1414,18 +1412,23 @@ end: INSTALLSTATE WINAPI MsiUseFeatureExW( LPCWSTR szProduct, LPCWSTR szFeature, DWORD dwInstallMode, DWORD dwReserved ) { - FIXME("%s %s %li %li\n", debugstr_w(szProduct), debugstr_w(szFeature), + INSTALLSTATE state; + + TRACE("%s %s %li %li\n", debugstr_w(szProduct), debugstr_w(szFeature), dwInstallMode, dwReserved); - /* - * Polls all the components of the feature to find install state and then - * writes: - * Software\\Microsoft\\Windows\\CurrentVersion\\ - * Installer\\Products\\\\ - * "Usage"=dword:........ - */ + state = MsiQueryFeatureStateW( szProduct, szFeature ); - return INSTALLSTATE_LOCAL; + if (dwReserved) + return INSTALLSTATE_INVALIDARG; + + if (state == INSTALLSTATE_LOCAL && dwInstallMode != INSTALLMODE_NODETECTION) + { + FIXME("mark product %s feature %s as used\n", + debugstr_w(szProduct), debugstr_w(szFeature) ); + } + + return state; } /*********************************************************************** diff --git a/dlls/msi/tests/.cvsignore b/dlls/msi/tests/.cvsignore index b620a5fffbc..d89b901d24f 100644 --- a/dlls/msi/tests/.cvsignore +++ b/dlls/msi/tests/.cvsignore @@ -1,6 +1,7 @@ Makefile db.ok format.ok +msi.ok package.ok record.ok suminfo.ok diff --git a/dlls/msi/tests/Makefile.in b/dlls/msi/tests/Makefile.in index 3196f5eede2..e2a43fcc4e3 100644 --- a/dlls/msi/tests/Makefile.in +++ b/dlls/msi/tests/Makefile.in @@ -8,6 +8,7 @@ IMPORTS = msi kernel32 CTESTS = \ db.c \ format.c \ + msi.c \ package.c \ record.c \ suminfo.c diff --git a/dlls/msi/tests/msi.c b/dlls/msi/tests/msi.c new file mode 100644 index 00000000000..c9afdca29d3 --- /dev/null +++ b/dlls/msi/tests/msi.c @@ -0,0 +1,76 @@ +/* + * tests for Microsoft Installer functionality + * + * Copyright 2005 Mike McCormack 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include + +#include "wine/test.h" + +typedef INSTALLSTATE (WINAPI *fnMsiUseFeatureExA)(LPCSTR, LPCSTR ,DWORD, DWORD ); +fnMsiUseFeatureExA pMsiUseFeatureExA; + +static void test_usefeature(void) +{ + UINT r; + + if (!pMsiUseFeatureExA) + return; + + r = MsiQueryFeatureState(NULL,NULL); + ok( r == INSTALLSTATE_INVALIDARG, "wrong return val\n"); + + r = MsiQueryFeatureState("{9085040-6000-11d3-8cfe-0150048383c9}" ,NULL); + ok( r == INSTALLSTATE_INVALIDARG, "wrong return val\n"); + + r = MsiUseFeatureExA(NULL,NULL,0,0); + ok( r == INSTALLSTATE_INVALIDARG, "wrong return val\n"); + + r = MsiUseFeatureExA(NULL, + "WORDVIEWFiles", -2, 1 ); + ok( r == INSTALLSTATE_INVALIDARG, "wrong return val\n"); + + r = MsiUseFeatureExA("{90850409-6000-11d3-8cfe-0150048383c9}", + NULL, -2, 0 ); + ok( r == INSTALLSTATE_INVALIDARG, "wrong return val\n"); + + r = MsiUseFeatureExA("{9085040-6000-11d3-8cfe-0150048383c9}", + "WORDVIEWFiles", -2, 0 ); + ok( r == INSTALLSTATE_INVALIDARG, "wrong return val\n"); + + r = MsiUseFeatureExA("{0085040-6000-11d3-8cfe-0150048383c9}", + "WORDVIEWFiles", -2, 0 ); + ok( r == INSTALLSTATE_INVALIDARG, "wrong return val\n"); + + r = MsiUseFeatureExA("{90850409-6000-11d3-8cfe-0150048383c9}", + "WORDVIEWFiles", -2, 1 ); + ok( r == INSTALLSTATE_INVALIDARG, "wrong return val\n"); + +} + +START_TEST(msi) +{ + HMODULE hmod = GetModuleHandle("msi.dll"); + pMsiUseFeatureExA = (fnMsiUseFeatureExA) + GetProcAddress(hmod, "MsiUseFeatureExA"); + + test_usefeature(); +}