1 package nom.tam.fits.test;
4 import static org.junit.Assert.assertTrue;
5 import static org.junit.Assert.assertEquals;
6 import static org.junit.Assert.assertNull;
7 import junit.framework.JUnit4TestAdapter;
8 import nom.tam.fits.HeaderCard;
9 import nom.tam.fits.FitsFactory;
11 public class HeaderCardTest {
14 public void test1() throws Exception {
17 p = new HeaderCard("SIMPLE = T");
19 assertEquals("t1", "SIMPLE", p.getKey());
20 assertEquals("t2", "T", p.getValue());
21 assertNull("t3", p.getComment());
23 p = new HeaderCard("VALUE = 123");
24 assertEquals("t4", "VALUE", p.getKey());
25 assertEquals("t5", "123", p.getValue());
26 assertNull("t3", p.getComment());
28 p = new HeaderCard("VALUE = 1.23698789798798E23 / Comment ");
29 assertEquals("t6", "VALUE", p.getKey());
30 assertEquals("t7", "1.23698789798798E23", p.getValue());
31 assertEquals("t8", "Comment", p.getComment());
33 String lng = "111111111111111111111111111111111111111111111111111111111111111111111111";
34 p = new HeaderCard("COMMENT " + lng);
35 assertEquals("t9", "COMMENT", p.getKey());
36 assertNull("t10", p.getValue());
37 assertEquals("t11", lng, p.getComment());
39 boolean thrown = false;
42 p = new HeaderCard("VALUE = ' ");
43 } catch (Exception e) {
46 assertEquals("t12", true, thrown);
49 p = new HeaderCard("COMMENT " + lng + lng);
50 assertEquals("t13", lng, p.getComment());
52 HeaderCard z = new HeaderCard("TTTT", 1.234567891234567891234567e101, "a comment");
53 assertTrue("t14", z.toString().indexOf("E") > 0);
57 public void test3() throws Exception {
59 HeaderCard p = new HeaderCard("KEY", "VALUE", "COMMENT");
61 "KEY = 'VALUE ' / COMMENT ",
64 p = new HeaderCard("KEY", 123, "COMMENT");
66 "KEY = 123 / COMMENT ",
68 p = new HeaderCard("KEY", 1.23, "COMMENT");
70 "KEY = 1.23 / COMMENT ",
72 p = new HeaderCard("KEY", true, "COMMENT");
78 boolean thrown = false;
80 p = new HeaderCard("LONGKEYWORD", 123, "COMMENT");
81 } catch (Exception e) {
84 assertEquals("x5", true, thrown);
87 String lng = "00000000001111111111222222222233333333334444444444555555555566666666667777777777";
89 p = new HeaderCard("KEY", lng, "COMMENT");
90 } catch (Exception e) {
93 assertEquals("x6", true, thrown);
96 // Only trailing spaces are stripped.
97 p = new HeaderCard("STRING", "VALUE", null);
98 assertEquals("x6", "VALUE", p.getValue());
100 p = new HeaderCard("STRING", "VALUE ", null);
101 assertEquals("x7", "VALUE", p.getValue());
103 p = new HeaderCard("STRING", " VALUE", null);
104 assertEquals("x8", " VALUE", p.getValue());
106 p = new HeaderCard("STRING", " VALUE ", null);
107 assertEquals("x9", " VALUE", p.getValue());
109 p = new HeaderCard("QUOTES", "ABC'DEF", null);
110 assertEquals("x10", "ABC'DEF", p.getValue());
111 assertEquals("x10b", p.toString().indexOf("''") > 0, true);
113 p = new HeaderCard("QUOTES", "ABC''DEF", null);
114 assertEquals("x11", "ABC''DEF", p.getValue());
115 assertEquals("x10b", p.toString().indexOf("''''") > 0, true);
119 public void testHierarch() throws Exception {
122 String key = "HIERARCH.TEST1.TEST2.INT";
123 boolean thrown = false;
125 hc = new HeaderCard(key, 123, "Comment");
126 } catch (Exception e) {
129 assertEquals("h1", true, thrown);
131 String card = "HIERARCH TEST1 TEST2 INT= 123 / Comment ";
132 hc = new HeaderCard(card);
133 assertEquals("h2", "HIERARCH", hc.getKey());
134 assertNull("h3", hc.getValue());
135 assertEquals("h4", "TEST1 TEST2 INT= 123 / Comment", hc.getComment());
137 FitsFactory.setUseHierarch(true);
139 hc = new HeaderCard(key, 123, "Comment");
141 assertEquals("h5", key, hc.getKey());
142 assertEquals("h6", "123", hc.getValue());
143 assertEquals("h7", "Comment", hc.getComment());
145 hc = new HeaderCard(card);
146 assertEquals("h8", key, hc.getKey());
147 assertEquals("h9", "123", hc.getValue());
148 assertEquals("h10", "Comment", hc.getComment());
152 public void testLongDoubles() throws Exception {
153 // Check to see if we make long double values
154 // fit in the recommended space.
155 HeaderCard hc = new HeaderCard("TEST", -1.234567890123456789e-123, "dummy");
156 String val = hc.getValue();
157 assertEquals("tld1", val.length(), 20);