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);
}
}
}
}
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);
}
}
}
}
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);
}
}
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);
}
}
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));
}
Aggregations