1 /*
   2  * Copyright (c) 2015, 2016 SAP SE. All rights reserved.
   3  * Copyright (c) 2018 Red Hat, Inc. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 public class TestFloatJNIArgs {
  26     static {
  27         try {
  28             System.loadLibrary("TestFloatJNIArgs");
  29         } catch (UnsatisfiedLinkError e) {
  30             System.out.println("could not load native lib: " + e);
  31         }
  32     }
  33 
  34     public static native float add15floats(
  35         float f1, float f2, float f3, float f4,
  36         float f5, float f6, float f7, float f8,
  37         float f9, float f10, float f11, float f12,
  38         float f13, float f14, float f15);
  39 
  40     public static native float add10floats(
  41         float f1, float f2, float f3, float f4,
  42         float f5, float f6, float f7, float f8,
  43         float f9, float f10);
  44 
  45     public static native float addFloatsInts(
  46         float f1, float f2, float f3, float f4,
  47         float f5, float f6, float f7, float f8,
  48         float f9, float f10, float f11, float f12,
  49         float f13, float f14, float f15, int a16, int a17);
  50 
  51     public static native double add15doubles(
  52         double d1, double d2, double d3, double d4,
  53         double d5, double d6, double d7, double d8,
  54         double d9, double d10, double d11, double d12,
  55         double d13, double d14, double d15);
  56 
  57     static void test() throws Exception {
  58         float sum = TestFloatJNIArgs.add15floats(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
  59                                                  1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
  60         if (sum != 15.0f) {
  61             throw new Error("Passed 15 times 1.0f to jni function which didn't add them properly: " + sum);
  62         }
  63 
  64         float sum1 = TestFloatJNIArgs.add10floats(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
  65         if (sum1 != 10.0f) {
  66             throw new Error("Passed 10 times 1.0f to jni function which didn't add them properly: " + sum1);
  67         }
  68 
  69         float sum2 = TestFloatJNIArgs.addFloatsInts(1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
  70                                                    1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1, 1);
  71         if (sum2 != 17.0f) {
  72             throw new Error("Passed 17 times 1 to jni function which didn't add them properly: " + sum2);
  73         }
  74 
  75         double dsum = TestFloatJNIArgs.add15doubles(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
  76                                                       1.0, 1.0, 1.0, 1.0, 1.0, 1.0);
  77         if (dsum != 15.0) {
  78             throw new Error("Passed 15 times 1.0 to jni function which didn't add them properly: " + dsum);
  79         }
  80     }
  81 
  82     public static void main(String[] args) throws Exception {
  83         for (int i = 0; i < 200; ++i) {
  84             test();
  85         }
  86     }
  87 }