From ff0f2b35e134cf56a753cb3e049ccc164f253c35 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Mon, 14 Jun 2010 14:21:31 +0200 Subject: [PATCH] msi: Add tests for MsiLocateComponent and make them pass. --- dlls/msi/msi.c | 6 ++ dlls/msi/tests/msi.c | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+) diff --git a/dlls/msi/msi.c b/dlls/msi/msi.c index 3e6a556b3e4..fb7eba5f54e 100644 --- a/dlls/msi/msi.c +++ b/dlls/msi/msi.c @@ -2160,6 +2160,9 @@ INSTALLSTATE WINAPI MsiLocateComponentA(LPCSTR szComponent, LPSTR lpPathBuf, TRACE("%s %p %p\n", debugstr_a(szComponent), lpPathBuf, pcchBuf); + if (!szComponent || !pcchBuf) + return INSTALLSTATE_INVALIDARG; + if (MsiGetProductCodeA( szComponent, szProduct ) != ERROR_SUCCESS) return INSTALLSTATE_UNKNOWN; @@ -2173,6 +2176,9 @@ INSTALLSTATE WINAPI MsiLocateComponentW(LPCWSTR szComponent, LPWSTR lpPathBuf, TRACE("%s %p %p\n", debugstr_w(szComponent), lpPathBuf, pcchBuf); + if (!szComponent || !pcchBuf) + return INSTALLSTATE_INVALIDARG; + if (MsiGetProductCodeW( szComponent, szProduct ) != ERROR_SUCCESS) return INSTALLSTATE_UNKNOWN; diff --git a/dlls/msi/tests/msi.c b/dlls/msi/tests/msi.c index a05abeb90b6..90a357b705b 100644 --- a/dlls/msi/tests/msi.c +++ b/dlls/msi/tests/msi.c @@ -1555,24 +1555,44 @@ static void test_MsiGetComponentPath(void) ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state); ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + size = MAX_PATH; + state = MsiLocateComponentA(NULL, path, &size); + ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state); + ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + /* NULL lpPathBuf */ size = MAX_PATH; state = MsiGetComponentPathA(prodcode, component, NULL, &size); ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + size = MAX_PATH; + state = MsiLocateComponentA(component, NULL, &size); + ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + /* NULL pcchBuf */ size = MAX_PATH; state = MsiGetComponentPathA(prodcode, component, path, NULL); ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state); ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + size = MAX_PATH; + state = MsiLocateComponentA(component, path, NULL); + ok(state == INSTALLSTATE_INVALIDARG, "Expected INSTALLSTATE_INVALIDARG, got %d\n", state); + ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + /* all params valid */ size = MAX_PATH; state = MsiGetComponentPathA(prodcode, component, path, &size); ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\"); lstrcatA(keypath, "Installer\\UserData\\S-1-5-18\\Components\\"); lstrcatA(keypath, comp_squashed); @@ -1586,16 +1606,29 @@ static void test_MsiGetComponentPath(void) ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"C:\\imapath", 10); ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); /* product value exists */ + path[0] = 0; size = MAX_PATH; state = MsiGetComponentPathA(prodcode, component, path, &size); ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state); ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); ok(size == 10, "Expected 10, got %d\n", size); + path[0] = 0; + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state); + ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); + ok(size == 10, "Expected 10, got %d\n", size); + lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\"); lstrcatA(keypath, "Installer\\UserData\\S-1-5-18\\Products\\"); lstrcatA(keypath, prod_squashed); @@ -1609,21 +1642,37 @@ static void test_MsiGetComponentPath(void) ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); /* install properties key exists */ + path[0] = 0; size = MAX_PATH; state = MsiGetComponentPathA(prodcode, component, path, &size); ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state); ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); ok(size == 10, "Expected 10, got %d\n", size); + path[0] = 0; + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state); + ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); + ok(size == 10, "Expected 10, got %d\n", size); + create_file("C:\\imapath", "C:\\imapath", 11); /* file exists */ + path[0] = 0; size = MAX_PATH; state = MsiGetComponentPathA(prodcode, component, path, &size); ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); ok(size == 10, "Expected 10, got %d\n", size); + path[0] = 0; + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); + ok(size == 10, "Expected 10, got %d\n", size); + RegDeleteValueA(compkey, prod_squashed); RegDeleteKeyA(compkey, ""); RegDeleteValueA(installprop, "WindowsInstaller"); @@ -1647,16 +1696,29 @@ static void test_MsiGetComponentPath(void) ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"C:\\imapath", 10); ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); /* product value exists */ + path[0] = 0; size = MAX_PATH; state = MsiGetComponentPathA(prodcode, component, path, &size); ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state); ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); ok(size == 10, "Expected 10, got %d\n", size); + path[0] = 0; + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state); + ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); + ok(size == 10, "Expected 10, got %d\n", size); + lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\"); lstrcatA(keypath, "Installer\\UserData\\S-1-5-18\\Products\\"); lstrcatA(keypath, prod_squashed); @@ -1670,21 +1732,37 @@ static void test_MsiGetComponentPath(void) ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); /* install properties key exists */ + path[0] = 0; size = MAX_PATH; state = MsiGetComponentPathA(prodcode, component, path, &size); ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state); ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); ok(size == 10, "Expected 10, got %d\n", size); + path[0] = 0; + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state); + ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); + ok(size == 10, "Expected 10, got %d\n", size); + create_file("C:\\imapath", "C:\\imapath", 11); /* file exists */ + path[0] = 0; size = MAX_PATH; state = MsiGetComponentPathA(prodcode, component, path, &size); ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); ok(size == 10, "Expected 10, got %d\n", size); + path[0] = 0; + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); + ok(size == 10, "Expected 10, got %d\n", size); + RegDeleteValueA(compkey, prod_squashed); RegDeleteKeyA(compkey, ""); RegDeleteValueA(installprop, "WindowsInstaller"); @@ -1708,6 +1786,11 @@ static void test_MsiGetComponentPath(void) ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\"); lstrcatA(keypath, "Installer\\UserData\\"); lstrcatA(keypath, usersid); @@ -1723,16 +1806,29 @@ static void test_MsiGetComponentPath(void) ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"C:\\imapath", 10); ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); /* product value exists */ + path[0] = 0; size = MAX_PATH; state = MsiGetComponentPathA(prodcode, component, path, &size); ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state); ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); ok(size == 10, "Expected 10, got %d\n", size); + path[0] = 0; + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state); + ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); + ok(size == 10, "Expected 10, got %d\n", size); + lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\"); lstrcatA(keypath, "Installer\\UserData\\S-1-5-18\\Products\\"); lstrcatA(keypath, prod_squashed); @@ -1746,21 +1842,37 @@ static void test_MsiGetComponentPath(void) ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); /* install properties key exists */ + path[0] = 0; size = MAX_PATH; state = MsiGetComponentPathA(prodcode, component, path, &size); ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state); ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); ok(size == 10, "Expected 10, got %d\n", size); + path[0] = 0; + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state); + ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); + ok(size == 10, "Expected 10, got %d\n", size); + create_file("C:\\imapath", "C:\\imapath", 11); /* file exists */ + path[0] = 0; size = MAX_PATH; state = MsiGetComponentPathA(prodcode, component, path, &size); ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); ok(size == 10, "Expected 10, got %d\n", size); + path[0] = 0; + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); + ok(size == 10, "Expected 10, got %d\n", size); + RegDeleteValueA(compkey, prod_squashed); RegDeleteKeyA(prodkey, ""); RegDeleteKeyA(compkey, ""); @@ -1783,6 +1895,11 @@ static void test_MsiGetComponentPath(void) ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\"); lstrcatA(keypath, "Installer\\UserData\\"); lstrcatA(keypath, usersid); @@ -1798,25 +1915,46 @@ static void test_MsiGetComponentPath(void) ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"C:\\imapath", 10); ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); /* product value exists */ + path[0] = 0; size = MAX_PATH; state = MsiGetComponentPathA(prodcode, component, path, &size); ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state); ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); ok(size == 10, "Expected 10, got %d\n", size); + path[0] = 0; + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state); + ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); + ok(size == 10, "Expected 10, got %d\n", size); + create_file("C:\\imapath", "C:\\imapath", 11); /* file exists */ + path[0] = 0; size = MAX_PATH; state = MsiGetComponentPathA(prodcode, component, path, &size); ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); ok(size == 10, "Expected 10, got %d\n", size); + path[0] = 0; + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); + ok(size == 10, "Expected 10, got %d\n", size); + RegDeleteValueA(compkey, prod_squashed); RegDeleteKeyA(prodkey, ""); RegDeleteKeyA(compkey, ""); @@ -1836,6 +1974,11 @@ static void test_MsiGetComponentPath(void) ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + lstrcpyA(keypath, "Software\\Microsoft\\Windows\\CurrentVersion\\"); lstrcatA(keypath, "Installer\\UserData\\S-1-5-18\\Components\\"); lstrcatA(keypath, comp_squashed); @@ -1849,25 +1992,46 @@ static void test_MsiGetComponentPath(void) ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_UNKNOWN, "Expected INSTALLSTATE_UNKNOWN, got %d\n", state); + ok(size == MAX_PATH, "Expected size to be unchanged, got %d\n", size); + res = RegSetValueExA(compkey, prod_squashed, 0, REG_SZ, (const BYTE *)"C:\\imapath", 10); ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res); /* product value exists */ + path[0] = 0; size = MAX_PATH; state = MsiGetComponentPathA(prodcode, component, path, &size); ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state); ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); ok(size == 10, "Expected 10, got %d\n", size); + path[0] = 0; + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_ABSENT, "Expected INSTALLSTATE_ABSENT, got %d\n", state); + ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); + ok(size == 10, "Expected 10, got %d\n", size); + create_file("C:\\imapath", "C:\\imapath", 11); /* file exists */ + path[0] = 0; size = MAX_PATH; state = MsiGetComponentPathA(prodcode, component, path, &size); ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); ok(size == 10, "Expected 10, got %d\n", size); + path[0] = 0; + size = MAX_PATH; + state = MsiLocateComponentA(component, path, &size); + ok(state == INSTALLSTATE_LOCAL, "Expected INSTALLSTATE_LOCAL, got %d\n", state); + ok(!lstrcmpA(path, "C:\\imapath"), "Expected C:\\imapath, got %s\n", path); + ok(size == 10, "Expected 10, got %d\n", size); + RegDeleteValueA(compkey, prod_squashed); RegDeleteKeyA(prodkey, ""); RegDeleteKeyA(compkey, ""); -- 2.11.4.GIT