/*
 * Copyright (C) 2019 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 {

  static String expected = "Hello";
  public static void main(String args[]) throws Throwable {
    Class<?> c = Class.forName("NewInstance");
    Method m = c.getMethod("initRange", String.class);
    String result = (String)m.invoke(null, expected);
    if (!expected.equals(result)) {
      throw new Error("Expected '" + expected + "', got " + result);
    }

    m = c.getMethod("initRange", byte[].class, int.class, int.class, int.class);
    byte[] byteArray = expected.getBytes();
    result = (String)m.invoke(null, byteArray, 0, 0, 5);
    if (!expected.equals(result)) {
      throw new Error("Expected '" + expected + "', got " + result);
    }

    m = c.getMethod("initRangeWithAlias", String.class);
    result = (String)m.invoke(null, expected);
    if (!expected.equals(result)) {
      throw new Error("Expected '" + expected + "', got " + result);
    }
  }
}
