package ev3dev.utils;

import ev3dev.actuators.LCD;
import ev3dev.hardware.EV3DevPlatform;
import ev3dev.hardware.EV3DevPlatforms;
import ev3dev.hardware.EV3DevFileSystem;
import ev3dev.hardware.EV3DevPlatform;
import fake_ev3dev.ev3dev.actuators.FakeLCD;
import fake_ev3dev.ev3dev.sensors.FakeBattery;
import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.io.IOException;

@Slf4j
public class BrickmanTest {

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    @Before
    public void resetTest() throws IOException {
        FakeLCD.resetEV3DevInfrastructure();
    }

    //OK EV3Brick
    //OK PiStorms

    @Test
    public void disableBrickmanOnEV3Test() throws Exception {

        final EV3DevPlatform platform = EV3DevPlatform.EV3BRICK;

        EV3DevPlatforms conf = new EV3DevPlatforms(platform);

        System.setProperty(EV3DevFileSystem.EV3DEV_TESTING_KEY, FakeBattery.EV3DEV_FAKE_SYSTEM_PATH);
        System.setProperty(LCD.EV3DEV_LCD_KEY, FakeLCD.EV3DEV_FAKE_SYSTEM_PATH + "/" + conf.getFramebufferInfo().getKernelPath());

        final FakeBattery fakeBattery = new FakeBattery(platform);
        final FakeLCD fakeLCD = new FakeLCD(platform);

        Brickman.disable();
    }

    @Test
    public void disableBrickmanOnBrickPiTest() throws Exception {

        thrown.expect(RuntimeException.class);

        final EV3DevPlatform platform = EV3DevPlatform.BRICKPI;

        EV3DevPlatforms conf = new EV3DevPlatforms(platform);

        System.setProperty(EV3DevFileSystem.EV3DEV_TESTING_KEY, FakeBattery.EV3DEV_FAKE_SYSTEM_PATH);
        System.setProperty(LCD.EV3DEV_LCD_KEY, FakeLCD.EV3DEV_FAKE_SYSTEM_PATH + "/" + conf.getFramebufferInfo().getKernelPath());

        final FakeBattery fakeBattery = new FakeBattery(platform);
        final FakeLCD fakeLCD = new FakeLCD(platform);

        Brickman.disable();
    }

    @Test
    public void disableBrickmanOnBrickPi3Test() throws Exception {

        thrown.expect(RuntimeException.class);

        final EV3DevPlatform platform = EV3DevPlatform.BRICKPI3;

        EV3DevPlatforms conf = new EV3DevPlatforms(platform);

        System.setProperty(EV3DevFileSystem.EV3DEV_TESTING_KEY, FakeBattery.EV3DEV_FAKE_SYSTEM_PATH);
        System.setProperty(LCD.EV3DEV_LCD_KEY, FakeLCD.EV3DEV_FAKE_SYSTEM_PATH + "/" + conf.getFramebufferInfo().getKernelPath());

        final FakeBattery fakeBattery = new FakeBattery(platform);
        final FakeLCD fakeLCD = new FakeLCD(platform);

        Brickman.disable();
    }

    @Ignore("Review how to reset a Static classic in JUnit")
    @Test
    public void disableBrickmanOnPiStormsTest() throws Exception {

        thrown.expect(RuntimeException.class);

        final EV3DevPlatform platform = EV3DevPlatform.PISTORMS;

        EV3DevPlatforms conf = new EV3DevPlatforms(platform);

        System.setProperty(EV3DevFileSystem.EV3DEV_TESTING_KEY, FakeBattery.EV3DEV_FAKE_SYSTEM_PATH);
        System.setProperty(LCD.EV3DEV_LCD_KEY, FakeLCD.EV3DEV_FAKE_SYSTEM_PATH + "/" + conf.getFramebufferInfo().getKernelPath());

        final FakeBattery fakeBattery = new FakeBattery(platform);
        final FakeLCD fakeLCD = new FakeLCD(platform);

        Brickman.disable();
    }

    @Test
    public void disableBrickmanOnUnknownPlatformTest() throws Exception {

        thrown.expect(RuntimeException.class);

        final EV3DevPlatform platform = EV3DevPlatform.UNKNOWN;

        EV3DevPlatforms conf = new EV3DevPlatforms(platform);

        System.setProperty(EV3DevFileSystem.EV3DEV_TESTING_KEY, FakeBattery.EV3DEV_FAKE_SYSTEM_PATH);
        System.setProperty(LCD.EV3DEV_LCD_KEY, FakeLCD.EV3DEV_FAKE_SYSTEM_PATH + "/" + conf.getFramebufferInfo().getKernelPath());

        final FakeBattery fakeBattery = new FakeBattery(platform);
        final FakeLCD fakeLCD = new FakeLCD(platform);

        Brickman.disable();
    }

}

@@ -802,16 +802,19 @@
 ickmanOn
+New
 EV3Test(
@@ -826,32 +826,32 @@
 ows Exception %7B%0A
-
 %0A        final E
@@ -1188,32 +1188,755 @@
 etKernelPath());
+%0A        System.setProperty(LCD.EV3DEV_LCD_MODE_KEY, %22xrgb%22);%0A%0A        final FakeBattery fakeBattery = new FakeBattery(platform);%0A        final FakeLCD fakeLCD = new FakeLCD(platform);%0A%0A        Brickman.disable();%0A    %7D%0A%0A    @Test%0A    public void disableBrickmanOnOldEV3Test() throws Exception %7B%0A%0A        final EV3DevPlatform platform = EV3DevPlatform.EV3BRICK;%0A%0A        EV3DevPlatforms conf = new EV3DevPlatforms(platform);%0A%0A        System.setProperty(EV3DevFileSystem.EV3DEV_TESTING_KEY, FakeBattery.EV3DEV_FAKE_SYSTEM_PATH);%0A        System.setProperty(LCD.EV3DEV_LCD_KEY, FakeLCD.EV3DEV_FAKE_SYSTEM_PATH + %22/%22 + conf.getFramebufferInfo().getKernelPath());%0A        System.setProperty(LCD.EV3DEV_LCD_MODE_KEY, %22bitplane%22);
 %0A%0A        final 
@@ -2556,32 +2556,93 @@
 etKernelPath());
+%0A        System.setProperty(LCD.EV3DEV_LCD_MODE_KEY, %22xrgb%22);
 %0A%0A        final 
@@ -3264,32 +3264,93 @@
 etKernelPath());
+%0A        System.setProperty(LCD.EV3DEV_LCD_MODE_KEY, %22xrgb%22);
 %0A%0A        final 
@@ -4033,32 +4033,93 @@
 etKernelPath());
+%0A        System.setProperty(LCD.EV3DEV_LCD_MODE_KEY, %22xrgb%22);
 %0A%0A        final 
@@ -4617,32 +4617,32 @@
 E_SYSTEM_PATH);%0A
-
         System.s
@@ -4755,16 +4755,77 @@
 Path());
+%0A        System.setProperty(LCD.EV3DEV_LCD_MODE_KEY, %22xrgb%22);
 %0A%0A      

Add tests for new/old LCD