Skip to content

Commit

Permalink
Fix testCustomizeDefaultStringEncoding for when default == file.encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
amake committed Apr 12, 2016
1 parent 0399562 commit a846d5c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions test/com/sun/jna/NativeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.io.File;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -152,10 +153,19 @@ public void testDefaultStringEncoding() throws Exception {

public void testCustomizeDefaultStringEncoding() {
Properties oldprops = (Properties)System.getProperties().clone();
final String ENCODING = System.getProperty("file.encoding");
String encoding = null;
// Choose a charset that is not the default encoding so we can actually
// tell we changed it.
for (String charset : Charset.availableCharsets().keySet()) {
if (!charset.equals(Native.DEFAULT_ENCODING)) {
encoding = charset;
break;
}
}
assertNotNull("No available encodings other than the default!?", encoding);
try {
System.setProperty("jna.encoding", ENCODING);
assertEquals("Default encoding should match jna.encoding setting", ENCODING, Native.getDefaultStringEncoding());
System.setProperty("jna.encoding", encoding);
assertEquals("Default encoding should match jna.encoding setting", encoding, Native.getDefaultStringEncoding());
}
finally {
System.setProperties(oldprops);
Expand Down

0 comments on commit a846d5c

Please sign in to comment.