@@ -50,6 +50,16 @@ public final void testTimeNoArgConstructor() {
5050 assertEquals (ClockType .SYSTEM_TIME , time .clockType ());
5151 }
5252
53+ @ Test
54+ public final void testTimeFromMsgConstructor () {
55+ builtin_interfaces .msg .Time timeMsg = new builtin_interfaces .msg .Time ();
56+ timeMsg .setSec (42 );
57+ timeMsg .setNanosec (100 );
58+ Time time = new Time (timeMsg , ClockType .SYSTEM_TIME );
59+ assertEquals (42000000100L , time .nanoseconds ());
60+ assertEquals (ClockType .SYSTEM_TIME , time .clockType ());
61+ }
62+
5363 @ Test
5464 public final void testTimeNanos () {
5565 Time time = new Time (45 , ClockType .SYSTEM_TIME );
@@ -73,4 +83,29 @@ public final void testTimeBadSecs() {
7383 public final void testTimeBadNanos () {
7484 Time time = new Time (0 , -45 , ClockType .SYSTEM_TIME );
7585 }
86+
87+ @ Test
88+ public final void testTimeToMsg () {
89+ {
90+ Time time = new Time ();
91+ builtin_interfaces .msg .Time timeMsgOut = time .toMsg ();
92+ assertEquals (0 , timeMsgOut .getSec ());
93+ assertEquals (0 , timeMsgOut .getNanosec ());
94+ }
95+ {
96+ builtin_interfaces .msg .Time timeMsg = new builtin_interfaces .msg .Time ();
97+ timeMsg .setSec (42 );
98+ timeMsg .setNanosec (100 );
99+ Time time = new Time (timeMsg , ClockType .SYSTEM_TIME );
100+ builtin_interfaces .msg .Time timeMsgOut = time .toMsg ();
101+ assertEquals (42 , timeMsgOut .getSec ());
102+ assertEquals (100 , timeMsgOut .getNanosec ());
103+ }
104+ {
105+ Time time = new Time (0 , 45 , ClockType .SYSTEM_TIME );
106+ builtin_interfaces .msg .Time timeMsgOut = time .toMsg ();
107+ assertEquals (0 , timeMsgOut .getSec ());
108+ assertEquals (45 , timeMsgOut .getNanosec ());
109+ }
110+ }
76111}
0 commit comments