Skip to content

Commit

Permalink
Merge pull request openhab#4034 from ivanfmartinez/rfxcom_test5
Browse files Browse the repository at this point in the history
RFXCOM test binding
  • Loading branch information
teichsta committed Feb 19, 2016
2 parents 0b3166b + 5c9d8e1 commit 62ea8a4
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bundles/binding/org.openhab.binding.rfxcom.test/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
28 changes: 28 additions & 0 deletions bundles/binding/org.openhab.binding.rfxcom.test/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.openhab.binding.rfxcom.test</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Tests for RFXCOM Binding
Bundle-SymbolicName: org.openhab.binding.rfxcom.test
Bundle-Version: 1.9.0.qualifier
Fragment-Host: org.openhab.binding.rfxcom
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-Vendor: openHAB.org
Require-Bundle: org.junit;bundle-version="4.8.1"
Bundle-ClassPath: .
Import-Package: org.openhab.core.library.items
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source.. = src/test/java/
output.. = target/classes/
bin.includes = META-INF/


34 changes: 34 additions & 0 deletions bundles/binding/org.openhab.binding.rfxcom.test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<parent>
<groupId>org.openhab.bundles</groupId>
<artifactId>binding</artifactId>
<version>1.9.0-SNAPSHOT</version>
</parent>

<properties>
<bundle.symbolicName>org.openhab.binding.rfxcom.test</bundle.symbolicName>
<bundle.namespace>org.openhab.binding.rfxcom.test</bundle.namespace>
</properties>

<modelVersion>4.0.0</modelVersion>
<groupId>org.openhab.binding</groupId>
<artifactId>org.openhab.binding.rfxcom.test</artifactId>

<name>openHAB rfxcom Binding Tests</name>

<packaging>eclipse-test-plugin</packaging>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Copyright (c) 2010-2016, openHAB.org and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.openhab.binding.rfxcom.internal.messages;

import static org.junit.Assert.*;

import org.junit.Test;
import org.junit.runner.RunWith;

import org.openhab.binding.rfxcom.internal.RFXComException;
import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType;

public class RFXComMessagesTest {

@Test
public void checkNotImplementedPackets() throws Exception {
String errors = "";

// Currently there are a lot of not implemented messages,group together and throw a single error message listing all
for (PacketType p : PacketType.values()) {
if (p != PacketType.UNKNOWN) {
try {
RFXComMessageInterface intf = RFXComMessageFactory.getMessageInterface(p);
} catch (Exception e) {
errors += "\n\t" + e.getMessage();
}
}
}
if (errors.length() > 0) {
throw new Exception("Packet messages not implemented : " + errors);
}
}


@Test
public void checkDecodeMessage() throws Exception {
String errors = "";

for (PacketType p : PacketType.values()) {
if (p != PacketType.UNKNOWN) {
try {
RFXComMessageInterface intf = RFXComMessageFactory.getMessageInterface(p);
try {
// This is a place where its easy to make mistakes in coding, and can result in errors, normally array bounds errors
byte[] message = intf.decodeMessage();
if (message[0] != (message.length-1)) {
errors += "\n\t" + intf.getClass().getName() + " wrong packet length";
}

} catch (Throwable t) {
errors += "\n\t" + intf.getClass().getName() + " " + t.getClass().getName() + " " + t.getMessage();
}
} catch (Exception e) {
// already checked in checkNotImplementedPackets()
}
}
}
if (errors.length() > 0) {
throw new Exception("Errors in decodeMessage :" + errors);
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Copyright (c) 2010-2016, openHAB.org and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.openhab.binding.rfxcom.internal.messages;

import static org.junit.Assert.*;

import javax.xml.bind.DatatypeConverter;


import org.junit.Test;
import org.junit.runner.RunWith;

import org.openhab.binding.rfxcom.internal.RFXComException;

public class RFXComTemperatureHumidityMessageTest {


private void testMessage(String hexMsg,
RFXComTemperatureHumidityMessage.SubType subType, int seqNbr, int sensorId,
double temperature, byte humidity,
RFXComTemperatureHumidityMessage.HumidityStatus humidityStatus, byte signalLevel, byte batteryLevel) throws RFXComException {
final RFXComTemperatureHumidityMessage msg = (RFXComTemperatureHumidityMessage)RFXComMessageFactory.getMessageInterface(DatatypeConverter.parseHexBinary(hexMsg));
assertEquals("SubType", subType, msg.subType);
assertEquals("Seq Number", seqNbr, (short) (msg.seqNbr & 0xFF));
assertEquals("Sensor Id", sensorId, msg.sensorId);
assertEquals("Temperature", temperature, msg.temperature, 0.01);
assertEquals("Humidity", humidity, msg.humidity);
assertEquals("Humidity Status", humidityStatus, msg.humidityStatus);
assertEquals("Signal Level", signalLevel, msg.signalLevel);
assertEquals("Battery Level", batteryLevel, msg.batteryLevel);
}

@Test
public void testSomeMessages() throws RFXComException {
testMessage("0A5201800F0201294C0349", RFXComTemperatureHumidityMessage.SubType.THGN122_123_132_THGR122_228_238_268, 128, 3842, 29.7, (byte)76, RFXComTemperatureHumidityMessage.HumidityStatus.WET, (byte)4, (byte)9);
//TODO add more real messages
}

}

0 comments on commit 62ea8a4

Please sign in to comment.