< prev index next >

modules/javafx.controls/src/test/java/test/javafx/scene/control/ControlTest.java

Print this page
rev 10863 : 8199071: Fix gradle deprecation warnings
Reviewed-by:


 988         assertEquals(0, c.getBaselineOffset(), 0f);
 989     }
 990 
 991     @Test public void baselineOffsetUpdatedWhenTheSkinChanges() {
 992         c.setSkin(s);
 993         assertEquals(BASELINE_OFFSET, c.getBaselineOffset(), 0);
 994     }
 995 
 996     @Test
 997     public void testRT18097() {
 998         try {
 999             File f = System.getProperties().containsKey("CSS_META_DATA_TEST_DIR") ?
1000                     new File(System.getProperties().get("CSS_META_DATA_TEST_DIR").toString()) :
1001                     null;
1002             if (f == null) {
1003                 ClassLoader cl = Thread.currentThread().getContextClassLoader();
1004                 URL base = cl.getResource("test/javafx/../javafx");
1005                 f = new File(base.toURI());
1006             }
1007             //System.err.println(f.getPath());

1008             recursiveCheck(f, f.getPath().length() - 7);
1009         } catch (Exception ex) {
1010             ex.printStackTrace(System.err);
1011             fail(ex.getMessage());
1012         }
1013     }
1014 
1015     private static void checkClass(Class someClass) {
1016 
1017         // Ignore inner classes
1018         if (someClass.getEnclosingClass() != null) return;
1019 
1020         if (javafx.scene.control.Control.class.isAssignableFrom(someClass) &&
1021                 Modifier.isAbstract(someClass.getModifiers()) == false &&
1022                 !Modifier.isPrivate(someClass.getModifiers()) == false) {
1023             String what = someClass.getName();
1024             try {
1025                 // should get NoSuchMethodException if ctor is not public
1026 //                Constructor ctor = someClass.getConstructor((Class[])null);
1027                 Method m = someClass.getMethod("getClassCssMetaData", (Class[]) null);
1028 //                Node node = (Node)ctor.newInstance((Object[])null);
1029                 Node node = (Node)someClass.newInstance();
1030                 for (CssMetaData styleable : (List<CssMetaData<? extends Styleable, ?>>) m.invoke(null)) {
1031 
1032                     what = someClass.getName() + " " + styleable.getProperty();
1033                     WritableValue writable = styleable.getStyleableProperty(node);
1034                     assertNotNull(what, writable);
1035 
1036                     Object defaultValue = writable.getValue();
1037                     Object initialValue = styleable.getInitialValue((Node) someClass.newInstance());
1038 
1039                     if (defaultValue instanceof Number) {
1040                         // 5 and 5.0 are not the same according to equals,
1041                         // but they should be...
1042                         assert(initialValue instanceof Number);


1058                 System.err.println("IllegalAccessException:  RT-18097 cannot be tested on " + what);
1059             } catch (IllegalArgumentException ex) {
1060                 fail("IllegalArgumentException:  RT-18097 cannot be tested on " + what);
1061             } catch (InvocationTargetException ex) {
1062                 fail("InvocationTargetException:  RT-18097 cannot be tested on " + what);
1063             } catch (InstantiationException ex) {
1064                 fail("InstantiationException:  RT-18097 cannot be tested on " + what);
1065             }
1066         }
1067     }
1068 
1069     private static void checkDirectory(File directory, final int pathLength) {
1070         if (directory.isDirectory()) {
1071 
1072             for (File file : directory.listFiles()) {
1073                 if (file.isFile() && file.getName().endsWith(".class")) {
1074                     final String filePath = file.getPath();
1075                     final int len = file.getPath().length() - ".class".length();
1076                     final String clName =
1077                         file.getPath().substring(pathLength+1, len).replace(File.separatorChar,'.');
1078                     if (clName.startsWith("test.javafx.scene") == false) continue;
1079                     try {
1080                         final Class cl = Class.forName(clName);
1081                         if (cl != null) checkClass(cl);
1082                     } catch(ClassNotFoundException ex) {
1083                         System.err.println(ex.toString() + " " + clName);
1084                     }
1085                 }
1086             }
1087         }
1088     }
1089 
1090     private static void recursiveCheck(File directory, int pathLength) {
1091         if (directory.isDirectory()) {
1092 //            System.out.println(directory.getPath());
1093             checkDirectory(directory, pathLength);
1094 
1095             for (File subFile : directory.listFiles()) {
1096                 recursiveCheck(subFile, pathLength);
1097             }
1098         }




 988         assertEquals(0, c.getBaselineOffset(), 0f);
 989     }
 990 
 991     @Test public void baselineOffsetUpdatedWhenTheSkinChanges() {
 992         c.setSkin(s);
 993         assertEquals(BASELINE_OFFSET, c.getBaselineOffset(), 0);
 994     }
 995 
 996     @Test
 997     public void testRT18097() {
 998         try {
 999             File f = System.getProperties().containsKey("CSS_META_DATA_TEST_DIR") ?
1000                     new File(System.getProperties().get("CSS_META_DATA_TEST_DIR").toString()) :
1001                     null;
1002             if (f == null) {
1003                 ClassLoader cl = Thread.currentThread().getContextClassLoader();
1004                 URL base = cl.getResource("test/javafx/../javafx");
1005                 f = new File(base.toURI());
1006             }
1007             //System.err.println(f.getPath());
1008             assertTrue("" + f.getCanonicalPath() + " is not a directory", f.isDirectory());
1009             recursiveCheck(f, f.getPath().length() - 7);
1010         } catch (Exception ex) {
1011             ex.printStackTrace(System.err);
1012             fail(ex.getMessage());
1013         }
1014     }
1015 
1016     private static void checkClass(Class someClass) {
1017 
1018         // Ignore inner classes
1019         if (someClass.getEnclosingClass() != null) return;
1020 
1021         if (javafx.scene.control.Control.class.isAssignableFrom(someClass) &&
1022                 Modifier.isAbstract(someClass.getModifiers()) == false &&
1023                 Modifier.isPrivate(someClass.getModifiers()) == false) {
1024             String what = someClass.getName();
1025             try {
1026                 // should get NoSuchMethodException if ctor is not public
1027 //                Constructor ctor = someClass.getConstructor((Class[])null);
1028                 Method m = someClass.getMethod("getClassCssMetaData", (Class[]) null);
1029 //                Node node = (Node)ctor.newInstance((Object[])null);
1030                 Node node = (Node)someClass.newInstance();
1031                 for (CssMetaData styleable : (List<CssMetaData<? extends Styleable, ?>>) m.invoke(null)) {
1032 
1033                     what = someClass.getName() + " " + styleable.getProperty();
1034                     WritableValue writable = styleable.getStyleableProperty(node);
1035                     assertNotNull(what, writable);
1036 
1037                     Object defaultValue = writable.getValue();
1038                     Object initialValue = styleable.getInitialValue((Node) someClass.newInstance());
1039 
1040                     if (defaultValue instanceof Number) {
1041                         // 5 and 5.0 are not the same according to equals,
1042                         // but they should be...
1043                         assert(initialValue instanceof Number);


1059                 System.err.println("IllegalAccessException:  RT-18097 cannot be tested on " + what);
1060             } catch (IllegalArgumentException ex) {
1061                 fail("IllegalArgumentException:  RT-18097 cannot be tested on " + what);
1062             } catch (InvocationTargetException ex) {
1063                 fail("InvocationTargetException:  RT-18097 cannot be tested on " + what);
1064             } catch (InstantiationException ex) {
1065                 fail("InstantiationException:  RT-18097 cannot be tested on " + what);
1066             }
1067         }
1068     }
1069 
1070     private static void checkDirectory(File directory, final int pathLength) {
1071         if (directory.isDirectory()) {
1072 
1073             for (File file : directory.listFiles()) {
1074                 if (file.isFile() && file.getName().endsWith(".class")) {
1075                     final String filePath = file.getPath();
1076                     final int len = file.getPath().length() - ".class".length();
1077                     final String clName =
1078                         file.getPath().substring(pathLength+1, len).replace(File.separatorChar,'.');
1079                     if (clName.startsWith("javafx.scene") == false) continue;
1080                     try {
1081                         final Class cl = Class.forName(clName);
1082                         if (cl != null) checkClass(cl);
1083                     } catch(ClassNotFoundException ex) {
1084                         System.err.println(ex.toString() + " " + clName);
1085                     }
1086                 }
1087             }
1088         }
1089     }
1090 
1091     private static void recursiveCheck(File directory, int pathLength) {
1092         if (directory.isDirectory()) {
1093 //            System.out.println(directory.getPath());
1094             checkDirectory(directory, pathLength);
1095 
1096             for (File subFile : directory.listFiles()) {
1097                 recursiveCheck(subFile, pathLength);
1098             }
1099         }


< prev index next >