1 /*
   2  * Copyright (c) 2013, 2014, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.javafx.scene;
  27 
  28 import test.com.sun.javafx.test.NodeOrientationTestBase;
  29 import java.util.Arrays;
  30 import java.util.Collection;
  31 import javafx.scene.Node;
  32 import javafx.scene.NodeShim;
  33 import javafx.scene.Scene;
  34 import org.junit.Assert;
  35 import org.junit.Test;
  36 import org.junit.runner.RunWith;
  37 import org.junit.runners.Parameterized;
  38 import org.junit.runners.Parameterized.Parameters;
  39 
  40 @RunWith(Parameterized.class)
  41 public final class Node_hasMirroring_Test extends NodeOrientationTestBase {
  42     private final Scene testScene;
  43     private final String orientationUpdate;
  44     private final String expectedMirroring;
  45 
  46     private static Scene lriiliScene() {
  47         return ltrScene(
  48                    rtlAutGroup(
  49                        inhAutGroup(
  50                            inhAutGroup(
  51                                ltrAutGroup(
  52                                    inhAutGroup())))));
  53     }
  54 
  55     private static Scene lriiliWithSubSceneScene() {
  56         return ltrScene(
  57                    rtlAutGroup(
  58                        inhSubScene(
  59                            inhAutGroup(
  60                                ltrAutGroup(
  61                                    inhAutGroup())))));
  62     }
  63 
  64 
  65     private static Scene lrIiliScene() {
  66         return ltrScene(
  67                    rtlAutGroup(
  68                        inhManGroup(
  69                            inhAutGroup(
  70                                ltrAutGroup(
  71                                    inhAutGroup())))));
  72     }
  73 
  74     private static Scene lrLRlrScene() {
  75         return ltrScene(
  76                    rtlAutGroup(
  77                        ltrManGroup(
  78                            rtlManGroup(
  79                                ltrAutGroup(
  80                                    rtlAutGroup())))));
  81     }
  82 
  83     private static Scene lrIiilScene() {
  84         return ltrScene(
  85                    rtlAutGroup(
  86                        inhManGroup(
  87                            inhAutGroup(
  88                                inhAutGroup(
  89                                    ltrAutGroup())))));
  90     }
  91 
  92     /*
  93      * Parameters: [testScene], [orientationUpdate], [expectedMirroring]
  94      */
  95     @Parameters
  96     public static Collection data() {
  97         return Arrays.asList(
  98                 new Object[][] {
  99                         { lriiliScene(), "......", ".M..M." }, // LRRRLL
 100                         { lriiliScene(), ".I....", "......" }, // LLLLLL
 101                         { lriiliScene(), "...L..", ".M.M.." }, // LRRLLL
 102                         { lriiliScene(), "....I.", ".M...." }, // LRRRRR
 103                         { lriiliScene(), "RIIIII", ".M...." }, // RRRRRR
 104 
 105                         {
 106                             lriiliWithSubSceneScene(),
 107                             "......", ".M..M."
 108                         },
 109 
 110                         /* effective: LRRRLL, automatic: LRLLLL */
 111                         { lrIiliScene(), "......", ".MMMM." },
 112                         /* effective: LRLRLR, automatic: LRLLLR */
 113                         { lrLRlrScene(), "......", ".MM..M" },
 114 
 115                         /* effective: LRRRRL, automatic: LRLRRL */
 116                         { lrIiilScene(), "...R..", ".MMM.M" },
 117                     });
 118     }
 119 
 120     public Node_hasMirroring_Test(
 121             final Scene testScene,
 122             final String orientationUpdate,
 123             final String expectedMirroring) {
 124         this.testScene = testScene;
 125         this.orientationUpdate = orientationUpdate;
 126         this.expectedMirroring = expectedMirroring;
 127     }
 128 
 129     @Test
 130     public void hasMirroringTest() {
 131         updateOrientation(testScene, orientationUpdate);
 132         assertMirroring(testScene, expectedMirroring);
 133     }
 134 
 135     private static void assertMirroring(
 136             final Scene scene,
 137             final String expectedMirroring) {
 138         final String actualMirroring = collectMirroring(scene);
 139         Assert.assertEquals("Mirroring mismatch",
 140                             expectedMirroring, actualMirroring);
 141     }
 142 
 143     private static final StateEncoder HAS_MIRRORING_ENCODER =
 144             new StateEncoder() {
 145                 @Override
 146                 public char map(final Scene scene) {
 147                     // no mirroring on scene
 148                     return map(false);
 149                 }
 150 
 151                 @Override
 152                 public char map(final Node node) {
 153                     return map(NodeShim.hasMirroring(node));
 154                 }
 155 
 156                 private char map(final boolean hasMirroring) {
 157                     return hasMirroring ? 'M' : '.';
 158                 }
 159             };
 160 
 161     private static String collectMirroring(final Scene scene) {
 162         return collectState(scene, HAS_MIRRORING_ENCODER);
 163     }
 164 }