< prev index next >

test/javax/swing/JFileChooser/ShellFolderQueries/ShellFolderQueriesTest.java

Print this page

        

@@ -21,18 +21,19 @@
  * questions.
  */
 
 /*
  * @test
- * @bug 8081722
+ * @bug 8081722 8182043
  * @summary Provide public API for file hierarchy provided by
  * sun.awt.shell.ShellFolder
  * @author Semyon Sadetsky
  * @run main ShellFolderQueriesTest
  */
 
 
+import javax.swing.*;
 import javax.swing.filechooser.FileSystemView;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;

@@ -48,13 +49,15 @@
             "oShellLink.TargetPath = \"";
     static String scriptEnd = "\"\noShellLink.WindowStyle = 1\noShellLink.Save";
 
     public static void main(String[] args) throws Exception {
         if(System.getProperty("os.name").toLowerCase().contains("windows")) {
-            System.out.println("Windows detected: will run shortcut test");
+            System.out.println("Windows detected: will run shortcut " +
+                                                       "and sytem icons tests");
             testGet();
             testLink();
+            testSystemIcon();
         } else {
             testGet();
         }
         System.out.println("ok");
     }

@@ -117,6 +120,35 @@
                         "Link shouldn't be in FileChooser combobox, "
                                 + file.getPath());
             }
         }
     }
+
+    static void testSystemIcon() {
+        try {
+            fsv.getSystemIcon(null, FileSystemView.FILE_ICON_SMALL);
+        } catch (NullPointerException e) {
+            String windir = System.getenv("windir");
+            testSystemIcon(new File(windir));
+            testSystemIcon(new File(windir + "/explorer.exe"));
+            return;
+        }
+        throw new RuntimeException("NPE was not thrown");
+    }
+
+    static void testSystemIcon(File file) {
+        ImageIcon icon = fsv.getSystemIcon(file, FileSystemView.FILE_ICON_SMALL);
+        System.out.println("Small icon size " + icon.getIconWidth());
+
+        icon = fsv.getSystemIcon(file, FileSystemView.FILE_ICON_LARGE);
+        System.out.println("Large icon size " + icon.getIconWidth());
+
+        int[] sizes = new int[] {16, 24, 32, 48, 64, 128, 50};
+        for (int size : sizes) {
+            icon = fsv.getSystemIcon(file, size);
+            if (icon.getIconWidth() != size) {
+                throw new RuntimeException("Wrong icon size " +
+                        icon.getIconWidth() + " when requested " + size);
+            }
+        }
+    }
 }
< prev index next >