]> git.gag.com Git - debian/openrocket/blob - test/net/sf/openrocket/rocketcomponent/FinSetTest.java
updates for 0.9.4
[debian/openrocket] / test / net / sf / openrocket / rocketcomponent / FinSetTest.java
1 package net.sf.openrocket.rocketcomponent;
2
3 import static org.junit.Assert.*;
4
5 import java.awt.Color;
6
7 import net.sf.openrocket.material.Material;
8 import net.sf.openrocket.material.Material.Type;
9 import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
10 import net.sf.openrocket.rocketcomponent.FinSet.CrossSection;
11 import net.sf.openrocket.rocketcomponent.FinSet.TabRelativePosition;
12 import net.sf.openrocket.rocketcomponent.RocketComponent.Position;
13 import net.sf.openrocket.util.LineStyle;
14
15 import org.junit.Test;
16
17 public class FinSetTest {
18         
19         
20         @Test
21         public void testFreeformConvert() {
22                 testFreeformConvert(new TrapezoidFinSet());
23                 testFreeformConvert(new EllipticalFinSet());
24                 testFreeformConvert(new FreeformFinSet());
25         }
26         
27         
28         private void testFreeformConvert(FinSet fin) {
29                 FreeformFinSet converted;
30                 Material mat = Material.newMaterial(Type.BULK, "foo", 0.1, true);
31                 
32                 fin.setBaseRotation(1.1);
33                 fin.setCantAngle(0.001);
34                 fin.setCGOverridden(true);
35                 fin.setColor(Color.YELLOW);
36                 fin.setComment("cmt");
37                 fin.setCrossSection(CrossSection.ROUNDED);
38                 fin.setFinCount(5);
39                 fin.setFinish(Finish.ROUGH);
40                 fin.setLineStyle(LineStyle.DASHDOT);
41                 fin.setMassOverridden(true);
42                 fin.setMaterial(mat);
43                 fin.setOverrideCGX(0.012);
44                 fin.setOverrideMass(0.0123);
45                 fin.setOverrideSubcomponents(true);
46                 fin.setPositionValue(0.1);
47                 fin.setRelativePosition(Position.ABSOLUTE);
48                 fin.setTabHeight(0.01);
49                 fin.setTabLength(0.02);
50                 fin.setTabRelativePosition(TabRelativePosition.END);
51                 fin.setTabShift(0.015);
52                 fin.setThickness(0.005);
53
54                 converted = FreeformFinSet.convertFinSet(fin);
55                 
56                 ComponentCompare.assertSimilarity(fin, converted, true);
57                 
58                 assertEquals(converted.getComponentName(), converted.getName());
59                 
60                 
61                 // Create test rocket
62                 Rocket rocket = new Rocket();
63                 Stage stage = new Stage();
64                 BodyTube body = new BodyTube();
65                 
66                 rocket.addChild(stage);
67                 stage.addChild(body);
68                 body.addChild(fin);
69                 
70                 Listener l1 = new Listener("l1");
71                 rocket.addComponentChangeListener(l1);
72                 
73                 fin.setName("Custom name");
74                 assertTrue(l1.changed);
75                 assertEquals(ComponentChangeEvent.NONFUNCTIONAL_CHANGE, l1.changetype);
76                 
77                 
78                 // Create copy
79                 RocketComponent rocketcopy = rocket.copy();
80                 
81                 Listener l2 = new Listener("l2");
82                 rocketcopy.addComponentChangeListener(l2);
83                 
84                 FinSet fincopy = (FinSet) rocketcopy.getChild(0).getChild(0).getChild(0);
85                 FreeformFinSet.convertFinSet(fincopy);
86                 
87                 assertTrue(l2.changed);
88                 assertEquals(ComponentChangeEvent.TREE_CHANGE, 
89                                 l2.changetype & ComponentChangeEvent.TREE_CHANGE);
90                 
91         }
92         
93         
94         private static class Listener implements ComponentChangeListener {
95                 private boolean changed = false;
96                 private int changetype = 0;
97                 private final String name;
98                 
99                 public Listener(String name) {
100                         this.name = name;
101                 }
102                 
103                 @Override
104                 public void componentChanged(ComponentChangeEvent e) {
105                         assertFalse("Ensuring listener "+name+" has not been called.", changed);
106                         changed = true;
107                         changetype = e.getType();
108                 }
109         }
110
111 }