1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.files.ccsds.utils.generation;
18
19 import org.hipparchus.util.FastMath;
20 import org.junit.jupiter.api.Assertions;
21 import org.junit.jupiter.api.Test;
22 import org.orekit.utils.Constants;
23 import org.orekit.utils.units.Unit;
24
25 import java.io.CharArrayWriter;
26 import java.io.IOException;
27
28 public class KvnGeneratorTest {
29
30 @Test
31 public void testSection() throws IOException {
32 CharArrayWriter caw = new CharArrayWriter();
33 try (Generator generator = new KvnGenerator(caw, 10, "", Constants.JULIAN_DAY, 25)) {
34 generator.startMessage("abc", "CCSDS_ABC_VERSION", 99.0);
35 generator.enterSection("BLOCK");
36 generator.writeEntry("KEY", 1234567.8, Unit.parse("Hz"), false);
37 generator.exitSection();
38 generator.endMessage("abc");
39 Assertions.assertEquals("CCSDS_ABC_VERSION = 99.0\n" +
40 "BLOCK_START\n" +
41 "KEY = 1234567.8 [Hz]\n" +
42 "BLOCK_STOP\n",
43 caw.toString());
44 }
45 }
46
47 @Test
48 public void testCcsdsUnits() throws IOException {
49 CharArrayWriter caw = new CharArrayWriter();
50 try (Generator generator = new KvnGenerator(caw, 10, "", Constants.JULIAN_DAY, 25)) {
51 generator.writeEntry("KEY_1", 1234567.8, Unit.parse("km.kg³/√s"), false);
52 generator.writeEntry("KEY_2", 1234567.8, Unit.parse("n/a"), false);
53 generator.writeEntry("KEY_3", 1234567.8, Unit.parse("1"), false);
54 generator.writeEntry("LOOOOONG", "1234567.8", null, false);
55 Assertions.assertEquals("KEY_1 = 1234.5678 [km*kg**3/s**0.5]\n" +
56 "KEY_2 = 1234567.8\n" +
57 "KEY_3 = 1234567.8\n" +
58 "LOOOOONG = 1234567.8\n",
59 caw.toString());
60 }
61 }
62
63 @Test
64 public void testUnitsPadding() throws IOException {
65 CharArrayWriter caw = new CharArrayWriter();
66 try (Generator generator = new KvnGenerator(caw, 10, "", Constants.JULIAN_DAY, 20)) {
67 generator.writeEntry("KEY_1", 0.5 * FastMath.PI, Unit.parse("°"), false);
68 generator.writeEntry("KEY_2", FastMath.PI, Unit.parse("◦"), false);
69 generator.writeEntry("PERCENT", 0.25, Unit.parse("%"), false);
70 Assertions.assertEquals("KEY_1 = 90.0 [deg]\n" +
71 "KEY_2 = 180.0 [deg]\n" +
72 "PERCENT = 25.0 [%]\n",
73 caw.toString());
74 }
75 }
76
77 @Test
78 public void testNoUnits() throws IOException {
79 CharArrayWriter caw = new CharArrayWriter();
80 try (Generator generator = new KvnGenerator(caw, 10, "", Constants.JULIAN_DAY, 0)) {
81 generator.writeEntry("KEY_1", 0.5 * FastMath.PI, Unit.parse("°"), false);
82 generator.writeEntry("KEY_2", FastMath.PI, Unit.parse("◦"), true);
83 Assertions.assertEquals("KEY_1 = 90.0\n" +
84 "KEY_2 = 180.0\n", caw.toString());
85 }
86 }
87
88 }