Skip to content

Commit

Permalink
Ensure all tests pass when Native.DEFAULT_ENCODING is Cp1252
Browse files Browse the repository at this point in the history
  • Loading branch information
amake committed Apr 12, 2016
1 parent a846d5c commit 8a9f5b0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
17 changes: 11 additions & 6 deletions test/com/sun/jna/CallbacksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.PrintStream;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -652,8 +653,9 @@ public String callback(String arg, String arg2) {
return arg + arg2;
}
};
final String VALUE = "value" + UNICODE;
final String VALUE2 = getName() + UNICODE;
Charset charset = Charset.forName(Native.getDefaultStringEncoding());
final String VALUE = "value" + charset.decode(charset.encode(UNICODE));
final String VALUE2 = getName() + charset.decode(charset.encode(UNICODE));
String value = lib.callStringCallback(cb, VALUE, VALUE2);
assertTrue("Callback not called", called[0]);
assertEquals("Wrong String callback argument 0", VALUE, cbargs[0]);
Expand All @@ -673,8 +675,9 @@ public String callback(String arg, String arg2) {
Map<?, ?> m = CallbackReference.allocations;
m.clear();

String arg = getName() + "1" + UNICODE;
String arg2 = getName() + "2" + UNICODE;
Charset charset = Charset.forName(Native.getDefaultStringEncoding());
String arg = getName() + "1" + charset.decode(charset.encode(UNICODE));
String arg2 = getName() + "2" + charset.decode(charset.encode(UNICODE));
String value = lib.callStringCallback(cb, arg, arg2);
WeakReference<Object> ref = new WeakReference<Object>(value);

Expand Down Expand Up @@ -723,7 +726,8 @@ public String[] callback(String[] arg) {
return arg;
}
};
final String VALUE = "value" + UNICODE;
Charset charset = Charset.forName(Native.getDefaultStringEncoding());
final String VALUE = "value" + charset.decode(charset.encode(UNICODE));
final String[] VALUE_ARRAY = { VALUE, null };
Pointer value = lib.callStringArrayCallback(cb, VALUE_ARRAY);
assertTrue("Callback not called", called[0]);
Expand Down Expand Up @@ -795,7 +799,8 @@ public TestStructure.ByValue callback(TestStructure.ByValue s) {
public void testUnionByValueCallbackArgument() throws Exception{
TestLibrary.TestUnion arg = new TestLibrary.TestUnion();
arg.setType(String.class);
final String VALUE = getName() + UNICODE;
Charset charset = Charset.forName(arg.getStringEncoding());
final String VALUE = getName() + charset.decode(charset.encode(UNICODE));
arg.f1 = VALUE;
final boolean[] called = { false };
final TestLibrary.TestUnion[] cbvalue = { null };
Expand Down
4 changes: 3 additions & 1 deletion test/com/sun/jna/ReturnTypesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package com.sun.jna;

import java.nio.charset.Charset;
import java.util.Collections;
import java.util.List;
import junit.framework.TestCase;
Expand Down Expand Up @@ -314,7 +315,8 @@ public void testReturnPointerArray() {
}

public void testReturnStringArray() {
final String VALUE = getName() + UNICODE;
Charset charset = Charset.forName(Native.getDefaultStringEncoding());
final String VALUE = getName() + charset.decode(charset.encode(UNICODE));
String[] input = {
VALUE, null,
};
Expand Down
6 changes: 4 additions & 2 deletions test/com/sun/jna/StructureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package com.sun.jna;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -1084,9 +1085,10 @@ protected List<String> getFieldOrder() {
return Arrays.asList("inner");
}
}
final String VALUE = getName() + UNICODE;
final WString WVALUE = new WString(VALUE);
StructureFromPointer o = new StructureFromPointer();
Charset charset = Charset.forName(o.getStringEncoding());
final String VALUE = getName() + charset.decode(charset.encode(UNICODE));
final WString WVALUE = new WString(VALUE);
o.s = VALUE;
o.ws = WVALUE;
o.write();
Expand Down

0 comments on commit 8a9f5b0

Please sign in to comment.