/*
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
 */

package com.sun.glass.tests;

import com.sun.glass.ui.*;

import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.AfterClass;

public class WindowMinimizeMaximize
{
    final static int WINDOW_X = 101;
    final static int WINDOW_Y = 102;

    final static int WINDOW_W = 511;
    final static int WINDOW_H = 512;

    @BeforeClass
    static public void prepare()
    {
        try
        {
            Application app = Application.GetApplication();
            Screen screen = Screen.getMainScreen();

            int windowMask = Window.TITLED|Window.CLOSABLE|Window.MINIMIZABLE;
            Window window = app.createWindow(screen, windowMask);
            window.setPosition(WINDOW_X, WINDOW_Y);
            window.setSize(WINDOW_W, WINDOW_H);
            window.setTitle(app.getName());
            window.setVisible(true);
        }
        catch (Throwable t)
        {
            t.printStackTrace();
            System.exit(0);
        }
    }

    @AfterClass
    static public void finish()
    {
        Window window = Window.getWindows().get(0);
        window.close();
    }

    @Test
    public void testMinimize()
    {
        Window window = Window.getWindows().get(0);
        assertTrue(window != null);

        window.setSize(WINDOW_W, WINDOW_H);
        window.maximize(true);
        window.maximize(false);

        assertTrue(window.getWidth() == WINDOW_W);
        assertTrue(window.getHeight() == WINDOW_H);
    }

    @Test
    public void testMaximize()
    {
        Window window = Window.getWindows().get(0);
        assertTrue(window != null);
        
        window.setSize(WINDOW_W, WINDOW_H);
        window.minimize(true);
        window.minimize(false);

        assertTrue(window.getWidth() == WINDOW_W);
        assertTrue(window.getHeight() == WINDOW_H);
    }
}
