44
55package org .phoebus .saveandrestore .util ;
66
7- import org .epics .pva .data .*;
8- import org .epics .util .array .*;
9- import org .epics .vtype .*;
7+ import org .epics .pva .data .PVABoolArray ;
8+ import org .epics .pva .data .PVAByteArray ;
9+ import org .epics .pva .data .PVADoubleArray ;
10+ import org .epics .pva .data .PVAFloatArray ;
11+ import org .epics .pva .data .PVAIntArray ;
12+ import org .epics .pva .data .PVALongArray ;
13+ import org .epics .pva .data .PVAShortArray ;
14+ import org .epics .pva .data .PVAStringArray ;
15+ import org .epics .util .array .ArrayBoolean ;
16+ import org .epics .util .array .ArrayByte ;
17+ import org .epics .util .array .ArrayDouble ;
18+ import org .epics .util .array .ArrayFloat ;
19+ import org .epics .util .array .ArrayInteger ;
20+ import org .epics .util .array .ArrayLong ;
21+ import org .epics .util .array .ArrayShort ;
22+ import org .epics .util .array .ArrayUByte ;
23+ import org .epics .util .array .ArrayUInteger ;
24+ import org .epics .util .array .ArrayULong ;
25+ import org .epics .util .array .ArrayUShort ;
26+ import org .epics .vtype .Alarm ;
27+ import org .epics .vtype .AlarmSeverity ;
28+ import org .epics .vtype .AlarmStatus ;
29+ import org .epics .vtype .Display ;
30+ import org .epics .vtype .EnumDisplay ;
31+ import org .epics .vtype .Time ;
32+ import org .epics .vtype .VBoolean ;
33+ import org .epics .vtype .VBooleanArray ;
34+ import org .epics .vtype .VByte ;
35+ import org .epics .vtype .VByteArray ;
36+ import org .epics .vtype .VDouble ;
37+ import org .epics .vtype .VDoubleArray ;
38+ import org .epics .vtype .VEnum ;
39+ import org .epics .vtype .VFloat ;
40+ import org .epics .vtype .VFloatArray ;
41+ import org .epics .vtype .VInt ;
42+ import org .epics .vtype .VIntArray ;
43+ import org .epics .vtype .VLong ;
44+ import org .epics .vtype .VLongArray ;
45+ import org .epics .vtype .VShort ;
46+ import org .epics .vtype .VShortArray ;
47+ import org .epics .vtype .VString ;
48+ import org .epics .vtype .VStringArray ;
49+ import org .epics .vtype .VTable ;
50+ import org .epics .vtype .VType ;
51+ import org .epics .vtype .VUByte ;
52+ import org .epics .vtype .VUByteArray ;
53+ import org .epics .vtype .VUInt ;
54+ import org .epics .vtype .VUIntArray ;
55+ import org .epics .vtype .VULong ;
56+ import org .epics .vtype .VULongArray ;
57+ import org .epics .vtype .VUShort ;
58+ import org .epics .vtype .VUShortArray ;
1059import org .junit .jupiter .api .Test ;
1160import org .phoebus .core .vtypes .VDisconnectedData ;
1261import org .phoebus .core .vtypes .VTypeHelper ;
13- import org .phoebus .saveandrestore .util .Threshold ;
14- import org .phoebus .saveandrestore .util .Utilities ;
1562
1663import java .time .temporal .ChronoUnit ;
1764import java .util .ArrayList ;
1865import java .util .Arrays ;
1966import java .util .List ;
2067import java .util .Optional ;
2168
22- import static org .junit .jupiter .api .Assertions .*;
69+ import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
70+ import static org .junit .jupiter .api .Assertions .assertEquals ;
71+ import static org .junit .jupiter .api .Assertions .assertFalse ;
72+ import static org .junit .jupiter .api .Assertions .assertInstanceOf ;
73+ import static org .junit .jupiter .api .Assertions .assertNotEquals ;
74+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
75+ import static org .junit .jupiter .api .Assertions .assertNull ;
76+ import static org .junit .jupiter .api .Assertions .assertTrue ;
77+ import static org .junit .jupiter .api .Assertions .fail ;
2378
2479public class UtilitiesTest {
2580
@@ -145,61 +200,61 @@ public void testValueFromString() {
145200
146201 VType val = VDouble .of (5d , alarm , time , display );
147202 VType result = Utilities .valueFromString ("5.0" , val );
148- assertTrue ( result instanceof VDouble );
203+ assertInstanceOf ( VDouble . class , result );
149204 assertEquals (5.0 , ((VDouble ) result ).getValue (), 0 );
150205
151206 result = Utilities .valueFromString ("" , val );
152- assertTrue ( result instanceof VDouble );
207+ assertInstanceOf ( VDouble . class , result );
153208 assertEquals (5.0 , ((VDouble ) result ).getValue (), 0 );
154209
155210 val = VFloat .of (5f , alarm , time , display );
156211 result = Utilities .valueFromString ("5.0" , val );
157- assertTrue ( result instanceof VFloat );
212+ assertInstanceOf ( VFloat . class , result );
158213 assertEquals (5.0f , ((VFloat ) result ).getValue (), 0 );
159214
160215 val = VLong .of (5L , alarm , time , display );
161216 result = Utilities .valueFromString ("5" , val );
162- assertTrue ( result instanceof VLong );
217+ assertInstanceOf ( VLong . class , result );
163218 assertEquals (5L , ((VLong ) result ).getValue ().longValue ());
164219
165220 val = VULong .of (5L , alarm , time , display );
166221 result = Utilities .valueFromString ("5" , val );
167- assertTrue ( result instanceof VULong );
222+ assertInstanceOf ( VULong . class , result );
168223 assertEquals (5L , ((VULong ) result ).getValue ().longValue ());
169224
170225 val = VUInt .of (5 , alarm , time , display );
171226 result = Utilities .valueFromString ("5" , val );
172- assertTrue ( result instanceof VUInt );
227+ assertInstanceOf ( VUInt . class , result );
173228 assertEquals (5 , ((VUInt ) result ).getValue ().intValue ());
174229
175230 val = VInt .of (5 , alarm , time , display );
176231 result = Utilities .valueFromString ("5" , val );
177- assertTrue ( result instanceof VInt );
232+ assertInstanceOf ( VInt . class , result );
178233 assertEquals (5 , ((VInt ) result ).getValue ().intValue ());
179234
180235 val = VShort .of ((short ) 5 , alarm , time , display );
181236 result = Utilities .valueFromString ("5" , val );
182- assertTrue ( result instanceof VShort );
237+ assertInstanceOf ( VShort . class , result );
183238 assertEquals ((short ) 5 , ((VShort ) result ).getValue ().shortValue ());
184239
185240 val = VUShort .of ((short ) 5 , alarm , time , display );
186241 result = Utilities .valueFromString ("5" , val );
187- assertTrue ( result instanceof VUShort );
242+ assertInstanceOf ( VUShort . class , result );
188243 assertEquals ((short ) 5 , ((VUShort ) result ).getValue ().shortValue ());
189244
190245 val = VByte .of ((byte ) 5 , alarm , time , display );
191246 result = Utilities .valueFromString ("5" , val );
192- assertTrue ( result instanceof VByte );
247+ assertInstanceOf ( VByte . class , result );
193248 assertEquals ((byte ) 5 , ((VByte ) result ).getValue ().byteValue ());
194249
195250 val = VUByte .of ((byte ) 5 , alarm , time , display );
196251 result = Utilities .valueFromString ("5" , val );
197- assertTrue ( result instanceof VUByte );
252+ assertInstanceOf ( VUByte . class , result );
198253 assertEquals ((byte ) 5 , ((VUByte ) result ).getValue ().byteValue ());
199254
200255 val = VEnum .of (1 , EnumDisplay .of ("first" , "second" , "third" ), alarm , time );
201256 result = Utilities .valueFromString ("second" , val );
202- assertTrue ( result instanceof VEnum );
257+ assertInstanceOf ( VEnum . class , result );
203258 assertEquals ("second" , ((VEnum ) result ).getValue ());
204259
205260 val = VEnum .of (1 , EnumDisplay .of ("first" , "second" , "third" ), alarm , time );
@@ -212,12 +267,12 @@ public void testValueFromString() {
212267
213268 val = VBoolean .of (false , alarm , time );
214269 result = Utilities .valueFromString ("false" , val );
215- assertTrue ( result instanceof VBoolean );
270+ assertInstanceOf ( VBoolean . class , result );
216271 assertEquals (false , ((VBoolean ) result ).getValue ());
217272
218273 val = VString .of ("third" , alarm , time );
219274 result = Utilities .valueFromString ("third" , val );
220- assertTrue ( result instanceof VString );
275+ assertInstanceOf ( VString . class , result );
221276 assertEquals ("third" , ((VString ) result ).getValue ());
222277
223278
@@ -267,30 +322,30 @@ public void testValueFromString() {
267322
268323 val = VStringArray .of (Arrays .asList ("first" , "second" , "third" ), alarm , time );
269324 result = Utilities .valueFromString ("[\" first\" , \" second\" , \" third\" ]" , val );
270- assertTrue ( result instanceof VStringArray );
325+ assertInstanceOf ( VStringArray . class , result );
271326 assertArrayEquals (new String []{"first" , "second" , "third" }, ((VStringArray ) result ).getData ().toArray (new String [0 ]));
272327
273328 val = VLongArray .of (ArrayLong .of (1 , 2 , 3 , 4 , 5 ), alarm , time , display );
274329 result = Utilities .valueFromString ("1, 2, 3, 4, 5" , val );
275- assertTrue ( result instanceof VLongArray );
330+ assertInstanceOf ( VLongArray . class , result );
276331 assertNotNull (((VLongArray ) result ).getData ());
277332
278333 val = VBooleanArray .of (ArrayBoolean .of (true , true , false , true ), alarm , time );
279334 result = Utilities .valueFromString ("[1, 1, 0, 2]" , val );
280- assertTrue ( result instanceof VBooleanArray );
335+ assertInstanceOf ( VBooleanArray . class , result );
281336 assertNotNull (((VBooleanArray ) result ).getData ());
282337
283338 val = VDisconnectedData .INSTANCE ;
284339 result = Utilities .valueFromString ("5" , val );
285- assertTrue ( result instanceof VLong );
340+ assertInstanceOf ( VLong . class , result );
286341 assertEquals (5L , ((VLong ) result ).getValue ().longValue ());
287342
288343 result = Utilities .valueFromString ("5.1" , val );
289- assertTrue ( result instanceof VDouble );
344+ assertInstanceOf ( VDouble . class , result );
290345 assertEquals (5.1 , ((VDouble ) result ).getValue (), 0 );
291346
292347 result = Utilities .valueFromString ("string" , val );
293- assertTrue ( result instanceof VString );
348+ assertInstanceOf ( VString . class , result );
294349 assertEquals ("string" , ((VString ) result ).getValue ());
295350 }
296351
@@ -499,7 +554,7 @@ public void testValueToCompareString() {
499554 assertEquals ("[1.0, 2.0, 3.0]" , result .getString ());
500555 assertNotEquals (0 , result .getValuesEqual ());
501556 assertFalse (result .isWithinThreshold ());
502- assertEquals (0 , result .getAbsoluteDelta (), 0.0 );
557+ assertEquals (1 , result .getAbsoluteDelta (), 0.0 );
503558
504559 //compare long values: equal, first less than second, second less than first
505560 val1 = VLong .of (6L , alarm , time , display );
@@ -631,15 +686,15 @@ public void testValueToCompareString() {
631686 assertEquals ("val2" , result .getString ());
632687 assertTrue (result .getValuesEqual () < 0 );
633688 assertFalse (result .isWithinThreshold ());
634- assertEquals (0 , result .getAbsoluteDelta (), 0.0 );
689+ assertEquals (1 , result .getAbsoluteDelta (), 0.0 );
635690
636691 val1 = VEnum .of (2 , labels , alarm , time );
637692 val2 = VEnum .of (1 , labels , alarm , time );
638693 result = Utilities .valueToCompareString (val1 , val2 , Optional .empty ());
639694 assertEquals ("val3" , result .getString ());
640695 assertTrue (result .getValuesEqual () > 0 );
641696 assertFalse (result .isWithinThreshold ());
642- assertEquals (0 , result .getAbsoluteDelta (), 0.0 );
697+ assertEquals (1 , result .getAbsoluteDelta (), 0.0 );
643698
644699 val1 = VByte .of ((byte ) 5 , alarm , time , display );
645700 val2 = VByte .of ((byte ) 6 , alarm , time , display );
@@ -696,6 +751,14 @@ public void testValueToCompareString() {
696751 assertTrue (result .isWithinThreshold ());
697752 assertEquals (0 , result .getAbsoluteDelta (), 0.0 );
698753
754+ val1 = VBoolean .of (false , alarm , time );
755+ val2 = VBoolean .of (true , alarm , time );
756+ result = Utilities .valueToCompareString (val1 , val2 , Optional .empty ());
757+ assertEquals ("false" , result .getString ());
758+ assertEquals (-1 , result .getValuesEqual ());
759+ assertFalse (result .isWithinThreshold ());
760+ assertEquals (1 , result .getAbsoluteDelta (), 0.0 );
761+
699762 val1 = VString .of ("a" , alarm , time );
700763 val2 = VString .of ("b" , alarm , time );
701764 result = Utilities .valueToCompareString (val1 , val2 , Optional .empty ());
@@ -1555,4 +1618,19 @@ public void testToPVArrayType() {
15551618 assertArrayEquals (new String []{"a" , "b" , "c" }, ((PVAStringArray ) converted ).get ());
15561619 assertEquals ("strings" , ((PVAStringArray ) converted ).getName ());
15571620 }
1621+
1622+ @ Test
1623+ public void testSorting () {
1624+ VLongArray longs1 = VLongArray .of (ArrayLong .of (-1 , 2 , 3 ), Alarm .none (), Time .now (), Display .none ());
1625+ VLongArray longs2 = VLongArray .of (ArrayLong .of (1 , 2 , 3 ), Alarm .none (), Time .now (), Display .none ());
1626+
1627+ Utilities .VTypeComparison vtc1 = Utilities .valueToCompareString (longs1 , longs2 , Optional .empty ());
1628+
1629+ VEnum vEnum1 = VEnum .of (0 , EnumDisplay .of ("negative" , "b" ), Alarm .none (), Time .now ());
1630+ VEnum vEnum2 = VEnum .of (0 , EnumDisplay .of ("negative" , "b" ), Alarm .none (), Time .now ());
1631+
1632+ Utilities .VTypeComparison vtc2 = Utilities .valueToCompareString (vEnum1 , vEnum2 , Optional .empty ());
1633+
1634+ assertEquals (1 , Double .compare (vtc1 .getAbsoluteDelta (), vtc2 .getAbsoluteDelta ()));
1635+ }
15581636}
0 commit comments