Skip to content
This repository has been archived by the owner on Aug 2, 2019. It is now read-only.

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markusressel committed Mar 7, 2016
1 parent 2145982 commit ec78bc9
Show file tree
Hide file tree
Showing 45 changed files with 3,864 additions and 12 deletions.
1 change: 0 additions & 1 deletion LocaleApi/build.gradle
Expand Up @@ -46,7 +46,6 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// testCompile 'junit:junit:4.12'
// compile 'com.android.support:appcompat-v7:+'
// compile project(path: ':Shared')
}
1 change: 1 addition & 0 deletions Shared/build.gradle
Expand Up @@ -48,4 +48,5 @@ dependencies {
compile 'de.mindpipe.android:android-logging-log4j:1.0.3'
compile fileTree(include: ['*.jar'], dir: 'libraries')
compile 'com.android.support:appcompat-v7:23.2.0'
testCompile 'junit:junit:4.12'
}
Expand Up @@ -16,16 +16,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.twofortyfouram.locale;
package eu.power_switch;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public abstract class ApplicationTest extends ApplicationTestCase<Application> {

public ApplicationTest() {
super(Application.class);
}

}
@@ -0,0 +1,40 @@
/*
* PowerSwitch by Max Rosin & Markus Ressel
* Copyright (C) 2015 Markus Ressel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package eu.power_switch.obj;

import eu.power_switch.ApplicationTest;
import eu.power_switch.obj.gateway.BrematicGWY433;
import eu.power_switch.obj.gateway.ConnAir;
import eu.power_switch.obj.gateway.Gateway;
import eu.power_switch.obj.gateway.ITGW433;

/**
* Created by Markus on 07.03.2016.
*/
public abstract class ReceiverTest extends ApplicationTest {

protected static Gateway connAir = new ConnAir((long) 0, true, "Gateway", "v0.1", "address", 0);
protected static Gateway itgw = new ITGW433((long) 0, true, "Gateway", "v0.1", "address", 0);
protected static Gateway brematicGWY433 = new BrematicGWY433((long) 0, true, "Gateway", "v0.1", "address", 0);

protected Gateway[] gateways = new Gateway[]{connAir, itgw, brematicGWY433};

protected Class<?>[] argClassesGetSignal = new Class[]{Gateway.class, String.class};

}
@@ -0,0 +1,177 @@
/*
* PowerSwitch by Max Rosin & Markus Ressel
* Copyright (C) 2015 Markus Ressel
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package eu.power_switch.obj.device.bat;

import org.junit.Assert;
import org.junit.Test;

import java.lang.reflect.Method;
import java.util.LinkedList;

import eu.power_switch.R;
import eu.power_switch.obj.ReceiverTest;
import eu.power_switch.obj.receiver.device.bat.RC3500_A_IP44_DE;

/**
* Created by Markus on 08.08.2015.
*/
public class RC3500_A_IP44_DE_Test extends ReceiverTest {

private static RC3500_A_IP44_DE receiver;

@Test
public void testCodeGeneration0000000000() throws Exception {
LinkedList<Boolean> dips = new LinkedList<>();
dips.add(false); // 1
dips.add(false); // 2
dips.add(false); // 3
dips.add(false); // 4
dips.add(false); // 5

dips.add(false); // A
dips.add(false); // B
dips.add(false); // C
dips.add(false); // D
dips.add(false); // E

receiver = new RC3500_A_IP44_DE(getContext(), (long) 0, "Name", dips, (long) 0);

Method method = receiver.getClass().getDeclaredMethod("getSignal", argClassesGetSignal);
method.setAccessible(true);
Object[] argObjects = new Object[]{connAir, getContext().getString(R.string.on)};
String generatedMessage = (String) method.invoke(receiver, argObjects);

// ON
String expectedMessage = "TXP:0,0,10,5600,350,25,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,1,3,1,3,3,1,1,14;";
Assert.assertEquals(expectedMessage, generatedMessage);

argObjects = new Object[]{connAir, getContext().getString(R.string.off)};
generatedMessage = (String) method.invoke(receiver, argObjects);

// OFF
expectedMessage = "TXP:0,0,10,5600,350,25,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,1,3,1,14;";
Assert.assertEquals(expectedMessage, generatedMessage);
}

@Test
public void testCodeGeneration1000000000() throws Exception {
LinkedList<Boolean> dips = new LinkedList<>();
dips.add(true); // 1
dips.add(false); // 2
dips.add(false); // 3
dips.add(false); // 4
dips.add(false); // 5

dips.add(false); // A
dips.add(false); // B
dips.add(false); // C
dips.add(false); // D
dips.add(false); // E

receiver = new RC3500_A_IP44_DE(getContext(), (long) 0, "Name", dips, (long) 0);

String methodName = "getSignal";
Method method = receiver.getClass().getDeclaredMethod(methodName, argClassesGetSignal);
method.setAccessible(true);
Object[] argObjects = new Object[]{connAir, getContext().getString(R.string.on)};
String generatedMessage = (String) method.invoke(receiver, argObjects);

// ON
String expectedMessage = "TXP:0,0,10,5600,350,25,1,3,1,3,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,1,3,1,3,3,1,1,14;";
Assert.assertEquals(expectedMessage, generatedMessage);

argObjects = new Object[]{connAir, getContext().getString(R.string.off)};
generatedMessage = (String) method.invoke(receiver, argObjects);

// OFF
expectedMessage = "TXP:0,0,10,5600,350,25,1,3,1,3,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,1,3,1,14;";
Assert.assertEquals(expectedMessage, generatedMessage);
}

@Test
public void testCodeGeneration1000010000() throws Exception {
LinkedList<Boolean> dips = new LinkedList<>();
dips.add(true); // 1
dips.add(false); // 2
dips.add(false); // 3
dips.add(false); // 4
dips.add(false); // 5

dips.add(true); // A
dips.add(false); // B
dips.add(false); // C
dips.add(false); // D
dips.add(false); // E

receiver = new RC3500_A_IP44_DE(getContext(), (long) 0, "Name", dips, (long) 0);

String methodName = "getSignal";
Method method = receiver.getClass().getDeclaredMethod(methodName, argClassesGetSignal);
method.setAccessible(true);
Object[] argObjects = new Object[]{connAir, getContext().getString(R.string.on)};
String generatedMessage = (String) method.invoke(receiver, argObjects);

// ON
String expectedMessage = "TXP:0,0,10,5600,350,25,1,3,1,3,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,1,3,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,1,3,1,3,3,1,1,14;";
Assert.assertEquals(expectedMessage, generatedMessage);

argObjects = new Object[]{connAir, getContext().getString(R.string.off)};
generatedMessage = (String) method.invoke(receiver, argObjects);

// OFF
expectedMessage = "TXP:0,0,10,5600,350,25,1,3,1,3,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,1,3,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,1,3,1,14;";
Assert.assertEquals(expectedMessage, generatedMessage);
}

@Test
public void testCodeGeneration1111111111() throws Exception {
LinkedList<Boolean> dips = new LinkedList<>();
dips.add(true); // 1
dips.add(true); // 2
dips.add(true); // 3
dips.add(true); // 4
dips.add(true); // 5

dips.add(true); // A
dips.add(true); // B
dips.add(true); // C
dips.add(true); // D
dips.add(true); // E

receiver = new RC3500_A_IP44_DE(getContext(), (long) 0, "Name", dips, (long) 0);

String methodName = "getSignal";
Method method = receiver.getClass().getDeclaredMethod(methodName, argClassesGetSignal);
method.setAccessible(true);
Object[] argObjects = new Object[]{connAir, getContext().getString(R.string.on)};
String generatedMessage = (String) method.invoke(receiver, argObjects);

// ON
String expectedMessage = "TXP:0,0,10,5600,350,25,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,3,1,1,14;";
Assert.assertEquals(expectedMessage, generatedMessage);

argObjects = new Object[]{connAir, getContext().getString(R.string.off)};
generatedMessage = (String) method.invoke(receiver, argObjects);

// OFF
expectedMessage = "TXP:0,0,10,5600,350,25,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,3,1,1,3,1,3,1,14;";
Assert.assertEquals(expectedMessage, generatedMessage);
}

}

0 comments on commit ec78bc9

Please sign in to comment.