/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.lang.reflect.Method;

public class Main {
  public static void main(String[] args) throws Exception {
    System.loadLibrary(args[0]);

    Class<?> c = Class.forName("Test");
    ensureJitCompiled(c, "testEmpty");
    ensureJitCompiled(c, "testPrimitive");

    Method m = c.getMethod("testEmpty");
    m.invoke(c.newInstance());
    if (field != null) {
      throw new Error("Expected null");
    }

    m = c.getMethod("testPrimitive");
    int a = (Integer)m.invoke(c.newInstance());
    if (a != 1) {
      throw new Error("Expected 1, got " + a);
    }
    if (field != null) {
      throw new Error("Expected null");
    }
  }

  public static Object field;

  private static native void ensureJitCompiled(Class<?> itf, String method_name);
  public static native Object getThisOfCaller();
}
