Search in sources :

Example 1 with Screen

use of com.b3dgs.lionengine.graphic.Screen in project lionengine by b3dgs.

the class LoaderTest method testInterruptedUnchecked.

/**
 * Test interrupted unchecked exception.
 *
 * @throws InterruptedException If error.
 */
@Test(timeout = SequenceInterruptMock.PAUSE_MILLI * 2L)
public void testInterruptedUnchecked() throws InterruptedException {
    try {
        Graphics.setFactoryGraphic(new FactoryGraphicMock() {

            @Override
            public Screen createScreen(Config config) {
                return null;
            }
        });
        final AtomicReference<Throwable> exception = new AtomicReference<>();
        final Semaphore semaphore = new Semaphore(0);
        final Thread thread = new Thread() {

            @Override
            public void run() {
                final TaskFuture future = Loader.start(CONFIG, SequenceInterruptMock.class);
                future.await();
            }
        };
        thread.setUncaughtExceptionHandler((t, throwable) -> {
            exception.set(throwable);
            semaphore.release();
        });
        Verbose.info("*********************************** EXPECTED VERBOSE ***********************************");
        thread.start();
        semaphore.acquire();
        Assert.assertTrue(exception.get().getCause() instanceof NullPointerException);
    } finally {
        Verbose.info("****************************************************************************************");
        Graphics.setFactoryGraphic(new FactoryGraphicMock());
    }
}
Also used : Config(com.b3dgs.lionengine.Config) Screen(com.b3dgs.lionengine.graphic.Screen) FactoryGraphicMock(com.b3dgs.lionengine.graphic.FactoryGraphicMock) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test)

Example 2 with Screen

use of com.b3dgs.lionengine.graphic.Screen in project lionengine by b3dgs.

the class LoopExtrapolatedTest method testNoSyncFullscreen.

/**
 * Test without sync full screen.
 *
 * @throws InterruptedException If error.
 */
@Test(timeout = 1000L)
public void testNoSyncFullscreen() throws InterruptedException {
    ScreenMock.setScreenWait(false);
    final Screen screen = new ScreenMock(new Config(new Resolution(320, 240, 0), 16, false));
    screen.getConfig().setSource(new Resolution(320, 240, 50));
    final Thread thread = getTask(screen);
    thread.start();
    thread.join();
    Assert.assertEquals(maxTick.get(), tick.get());
    Assert.assertEquals(tick.get(), rendered.get());
    Assert.assertTrue(String.valueOf(extrapolation.get()), extrapolation.get().doubleValue() > 0);
    final int expectedRate = screen.getConfig().getOutput().getRate();
    Assert.assertTrue(String.valueOf(computed.get()), computed.get() > expectedRate);
}
Also used : Screen(com.b3dgs.lionengine.graphic.Screen) Config(com.b3dgs.lionengine.Config) ScreenMock(com.b3dgs.lionengine.graphic.ScreenMock) Resolution(com.b3dgs.lionengine.Resolution) Test(org.junit.Test)

Example 3 with Screen

use of com.b3dgs.lionengine.graphic.Screen in project lionengine by b3dgs.

the class LoopExtrapolatedTest method testEngineNotStarted.

/**
 * Test with not started engine.
 *
 * @throws InterruptedException If error.
 */
@Test(timeout = 1000L)
public void testEngineNotStarted() throws InterruptedException {
    ScreenMock.setScreenWait(false);
    final Screen screen = new ScreenMock(new Config(new Resolution(320, 240, 50), 16, true));
    screen.getConfig().setSource(new Resolution(320, 240, 50));
    maxTick.set(-1);
    final Thread thread = getTask(screen);
    thread.start();
    while (tick.get() < 1) {
    // Continue
    }
    Engine.terminate();
    thread.join();
    Assert.assertEquals(tick.get(), rendered.get());
    Assert.assertEquals(1.0, extrapolation.get().doubleValue(), 0.1);
    final int expectedRate = screen.getConfig().getOutput().getRate();
    Assert.assertTrue(String.valueOf(computed.get()), computed.get() <= expectedRate);
}
Also used : Screen(com.b3dgs.lionengine.graphic.Screen) Config(com.b3dgs.lionengine.Config) ScreenMock(com.b3dgs.lionengine.graphic.ScreenMock) Resolution(com.b3dgs.lionengine.Resolution) Test(org.junit.Test)

Example 4 with Screen

use of com.b3dgs.lionengine.graphic.Screen in project lionengine by b3dgs.

the class LoopFrameSkippingTest method testMaxRate.

/**
 * Test with max rate.
 *
 * @throws InterruptedException If error.
 */
@Test(timeout = 1000L)
public void testMaxRate() throws InterruptedException {
    ScreenMock.setScreenWait(false);
    final Screen screen = new ScreenMock(new Config(new Resolution(320, 240, 50), 16, true));
    screen.getConfig().setSource(new Resolution(320, 240, 0));
    final Thread thread = getTask(screen);
    thread.start();
    thread.join();
    Assert.assertTrue(tick.get() + " " + maxTick.get(), tick.get() >= maxTick.get());
    Assert.assertTrue(rendered.get() + " " + tick.get(), rendered.get() <= tick.get());
    Assert.assertTrue(String.valueOf(rendered.get()), rendered.get() > 0);
    Assert.assertTrue(String.valueOf(computed.get()), computed.get() > 0);
}
Also used : Screen(com.b3dgs.lionengine.graphic.Screen) Config(com.b3dgs.lionengine.Config) ScreenMock(com.b3dgs.lionengine.graphic.ScreenMock) Resolution(com.b3dgs.lionengine.Resolution) Test(org.junit.Test)

Example 5 with Screen

use of com.b3dgs.lionengine.graphic.Screen in project lionengine by b3dgs.

the class LoopFrameSkippingTest method testUnready.

/**
 * Test with not ready screen.
 *
 * @throws InterruptedException If error.
 */
@Test(timeout = 1000L)
public void testUnready() throws InterruptedException {
    ScreenMock.setScreenWait(true);
    final Screen screen = new ScreenMock(new Config(new Resolution(320, 240, 50), 16, true));
    screen.getConfig().setSource(new Resolution(320, 240, 50));
    final Thread thread = getTask(screen);
    thread.start();
    latch.await();
    loop.stop();
    thread.join();
    Assert.assertEquals(0, tick.get());
    Assert.assertEquals(0, rendered.get());
    Assert.assertEquals(-1, computed.get());
}
Also used : Screen(com.b3dgs.lionengine.graphic.Screen) Config(com.b3dgs.lionengine.Config) ScreenMock(com.b3dgs.lionengine.graphic.ScreenMock) Resolution(com.b3dgs.lionengine.Resolution) Test(org.junit.Test)

Aggregations

Screen (com.b3dgs.lionengine.graphic.Screen)56 Config (com.b3dgs.lionengine.Config)47 Resolution (com.b3dgs.lionengine.Resolution)45 ScreenMock (com.b3dgs.lionengine.graphic.ScreenMock)45 Test (org.junit.jupiter.api.Test)26 Test (org.junit.Test)23 Semaphore (java.util.concurrent.Semaphore)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 InputDeviceKeyListener (com.b3dgs.lionengine.InputDeviceKeyListener)3 ScreenListener (com.b3dgs.lionengine.graphic.ScreenListener)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 FactoryGraphicMock (com.b3dgs.lionengine.graphic.FactoryGraphicMock)2 Context (com.b3dgs.lionengine.Context)1 InputDevice (com.b3dgs.lionengine.InputDevice)1