Run setup for full tests only once. [DO NOT MERGE]

Change-Id: Iee64dbd88d473b7be08581f26ccddf649aed8e56
(cherry picked from commit a12ec8f1e2)
This commit is contained in:
Deepanshu Gupta
2015-05-09 13:33:55 -07:00
parent 3ba16c1d9d
commit 723e136f96

View File

@@ -35,7 +35,8 @@ import com.android.resources.Density;
import com.android.resources.Navigation; import com.android.resources.Navigation;
import com.android.utils.ILogger; import com.android.utils.ILogger;
import org.junit.Before; import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import android.annotation.NonNull; import android.annotation.NonNull;
@@ -84,11 +85,11 @@ public class Main {
/** Location of the app's res dir inside {@link #TEST_RES_DIR}*/ /** Location of the app's res dir inside {@link #TEST_RES_DIR}*/
private static final String APP_TEST_RES = APP_TEST_DIR + "/src/main/res"; private static final String APP_TEST_RES = APP_TEST_DIR + "/src/main/res";
private LayoutLog mLayoutLibLog; private static LayoutLog sLayoutLibLog;
private FrameworkResources mFrameworkRepo; private static FrameworkResources sFrameworkRepo;
private ResourceRepository mProjectResources; private static ResourceRepository sProjectResources;
private ILogger mLogger; private static ILogger sLogger;
private Bridge mBridge; private static Bridge sBridge;
static { static {
// Test that System Properties are properly set. // Test that System Properties are properly set.
@@ -257,15 +258,15 @@ public class Main {
/** /**
* Initialize the bridge and the resource maps. * Initialize the bridge and the resource maps.
*/ */
@Before @BeforeClass
public void setUp() { public static void setUp() {
File data_dir = new File(PLATFORM_DIR, "data"); File data_dir = new File(PLATFORM_DIR, "data");
File res = new File(data_dir, "res"); File res = new File(data_dir, "res");
mFrameworkRepo = new FrameworkResources(new FolderWrapper(res)); sFrameworkRepo = new FrameworkResources(new FolderWrapper(res));
mFrameworkRepo.loadResources(); sFrameworkRepo.loadResources();
mFrameworkRepo.loadPublicResources(getLogger()); sFrameworkRepo.loadPublicResources(getLogger());
mProjectResources = sProjectResources =
new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) { new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) {
@NonNull @NonNull
@Override @Override
@@ -273,13 +274,13 @@ public class Main {
return new ResourceItem(name); return new ResourceItem(name);
} }
}; };
mProjectResources.loadResources(); sProjectResources.loadResources();
File fontLocation = new File(data_dir, "fonts"); File fontLocation = new File(data_dir, "fonts");
File buildProp = new File(PLATFORM_DIR, "build.prop"); File buildProp = new File(PLATFORM_DIR, "build.prop");
File attrs = new File(res, "values" + File.separator + "attrs.xml"); File attrs = new File(res, "values" + File.separator + "attrs.xml");
mBridge = new Bridge(); sBridge = new Bridge();
mBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation,
ConfigGenerator.getEnumMap(attrs), getLayoutLog()); ConfigGenerator.getEnumMap(attrs), getLayoutLog());
} }
@@ -301,6 +302,15 @@ public class Main {
renderAndVerify("array_check.xml", "array_check.png"); renderAndVerify("array_check.xml", "array_check.png");
} }
@AfterClass
public static void tearDown() {
sLayoutLibLog = null;
sFrameworkRepo = null;
sProjectResources = null;
sLogger = null;
sBridge = null;
}
/** Test expand_layout.xml */ /** Test expand_layout.xml */
@Test @Test
public void testExpand() throws ClassNotFoundException { public void testExpand() throws ClassNotFoundException {
@@ -345,7 +355,7 @@ public class Main {
throws ClassNotFoundException { throws ClassNotFoundException {
// TODO: Set up action bar handler properly to test menu rendering. // TODO: Set up action bar handler properly to test menu rendering.
// Create session params. // Create session params.
RenderSession session = mBridge.createSession(params); RenderSession session = sBridge.createSession(params);
if (!session.getResult().isSuccess()) { if (!session.getResult().isSuccess()) {
getLogger().error(session.getResult().getException(), getLogger().error(session.getResult().getException(),
session.getResult().getErrorMessage()); session.getResult().getErrorMessage());
@@ -390,8 +400,8 @@ public class Main {
String themeName, RenderingMode renderingMode, int targetSdk) { String themeName, RenderingMode renderingMode, int targetSdk) {
FolderConfiguration config = configGenerator.getFolderConfig(); FolderConfiguration config = configGenerator.getFolderConfig();
ResourceResolver resourceResolver = ResourceResolver resourceResolver =
ResourceResolver.create(mProjectResources.getConfiguredResources(config), ResourceResolver.create(sProjectResources.getConfiguredResources(config),
mFrameworkRepo.getConfiguredResources(config), sFrameworkRepo.getConfiguredResources(config),
themeName, false); themeName, false);
return new SessionParams( return new SessionParams(
layoutParser, layoutParser,
@@ -405,9 +415,9 @@ public class Main {
getLayoutLog()); getLayoutLog());
} }
private LayoutLog getLayoutLog() { private static LayoutLog getLayoutLog() {
if (mLayoutLibLog == null) { if (sLayoutLibLog == null) {
mLayoutLibLog = new LayoutLog() { sLayoutLibLog = new LayoutLog() {
@Override @Override
public void warning(String tag, String message, Object data) { public void warning(String tag, String message, Object data) {
System.out.println("Warning " + tag + ": " + message); System.out.println("Warning " + tag + ": " + message);
@@ -440,12 +450,12 @@ public class Main {
} }
}; };
} }
return mLayoutLibLog; return sLayoutLibLog;
} }
private ILogger getLogger() { private static ILogger getLogger() {
if (mLogger == null) { if (sLogger == null) {
mLogger = new ILogger() { sLogger = new ILogger() {
@Override @Override
public void error(Throwable t, String msgFormat, Object... args) { public void error(Throwable t, String msgFormat, Object... args) {
if (t != null) { if (t != null) {
@@ -470,7 +480,7 @@ public class Main {
} }
}; };
} }
return mLogger; return sLogger;
} }
private static void failWithMsg(@NonNull String msgFormat, Object... args) { private static void failWithMsg(@NonNull String msgFormat, Object... args) {