< prev index next >

test/jdk/com/sun/tools/jextract/complex/ComplexTest.java

Print this page




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.foreign.Libraries;
  25 import java.foreign.Library;
  26 import java.foreign.Scope;
  27 import java.foreign.memory.DoubleComplex;
  28 import java.foreign.memory.FloatComplex;
  29 import java.foreign.memory.LongDoubleComplex;
  30 import java.lang.invoke.MethodHandle;
  31 import java.lang.invoke.MethodHandles;
  32 import org.testng.annotations.BeforeTest;
  33 import org.testng.annotations.Test;
  34 import org.c99.libcomplex_aux;
  35 import org.c99.mycomplex;
  36 
  37 import static org.testng.Assert.assertEquals;
  38 import static org.testng.Assert.assertTrue;
  39 
  40 // FIXME: long double _Complex is not yet supported because long double is not
  41 // yet supported. Fix this test to include long double _Complex when binder
  42 // supports long double.
  43 
  44 /*
  45  * @test
  46  * @requires os.family != "windows"
  47  * @bug 8213013
  48  * @summary jextract does not handle C99 _Complex type
  49  * @library ..
  50  * @run driver JtregJextract -t org.c99 -- mycomplex.h
  51  * @run driver JtregJextract -t org.c99 -- libcomplex_aux.h
  52  * @run testng ComplexTest
  53  */
  54 public class ComplexTest {
  55 
  56     private static final double TOLERANCE = 0.0001;
  57     private static final float TOLERANCEF = 0.0001f;
  58 
  59     private mycomplex comlib;
  60     private libcomplex_aux auxlib;
  61 
  62     @BeforeTest
  63     public void init() {
  64         comlib = Libraries.bind(MethodHandles.lookup(), mycomplex.class);
  65         Library l = Libraries.loadLibrary(MethodHandles.lookup(), "complex_aux");
  66         auxlib = Libraries.bind(libcomplex_aux.class, l);
  67     }
  68 
  69     @Test
  70     public void testDoubleComplex() {
  71         try (Scope s = Scope.globalScope().fork()) {
  72             // check Euler's identity
  73             DoubleComplex dc = s.allocateStruct(DoubleComplex.class);
  74             dc.real$set(0.0);
  75             dc.imag$set(Math.PI);
  76             dc = comlib.cexp(dc);
  77             assertEquals(dc.real$get(), -1.0, TOLERANCE);
  78             assertEquals(dc.imag$get(), 0.0, TOLERANCE);
  79 
  80             // arg of i is pi/2
  81             dc.real$set(0.0);
  82             dc.imag$set(1.0);
  83             assertEquals(comlib.carg(dc), Math.PI/2.0, TOLERANCE);
  84 
  85             // abs of 1+i is sqrt(2)
  86             dc.real$set(1.0);




  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.foreign.Libraries;
  25 import java.foreign.Library;
  26 import java.foreign.Scope;
  27 import java.foreign.memory.DoubleComplex;
  28 import java.foreign.memory.FloatComplex;
  29 import java.foreign.memory.LongDoubleComplex;
  30 import java.lang.invoke.MethodHandle;
  31 import java.lang.invoke.MethodHandles;
  32 import org.testng.annotations.BeforeTest;
  33 import org.testng.annotations.Test;
  34 import org.c99.libcomplex_aux_h;
  35 import org.c99.mycomplex_h;
  36 
  37 import static org.testng.Assert.assertEquals;
  38 import static org.testng.Assert.assertTrue;
  39 
  40 // FIXME: long double _Complex is not yet supported because long double is not
  41 // yet supported. Fix this test to include long double _Complex when binder
  42 // supports long double.
  43 
  44 /*
  45  * @test
  46  * @requires os.family != "windows"
  47  * @bug 8213013
  48  * @summary jextract does not handle C99 _Complex type
  49  * @library ..
  50  * @run driver JtregJextract -t org.c99 -- mycomplex.h
  51  * @run driver JtregJextract -t org.c99 -- libcomplex_aux.h
  52  * @run testng ComplexTest
  53  */
  54 public class ComplexTest {
  55 
  56     private static final double TOLERANCE = 0.0001;
  57     private static final float TOLERANCEF = 0.0001f;
  58 
  59     private mycomplex_h comlib;
  60     private libcomplex_aux_h auxlib;
  61 
  62     @BeforeTest
  63     public void init() {
  64         comlib = Libraries.bind(MethodHandles.lookup(), mycomplex_h.class);
  65         Library l = Libraries.loadLibrary(MethodHandles.lookup(), "complex_aux");
  66         auxlib = Libraries.bind(libcomplex_aux_h.class, l);
  67     }
  68 
  69     @Test
  70     public void testDoubleComplex() {
  71         try (Scope s = Scope.globalScope().fork()) {
  72             // check Euler's identity
  73             DoubleComplex dc = s.allocateStruct(DoubleComplex.class);
  74             dc.real$set(0.0);
  75             dc.imag$set(Math.PI);
  76             dc = comlib.cexp(dc);
  77             assertEquals(dc.real$get(), -1.0, TOLERANCE);
  78             assertEquals(dc.imag$get(), 0.0, TOLERANCE);
  79 
  80             // arg of i is pi/2
  81             dc.real$set(0.0);
  82             dc.imag$set(1.0);
  83             assertEquals(comlib.carg(dc), Math.PI/2.0, TOLERANCE);
  84 
  85             // abs of 1+i is sqrt(2)
  86             dc.real$set(1.0);


< prev index next >