Search in sources :

Example 51 with VType

use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.

the class FormatOptionHandlerTest method testHexFormat.

@Test
public void testHexFormat() throws Exception {
    VType number = ValueFactory.newVDouble(65535.0, display);
    String text = FormatOptionHandler.format(number, FormatOption.HEX, 4, true);
    System.out.println(text);
    assertThat(text, equalTo("0xFFFF V"));
    text = FormatOptionHandler.format(number, FormatOption.HEX, 8, true);
    System.out.println(text);
    assertThat(text, equalTo("0x0000FFFF V"));
    text = FormatOptionHandler.format(number, FormatOption.HEX, 16, true);
    System.out.println(text);
    assertThat(text, equalTo("0x000000000000FFFF V"));
}
Also used : VType(org.diirt.vtype.VType) Test(org.junit.Test)

Example 52 with VType

use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.

the class FormatOptionHandlerTest method testNumberArrayParsing.

@Test
public void testNumberArrayParsing() throws Exception {
    final ListNumber data = new ArrayDouble(1.0, 2.0, 3.0, 4.0);
    final VType value = ValueFactory.newVNumberArray(data, ValueFactory.alarmNone(), ValueFactory.timeNow(), display);
    Object parsed = FormatOptionHandler.parse(value, " [  1, 2.5  ,  3 ] ", FormatOption.DEFAULT);
    assertThat(parsed, instanceOf(double[].class));
    final double[] numbers = (double[]) parsed;
    assertThat(numbers, equalTo(new double[] { 1.0, 2.5, 3.0 }));
}
Also used : ListNumber(org.diirt.util.array.ListNumber) VType(org.diirt.vtype.VType) ArrayDouble(org.diirt.util.array.ArrayDouble) Test(org.junit.Test)

Example 53 with VType

use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.

the class FormatOptionHandlerTest method testExponential.

@Test
public void testExponential() throws Exception {
    VType number = ValueFactory.newVDouble(3.16, display);
    String text = FormatOptionHandler.format(number, FormatOption.DEFAULT, -1, true);
    System.out.println(text);
    assertThat(text, equalTo("3.160 V"));
    text = FormatOptionHandler.format(number, FormatOption.EXPONENTIAL, 3, true);
    System.out.println(text);
    assertThat(text, equalTo("3.160E0 V"));
    text = FormatOptionHandler.format(number, FormatOption.EXPONENTIAL, 1, true);
    System.out.println(text);
    assertThat(text, equalTo("3.2E0 V"));
}
Also used : VType(org.diirt.vtype.VType) Test(org.junit.Test)

Example 54 with VType

use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.

the class FormatOptionHandlerTest method testSexagesimalFormat.

@Test
public void testSexagesimalFormat() throws Exception {
    final VType sexaPositiveValue = ValueFactory.newVDouble(12.5824414), sexaNegativeValue = ValueFactory.newVDouble(-12.5824414), sexaRoundedValue = ValueFactory.newVDouble(12.9999999);
    assertThat(FormatOptionHandler.format(sexaPositiveValue, FormatOption.SEXAGESIMAL, 7, false), equalTo("12:34:56.789"));
    assertThat(FormatOptionHandler.format(sexaPositiveValue, FormatOption.SEXAGESIMAL, 2, false), equalTo("12:35"));
    assertThat(FormatOptionHandler.format(sexaPositiveValue, FormatOption.SEXAGESIMAL, 4, false), equalTo("12:34:57"));
    assertThat(FormatOptionHandler.format(sexaNegativeValue, FormatOption.SEXAGESIMAL, 7, false), equalTo("-12:34:56.789"));
    assertThat(FormatOptionHandler.format(sexaRoundedValue, FormatOption.SEXAGESIMAL, 7, false), equalTo("13:00:00.000"));
    assertThat(FormatOptionHandler.format(sexaRoundedValue, FormatOption.SEXAGESIMAL, 8, false), equalTo("12:59:59.9996"));
    assertThat(FormatOptionHandler.format(ValueFactory.newVDouble(2 * Math.PI), FormatOption.SEXAGESIMAL_HMS, 7, false), equalTo("24:00:00.000"));
    assertThat(FormatOptionHandler.format(sexaPositiveValue, FormatOption.SEXAGESIMAL_HMS, 7, false), equalTo("48:03:40.989"));
    assertThat(FormatOptionHandler.format(sexaNegativeValue, FormatOption.SEXAGESIMAL_HMS, 7, false), equalTo("-48:03:40.989"));
    assertThat(FormatOptionHandler.format(ValueFactory.newVDouble(2 * Math.PI), FormatOption.SEXAGESIMAL_DMS, 7, false), equalTo("360:00:00.000"));
    assertThat(FormatOptionHandler.format(sexaPositiveValue, FormatOption.SEXAGESIMAL_DMS, 7, false), equalTo("720:55:14.837"));
    assertThat(FormatOptionHandler.format(sexaNegativeValue, FormatOption.SEXAGESIMAL_DMS, 7, false), equalTo("-720:55:14.837"));
    assertThat(FormatOptionHandler.format(sexaRoundedValue, FormatOption.SEXAGESIMAL_DMS, 7, false), equalTo("744:50:42.461"));
}
Also used : VType(org.diirt.vtype.VType) Test(org.junit.Test)

Example 55 with VType

use of org.diirt.vtype.VType in project org.csstudio.display.builder by kasemir.

the class FormatOptionHandlerTest method testArray.

@Test
public void testArray() throws Exception {
    final ListNumber data = new ArrayDouble(1.0, 2.0, 3.0, 4.0);
    VType value = ValueFactory.newVNumberArray(data, ValueFactory.alarmNone(), ValueFactory.timeNow(), display);
    System.out.println(value);
    String text = FormatOptionHandler.format(value, FormatOption.DEFAULT, 0, true);
    System.out.println(text);
    assertThat(text, equalTo("[1, 2, 3, 4] V"));
    text = FormatOptionHandler.format(value, FormatOption.DECIMAL, 2, true);
    System.out.println(text);
    assertThat(text, equalTo("[1.00, 2.00, 3.00, 4.00] V"));
}
Also used : ListNumber(org.diirt.util.array.ListNumber) VType(org.diirt.vtype.VType) ArrayDouble(org.diirt.util.array.ArrayDouble) Test(org.junit.Test)

Aggregations

VType (org.diirt.vtype.VType)69 Test (org.junit.Test)17 IPV (org.csstudio.simplepv.IPV)8 ArrayList (java.util.ArrayList)7 Display (org.diirt.vtype.Display)7 VEnum (org.diirt.vtype.VEnum)7 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)6 ListNumber (org.diirt.util.array.ListNumber)6 IFigure (org.eclipse.draw2d.IFigure)6 Instant (java.time.Instant)5 ModelItem (org.csstudio.trends.databrowser3.model.ModelItem)5 VNumberArray (org.diirt.vtype.VNumberArray)5 VString (org.diirt.vtype.VString)5 List (java.util.List)4 RuntimePV (org.csstudio.display.builder.runtime.pv.RuntimePV)4 RuntimePVListener (org.csstudio.display.builder.runtime.pv.RuntimePVListener)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 ValueIterator (org.csstudio.archive.reader.ValueIterator)3 ArchiveVNumber (org.csstudio.archive.vtype.ArchiveVNumber)3 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)3