modules/graphics/src/test/java/test/javafx/scene/Parent_structure_sync_Test.java

Print this page




  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.pgstub.StubToolkit;
  29 import com.sun.javafx.sg.prism.NGGroup;
  30 import com.sun.javafx.tk.Toolkit;
  31 import java.util.List;
  32 import javafx.scene.Group;
  33 import javafx.scene.Parent;
  34 import javafx.scene.ParentShim;
  35 import javafx.scene.Scene;

  36 import javafx.scene.shape.Rectangle;
  37 import javafx.stage.Stage;
  38 import org.junit.Before;
  39 import org.junit.Test;
  40 
  41 import static org.junit.Assert.*;
  42 
  43 /**
  44  * Tests to make sure the synchronization of children between a Parent and PGGroup
  45  * works as expected.
  46  */
  47 public class Parent_structure_sync_Test {
  48     private Rectangle r1, r2, r3, r4, r5;
  49     private Parent parent;
  50     private NGGroup peer;
  51     
  52     @Before public void setup() {
  53         parent = new Group();
  54         r1 = new Rectangle(0, 0, 10, 10);
  55         r2 = new Rectangle(0, 0, 10, 10);


 321         assertSame(r3.impl_getPeer(), peer.getChildren().get(2));
 322     }
 323 
 324     @Test
 325     public void validateParentsRemovedList() {
 326         Group parent2 = new Group();
 327         ParentShim.getChildren(parent2).addAll(r1, r2);
 328         ParentShim.getChildren(parent).add(parent2);
 329         sync();
 330         ParentShim.getChildren(parent2).remove(r1);
 331         assertNotNull(ParentShim.test_getRemoved(parent2));
 332         assertFalse(ParentShim.test_getRemoved(parent2).isEmpty());
 333         sync();
 334         assertTrue(ParentShim.test_getRemoved(parent2).isEmpty());
 335         ParentShim.getChildren(parent2).remove(r2);
 336         parent.setVisible(false);
 337         assertFalse(ParentShim.test_getRemoved(parent2).isEmpty());
 338         sync();
 339         assertTrue(ParentShim.test_getRemoved(parent2).isEmpty());
 340     }































 341 }


  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.pgstub.StubToolkit;
  29 import com.sun.javafx.sg.prism.NGGroup;
  30 import com.sun.javafx.tk.Toolkit;
  31 import java.util.List;
  32 import javafx.scene.Group;
  33 import javafx.scene.Parent;
  34 import javafx.scene.ParentShim;
  35 import javafx.scene.Scene;
  36 import javafx.scene.layout.BorderPane;
  37 import javafx.scene.shape.Rectangle;
  38 import javafx.stage.Stage;
  39 import org.junit.Before;
  40 import org.junit.Test;
  41 
  42 import static org.junit.Assert.*;
  43 
  44 /**
  45  * Tests to make sure the synchronization of children between a Parent and PGGroup
  46  * works as expected.
  47  */
  48 public class Parent_structure_sync_Test {
  49     private Rectangle r1, r2, r3, r4, r5;
  50     private Parent parent;
  51     private NGGroup peer;
  52     
  53     @Before public void setup() {
  54         parent = new Group();
  55         r1 = new Rectangle(0, 0, 10, 10);
  56         r2 = new Rectangle(0, 0, 10, 10);


 322         assertSame(r3.impl_getPeer(), peer.getChildren().get(2));
 323     }
 324 
 325     @Test
 326     public void validateParentsRemovedList() {
 327         Group parent2 = new Group();
 328         ParentShim.getChildren(parent2).addAll(r1, r2);
 329         ParentShim.getChildren(parent).add(parent2);
 330         sync();
 331         ParentShim.getChildren(parent2).remove(r1);
 332         assertNotNull(ParentShim.test_getRemoved(parent2));
 333         assertFalse(ParentShim.test_getRemoved(parent2).isEmpty());
 334         sync();
 335         assertTrue(ParentShim.test_getRemoved(parent2).isEmpty());
 336         ParentShim.getChildren(parent2).remove(r2);
 337         parent.setVisible(false);
 338         assertFalse(ParentShim.test_getRemoved(parent2).isEmpty());
 339         sync();
 340         assertTrue(ParentShim.test_getRemoved(parent2).isEmpty());
 341     }
 342 
 343     @Test
 344     public void validateParentsRemovedList2() {
 345         BorderPane borderPane = new BorderPane(r1);
 346         Group parent2 = new Group();
 347         ParentShim.getChildren(parent2).addAll(r2);
 348         ParentShim.getChildren(parent).add(parent2);
 349         sync();
 350         ParentShim.getChildren(parent2).remove(r2);
 351         borderPane.setCenter(null);
 352         assertNotNull(ParentShim.test_getRemoved(parent2));
 353         assertFalse(ParentShim.test_getRemoved(parent2).isEmpty());
 354         assertNotNull(ParentShim.test_getRemoved(borderPane));
 355         assertTrue(ParentShim.test_getRemoved(borderPane).isEmpty());
 356         sync();
 357         assertTrue(ParentShim.test_getRemoved(parent2).isEmpty());
 358         assertTrue(ParentShim.test_getRemoved(borderPane).isEmpty());        
 359     }
 360 
 361     @Test
 362     public void validateParentsRemovedList3() {
 363         BorderPane borderPane = new BorderPane(r1);
 364         parent.getScene().setRoot(borderPane);
 365         sync();
 366         borderPane.getScene().setRoot(parent);
 367         borderPane.setCenter(null);
 368         assertNotNull(ParentShim.test_getRemoved(borderPane));
 369         assertTrue(ParentShim.test_getRemoved(borderPane).isEmpty());
 370         sync();
 371         assertTrue(ParentShim.test_getRemoved(borderPane).isEmpty());
 372     }
 373 }