Statically link DLL to remove need for VC++ installation
2762275 support conversion of arrays of primitives 2171967 throw exception for unexpected data types rather than crash VM
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.jacob.com;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import com.jacob.test.BaseTestCase;
|
||||
@@ -30,4 +31,73 @@ public class VariantUtilitiesTest extends BaseTestCase {
|
||||
System.out.println("currency returned was: " + someMoneyConverted);
|
||||
|
||||
}
|
||||
|
||||
public void testPrimitiveByteArray() {
|
||||
byte[] arr = new byte[] { 1, 2, 3 };
|
||||
|
||||
Variant arrVar = VariantUtilities.objectToVariant(arr);
|
||||
assertNotNull(arrVar);
|
||||
SafeArray sa = arrVar.toSafeArray();
|
||||
assertNotNull(sa);
|
||||
|
||||
assertEquals(Variant.VariantByte, sa.getvt());
|
||||
|
||||
assertEquals(0, sa.getLBound());
|
||||
assertEquals(2, sa.getUBound());
|
||||
|
||||
byte[] bytes = sa.toByteArray();
|
||||
assertTrue(Arrays.equals(bytes, arr));
|
||||
}
|
||||
|
||||
public void testPrimitiveIntArray() {
|
||||
int[] arr = new int[] { 1000, 2000, 3 };
|
||||
|
||||
Variant arrVar = VariantUtilities.objectToVariant(arr);
|
||||
assertNotNull(arrVar);
|
||||
SafeArray sa = arrVar.toSafeArray();
|
||||
assertNotNull(sa);
|
||||
|
||||
assertEquals(Variant.VariantInt, sa.getvt());
|
||||
|
||||
assertEquals(0, sa.getLBound());
|
||||
assertEquals(2, sa.getUBound());
|
||||
|
||||
int[] ints = sa.toIntArray();
|
||||
assertTrue(Arrays.equals(ints, arr));
|
||||
}
|
||||
|
||||
public void testPrimitiveDoubleArray() {
|
||||
double[] arr = new double[] { 1000, 2000, 3 };
|
||||
|
||||
Variant arrVar = VariantUtilities.objectToVariant(arr);
|
||||
assertNotNull(arrVar);
|
||||
SafeArray sa = arrVar.toSafeArray();
|
||||
assertNotNull(sa);
|
||||
|
||||
assertEquals(Variant.VariantDouble, sa.getvt());
|
||||
|
||||
assertEquals(0, sa.getLBound());
|
||||
assertEquals(2, sa.getUBound());
|
||||
|
||||
double[] doubles = sa.toDoubleArray();
|
||||
assertTrue(Arrays.equals(doubles, arr));
|
||||
}
|
||||
|
||||
public void testPrimitiveLongArray() {
|
||||
long[] arr = new long[] { 0xcafebabecafebabeL, 42, 0xbabecafebabeL };
|
||||
|
||||
Variant arrVar = VariantUtilities.objectToVariant(arr);
|
||||
assertNotNull(arrVar);
|
||||
SafeArray sa = arrVar.toSafeArray();
|
||||
assertNotNull(sa);
|
||||
|
||||
assertEquals(Variant.VariantLongInt, sa.getvt());
|
||||
|
||||
assertEquals(0, sa.getLBound());
|
||||
assertEquals(2, sa.getUBound());
|
||||
|
||||
long[] longs = sa.toLongArray();
|
||||
assertTrue(Arrays.equals(longs, arr));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,11 @@ public class ExcelEventTest extends BaseTestCase {
|
||||
// You can probably also listen Excel.Sheet and Excel.Chart
|
||||
String excelApplicationProgramId = "Excel.Application";
|
||||
String excelSheetProgramId = "Excel.Sheet";
|
||||
String typeLibLocation = "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE";
|
||||
String typeLibLocation;
|
||||
// office 2003
|
||||
typeLibLocation = "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE";
|
||||
// office 2007
|
||||
typeLibLocation = "C:\\Program Files\\Microsoft Office\\OFFICE12\\EXCEL.EXE";
|
||||
|
||||
// Grab The Component.
|
||||
ActiveXComponent axc = new ActiveXComponent(excelApplicationProgramId);
|
||||
@@ -46,7 +50,14 @@ public class ExcelEventTest extends BaseTestCase {
|
||||
Dispatch workbooks = axc.getPropertyAsComponent("Workbooks");
|
||||
Dispatch workbook = Dispatch.get(workbooks, "Add").toDispatch();
|
||||
Dispatch sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
|
||||
hookupListener(sheet, excelSheetProgramId, typeLibLocation);
|
||||
System.out.println("Workbook: "+workbook);
|
||||
System.out.println("Sheet: "+sheet);
|
||||
if (typeLibLocation.contains("OFFICE11")){
|
||||
// office 2007 throws crashes the VM
|
||||
System.out.println("Hooking up sheet listener");
|
||||
hookupListener(sheet, excelSheetProgramId, typeLibLocation);
|
||||
}
|
||||
System.out.println("Retrieving cells");
|
||||
Dispatch a1 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
new Object[] { "A1" }, new int[1]).toDispatch();
|
||||
Dispatch a2 = Dispatch.invoke(sheet, "Range", Dispatch.Get,
|
||||
@@ -101,7 +112,7 @@ public class ExcelEventTest extends BaseTestCase {
|
||||
.println("No exception thrown but no dispatch returned for Excel events");
|
||||
} else {
|
||||
// Yea!
|
||||
System.out.println("Successfully attached to " + programId);
|
||||
System.out.println("Successfully attached listener to " + programId);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,12 @@ import com.jacob.test.BaseTestCase;
|
||||
*
|
||||
* power point test program posted to sourceforge to demonstrate memory problem.
|
||||
* The submitter stated they had the problem on windows 2000 with office 2000 I
|
||||
* have been unable to duplicate on windows XP with office 2003. I am comitting
|
||||
* have been unable to duplicate on windows XP with office 2003. I am adding
|
||||
* this to the tree just in case we need to come back to it.
|
||||
* <P>
|
||||
* This test was modified for office 2007 to synchronize communication with Excel.
|
||||
* Office 2003 didn't require this.
|
||||
* <p>
|
||||
* This relies on BaseTestCase to provide the root path to the file under test
|
||||
* <p>
|
||||
* May need to run with some command line options (including from inside
|
||||
@@ -117,8 +120,13 @@ public class PowerpointTest extends BaseTestCase {
|
||||
+ ": Iteration " + i);
|
||||
System.out.flush();
|
||||
}
|
||||
// office 2003 seems to have been able to handle more
|
||||
// multi-threaded requests than office 2007
|
||||
// office 2003 could handle 5 threads @ 50 iterations
|
||||
// office 2007 can only handle 1 thread at a time
|
||||
synchronized(comPowerpoint){
|
||||
Dispatch comPresentations = Dispatch.get(comPowerpoint,
|
||||
"Presentations").toDispatch();
|
||||
"Presentations").toDispatch();
|
||||
Dispatch comPresentation = Dispatch.call(
|
||||
comPresentations,
|
||||
"Open",
|
||||
@@ -127,6 +135,7 @@ public class PowerpointTest extends BaseTestCase {
|
||||
new Integer(0), new Integer(0), new Integer(0))
|
||||
.toDispatch();
|
||||
Dispatch.call(comPresentation, "Close");
|
||||
}
|
||||
}
|
||||
} catch (ComFailException cfe) {
|
||||
threadFailedWithException = cfe;
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user