@Test public void shouldReturnCorrectConstantStringWhenSpecified() throws Exception { final String strConst = "string constant"; final String testXmlString = "<types>" + " <type name=\"testTypeConstString\" primitiveType=\"char\" presence=\"constant\" " + "length=\"" + strConst.length() + "\"" + ">" + strConst + "</type>" + "</types>"; final Map<String, Type> map = parseTestXmlWithMap("/types/type", testXmlString); assertThat((((EncodedDataType)map.get("testTypeConstString")).constVal()), is(parse(strConst, strConst.length(), "US-ASCII"))); }
@Test public void shouldReturnCorrectPresenceConstantWhenSpecified() throws Exception { final String testXmlString = "<types>" + " <type name=\"testTypePresenceConst\" primitiveType=\"char\" presence=\"constant\">F</type>" + "</types>"; final Map<String, Type> map = parseTestXmlWithMap("/types/type", testXmlString); final String expectedString = "F"; final PrimitiveValue expectedValue = parse(expectedString, PrimitiveType.CHAR); assertThat((((EncodedDataType)map.get("testTypePresenceConst")).constVal()), is(expectedValue)); }
@Test public void shouldHandleDecimal64CompositeType() throws Exception { final String testXmlString = "<types>" + "<composite name=\"decimal64\">" + " <type name=\"mantissa\" primitiveType=\"int64\"/>" + " <type name=\"exponent\" primitiveType=\"int8\" presence=\"constant\">-2</type>" + "</composite>" + "</types>"; final Map<String, Type> map = parseTestXmlWithMap("/types/composite", testXmlString); final CompositeType decimal64 = (CompositeType)map.get("decimal64"); assertThat(decimal64.name(), is("decimal64")); final EncodedDataType mantissa = (EncodedDataType)decimal64.getType("mantissa"); final EncodedDataType exponent = (EncodedDataType)decimal64.getType("exponent"); assertThat(mantissa.primitiveType(), is(PrimitiveType.INT64)); assertThat(exponent.primitiveType(), is(PrimitiveType.INT8)); assertThat(exponent.presence(), is(Presence.CONSTANT)); assertThat(exponent.constVal(), is(PrimitiveValue.parse("-2", PrimitiveType.INT8))); assertThat(decimal64.encodedLength(), is(8)); }
@Test public void shouldHandleDecimal32CompositeType() throws Exception { final String testXmlString = "<types>" + "<composite name=\"decimal32\">" + " <type name=\"mantissa\" primitiveType=\"int32\"/>" + " <type name=\"exponent\" primitiveType=\"int8\" presence=\"constant\">-2</type>" + "</composite>" + "</types>"; final Map<String, Type> map = parseTestXmlWithMap("/types/composite", testXmlString); final CompositeType decimal32 = (CompositeType)map.get("decimal32"); assertThat(decimal32.name(), is("decimal32")); final EncodedDataType mantissa = (EncodedDataType)decimal32.getType("mantissa"); final EncodedDataType exponent = (EncodedDataType)decimal32.getType("exponent"); assertThat(mantissa.primitiveType(), is(PrimitiveType.INT32)); assertThat(exponent.primitiveType(), is(PrimitiveType.INT8)); assertThat(exponent.presence(), is(Presence.CONSTANT)); assertThat(exponent.constVal(), is(PrimitiveValue.parse("-2", PrimitiveType.INT8))); assertThat(decimal32.encodedLength(), is(4)); }
encodingBuilder .presence(Encoding.Presence.CONSTANT) .constValue(type.constVal()); break;
encodingBuilder .presence(Encoding.Presence.CONSTANT) .constValue(valueRef != null ? lookupValueRef(valueRef) : type.constVal()); break;
encodingBuilder .presence(Encoding.Presence.CONSTANT) .constValue(type.constVal()); break;
.constValue(type.constVal()); break;
encodingBuilder .presence(Encoding.Presence.CONSTANT) .constValue(type.constVal()); break;
encodingBuilder .presence(Encoding.Presence.CONSTANT) .constValue(valueRef != null ? lookupValueRef(valueRef) : type.constVal()); break;
encodingBuilder .presence(Encoding.Presence.CONSTANT) .constValue(valueRef != null ? lookupValueRef(valueRef) : type.constVal()); break;