1 /* 2 * Copyright (c) 2011, 2013, 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.shape; 27 28 import com.sun.javafx.geom.Path2D; 29 import com.sun.javafx.pgstub.SVGPathImpl; 30 import com.sun.javafx.sg.prism.NGNode; 31 import com.sun.javafx.sg.prism.NGSVGPath; 32 import javafx.beans.property.SimpleStringProperty; 33 import javafx.beans.property.StringProperty; 34 import javafx.scene.NodeTest; 35 import org.junit.Test; 36 37 import static org.junit.Assert.*; 38 39 public class SVGPathTest { 40 41 @Test public void testBoundPropertySync_Content() throws Exception { 42 StubSVGPath svgPath = new StubSVGPath(); 43 svgPath.setContent("M40,60 C42,48 44,30 25,32"); 44 45 StringProperty content = new SimpleStringProperty(); 46 svgPath.contentProperty().bind(content); 47 String s = "M11,11 C22,22 33,33"; 48 content.set(s); 49 NodeTest.syncNode(svgPath); 50 51 SVGPathImpl geometry = ((StubNGSVGPath) svgPath.impl_getPeer()).geometry; 52 assertEquals(s, geometry.getContent()); 53 } 54 55 @Test 56 public void testDefaultValues() { 57 StubSVGPath svgPath = new StubSVGPath(); 58 assertEquals("", svgPath.getContent()); 59 assertEquals("", svgPath.contentProperty().get()); 60 assertEquals(FillRule.NON_ZERO, svgPath.getFillRule()); 61 assertEquals(FillRule.NON_ZERO, svgPath.fillRuleProperty().get()); 62 } 63 64 @Test public void testFillRuleSync() { 65 StubSVGPath svgPath = new StubSVGPath(); 66 svgPath.setContent("M40,60 C42,48 44,30 25,32"); 67 svgPath.setFillRule(FillRule.EVEN_ODD); 68 StubNGSVGPath peer = svgPath.impl_getPeer(); 69 peer.setAcceptsPath2dOnUpdate(true); 70 71 NodeTest.syncNode(svgPath); 72 Path2D path = peer.path; 73 assertEquals(Path2D.WIND_EVEN_ODD, path.getWindingRule()); 74 75 svgPath.setFillRule(FillRule.NON_ZERO); 76 NodeTest.syncNode(svgPath); 77 // internal shape might have changed, getting it again 78 path = peer.path; 79 assertEquals(Path2D.WIND_NON_ZERO, path.getWindingRule()); 80 } 81 82 @Test public void toStringShouldReturnNonEmptyString() { 83 String s = new StubSVGPath().toString(); 84 assertNotNull(s); 85 assertFalse(s.isEmpty()); 86 } 87 88 private class StubSVGPath extends SVGPath { 89 @Override 90 protected NGNode impl_createPeer() { 91 return new StubNGSVGPath(); 92 } 93 } 94 95 private class StubNGSVGPath extends NGSVGPath { 96 private SVGPathImpl geometry; 97 private Path2D path; 98 private boolean acceptsPath2dOnUpdate = false; 99 100 @Override 101 public void setContent(Object content) { 102 if (acceptsPath2dOnUpdate) { 103 path = (Path2D) content; 104 } else { 105 geometry = (SVGPathImpl) content; 106 } 107 } 108 109 public void setAcceptsPath2dOnUpdate(boolean acceptsPath2dOnUpdate) { 110 this.acceptsPath2dOnUpdate = acceptsPath2dOnUpdate; 111 } 112 113 @Override 114 public boolean acceptsPath2dOnUpdate() { 115 return acceptsPath2dOnUpdate; 116 } 117 } 118 }