Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a2366b0c authored by Deepanshu Gupta's avatar Deepanshu Gupta Committed by Android (Google) Code Review
Browse files

Merge "Run setup for full tests only once." into mnc-dev

parents db42c336 a12ec8f1
Loading
Loading
Loading
Loading
+36 −26
Original line number Diff line number Diff line
@@ -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;
@@ -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.
@@ -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
@@ -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());
    }

@@ -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.
@@ -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());
@@ -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(
@@ -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);
@@ -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) {
@@ -409,7 +419,7 @@ public class Main {
                }
            };
        }
        return mLogger;
        return sLogger;
    }

    private static void failWithMsg(@NonNull String msgFormat, Object... args) {