-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #653 from matthiasblaesing/combindingbaseobject_ex…
…ceptionhandling Exception from COMBindingBaseObject swallows real reason + HRESULT
- Loading branch information
Showing
3 changed files
with
74 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...b/platform/test/com/sun/jna/platform/win32/COM/ComExceptionWithoutInitializationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.sun.jna.platform.win32.COM; | ||
|
||
import com.sun.jna.platform.win32.Guid; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
import org.junit.Test; | ||
|
||
public class ComExceptionWithoutInitializationTest { | ||
|
||
@Test | ||
public void testCorrectExceptionOnFailedInitialization() { | ||
String message = null; | ||
try { | ||
InternetExplorer ie = new InternetExplorer(); | ||
} catch (COMException ex) { | ||
message = ex.getMessage(); | ||
} | ||
|
||
// This invocation must raise an exception, as the COM thread is not | ||
// initialized, in the message it is expected, that the HRESULT is reported | ||
// and the HRESULT resulting from calling into COM with it being initialized | ||
// is 800401f0. The message is also expected to point the to correct | ||
// initialization via CoInitialize | ||
assertNotNull(message); | ||
assertTrue(message.contains("HRESULT")); | ||
assertTrue(message.contains("800401f0")); | ||
assertTrue(message.contains("CoInitialize")); | ||
} | ||
|
||
/** | ||
* InternetExplorer / IWebBrowser2 - see | ||
* http://msdn.microsoft.com/en-us/library/aa752127(v=vs.85).aspx | ||
*/ | ||
private static class InternetExplorer extends COMLateBindingObject { | ||
|
||
public InternetExplorer(IDispatch iDispatch) { | ||
super(iDispatch); | ||
} | ||
|
||
public InternetExplorer() { | ||
super(new Guid.CLSID("{0002DF01-0000-0000-C000-000000000046}"), true); | ||
} | ||
|
||
/** | ||
* IWebBrowser2::get_LocationURL<br> | ||
* Read-only COM property.<br> | ||
* | ||
* @return the URL of the resource that is currently displayed. | ||
*/ | ||
public String getURL() { | ||
return getStringProperty("LocationURL"); | ||
} | ||
} | ||
} |