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 javafx.scene;
  27 
  28 import com.sun.javafx.test.NodeOrientationTestBase;
  29 import java.util.Arrays;
  30 import java.util.Collection;
  31 import org.junit.Assert;
  32 import org.junit.Test;
  33 import org.junit.runner.RunWith;
  34 import org.junit.runners.Parameterized;
  35 import org.junit.runners.Parameterized.Parameters;
  36 
  37 @RunWith(Parameterized.class)
  38 public final class Node_hasMirroring_Test extends NodeOrientationTestBase {
  39     private final Scene testScene;
  40     private final String orientationUpdate;
  41     private final String expectedMirroring;
  42 
  43     private static Scene lriiliScene() {
  44         return ltrScene(
  45                    rtlAutGroup(
  46                        inhAutGroup(
  47                            inhAutGroup(
  48                                ltrAutGroup(
  49                                    inhAutGroup())))));
  50     }
  51 
  52     private static Scene lriiliWithSubSceneScene() {
  53         return ltrScene(
  54                    rtlAutGroup(
  55                        inhSubScene(
  56                            inhAutGroup(
  57                                ltrAutGroup(
  58                                    inhAutGroup())))));
  59     }
  60 
  61 
  62     private static Scene lrIiliScene() {
  63         return ltrScene(
  64                    rtlAutGroup(
  65                        inhManGroup(
  66                            inhAutGroup(
  67                                ltrAutGroup(
  68                                    inhAutGroup())))));
  69     }
  70 
  71     private static Scene lrLRlrScene() {
  72         return ltrScene(
  73                    rtlAutGroup(
  74                        ltrManGroup(
  75                            rtlManGroup(
  76                                ltrAutGroup(
  77                                    rtlAutGroup())))));
  78     }
  79 
  80     private static Scene lrIiilScene() {
  81         return ltrScene(
  82                    rtlAutGroup(
  83                        inhManGroup(
  84                            inhAutGroup(
  85                                inhAutGroup(
  86                                    ltrAutGroup())))));
  87     }
  88 
  89     /*
  90      * Parameters: [testScene], [orientationUpdate], [expectedMirroring]
  91      */
  92     @Parameters
  93     public static Collection data() {
  94         return Arrays.asList(
  95                 new Object[][] {
  96                         { lriiliScene(), "......", ".M..M." }, // LRRRLL
  97                         { lriiliScene(), ".I....", "......" }, // LLLLLL
  98                         { lriiliScene(), "...L..", ".M.M.." }, // LRRLLL
  99                         { lriiliScene(), "....I.", ".M...." }, // LRRRRR
 100                         { lriiliScene(), "RIIIII", ".M...." }, // RRRRRR
 101 
 102                         {
 103                             lriiliWithSubSceneScene(),
 104                             "......", ".M..M."
 105                         },
 106 
 107                         /* effective: LRRRLL, automatic: LRLLLL */
 108                         { lrIiliScene(), "......", ".MMMM." },
 109                         /* effective: LRLRLR, automatic: LRLLLR */
 110                         { lrLRlrScene(), "......", ".MM..M" },
 111 
 112                         /* effective: LRRRRL, automatic: LRLRRL */
 113                         { lrIiilScene(), "...R..", ".MMM.M" },
 114                     });
 115     }
 116 
 117     public Node_hasMirroring_Test(
 118             final Scene testScene,
 119             final String orientationUpdate,
 120             final String expectedMirroring) {
 121         this.testScene = testScene;
 122         this.orientationUpdate = orientationUpdate;
 123         this.expectedMirroring = expectedMirroring;
 124     }
 125 
 126     @Test
 127     public void hasMirroringTest() {
 128         updateOrientation(testScene, orientationUpdate);
 129         assertMirroring(testScene, expectedMirroring);
 130     }
 131 
 132     private static void assertMirroring(
 133             final Scene scene,
 134             final String expectedMirroring) {
 135         final String actualMirroring = collectMirroring(scene);
 136         Assert.assertEquals("Mirroring mismatch",
 137                             expectedMirroring, actualMirroring);
 138     }
 139 
 140     private static final StateEncoder HAS_MIRRORING_ENCODER =
 141             new StateEncoder() {
 142                 @Override
 143                 public char map(final Scene scene) {
 144                     // no mirroring on scene
 145                     return map(false);
 146                 }
 147 
 148                 @Override
 149                 public char map(final Node node) {
 150                     return map(node.hasMirroring());
 151                 }
 152 
 153                 private char map(final boolean hasMirroring) {
 154                     return hasMirroring ? 'M' : '.';
 155                 }
 156             };
 157 
 158     private static String collectMirroring(final Scene scene) {
 159         return collectState(scene, HAS_MIRRORING_ENCODER);
 160     }
 161 }