File: PathNodeTest.java

package info (click to toggle)
piccolo 1.2-1.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,668 kB
  • sloc: java: 16,496; xml: 259; sh: 18; makefile: 13
file content (50 lines) | stat: -rw-r--r-- 1,375 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

import junit.framework.TestCase;
import edu.umd.cs.piccolo.nodes.PPath;
import edu.umd.cs.piccolo.util.PBounds;
import edu.umd.cs.piccolo.util.PObjectOutputStream;

public class PathNodeTest extends TestCase {

	public PathNodeTest(String name) {
		super(name);
	}
	
	public void testCopy() {
		PPath p = PPath.createEllipse(0, 0, 100, 100);
		PBounds b = p.getBounds();
		p = (PPath) p.clone();
		assertEquals(p.getBounds(), b);
	}	
	
	public void testSaveToFile() {
		PPath p = PPath.createEllipse(0, 0, 100, 100);
		PBounds b = p.getBounds();
		try {
			File file = new File("myfile");
			FileOutputStream fout = new FileOutputStream(file);
			PObjectOutputStream out = new PObjectOutputStream(fout);
			out.writeObjectTree(p);
			out.flush();
			out.close();
			
			FileInputStream fin = new FileInputStream(file);
			ObjectInputStream in = new ObjectInputStream(fin);
			p = (PPath) in.readObject();
			assertEquals(p.getBounds(), b);
			file.delete();
		} catch (FileNotFoundException e) {
			assertTrue(false);
		} catch (ClassNotFoundException e) {
			assertTrue(false);
		} catch (IOException e) {
			assertTrue(false);
		}
	}
}