From 8a9f5b0b095d1525a0fd686d1573ab44bc507bbe Mon Sep 17 00:00:00 2001 From: Aaron Madlon-Kay Date: Sun, 10 Apr 2016 16:51:05 +0900 Subject: [PATCH] Ensure all tests pass when Native.DEFAULT_ENCODING is Cp1252 --- test/com/sun/jna/CallbacksTest.java | 17 +++++++++++------ test/com/sun/jna/ReturnTypesTest.java | 4 +++- test/com/sun/jna/StructureTest.java | 6 ++++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/test/com/sun/jna/CallbacksTest.java b/test/com/sun/jna/CallbacksTest.java index 4bcc7737c3..e5b3436096 100644 --- a/test/com/sun/jna/CallbacksTest.java +++ b/test/com/sun/jna/CallbacksTest.java @@ -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; @@ -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]); @@ -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 ref = new WeakReference(value); @@ -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]); @@ -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 }; diff --git a/test/com/sun/jna/ReturnTypesTest.java b/test/com/sun/jna/ReturnTypesTest.java index 646ee2216e..6afbd58b9f 100644 --- a/test/com/sun/jna/ReturnTypesTest.java +++ b/test/com/sun/jna/ReturnTypesTest.java @@ -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; @@ -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, }; diff --git a/test/com/sun/jna/StructureTest.java b/test/com/sun/jna/StructureTest.java index f2ef9a36c0..833d057019 100644 --- a/test/com/sun/jna/StructureTest.java +++ b/test/com/sun/jna/StructureTest.java @@ -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; @@ -1084,9 +1085,10 @@ protected List 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();