forked from openhab/openhab1-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openhab#4034 from ivanfmartinez/rfxcom_test5
RFXCOM test binding
- Loading branch information
Showing
10 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
2 changes: 2 additions & 0 deletions
2
bundles/binding/org.openhab.binding.rfxcom.test/.settings/org.eclipse.core.resources.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eclipse.preferences.version=1 | ||
encoding/<project>=UTF-8 |
11 changes: 11 additions & 0 deletions
11
bundles/binding/org.openhab.binding.rfxcom.test/.settings/org.eclipse.jdt.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
4 changes: 4 additions & 0 deletions
4
bundles/binding/org.openhab.binding.rfxcom.test/.settings/org.eclipse.m2e.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
11 changes: 11 additions & 0 deletions
11
bundles/binding/org.openhab.binding.rfxcom.test/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
5 changes: 5 additions & 0 deletions
5
bundles/binding/org.openhab.binding.rfxcom.test/build.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
69 changes: 69 additions & 0 deletions
69
...m.test/src/test/java/org/openhab/binding/rfxcom/internal/messages/RFXComMessagesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
|
45 changes: 45 additions & 0 deletions
45
...va/org/openhab/binding/rfxcom/internal/messages/RFXComTemperatureHumidityMessageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |