1   /* Copyright 2002-2022 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.time;
18  
19  import java.io.ByteArrayInputStream;
20  import java.io.ByteArrayOutputStream;
21  import java.io.IOException;
22  import java.io.ObjectInputStream;
23  import java.io.ObjectOutputStream;
24  
25  import org.junit.Assert;
26  import org.junit.Before;
27  import org.junit.Test;
28  import org.orekit.Utils;
29  
30  public class GLONASSDateTest {
31  
32      private TimeScale glo;
33  
34      @Before
35      public void setUp() {
36          Utils.setDataRoot("regular-data");
37          glo = TimeScalesFactory.getGLONASS();
38      }
39  
40      @Test
41      public void testFromNaAndN4() {
42          GLONASSDate date = new GLONASSDate(251, 5, 7200.0);
43          AbsoluteDate ref  = new AbsoluteDate(new DateComponents(2012, 9, 7),
44                                               new TimeComponents(2, 0, 0.0),
45                                               glo);
46          Assert.assertEquals(251, date.getDayNumber());
47          Assert.assertEquals(5,   date.getIntervalNumber());
48          Assert.assertEquals(2456177.5, date.getJD0(), 1.0e-16);
49          Assert.assertEquals(29191.442830, date.getGMST(), 3.0e-3);
50          Assert.assertEquals(0,   date.getDate().durationFrom(ref), 1.0e-15);
51      }
52  
53      @Test
54      public void testFromAbsoluteDate() {
55          GLONASSDate date = new GLONASSDate(new AbsoluteDate(new DateComponents(2012, 9, 7),
56                                                              new TimeComponents(2, 0, 0.0),
57                                                              glo));
58          Assert.assertEquals(251,    date.getDayNumber());
59          Assert.assertEquals(5,      date.getIntervalNumber());
60          Assert.assertEquals(2456177.5, date.getJD0(), 1.0e-16);
61          Assert.assertEquals(29191.442830, date.getGMST(), 3.0e-3);
62          Assert.assertEquals(7200.0, date.getSecInDay(), 1.0e-15);
63      }
64  
65      @Test
66      public void testSerialization() throws IOException, ClassNotFoundException {
67          GLONASSDate date = new GLONASSDate(251, 5, 7200.0);
68  
69          ByteArrayOutputStream bos = new ByteArrayOutputStream();
70          ObjectOutputStream    oos = new ObjectOutputStream(bos);
71          oos.writeObject(date);
72  
73          Assert.assertTrue(bos.size() > 95);
74          Assert.assertTrue(bos.size() < 105);
75  
76          ByteArrayInputStream  bis = new ByteArrayInputStream(bos.toByteArray());
77          ObjectInputStream     ois = new ObjectInputStream(bis);
78          GLONASSDate deserialized  = (GLONASSDate) ois.readObject();
79          AbsoluteDate ref  = new AbsoluteDate(new DateComponents(2012, 9, 7),
80                                               new TimeComponents(2, 0, 0),
81                                               glo);
82          Assert.assertEquals(251, deserialized.getDayNumber());
83          Assert.assertEquals(5, deserialized.getIntervalNumber());
84          Assert.assertEquals(2456177.5, date.getJD0(), 1.0e-16);
85          Assert.assertEquals(29191.442830, date.getGMST(), 3.0e-3);
86          Assert.assertEquals(0, deserialized.getDate().durationFrom(ref), 1.0e-15);
87  
88      }
89  
90  }