Search in sources :

Example 1 with BuiltinDataType

use of org.eclipse.milo.opcua.stack.core.BuiltinDataType in project milo by eclipse.

the class AbstractConversionTest method testExplicitConversionsCalledImplicitlyAreNull.

@Test
public void testExplicitConversionsCalledImplicitlyAreNull() {
    for (BuiltinDataType targetType : BuiltinDataType.values()) {
        Conversion[] conversions = getConversions(targetType);
        for (Conversion conversion : conversions) {
            ConversionType conversionType = getConversionType(conversion.targetType);
            if (conversionType == ConversionType.EXPLICIT) {
                S fromValue = getSourceClass().cast(conversion.fromValue);
                Object convertedValue = convert(fromValue, targetType, true);
                assertNull(convertedValue);
            }
        }
    }
}
Also used : BuiltinDataType(org.eclipse.milo.opcua.stack.core.BuiltinDataType) Test(org.testng.annotations.Test)

Example 2 with BuiltinDataType

use of org.eclipse.milo.opcua.stack.core.BuiltinDataType in project milo by eclipse.

the class AbstractConversionTest method testImplicitConversionsCalledExplicitly.

@Test
public void testImplicitConversionsCalledExplicitly() {
    for (BuiltinDataType targetType : BuiltinDataType.values()) {
        Conversion[] conversions = getConversions(targetType);
        for (Conversion conversion : conversions) {
            ConversionType conversionType = getConversionType(conversion.targetType);
            if (conversionType == ConversionType.IMPLICIT) {
                S fromValue = getSourceClass().cast(conversion.fromValue);
                Object convertedValue = convert(fromValue, targetType, false);
                System.out.println(String.format("[%s] fromValue=%s targetType=%s targetValue=%s", conversionType, fromValue, targetType, conversion.targetValue));
                assertEquals(convertedValue, conversion.targetValue);
            }
        }
    }
}
Also used : BuiltinDataType(org.eclipse.milo.opcua.stack.core.BuiltinDataType) Test(org.testng.annotations.Test)

Example 3 with BuiltinDataType

use of org.eclipse.milo.opcua.stack.core.BuiltinDataType in project milo by eclipse.

the class ByteConversionsTest method testConversions.

@Test
public void testConversions() {
    for (Object[] conversion : CONVERSIONS) {
        UByte b = (UByte) conversion[0];
        Object expected = conversion[1];
        BuiltinDataType targetType = BuiltinDataType.fromBackingClass(expected.getClass());
        assertNotNull(targetType);
        assertEquals(explicitConversion(b, targetType), expected);
    }
}
Also used : UByte(org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte) BuiltinDataType(org.eclipse.milo.opcua.stack.core.BuiltinDataType) Test(org.testng.annotations.Test)

Example 4 with BuiltinDataType

use of org.eclipse.milo.opcua.stack.core.BuiltinDataType in project milo by eclipse.

the class ImplicitConversionBinaryOperator method apply.

@Nullable
@Override
public T apply(OperatorContext context, BaseEventTypeNode eventNode, FilterOperand[] operands) throws UaException {
    validate(context, operands);
    FilterOperand op0 = operands[0];
    FilterOperand op1 = operands[1];
    Object value0 = context.resolve(op0, eventNode);
    Object value1 = context.resolve(op1, eventNode);
    if (value0 == null || value1 == null) {
        return null;
    }
    BuiltinDataType dt0 = getType(value0);
    BuiltinDataType dt1 = getType(value1);
    if (dt0 == null || dt1 == null) {
        throw new UaException(StatusCodes.Bad_UnexpectedError);
    }
    int p0 = ImplicitConversions.getPrecedence(dt0);
    int p1 = ImplicitConversions.getPrecedence(dt1);
    if (p0 == p1) {
        assert dt0 == dt1;
        return apply(context, eventNode, dt0, value0, value1);
    } else if (p0 >= p1) {
        // convert value1 to type of value0 (dt0)
        Object converted1 = convert(value1, dt0);
        return apply(context, eventNode, dt0, value0, converted1);
    } else {
        // convert value0 to type of value1 (dt1)
        Object converted0 = convert(value0, dt1);
        return apply(context, eventNode, dt1, converted0, value1);
    }
}
Also used : BuiltinDataType(org.eclipse.milo.opcua.stack.core.BuiltinDataType) UaException(org.eclipse.milo.opcua.stack.core.UaException) FilterOperand(org.eclipse.milo.opcua.stack.core.types.structured.FilterOperand) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with BuiltinDataType

use of org.eclipse.milo.opcua.stack.core.BuiltinDataType in project milo by eclipse.

the class DataTypeTreeTest method testGetBuiltinType.

@Test
public void testGetBuiltinType() {
    // Check all the builtin types
    for (BuiltinDataType expectedType : BuiltinDataType.values()) {
        BuiltinDataType builtinType = dataTypeTree.getBuiltinType(expectedType.getNodeId());
        assertEquals(expectedType, builtinType);
    }
    // Check that subtypes resolve to their builtin types
    assertEquals(BuiltinDataType.String, dataTypeTree.getBuiltinType(Identifiers.NumericRange));
    assertEquals(BuiltinDataType.DateTime, dataTypeTree.getBuiltinType(Identifiers.Date));
    assertEquals(BuiltinDataType.ByteString, dataTypeTree.getBuiltinType(Identifiers.Image));
    assertEquals(BuiltinDataType.ByteString, dataTypeTree.getBuiltinType(Identifiers.ImageBMP));
    assertEquals(BuiltinDataType.NodeId, dataTypeTree.getBuiltinType(Identifiers.SessionAuthenticationToken));
    assertEquals(BuiltinDataType.ExtensionObject, dataTypeTree.getBuiltinType(Identifiers.TrustListDataType));
    assertEquals(BuiltinDataType.Double, dataTypeTree.getBuiltinType(Identifiers.Duration));
    assertEquals(BuiltinDataType.UInt32, dataTypeTree.getBuiltinType(Identifiers.IntegerId));
    assertEquals(BuiltinDataType.UInt64, dataTypeTree.getBuiltinType(Identifiers.BitFieldMaskDataType));
    // note: enumerations resolve to BaseDataType aka Variant
    assertEquals(BuiltinDataType.Variant, dataTypeTree.getBuiltinType(Identifiers.NamingRuleType));
}
Also used : BuiltinDataType(org.eclipse.milo.opcua.stack.core.BuiltinDataType) Test(org.junit.jupiter.api.Test) AbstractClientServerTest(org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)

Aggregations

BuiltinDataType (org.eclipse.milo.opcua.stack.core.BuiltinDataType)9 Test (org.testng.annotations.Test)5 FilterOperand (org.eclipse.milo.opcua.stack.core.types.structured.FilterOperand)3 Nullable (org.jetbrains.annotations.Nullable)3 UaException (org.eclipse.milo.opcua.stack.core.UaException)2 AbstractClientServerTest (org.eclipse.milo.opcua.sdk.test.AbstractClientServerTest)1 ExpandedNodeId (org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)1 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)1 UByte (org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UByte)1 Test (org.junit.jupiter.api.Test)1