Loading tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java +36 −26 Original line number Diff line number Diff line Loading @@ -34,7 +34,8 @@ import com.android.layoutlib.bridge.intensive.setup.LayoutLibTestCallback; import com.android.layoutlib.bridge.intensive.setup.LayoutPullParser; import com.android.utils.ILogger; import org.junit.Before; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import java.io.File; Loading Loading @@ -81,11 +82,11 @@ public class Main { /** 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 LayoutLog mLayoutLibLog; private FrameworkResources mFrameworkRepo; private ResourceRepository mProjectResources; private ILogger mLogger; private Bridge mBridge; private static LayoutLog sLayoutLibLog; private static FrameworkResources sFrameworkRepo; private static ResourceRepository sProjectResources; private static ILogger sLogger; private static Bridge sBridge; static { // Test that System Properties are properly set. Loading Loading @@ -249,15 +250,15 @@ public class Main { /** * Initialize the bridge and the resource maps. */ @Before public void setUp() { @BeforeClass public static void setUp() { File data_dir = new File(PLATFORM_DIR, "data"); File res = new File(data_dir, "res"); mFrameworkRepo = new FrameworkResources(new FolderWrapper(res)); mFrameworkRepo.loadResources(); mFrameworkRepo.loadPublicResources(getLogger()); sFrameworkRepo = new FrameworkResources(new FolderWrapper(res)); sFrameworkRepo.loadResources(); sFrameworkRepo.loadPublicResources(getLogger()); mProjectResources = sProjectResources = new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) { @NonNull @Override Loading @@ -265,13 +266,13 @@ public class Main { return new ResourceItem(name); } }; mProjectResources.loadResources(); sProjectResources.loadResources(); File fontLocation = new File(data_dir, "fonts"); File buildProp = new File(PLATFORM_DIR, "build.prop"); File attrs = new File(res, "values" + File.separator + "attrs.xml"); mBridge = new Bridge(); mBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, sBridge = new Bridge(); sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, ConfigGenerator.getEnumMap(attrs), getLayoutLog()); } Loading @@ -288,6 +289,15 @@ public class Main { renderAndVerify("allwidgets.xml", "allwidgets.png"); } @AfterClass public static void tearDown() { sLayoutLibLog = null; sFrameworkRepo = null; sProjectResources = null; sLogger = null; sBridge = null; } /** * Create a new rendering session and test that rendering given layout on nexus 5 * doesn't throw any exceptions and matches the provided image. Loading @@ -302,7 +312,7 @@ public class Main { // TODO: Set up action bar handler properly to test menu rendering. // Create session params. SessionParams params = getSessionParams(parser, ConfigGenerator.NEXUS_5, layoutLibCallback); RenderSession session = mBridge.createSession(params); RenderSession session = sBridge.createSession(params); if (!session.getResult().isSuccess()) { getLogger().error(session.getResult().getException(), session.getResult().getErrorMessage()); Loading @@ -328,8 +338,8 @@ public class Main { ConfigGenerator configGenerator, LayoutLibTestCallback layoutLibCallback) { FolderConfiguration config = configGenerator.getFolderConfig(); ResourceResolver resourceResolver = ResourceResolver.create(mProjectResources.getConfiguredResources(config), mFrameworkRepo.getConfiguredResources(config), ResourceResolver.create(sProjectResources.getConfiguredResources(config), sFrameworkRepo.getConfiguredResources(config), "Theme.Material.Light.DarkActionBar", false); return new SessionParams( Loading @@ -344,9 +354,9 @@ public class Main { getLayoutLog()); } private LayoutLog getLayoutLog() { if (mLayoutLibLog == null) { mLayoutLibLog = new LayoutLog() { private static LayoutLog getLayoutLog() { if (sLayoutLibLog == null) { sLayoutLibLog = new LayoutLog() { @Override public void warning(String tag, String message, Object data) { System.out.println("Warning " + tag + ": " + message); Loading Loading @@ -379,12 +389,12 @@ public class Main { } }; } return mLayoutLibLog; return sLayoutLibLog; } private ILogger getLogger() { if (mLogger == null) { mLogger = new ILogger() { private static ILogger getLogger() { if (sLogger == null) { sLogger = new ILogger() { @Override public void error(Throwable t, String msgFormat, Object... args) { if (t != null) { Loading @@ -409,7 +419,7 @@ public class Main { } }; } return mLogger; return sLogger; } private static void failWithMsg(@NonNull String msgFormat, Object... args) { Loading Loading
tools/layoutlib/bridge/tests/src/com/android/layoutlib/bridge/intensive/Main.java +36 −26 Original line number Diff line number Diff line Loading @@ -34,7 +34,8 @@ import com.android.layoutlib.bridge.intensive.setup.LayoutLibTestCallback; import com.android.layoutlib.bridge.intensive.setup.LayoutPullParser; import com.android.utils.ILogger; import org.junit.Before; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import java.io.File; Loading Loading @@ -81,11 +82,11 @@ public class Main { /** 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 LayoutLog mLayoutLibLog; private FrameworkResources mFrameworkRepo; private ResourceRepository mProjectResources; private ILogger mLogger; private Bridge mBridge; private static LayoutLog sLayoutLibLog; private static FrameworkResources sFrameworkRepo; private static ResourceRepository sProjectResources; private static ILogger sLogger; private static Bridge sBridge; static { // Test that System Properties are properly set. Loading Loading @@ -249,15 +250,15 @@ public class Main { /** * Initialize the bridge and the resource maps. */ @Before public void setUp() { @BeforeClass public static void setUp() { File data_dir = new File(PLATFORM_DIR, "data"); File res = new File(data_dir, "res"); mFrameworkRepo = new FrameworkResources(new FolderWrapper(res)); mFrameworkRepo.loadResources(); mFrameworkRepo.loadPublicResources(getLogger()); sFrameworkRepo = new FrameworkResources(new FolderWrapper(res)); sFrameworkRepo.loadResources(); sFrameworkRepo.loadPublicResources(getLogger()); mProjectResources = sProjectResources = new ResourceRepository(new FolderWrapper(TEST_RES_DIR + APP_TEST_RES), false) { @NonNull @Override Loading @@ -265,13 +266,13 @@ public class Main { return new ResourceItem(name); } }; mProjectResources.loadResources(); sProjectResources.loadResources(); File fontLocation = new File(data_dir, "fonts"); File buildProp = new File(PLATFORM_DIR, "build.prop"); File attrs = new File(res, "values" + File.separator + "attrs.xml"); mBridge = new Bridge(); mBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, sBridge = new Bridge(); sBridge.init(ConfigGenerator.loadProperties(buildProp), fontLocation, ConfigGenerator.getEnumMap(attrs), getLayoutLog()); } Loading @@ -288,6 +289,15 @@ public class Main { renderAndVerify("allwidgets.xml", "allwidgets.png"); } @AfterClass public static void tearDown() { sLayoutLibLog = null; sFrameworkRepo = null; sProjectResources = null; sLogger = null; sBridge = null; } /** * Create a new rendering session and test that rendering given layout on nexus 5 * doesn't throw any exceptions and matches the provided image. Loading @@ -302,7 +312,7 @@ public class Main { // TODO: Set up action bar handler properly to test menu rendering. // Create session params. SessionParams params = getSessionParams(parser, ConfigGenerator.NEXUS_5, layoutLibCallback); RenderSession session = mBridge.createSession(params); RenderSession session = sBridge.createSession(params); if (!session.getResult().isSuccess()) { getLogger().error(session.getResult().getException(), session.getResult().getErrorMessage()); Loading @@ -328,8 +338,8 @@ public class Main { ConfigGenerator configGenerator, LayoutLibTestCallback layoutLibCallback) { FolderConfiguration config = configGenerator.getFolderConfig(); ResourceResolver resourceResolver = ResourceResolver.create(mProjectResources.getConfiguredResources(config), mFrameworkRepo.getConfiguredResources(config), ResourceResolver.create(sProjectResources.getConfiguredResources(config), sFrameworkRepo.getConfiguredResources(config), "Theme.Material.Light.DarkActionBar", false); return new SessionParams( Loading @@ -344,9 +354,9 @@ public class Main { getLayoutLog()); } private LayoutLog getLayoutLog() { if (mLayoutLibLog == null) { mLayoutLibLog = new LayoutLog() { private static LayoutLog getLayoutLog() { if (sLayoutLibLog == null) { sLayoutLibLog = new LayoutLog() { @Override public void warning(String tag, String message, Object data) { System.out.println("Warning " + tag + ": " + message); Loading Loading @@ -379,12 +389,12 @@ public class Main { } }; } return mLayoutLibLog; return sLayoutLibLog; } private ILogger getLogger() { if (mLogger == null) { mLogger = new ILogger() { private static ILogger getLogger() { if (sLogger == null) { sLogger = new ILogger() { @Override public void error(Throwable t, String msgFormat, Object... args) { if (t != null) { Loading @@ -409,7 +419,7 @@ public class Main { } }; } return mLogger; return sLogger; } private static void failWithMsg(@NonNull String msgFormat, Object... args) { Loading