Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright (C) 2006 The Android Open Source Project
      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 android.core;
     18 
     19 import android.test.suitebuilder.annotation.Suppress;
     20 import android.util.Log;
     21 import junit.framework.TestCase;
     22 
     23 
     24 @Suppress
     25 public class JniLibTest extends TestCase {
     26 
     27     @Override
     28     protected void setUp() throws Exception {
     29         super.setUp();
     30         /*
     31          * This causes the native shared library to be loaded when the
     32          * class is first used.  The library is only loaded once, even if
     33          * multiple classes include this line.
     34          *
     35          * The library must be in java.library.path, which is derived from
     36          * LD_LIBRARY_PATH.  The actual library name searched for will be
     37          * "libjni_lib_test.so" under Linux, but may be different on other
     38          * platforms.
     39          */
     40         try {
     41             System.loadLibrary("jni_lib_test");
     42         } catch (UnsatisfiedLinkError ule) {
     43             Log.e("JniLibTest", "WARNING: Could not load jni_lib_test natives");
     44         }
     45     }
     46 
     47     private static native int nativeStaticThing(float f);
     48     private native void nativeThing(int val);
     49 
     50     public void testNativeCall() {
     51         Log.i("JniLibTest", "JNI search path is "
     52                 + System.getProperty("java.library.path"));
     53         Log.i("JniLibTest", "'jni_lib_test' becomes '"
     54                 + System.mapLibraryName("jni_lib_test") + "'");
     55 
     56         int result = nativeStaticThing(1234.5f);
     57         nativeThing(result);
     58     }
     59 }
     60