1
2
3
4
5
6
7 package org.sourceforge.jvb3d.Model;
8
9 import java.awt.GraphicsConfiguration;
10 import java.io.ByteArrayInputStream;
11 import java.io.ByteArrayOutputStream;
12 import java.io.ObjectInputStream;
13 import java.io.ObjectOutputStream;
14
15 import javax.media.j3d.Canvas3D;
16
17 import com.sun.j3d.utils.universe.SimpleUniverse;
18
19 import junit.framework.TestCase;
20
21 /***
22 * @author serwis
23 *
24 * TODO To change the template for this generated type comment go to
25 * Window - Preferences - Java - Code Style - Code Templates
26 */
27 public class ModelTest extends TestCase {
28
29 Model m1,m2;
30
31
32
33 protected void setUp() throws Exception {
34 super.setUp();
35 GraphicsConfiguration config =
36 SimpleUniverse.getPreferredConfiguration();
37
38 Canvas3D canvas3D = new Canvas3D(config);
39 Canvas3D canvas3D2 = new Canvas3D(config);
40 m1=new Model(canvas3D,false);
41 m1.createLocalPlayer("test");
42 m2=new Model(canvas3D2,false);
43 m2.createLocalPlayer("test");
44 }
45
46
47
48
49 protected void tearDown() throws Exception {
50 super.tearDown();
51 }
52
53 /***
54 * Constructor for ModelTest.
55 * @param arg0
56 */
57 public ModelTest(String arg0) {
58 super(arg0);
59 }
60 public void testCreateRemove(){
61 String id=m1.createPlayer();
62 assertTrue("niepoprawne id pierwszego obiektu: "+id,id.equalsIgnoreCase("0"));
63 id=m1.createPlayer();
64 assertTrue("niepoprawne id drugiego obiektu: "+id,id.equalsIgnoreCase("1"));
65 m1.removeObject("1");
66 m1.removeObject("0");
67 id=m1.createPlayer();
68 assertTrue("niepoprawne id trzeciego obiektu: "+id,id.equalsIgnoreCase("2"));
69 }
70 public void testExternalizable() throws Exception{
71 m1.createPlayer();
72 m1.moveLeftRight(10f);
73 m1.nextTurn(1000);
74 m1.setSerializeAll();
75 ByteArrayOutputStream bao = new ByteArrayOutputStream();
76 ObjectOutputStream out= new ObjectOutputStream(bao);
77 m1.writeExternal(out);
78 out.close();
79 byte[] buf=bao.toByteArray();
80 ByteArrayInputStream bai = new ByteArrayInputStream(buf);
81 ObjectInputStream in = new ObjectInputStream(bai);
82 m2.readExternal(in);
83 String id=m2.createPlayer();
84 assertTrue("Z³y identyfikator po stworzeniu obiektu po deserializacji: "+id,id.equals("1"));
85 }
86 }