|
7 | 7 | ******************************************************************************/ |
8 | 8 | package org.csstudio.apputil.formula; |
9 | 9 |
|
| 10 | +import org.csstudio.apputil.formula.enums.IndexOfFunction; |
| 11 | + |
10 | 12 | import org.epics.vtype.Alarm; |
11 | 13 | import org.epics.vtype.AlarmSeverity; |
12 | 14 | import org.epics.vtype.AlarmStatus; |
| 15 | +import org.epics.vtype.Display; |
13 | 16 | import org.epics.vtype.Time; |
| 17 | +import org.epics.vtype.VDouble; |
14 | 18 | import org.epics.vtype.VString; |
| 19 | +import org.epics.vtype.VType; |
15 | 20 | import org.junit.jupiter.api.BeforeAll; |
16 | 21 | import org.junit.jupiter.api.Test; |
17 | 22 | import org.phoebus.core.vtypes.VTypeHelper; |
@@ -293,6 +298,31 @@ public void testSPI() throws Exception { |
293 | 298 | } |
294 | 299 | } |
295 | 300 |
|
| 301 | + @Test |
| 302 | + public void testEnums() throws Exception { |
| 303 | + Formula f = new Formula("enumOf(1, arrayOf(1,2,3), arrayOf(\"a\",\"b\",\"c\"))"); |
| 304 | + assertEquals("b", VTypeHelper.toString(f.eval())); |
| 305 | + |
| 306 | + f = new Formula("indexOf(enumOf(1, arrayOf(1,2,3), arrayOf(\"a\",\"b\",\"c\")))"); |
| 307 | + assertEquals(1, VTypeHelper.toDouble(f.eval())); |
| 308 | + |
| 309 | + // Exception is thrown |
| 310 | + IndexOfFunction indexFunc = new IndexOfFunction(); |
| 311 | + try { |
| 312 | + indexFunc.compute(VDouble.of(3.2, Alarm.none(), Time.now(), Display.none())); |
| 313 | + } catch (Exception ex) { |
| 314 | + assertTrue(ex.getMessage().contains("Function indexOf requires an enum argument")); |
| 315 | + } |
| 316 | + |
| 317 | + // Disconnected or not set values should not throw an exception |
| 318 | + // and should return the same input. |
| 319 | + VType input = VDouble.of(Double.NaN, Alarm.none(), Time.now(), Display.none()); |
| 320 | + assertEquals(indexFunc.compute(input), input); |
| 321 | + |
| 322 | + input = VDouble.of(Double.NaN, Alarm.disconnected(), Time.now(), Display.none()); |
| 323 | + assertEquals(indexFunc.compute(input), input); |
| 324 | + } |
| 325 | + |
296 | 326 | @Test |
297 | 327 | public void testVariableDetermination() throws Exception { |
298 | 328 | Formula f = new Formula("RFQ_Vac:Pump2:Pressure < 10", true); |
|
0 commit comments