• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright 2011 See AUTHORS file.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 
17 package com.badlogic.gdx.jnigen.test;
18 
19 import java.nio.Buffer;
20 import java.nio.ByteBuffer;
21 
22 import com.badlogic.gdx.jnigen.AntScriptGenerator;
23 import com.badlogic.gdx.jnigen.BuildConfig;
24 import com.badlogic.gdx.jnigen.BuildExecutor;
25 import com.badlogic.gdx.jnigen.BuildTarget;
26 import com.badlogic.gdx.jnigen.BuildTarget.TargetOs;
27 import com.badlogic.gdx.jnigen.JniGenSharedLibraryLoader;
28 import com.badlogic.gdx.jnigen.NativeCodeGenerator;
29 
30 public class MyJniClass {
test(boolean boolArg, byte byteArg, char charArg, short shortArg, int intArg, long longArg, float floatArg, double doubleArg, Buffer byteBuffer, boolean[] boolArray, char[] charArray, short[] shortArray, int[] intArray, long[] longArray, float[] floatArray, double[] doubleArray, double[][] multidim, String string)31 	public static native void test (boolean boolArg, byte byteArg, char charArg, short shortArg, int intArg, long longArg,
32 		float floatArg, double doubleArg, Buffer byteBuffer, boolean[] boolArray, char[] charArray, short[] shortArray,
33 		int[] intArray, long[] longArray, float[] floatArray, double[] doubleArray, double[][] multidim, String string); /*
34 																																								 * printf(
35 																																								 * "boolean: %s\n"
36 																																								 * ,
37 																																								 * boolArg
38 																																								 * ?
39 																																								 * "true":
40 																																								 * "false"
41 																																								 * );
42 																																								 * printf(
43 																																								 * "byte: %d\n"
44 																																								 * ,
45 																																								 * byteArg
46 																																								 * );
47 																																								 * printf(
48 																																								 * "char: %c\n"
49 																																								 * ,
50 																																								 * charArg
51 																																								 * );
52 																																								 * printf(
53 																																								 * "short: %d\n"
54 																																								 * ,
55 																																								 * shortArg
56 																																								 * );
57 																																								 * printf(
58 																																								 * "int: %d\n"
59 																																								 * ,
60 																																								 * intArg
61 																																								 * );
62 																																								 * printf(
63 																																								 * "long: %l\n"
64 																																								 * ,
65 																																								 * longArg
66 																																								 * );
67 																																								 * printf(
68 																																								 * "float: %f\n"
69 																																								 * ,
70 																																								 * floatArg
71 																																								 * );
72 																																								 * printf(
73 																																								 * "double: %d\n"
74 																																								 * ,
75 																																								 * doubleArg
76 																																								 * );
77 																																								 * printf(
78 																																								 * "byteBuffer: %d\n"
79 																																								 * ,
80 																																								 * byteBuffer
81 																																								 * [0]);
82 																																								 * printf(
83 																																								 * "bool[0]: %s\n"
84 																																								 * ,
85 																																								 * boolArray
86 																																								 * [
87 																																								 * 0]?"true"
88 																																								 * :
89 																																								 * "false"
90 																																								 * );
91 																																								 * printf(
92 																																								 * "char[0]: %c\n"
93 																																								 * ,
94 																																								 * charArray
95 																																								 * [0]);
96 																																								 * printf(
97 																																								 * "short[0]: %d\n"
98 																																								 * ,
99 																																								 * shortArray
100 																																								 * [0]);
101 																																								 * printf(
102 																																								 * "int[0]: %d\n"
103 																																								 * ,
104 																																								 * intArray
105 																																								 * [0]);
106 																																								 * printf(
107 																																								 * "long[0]: %ll\n"
108 																																								 * ,
109 																																								 * longArray
110 																																								 * [0]);
111 																																								 * printf(
112 																																								 * "float[0]: %f\n"
113 																																								 * ,
114 																																								 * floatArray
115 																																								 * [0]);
116 																																								 * printf(
117 																																								 * "double[0]: %f\n"
118 																																								 * ,
119 																																								 * doubleArray
120 																																								 * [0]);
121 																																								 * printf(
122 																																								 * "string: %s fuck this nuts\n"
123 																																								 * ,
124 																																								 * string
125 																																								 * );
126 																																								 */
127 
128 	// @off
129 	/*JNI
130 	#include <stdio.h>
131 	 */
132 
133 //	public static class TestInner {
134 //		public native void testInner(int arg); /*
135 //			printf("%d\n", arg);
136 //		*/
137 //	}
138 
main(String[] args)139 	public static void main(String[] args) throws Exception {
140 		// generate C/C++ code
141 		new NativeCodeGenerator().generate("src", "bin", "jni", new String[] { "**/MyJniClass.java" }, null);
142 
143 		// generate build scripts, for win32 only
144 		BuildConfig buildConfig = new BuildConfig("test");
145 		BuildTarget win32 = BuildTarget.newDefaultTarget(TargetOs.Windows, false);
146 		win32.compilerPrefix = "";
147 		win32.cppFlags += " -g";
148 		new AntScriptGenerator().generate(buildConfig, win32);
149 
150 		// build natives
151 		BuildExecutor.executeAnt("jni/build.xml", "clean all -v");
152 
153 		// load the test-natives.jar and from it the shared library, then execute the test.
154 		new JniGenSharedLibraryLoader("libs/test-natives.jar").load("test");
155 		ByteBuffer buffer = ByteBuffer.allocateDirect(1);
156 		buffer.put(0, (byte)8);
157 		MyJniClass.test(true, (byte)1, (char)2, (short)3, 4, 5, 6, 7, buffer, new boolean[] { false }, new char[] { 9 }, new short[] { 10 }, new int[] { 11 }, new long[] { 12 }, new float[] { 13 }, new double[] { 14 }, null, "Hurray");
158 	}
159 }