Skip to content

Commit

Permalink
Improved MsiTest to get better errors
Browse files Browse the repository at this point in the history
Signed-off-by: Torbjörn Svensson <[email protected]>
  • Loading branch information
T-Svensson authored and dbwiddis committed Jul 15, 2020
1 parent 2629442 commit e857318
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions contrib/platform/test/com/sun/jna/platform/win32/MsiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,63 +22,72 @@
*/
package com.sun.jna.platform.win32;

import java.util.Arrays;

import com.sun.jna.ptr.IntByReference;

import junit.framework.TestCase;

public class MsiTest extends TestCase {

public static void main(String[] args) {
junit.textui.TestRunner.run(MsiTest.class);
}

public void testMsiEnumComponents() {
char[] componentBuffer = new char[40];
assertTrue(W32Errors.ERROR_SUCCESS == Msi.INSTANCE.MsiEnumComponents(new WinDef.DWORD(0), componentBuffer));
assertEquals("MsiEnumComponents", W32Errors.ERROR_SUCCESS, Msi.INSTANCE.MsiEnumComponents(new WinDef.DWORD(0), componentBuffer));
String component = new String(componentBuffer).trim();
assertTrue(component.length() > 0);
assertFalse("Component is empty", component.isEmpty());
}

public void testMsiGetProductCodeW() {
char[] componentBuffer = new char[40];
assertTrue(W32Errors.ERROR_SUCCESS == Msi.INSTANCE.MsiEnumComponents(new WinDef.DWORD(0), componentBuffer));
assertEquals("MsiEnumComponents", W32Errors.ERROR_SUCCESS, Msi.INSTANCE.MsiEnumComponents(new WinDef.DWORD(0), componentBuffer));
String component = new String(componentBuffer).trim();
assertFalse("Component is empty", component.isEmpty());

char[] productBuffer = new char[40];
assertTrue(W32Errors.ERROR_SUCCESS == Msi.INSTANCE.MsiGetProductCode(component, productBuffer));
assertEquals("MsiGetProductCode", W32Errors.ERROR_SUCCESS, Msi.INSTANCE.MsiGetProductCode(component, productBuffer));

String product = new String(productBuffer).trim();
assertTrue(product.length() > 0);
assertFalse("Product is empty", product.isEmpty());
}

public void testMsiLocateComponentW() {
char[] componentBuffer = new char[40];
assertTrue(W32Errors.ERROR_SUCCESS == Msi.INSTANCE.MsiEnumComponents(new WinDef.DWORD(0), componentBuffer));
assertEquals("MsiEnumComponents", W32Errors.ERROR_SUCCESS, Msi.INSTANCE.MsiEnumComponents(new WinDef.DWORD(0), componentBuffer));
String component = new String(componentBuffer).trim();
assertFalse("Component is empty", component.isEmpty());

char[] pathBuffer = new char[WinDef.MAX_PATH];
IntByReference pathBufferSize = new IntByReference(pathBuffer.length);
Msi.INSTANCE.MsiLocateComponent(component, pathBuffer, pathBufferSize);
int installState = Msi.INSTANCE.MsiLocateComponent(component, pathBuffer, pathBufferSize);
assertTrue(String.format("MsiLocateComponent returned %d for component %s", installState, component),
Arrays.asList(Msi.INSTALLSTATE_LOCAL, Msi.INSTALLSTATE_SOURCE).contains(installState));

String path = new String(pathBuffer, 0, pathBufferSize.getValue()).trim();
assertTrue(path.length() > 0);
assertFalse("Path is empty", path.isEmpty());
}

public void testMsiGetComponentPathW() {
char[] componentBuffer = new char[40];
assertTrue(W32Errors.ERROR_SUCCESS == Msi.INSTANCE.MsiEnumComponents(new WinDef.DWORD(0), componentBuffer));
assertEquals("MsiEnumComponents", W32Errors.ERROR_SUCCESS, Msi.INSTANCE.MsiEnumComponents(new WinDef.DWORD(0), componentBuffer));
String component = new String(componentBuffer).trim();
assertFalse("Component is empty", component.isEmpty());

char[] productBuffer = new char[40];
assertTrue(W32Errors.ERROR_SUCCESS == Msi.INSTANCE.MsiGetProductCode(component, productBuffer));
assertEquals("MsiGetProductCode", W32Errors.ERROR_SUCCESS, Msi.INSTANCE.MsiGetProductCode(component, productBuffer));

String product = new String(productBuffer).trim();
assertTrue(product.length() > 0);
assertFalse("Product is empty", product.isEmpty());

char[] pathBuffer = new char[WinDef.MAX_PATH];
IntByReference pathBufferSize = new IntByReference(pathBuffer.length);
Msi.INSTANCE.MsiGetComponentPath(product, component, pathBuffer, pathBufferSize);
int installState = Msi.INSTANCE.MsiGetComponentPath(product, component, pathBuffer, pathBufferSize);
assertTrue(String.format("MsiGetComponentPath returned %d for component %s in product %s", installState, component, product),
Arrays.asList(Msi.INSTALLSTATE_LOCAL, Msi.INSTALLSTATE_SOURCE).contains(installState));

String path = new String(pathBuffer, 0, pathBufferSize.getValue()).trim();
assertTrue(path.length() > 0);
assertFalse("Path is empty", path.isEmpty());
}
}

0 comments on commit e857318

Please sign in to comment.