use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMapping2ByteUnsigned_7_004.
/**
* KNXCoreTypeMapper tests for method typeMapper.toType() type “2-Octet Unsigned Value" KNX ID: 7.004
* DPT_TIMEPERIOD_100
*
* @throws KNXFormatException
*/
@Test
public void testTypeMapping2ByteUnsigned_7_004() throws KNXFormatException {
DPT dpt = DPTXlator2ByteUnsigned.DPT_TIMEPERIOD_100;
testToTypeClass(dpt, DecimalType.class);
// Use a too short byte array
assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, DecimalType.class));
Type type = testToType(dpt, new byte[] { 0x00, 0x00 }, DecimalType.class);
testToDPTValue(dpt, type, "0");
type = testToType(dpt, new byte[] { (byte) 0xFF, 0x00 }, DecimalType.class);
testToDPTValue(dpt, type, "6528000");
type = testToType(dpt, new byte[] { (byte) 0xFF, (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "6553500");
// Use a too long byte array expecting that additional bytes will be ignored
type = testToType(dpt, new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "6553500");
}
use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMappingSceneNumber_18_001.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “Scene Number" KNX ID: 18.001 DPT_SCENE_CONTROL
*
* @throws KNXFormatException
*/
@Test
public void testTypeMappingSceneNumber_18_001() throws KNXFormatException {
DPT dpt = DPTXlatorSceneControl.DPT_SCENE_CONTROL;
testToTypeClass(dpt, DecimalType.class);
// Use a too short byte array
assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, DecimalType.class));
// Use a too long byte array expecting that additional bytes will be ignored
Type type = testToType(dpt, new byte[] { (byte) 0xFF, 0 }, DecimalType.class);
testToDPTValue(dpt, type, "learn 63");
type = testToType(dpt, new byte[] { 0x00 }, DecimalType.class);
testToDPTValue(dpt, type, "activate 0");
type = testToType(dpt, new byte[] { 0x3F }, DecimalType.class);
testToDPTValue(dpt, type, "activate 63");
// Test that the second msb (reserved) are ignored
type = testToType(dpt, new byte[] { (byte) 0xC0 }, DecimalType.class);
testToDPTValue(dpt, type, "learn 0");
// Test that the second msb (reserved) are ignored
type = testToType(dpt, new byte[] { (byte) 0xFF }, DecimalType.class);
testToDPTValue(dpt, type, "learn 63");
}
use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMappingString.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “String" KNX ID: 16.001 DPT_STRING_8859_1
*
* @throws KNXFormatException
*/
@Test
public void testTypeMappingString() throws KNXFormatException {
DPT dpt = DPTXlatorString.DPT_STRING_8859_1;
testToTypeClass(dpt, StringType.class);
/*
* According to spec the length of this DPT is fixed to 14 bytes.
*
* Test the that a too short array results in an <null> string. There should be an error logged by calimero lib
* (V2.2.0).
*/
Type type = testToType(dpt, new byte[] { 0x61, 0x62 }, StringType.class);
testToDPTValue(dpt, type, null);
/*
* FIXME: According to spec the length of this DPT is fixed to 14 bytes. Calimero lib (V 2.2.0) isn't checking
* this correctly and has a bug in
* tuwien.auto.calimero.dptxlator.DPTXlatorString.toDPT(final byte[] buf, final int offset). Calimero accepts
* any byte array larger or equal to 14 bytes
* without error. As a result: anything less then 14 bytes and above a multiple of 14 bytes will be accepted but
* cutoff. Even for the failed check (less
* then 14 bytes) calimero is not throwing an exception but is logging an error which we cannot check for here.
*
* Test the erroneous behavior that a too long arrays result in a cutoff string. There probably won't be an
* error logged by calimero lib (V2.2.0).
*/
type = testToType(dpt, new byte[] { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F }, StringType.class);
testToDPTValue(dpt, type, "abcdefghijklmn");
/*
* Test a 14 byte array.
*/
type = testToType(dpt, new byte[] { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E }, StringType.class);
testToDPTValue(dpt, type, "abcdefghijklmn");
/*
* Test that a byte array filled with 0 and correct length is resulting in an empty string.
*/
type = testToType(dpt, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, StringType.class);
testToDPTValue(dpt, type, "");
}
use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMappingTime_10_001_HoursOutOfBounds.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “Time" KNX ID: 10.001 DPT_TIMEOFDAY
*
* Test case: Set day to Monday, 24 hours, 59 minutes and 59 seconds
*
* @throws KNXFormatException
*/
@Test
public void testTypeMappingTime_10_001_HoursOutOfBounds() throws KNXFormatException {
DPT dpt = DPTXlatorTime.DPT_TIMEOFDAY;
testToTypeClass(dpt, DateTimeType.class);
assertNull("KNXCoreTypeMapper.toType() should return null", testToType(dpt, new byte[] { 0x38, 59, 59 }, DateTimeType.class));
}
use of tuwien.auto.calimero.dptxlator.DPT in project openhab1-addons by openhab.
the class KNXCoreTypeMapperTest method testTypeMappingTime_10_001.
/**
* KNXCoreTypeMapper tests method typeMapper.toType() for type “Time" KNX ID: 10.001 DPT_TIMEOFDAY
*
* Test case: positive tests
*
* @throws KNXFormatException
*/
@Test
public void testTypeMappingTime_10_001() throws KNXFormatException {
DPT dpt = DPTXlatorTime.DPT_TIMEOFDAY;
testToTypeClass(dpt, DateTimeType.class);
// Use a too short byte array
assertNull("KNXCoreTypeMapper.toType() should return null (required data length too short)", testToType(dpt, new byte[] {}, DateTimeType.class));
// Use a too long byte array expecting that additional bytes will be ignored
Type type = testToType(dpt, new byte[] { 0x20, 0x00, 0x00, (byte) 0xFF }, DateTimeType.class);
testToDPTValue(dpt, type, "Mon, 00:00:00");
/*
* Set day to no day, 0 hours, 0 minutes and 0 seconds
*
*/
type = testToType(dpt, new byte[] { 0x00, 0x00, 0x00 }, DateTimeType.class);
String today = String.format(Locale.US, "%1$ta", Calendar.getInstance());
testToDPTValue(dpt, type, today + ", 00:00:00");
/*
* Set day to Monday, 0 hours, 0 minutes and 0 seconds January 5th, 1970 was a Monday
*/
type = testToType(dpt, new byte[] { 0x20, 0x00, 0x00 }, DateTimeType.class);
testToDPTValue(dpt, type, "Mon, 00:00:00");
/*
* * Set day to Tuesday, 0 hours, 0 minutes and 0 seconds January 6th, 1970 was a Tuesday
*/
type = testToType(dpt, new byte[] { 0x40, 0, 0 }, DateTimeType.class);
testToDPTValue(dpt, type, "Tue, 00:00:00");
/*
* Set day to Wednesday, 0 hours, 0 minutes and 0 seconds January 7th, 1970 was a Wednesday
*/
type = testToType(dpt, new byte[] { 0x60, 0, 0 }, DateTimeType.class);
testToDPTValue(dpt, type, "Wed, 00:00:00");
/*
* Set day to Thursday, 0 hours, 0 minutes and 0 seconds January 1st, 1970 was a Thursday
*/
type = testToType(dpt, new byte[] { (byte) 0x80, 0, 0 }, DateTimeType.class);
testToDPTValue(dpt, type, "Thu, 00:00:00");
/*
* Set day to Friday, 0 hours, 0 minutes and 0 seconds January 2nd, 1970 was a Friday
*/
type = testToType(dpt, new byte[] { (byte) 0xA0, 0, 0 }, DateTimeType.class);
testToDPTValue(dpt, type, "Fri, 00:00:00");
/*
* Set day to Saturday, 0 hours, 0 minutes and 0 seconds January 3rd, 1970 was a Saturday
*/
type = testToType(dpt, new byte[] { (byte) 0xC0, 0, 0 }, DateTimeType.class);
testToDPTValue(dpt, type, "Sat, 00:00:00");
/*
* Set day to Sunday, 0 hours, 0 minutes and 0 seconds January 4th, 1970 was a Sunday
*/
type = testToType(dpt, new byte[] { (byte) 0xE0, 0, 0 }, DateTimeType.class);
testToDPTValue(dpt, type, "Sun, 00:00:00");
/*
* Set day to Monday, 1 hour, 0 minutes and 0 seconds
*/
type = testToType(dpt, new byte[] { 0x21, 0, 0 }, DateTimeType.class);
testToDPTValue(dpt, type, "Mon, 01:00:00");
/*
* Set day to Monday, 0 hour, 1 minute and 0 seconds
*/
type = testToType(dpt, new byte[] { 0x20, 1, 0 }, DateTimeType.class);
testToDPTValue(dpt, type, "Mon, 00:01:00");
/*
* Set day to Monday, 0 hour, 0 minute and 1 seconds
*/
type = testToType(dpt, new byte[] { 0x20, 0, 1 }, DateTimeType.class);
testToDPTValue(dpt, type, "Mon, 00:00:01");
/*
* Set day to Monday, 23 hours, 59 minutes and 59 seconds
*/
type = testToType(dpt, new byte[] { 0x37, 59, 59 }, DateTimeType.class);
testToDPTValue(dpt, type, "Mon, 23:59:59");
}
Aggregations