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.css;
27
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertFalse;
30 import static org.junit.Assert.assertTrue;
31
32 import com.sun.javafx.css.ParsedValueImpl;
33 import javafx.css.StyleConverter.StringStore;
34 import javafx.css.converter.SizeConverter;
35
36 import javafx.scene.text.Font;
37
38 import org.junit.Test;
39
40 import java.io.ByteArrayInputStream;
41 import java.io.ByteArrayOutputStream;
42 import java.io.DataInputStream;
43 import java.io.DataOutputStream;
44 import java.io.IOException;
45
46 public class ParsedValueTest {
47
48 public ParsedValueTest() {
49 }
50
51 /**
52 * Test of getValue method, of class ParsedValue.
53 */
54 @Test
55 public void testGetValue() {
56 //System.out.println("getValue");
57 ParsedValue<Size,Size> instance =
58 new ParsedValueImpl<Size,Size>(new Size(100.0, SizeUnits.PERCENT), null);
59 Size expResult = new Size(100.0, SizeUnits.PERCENT);;
60 Size result = instance.getValue();
61 assertEquals(expResult, result);
62 }
63
64 /**
473 },
474 null
475 }, null
476 );
477
478 writeBinary(parsedValue);
479
480 }
481
482 private void writeAndReadBinary(ParsedValueImpl<?,?> parsedValue) {
483
484 try {
485 StringStore stringStore = new StringStore();
486 ByteArrayOutputStream baos = new ByteArrayOutputStream();
487 DataOutputStream dos = new DataOutputStream(baos);
488 parsedValue.writeBinary(dos, stringStore);
489 dos.close();
490 String[] strings = stringStore.strings.toArray(new String[]{});
491 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
492 DataInputStream dis = new DataInputStream(bais);
493 ParsedValue<?,?> pv = ParsedValueImpl.readBinary(Stylesheet.BINARY_CSS_VERSION, dis, strings);
494 org.junit.Assert.assertEquals(parsedValue, pv);
495 } catch (IOException ioe) {
496 System.err.println(ioe);
497 org.junit.Assert.fail(parsedValue.toString());
498 }
499
500 }
501 /**
502 * Test of readBinary method, of class ParsedValueImpl.
503 */
504 @Test
505 public void testReadBinary() throws Exception {
506 Font font = Font.getDefault();
507 Size size = new Size(1.0, SizeUnits.EM);
508
509 ParsedValueImpl parsedValue =
510 new ParsedValueImpl<ParsedValue<?,Size>,Number>(
511 new ParsedValueImpl<Size,Size>(new Size(1.0, SizeUnits.EM), null),
512 SizeConverter.getInstance());
513
|
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.css;
27
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertFalse;
30 import static org.junit.Assert.assertTrue;
31
32 import com.sun.javafx.css.ParsedValueImpl;
33 import javafx.css.StylesheetShim;
34 import javafx.css.StyleConverter.StringStore;
35 import javafx.css.converter.SizeConverter;
36
37 import javafx.scene.text.Font;
38
39 import org.junit.Test;
40
41 import java.io.ByteArrayInputStream;
42 import java.io.ByteArrayOutputStream;
43 import java.io.DataInputStream;
44 import java.io.DataOutputStream;
45 import java.io.IOException;
46 import javafx.css.ParsedValue;
47 import javafx.css.Size;
48 import javafx.css.SizeUnits;
49 import javafx.css.StylesheetShim;
50
51 public class ParsedValueTest {
52
53 public ParsedValueTest() {
54 }
55
56 /**
57 * Test of getValue method, of class ParsedValue.
58 */
59 @Test
60 public void testGetValue() {
61 //System.out.println("getValue");
62 ParsedValue<Size,Size> instance =
63 new ParsedValueImpl<Size,Size>(new Size(100.0, SizeUnits.PERCENT), null);
64 Size expResult = new Size(100.0, SizeUnits.PERCENT);;
65 Size result = instance.getValue();
66 assertEquals(expResult, result);
67 }
68
69 /**
478 },
479 null
480 }, null
481 );
482
483 writeBinary(parsedValue);
484
485 }
486
487 private void writeAndReadBinary(ParsedValueImpl<?,?> parsedValue) {
488
489 try {
490 StringStore stringStore = new StringStore();
491 ByteArrayOutputStream baos = new ByteArrayOutputStream();
492 DataOutputStream dos = new DataOutputStream(baos);
493 parsedValue.writeBinary(dos, stringStore);
494 dos.close();
495 String[] strings = stringStore.strings.toArray(new String[]{});
496 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
497 DataInputStream dis = new DataInputStream(bais);
498 ParsedValue<?,?> pv = ParsedValueImpl.readBinary(StylesheetShim.BINARY_CSS_VERSION, dis, strings);
499 org.junit.Assert.assertEquals(parsedValue, pv);
500 } catch (IOException ioe) {
501 System.err.println(ioe);
502 org.junit.Assert.fail(parsedValue.toString());
503 }
504
505 }
506 /**
507 * Test of readBinary method, of class ParsedValueImpl.
508 */
509 @Test
510 public void testReadBinary() throws Exception {
511 Font font = Font.getDefault();
512 Size size = new Size(1.0, SizeUnits.EM);
513
514 ParsedValueImpl parsedValue =
515 new ParsedValueImpl<ParsedValue<?,Size>,Number>(
516 new ParsedValueImpl<Size,Size>(new Size(1.0, SizeUnits.EM), null),
517 SizeConverter.getInstance());
518
|