Esempio n. 1
0
  /**
   * Convenience method for above, which assumes stdMethodName, a return type of 'int', and no
   * arguments.
   */
  public void assertInvokeInterfaceEquals(int value, Class target, Interface iface) {

    Compiler compiler = compilerLocal.get();
    compiler.setFlags(compilerFlags());

    assertInvokeInterfaceEquals(value, target, new Extends(iface), stdAM);

    compiler.cleanup();
  }
Esempio n. 2
0
 public Compiler.Flags[] compilerFlags() {
   HashSet<Compiler.Flags> flags = new HashSet<>();
   if (verboseLocal.get() == Boolean.TRUE) {
     flags.add(Compiler.Flags.VERBOSE);
   }
   if (this.canUseCompilerCache) {
     flags.add(Compiler.Flags.USECACHE);
   }
   return flags.toArray(new Compiler.Flags[0]);
 }
Esempio n. 3
0
  /**
   * Creates a class which calls target::method(args) via invokeinterface through 'iface', compiles
   * and loads both it and 'target', and then invokes the method. If the returned value does not
   * match 'value' then a test failure is indicated.
   */
  public void assertInvokeInterfaceEquals(
      Object value, Class target, Extends iface, AbstractMethod method, String... args) {

    Compiler compiler = compilerLocal.get();
    compiler.setFlags(compilerFlags());

    Class ii = invokeInterfaceHarness(target, iface, method, args);
    ClassLoader loader = compiler.compile(ii, target);

    assertStaticCallEquals(loader, ii, method.getName(), value);
    compiler.cleanup();
  }
Esempio n. 4
0
  /**
   * Creates a class which calls target::method(args) via invokevirtual, compiles and loads both the
   * new class and 'target', and then invokes the method. If the returned value does not match
   * 'value' then a test failure is indicated.
   */
  public void assertInvokeVirtualEquals(
      Object value, Class target, ConcreteMethod method, String returns, String... args) {

    Compiler compiler = compilerLocal.get();
    compiler.setFlags(compilerFlags());

    Class iv = invokeVirtualHarness(target, method, returns, args);
    ClassLoader loader = compiler.compile(iv, target);

    assertStaticCallEquals(loader, iv, method.getName(), value);
    compiler.cleanup();
  }
Esempio n. 5
0
  /**
   * Creates a class which calls target::method(args) via invokevirtual, compiles and loads both the
   * new class and 'target', and then invokes the method. If an exception of type 'exceptionType' is
   * not thrown, then a test failure is indicated.
   */
  public void assertThrows(
      java.lang.Class<?> exceptionType,
      Class target,
      ConcreteMethod method,
      String returns,
      String... args) {

    Compiler compiler = compilerLocal.get();
    compiler.setFlags(compilerFlags());

    Class iv = invokeVirtualHarness(target, method, returns, args);
    ClassLoader loader = compiler.compile(iv, target);

    java.lang.Class<?> cls = null;
    try {
      cls = java.lang.Class.forName(iv.getName(), true, loader);
    } catch (ClassNotFoundException e) {
    }
    assertNotNull(cls);

    java.lang.reflect.Method m = null;
    try {
      m = cls.getMethod(method.getName());
    } catch (NoSuchMethodException e) {
    }
    assertNotNull(m);

    try {
      m.invoke(null);
      fail("Exception should have been thrown");
    } catch (InvocationTargetException | IllegalAccessException e) {
      if (verboseLocal.get() == Boolean.TRUE) {
        System.out.println(e.getCause());
      }
      assertTrue(exceptionType.isAssignableFrom(e.getCause().getClass()));
    }
    compiler.cleanup();
  }
Esempio n. 6
0
 @AfterMethod
 public void reset() {
   if (!this.verbose) {
     verboseLocal.set(Boolean.FALSE);
   }
 }
Esempio n. 7
0
 public void setTestVerbose() {
   verboseLocal.set(Boolean.TRUE);
 }