1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 /*
  24  * @test
  25  * @bug 8147002
  26  * @summary  Verifies if Arabic character alef is rendered in osx
  27  * @run main/manual MissingGlyphTest
  28  */
  29 import java.awt.Font;
  30 import java.awt.BorderLayout;
  31 import java.awt.Color;
  32 import java.awt.FlowLayout;
  33 import java.awt.Graphics;
  34 import java.awt.event.WindowAdapter;
  35 import java.awt.event.WindowEvent;
  36 import javax.swing.JButton;
  37 import javax.swing.JDialog;
  38 import javax.swing.JFrame;
  39 import javax.swing.JPanel;
  40 import javax.swing.JTextArea;
  41 import javax.swing.JComponent;
  42 import javax.swing.SwingUtilities;
  43 import javax.swing.WindowConstants;
  44 
  45 public class MissingGlyphTest {
  46     private static Thread mainThread;
  47     private static boolean testPassed;
  48     private static boolean testGeneratedInterrupt;
  49     private static JFrame frame;
  50     
  51     public static void main(String[] args) throws Exception {
  52         if (!System.getProperty("os.name").startsWith("Mac")) {
  53             return;
  54         }
  55         SwingUtilities.invokeAndWait(() -> {
  56             doTest(MissingGlyphTest::glyphTest);
  57         });
  58         mainThread = Thread.currentThread();
  59         try {
  60             Thread.sleep(180000);
  61         } catch (InterruptedException e) {
  62             if (!testPassed && testGeneratedInterrupt) {
  63                 throw new RuntimeException("Alef character is not rendered");
  64             }
  65         }
  66         if (!testGeneratedInterrupt) {
  67             throw new RuntimeException("user has not executed the test");
  68         }
  69     }
  70 
  71     private static void glyphTest() {
  72         frame = new JFrame("Test");
  73         frame.add(new MyComponent());
  74         frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  75         frame.setSize(200, 200);
  76         frame.setLocationRelativeTo(null);
  77         frame.setVisible(true);
  78     }
  79     
  80     
  81 
  82     public static synchronized void pass() {
  83         testPassed = true;
  84         testGeneratedInterrupt = true;
  85         mainThread.interrupt();
  86     }
  87 
  88     public static synchronized void fail() {
  89         testPassed = false;
  90         testGeneratedInterrupt = true;
  91         mainThread.interrupt();
  92     }
  93 
  94     private static void doTest(Runnable action) {
  95         String description
  96                 = " The test is supposed to display arabic alef character.\n"
  97                 + " If it resembles like the one shown in\n "
  98                 + " www.fileformat.info/info/unicode/char/0627/index.htm\n "
  99                 + " in Italic style ,press PASS.\n" 
 100                 + " If the glyph is not shown or empty rectangle is shown, press FAIL";
 101 
 102         final JDialog dialog = new JDialog();
 103         dialog.setTitle("printBannerTest");
 104         JTextArea textArea = new JTextArea(description);
 105         textArea.setEditable(false);
 106         final JButton testButton = new JButton("Start Test");
 107         final JButton passButton = new JButton("PASS");
 108         passButton.setEnabled(false);
 109         passButton.addActionListener((e) -> {
 110             dialog.dispose();
 111             frame.dispose();
 112             pass();
 113         });
 114         final JButton failButton = new JButton("FAIL");
 115         failButton.setEnabled(false);
 116         failButton.addActionListener((e) -> {
 117             dialog.dispose();
 118             frame.dispose();
 119             fail();
 120         });
 121         testButton.addActionListener((e) -> {
 122             testButton.setEnabled(false);
 123             action.run();
 124             passButton.setEnabled(true);
 125             failButton.setEnabled(true);
 126         });
 127         JPanel mainPanel = new JPanel(new BorderLayout());
 128         mainPanel.add(textArea, BorderLayout.CENTER);
 129         JPanel buttonPanel = new JPanel(new FlowLayout());
 130         buttonPanel.add(testButton);
 131         buttonPanel.add(passButton);
 132         buttonPanel.add(failButton);
 133         mainPanel.add(buttonPanel, BorderLayout.SOUTH);
 134         dialog.add(mainPanel);
 135         dialog.pack();
 136         dialog.setVisible(true);
 137         dialog.addWindowListener(new WindowAdapter() {
 138            @Override
 139             public void windowClosing(WindowEvent e) {
 140                 System.out.println("main dialog closing");
 141                 testGeneratedInterrupt = false;
 142                 mainThread.interrupt();
 143             }
 144         });
 145     }
 146 }
 147 
 148 class MyComponent extends JComponent {
 149     private final Font font = new Font("Menlo", Font.ITALIC, 100);
 150     private final String text = "\u0627"; // Arabic letter alef
 151 
 152     @Override
 153     protected void paintComponent(Graphics g) {
 154         if (font.canDisplayUpTo(text) == -1) {
 155             g.setColor(Color.black);
 156             g.setFont(font);
 157             g.drawString(text, 70, 110);
 158         }
 159     }
 160 }
 161 
 162 
 163 
 164