forked from JavaTX/JavaCompilerCore
58 lines
1.2 KiB
Java
58 lines
1.2 KiB
Java
package bytecode;
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.net.MalformedURLException;
|
|
import java.net.URL;
|
|
import java.net.URLClassLoader;
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
import org.junit.BeforeClass;
|
|
import org.junit.Test;
|
|
|
|
public abstract class BytecodeTest extends TestCase{
|
|
public String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
|
public String testFile;
|
|
public String outputDirectory;
|
|
|
|
protected String testName;
|
|
|
|
public BytecodeTest(){
|
|
init();
|
|
|
|
if(testName != null){
|
|
|
|
testFile = testName+".jav";
|
|
outputDirectory = "";
|
|
|
|
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputDirectory);
|
|
}else{
|
|
throw new RuntimeException("rootDirectory, testFile or outputFile is null.");
|
|
}
|
|
}
|
|
|
|
protected abstract void init();
|
|
|
|
protected Class getClassToTest(){
|
|
Class classToTest = null;
|
|
try {
|
|
File file = new File(rootDirectory);
|
|
URL url = file.toURL();
|
|
URL[] urls = new URL[]{url};
|
|
|
|
ClassLoader classLoader = new URLClassLoader(urls);
|
|
|
|
classToTest = classLoader.loadClass(testName);
|
|
|
|
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
|
|
return classToTest;
|
|
}
|
|
}
|