Java Code Examples for jdk.testlibrary.OSInfo#getOSType()

The following examples show how to use jdk.testlibrary.OSInfo#getOSType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: bug7172652.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("ok");
        return;
    }
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            setup();
        }
    });

    test();
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            frame.dispose();
        }
    });
}
 
Example 2
Source File: bug8046391.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    OSType type = OSInfo.getOSType();
    if (type != OSType.WINDOWS) {
        System.out.println("This test is for Windows only... skipping!");
        return;
    }

    SwingUtilities.invokeAndWait(() -> {
        try {
            UIManager.setLookAndFeel(new WindowsLookAndFeel());
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
        System.out.println("Creating JFileChooser...");
        JFileChooser fileChooser = new JFileChooser();
        System.out.println("Test passed: chooser = " + fileChooser);
    });
    // Test fails if creating JFileChooser hangs
}
 
Example 3
Source File: FileDialogForPackages.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void init() {
    if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
        Sysout.createDialogWithInstructions(new String[]{
                "Press PASS, this test is for MacOS X only."});
        return;
    }

    System.setProperty("apple.awt.use-file-dialog-packages", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");
    fd.setDirectory(APPLICATIONS_FOLDER);

    showBtn = new Button("Show File Dialog");
    showBtn.addActionListener(this);
    add(showBtn);
    String[] instructions = {
            "1) Click on 'Show File Dialog' button. A file dialog will come up.",
            "2) Navigate to the Applications folder if not already there",
            "3) Check that the application bundles can be selected and can not be navigated",
            "4) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
 
Example 4
Source File: bug7172652.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("ok");
        return;
    }
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            setup();
        }
    });

    test();
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            frame.dispose();
        }
    });
}
 
Example 5
Source File: bug7172652.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("ok");
        return;
    }
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            setup();
        }
    });

    test();
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            frame.dispose();
        }
    });
}
 
Example 6
Source File: bug6840086.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("The test was skipped because it is sensible only for Windows.");

        return;
    }

    for (String key : KEYS) {
        Image image = (Image) ShellFolder.get(key);

        if (image == null) {
            throw new RuntimeException("The image '" + key + "' not found.");
        }

        if (image != ShellFolder.get(key)) {
            throw new RuntimeException("The image '" + key + "' is not cached.");
        }
    }

    System.out.println("The test passed.");
}
 
Example 7
Source File: bug8017487.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] p_args) throws Exception {
    if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS &&
            OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_VISTA) > 0 ) {
        test();
        System.out.println("ok");
    }
}
 
Example 8
Source File: bug8072769.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
        if (SystemTray.isSupported()) {
            test();
        } else {
            System.out.println("SystemTray not supported. " +
                    "Test is skipped.");
        }
    } else {
        System.out.println("Test will only run on Windows platform. " +
                "Test is skipped.");
    }
    System.out.println("ok");
}
 
Example 9
Source File: bug8072769.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
        if (SystemTray.isSupported()) {
            test();
        } else {
            System.out.println("SystemTray not supported. " +
                    "Test is skipped.");
        }
    } else {
        System.out.println("Test will only run on Windows platform. " +
                "Test is skipped.");
    }
    System.out.println("ok");
}
 
Example 10
Source File: bug6579827.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS ||
            OSInfo.getWindowsVersion() != OSInfo.WINDOWS_VISTA) {
        System.out.println("This test is only for Windows Vista. Skipped.");

        return;
    }

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try {
                UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            } catch (Exception e) {
                e.printStackTrace();

                throw new RuntimeException(e);
            }

            JSlider slider = new JSlider(JSlider.VERTICAL, 0, 100, 0);

            Dimension prefferdSize = slider.getPreferredSize();

            slider.setPaintTrack(false);
            slider.putClientProperty("Slider.paintThumbArrowShape", Boolean.TRUE);

            if (prefferdSize.equals(slider.getPreferredSize())) {
                throw new RuntimeException();
            }
        }
    });
}
 
Example 11
Source File: bug8020209.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
        System.out.println("This test is for MacOS only. Automatically passed on other platforms.");
        return;
    }

    System.setProperty("apple.laf.useScreenMenuBar", "true");

    Robot robot = new Robot();
    robot.setAutoDelay(50);

    createAndShowGUI();
    robot.waitForIdle();

    for (int i = 0; i < keyStrokes.length; ++i) {
        AWTKeyStroke ks = keyStrokes[i];

        int modKeyCode = getModKeyCode(ks.getModifiers());
        robot.keyPress(modKeyCode);

        robot.keyPress(ks.getKeyCode());
        robot.keyRelease(ks.getKeyCode());

        robot.keyRelease(modKeyCode);

        robot.waitForIdle();

        if (listenerCallCounter != 4) {
            throw new Exception("Test failed: KeyListener for '" + ks.toString() +
                    "' called " + listenerCallCounter + " times instead of 4!");
        }

        listenerCallCounter = 0;
    }

}
 
Example 12
Source File: bug4251301.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {
        System.out.println("This test is not applicable for MacOS. Passed.");
        return;
    }
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
    Robot robot = new Robot();
    robot.waitForIdle();
    test.waitTestResult();
}
 
Example 13
Source File: bug6416920.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {

        if(OSInfo.getOSType() != OSInfo.OSType.WINDOWS){
            return;
        }

        bug6416920 test = new bug6416920();
        test.layout.padSelectedTab(SwingConstants.TOP, 0);
        if (test.rects[0].width < 0) {
            throw new RuntimeException("A selected tab isn't painted properly " +
                    "in the scroll tab layout under WindowsLookAndFeel " +
                    "in Windows' \"Windows XP\" theme.");
        }
    }
 
Example 14
Source File: bug4796987.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS
            && OSInfo.getWindowsVersion() == OSInfo.WINDOWS_XP) {
        UIManager.setLookAndFeel(new WindowsLookAndFeel());
        testButtonBorder();
    }
}
 
Example 15
Source File: NSImageToMultiResolutionImageTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
            return;
        }

        String icon = "NSImage://NSApplicationIcon";
        final Image image = Toolkit.getDefaultToolkit().getImage(icon);

        if (!(image instanceof MultiResolutionImage)) {
            throw new RuntimeException("Icon does not have resolution variants!");
        }

        MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;

        int width = 0;
        int height = 0;

        for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
            int rvWidth = resolutionVariant.getWidth(null);
            int rvHeight = resolutionVariant.getHeight(null);
            if (rvWidth < width || rvHeight < height) {
                throw new RuntimeException("Resolution variants are not sorted!");
            }
            width = rvWidth;
            height = rvHeight;
        }
    }
 
Example 16
Source File: MissedHtmlAndRtfBug.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void start() {
    if (OSInfo.getOSType() != OSInfo.OSType.MACOSX
            && OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
        System.out.println("This test is for Windows and Mac only. Passed.");
        return;
    }

    final Frame sourceFrame = new Frame("Source frame");
    final SourcePanel sourcePanel = new SourcePanel();
    sourceFrame.add(sourcePanel);
    sourceFrame.pack();
    sourceFrame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            sourceFrame.dispose();
        }
    });
    sourceFrame.setVisible(true);

    Util.waitForIdle(null);

    NextFramePositionCalculator positionCalculator = new NextFramePositionCalculator(sourceFrame);

    ArrayList<String> args = new ArrayList<String>(5);
    args.add(String.valueOf(positionCalculator.getNextLocationX()));
    args.add(String.valueOf(positionCalculator.getNextLocationY()));
    args.add(String.valueOf(AbsoluteComponentCenterCalculator.calculateXCenterCoordinate(sourcePanel)));
    args.add(String.valueOf(AbsoluteComponentCenterCalculator.calculateYCenterCoordinate(sourcePanel)));
    args.add(concatStrings(DataFlavorSearcher.RICH_TEXT_NAMES));

    ProcessResults processResults =
            ProcessCommunicator.executeChildProcess(this.getClass(),
                    "." + File.separator + System.getProperty("java.class.path"), args.toArray(new String[]{}));

    verifyTestResults(processResults);

    args.set(args.size() - 1, concatStrings(DataFlavorSearcher.HTML_NAMES));

    ProcessCommunicator.executeChildProcess(this.getClass(),
            "." + File.separator + System.getProperty("java.class.path"), args.toArray(new String[]{}));
    verifyTestResults(processResults);


}
 
Example 17
Source File: bug6470128.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JMenuBar bar = new JMenuBar();
            JMenu menu = new JMenu("Menu");
            menu.setMnemonic('m');
            subMenu = new JMenu("SubMenu");
            JMenuItem item = new JMenuItem("Item");

            frame.setJMenuBar(bar);
            bar.add(menu);
            menu.add(subMenu);
            subMenu.add(item);

            frame.setSize(200, 200);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    Robot robot = new Robot();
    robot.setAutoDelay(10);
    robot.waitForIdle();
    if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {
        robot.keyPress(KeyEvent.VK_CONTROL);
    }
    robot.keyPress(KeyEvent.VK_ALT);
    robot.keyPress(KeyEvent.VK_M);
    robot.keyRelease(KeyEvent.VK_M);
    robot.keyRelease(KeyEvent.VK_ALT);
    if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {
        robot.keyRelease(KeyEvent.VK_CONTROL);
    }
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);
    robot.keyPress(KeyEvent.VK_ESCAPE);
    robot.keyRelease(KeyEvent.VK_ESCAPE);
    robot.waitForIdle();
    if (!subMenu.isSelected()) {
        throw new RuntimeException("Submenu is unexpectedly unselected");
    }
}
 
Example 18
Source File: MultiDisplayTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private static boolean checkOS() {
    OSInfo.OSType os = OSInfo.getOSType();
    return (os.equals(OSInfo.OSType.WINDOWS) ||
        os.equals(OSInfo.OSType.MACOSX));
}
 
Example 19
Source File: bug8016356.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        // Windows only test
        if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {

            // Retrieving top edge of Desktop
            GraphicsConfiguration grConf = GraphicsEnvironment
                    .getLocalGraphicsEnvironment().getDefaultScreenDevice()
                    .getDefaultConfiguration();
            Rectangle scrRect = grConf.getBounds();
            Insets scrInsets = Toolkit.getDefaultToolkit().getScreenInsets(grConf);
            scrTop = scrRect.y + scrInsets.top;

            color = new Color(0, 255, 0);

            SwingUtilities.invokeAndWait(() -> {
                createAndShowUI();
            });

            try {
                Robot robot = new Robot();
                robot.setAutoDelay(500);
                robot.setAutoWaitForIdle(true);
                robot.delay(1000);

                // Resizing a window to invoke Windows Snap feature
                readFrameInfo();
                robot.mouseMove(frLoc.x + frSize.width / 2, frLoc.y);
                robot.mousePress(InputEvent.BUTTON1_MASK);
                robot.mouseMove(frLoc.x + frSize.width / 2, scrTop);
                robot.mouseRelease(InputEvent.BUTTON1_MASK);

                // Retrieving the color of window expanded area
                readFrameInfo();
                Insets insets = frame.getInsets();
                Color bgColor = robot.getPixelColor(frLoc.x + frSize.width / 2,
                        frLoc.y + frSize.height - insets.bottom - 1);

                frame.dispose();

                if (!bgColor.equals(color)) {
                    throw new RuntimeException("TEST FAILED: got "
                            + bgColor + " instead of " + color);
                }
                System.out.println("TEST PASSED!");
            } catch (AWTException ex) {
                throw new RuntimeException("TEST FAILED!");
            }
        }
    }
 
Example 20
Source File: MaximizedByPlatform.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
        // Test only for macosx. Pass
        return;
    }

    Robot robot;
    try {
        robot = new Robot();
    }catch(Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException("Unexpected failure");
    }
    availableScreenBounds = getAvailableScreenBounds();

    // Test 1. The maximized state is set in setBounds
    try {
        frame = new Frame();
        frame.setBounds(100, 100, 100, 100);
        frame.setVisible(true);

        robot.waitForIdle();

        frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
                availableScreenBounds.width, availableScreenBounds.height);

        robot.waitForIdle();

        if (frame.getExtendedState() != Frame.MAXIMIZED_BOTH) {
            throw new RuntimeException("Maximized state was not set for frame in setBounds");
        }
    } finally {
        frame.dispose();
    }


    // Test 2. The maximized state is set in setVisible
    try {
        frame = new Frame();
        frame.setBounds(availableScreenBounds.x, availableScreenBounds.y,
                availableScreenBounds.width + 100, availableScreenBounds.height);
        frame.setVisible(true);

        robot.waitForIdle();

        if (frame.getExtendedState() != Frame.MAXIMIZED_BOTH) {
            throw new RuntimeException("Maximized state was not set for frame in setVisible");
        }
    } finally {
        frame.dispose();
    }
}