1 42 43 package org.jfree.chart.block.junit; 44 45 import java.io.ByteArrayInputStream ; 46 import java.io.ByteArrayOutputStream ; 47 import java.io.ObjectInput ; 48 import java.io.ObjectInputStream ; 49 import java.io.ObjectOutput ; 50 import java.io.ObjectOutputStream ; 51 52 import junit.framework.Test; 53 import junit.framework.TestCase; 54 import junit.framework.TestSuite; 55 56 import org.jfree.chart.block.Block; 57 import org.jfree.chart.block.BlockContainer; 58 import org.jfree.chart.block.EmptyBlock; 59 import org.jfree.chart.block.GridArrangement; 60 import org.jfree.chart.block.LengthConstraintType; 61 import org.jfree.chart.block.RectangleConstraint; 62 import org.jfree.ui.Size2D; 63 64 67 public class GridArrangementTests extends TestCase { 68 69 74 public static Test suite() { 75 return new TestSuite(GridArrangementTests.class); 76 } 77 78 83 public GridArrangementTests(String name) { 84 super(name); 85 } 86 87 90 public void testEquals() { 91 GridArrangement f1 = new GridArrangement(11, 22); 92 GridArrangement f2 = new GridArrangement(11, 22); 93 assertTrue(f1.equals(f2)); 94 assertTrue(f2.equals(f1)); 95 96 f1 = new GridArrangement(33, 22); 97 assertFalse(f1.equals(f2)); 98 f2 = new GridArrangement(33, 22); 99 assertTrue(f1.equals(f2)); 100 101 f1 = new GridArrangement(33, 44); 102 assertFalse(f1.equals(f2)); 103 f2 = new GridArrangement(33, 44); 104 assertTrue(f1.equals(f2)); 105 } 106 107 110 public void testCloning() { 111 GridArrangement f1 = new GridArrangement(1, 2); 112 assertFalse(f1 instanceof Cloneable ); 113 } 114 115 118 public void testSerialization() { 119 GridArrangement f1 = new GridArrangement(33, 44); 120 GridArrangement f2 = null; 121 try { 122 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 123 ObjectOutput out = new ObjectOutputStream (buffer); 124 out.writeObject(f1); 125 out.close(); 126 127 ObjectInput in = new ObjectInputStream ( 128 new ByteArrayInputStream (buffer.toByteArray()) 129 ); 130 f2 = (GridArrangement) in.readObject(); 131 in.close(); 132 } 133 catch (Exception e) { 134 e.printStackTrace(); 135 } 136 assertEquals(f1, f2); 137 } 138 139 private static final double EPSILON = 0.000000001; 140 141 144 public void testNN() { 145 BlockContainer c = createTestContainer1(); 146 Size2D s = c.arrange(null, RectangleConstraint.NONE); 147 assertEquals(90.0, s.width, EPSILON); 148 assertEquals(33.0, s.height, EPSILON); 149 } 150 151 154 public void testFN() { 155 BlockContainer c = createTestContainer1(); 156 RectangleConstraint constraint = new RectangleConstraint( 157 100.0, null, LengthConstraintType.FIXED, 158 0.0, null, LengthConstraintType.NONE 159 ); 160 Size2D s = c.arrange(null, constraint); 161 assertEquals(100.0, s.width, EPSILON); 162 assertEquals(33.0, s.height, EPSILON); 163 } 164 165 private BlockContainer createTestContainer1() { 166 Block b1 = new EmptyBlock(10, 11); 167 Block b2 = new EmptyBlock(20, 22); 168 Block b3 = new EmptyBlock(30, 33); 169 BlockContainer result = new BlockContainer(new GridArrangement(1, 3)); 170 result.add(b1); 171 result.add(b2); 172 result.add(b3); 173 return result; 174 } 175 176 } 177 | Popular Tags |