DanaRS tests
This commit is contained in:
parent
7be6a7b7a6
commit
44edc7ce96
|
@ -2,8 +2,6 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
|||
|
||||
import com.cozmo.danar.util.BleCommandUtil
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.L
|
||||
import info.nightscout.androidaps.logging.L.isEnabled
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
|
||||
|
||||
|
@ -94,24 +92,22 @@ class DanaRS_Packet_Bolus_Get_CIR_CF_Array(
|
|||
danaRPump.nightCF = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100.0
|
||||
}
|
||||
if (danaRPump.units < 0 || danaRPump.units > 1) failed = true
|
||||
if (isEnabled(L.PUMPCOMM)) {
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Language: $language")
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Pump units: " + if (danaRPump.units == DanaRPump.UNITS_MGDL) "MGDL" else "MMOL")
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Current pump morning CIR: " + danaRPump.morningCIR)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Current pump morning CF: " + danaRPump.morningCF)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Current pump afternoon CIR: " + danaRPump.afternoonCIR)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Current pump afternoon CF: " + danaRPump.afternoonCF)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Current pump evening CIR: " + danaRPump.eveningCIR)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Current pump evening CF: " + danaRPump.eveningCF)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Current pump night CIR: " + danaRPump.nightCIR)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Current pump night CF: " + danaRPump.nightCF)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "cir02: $cir02")
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "cir04: $cir04")
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "cir06: $cir06")
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "cf02: $cf02")
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "cf04: $cf04")
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "cf06: $cf06")
|
||||
}
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Language: $language")
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Pump units: " + if (danaRPump.units == DanaRPump.UNITS_MGDL) "MGDL" else "MMOL")
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Current pump morning CIR: " + danaRPump.morningCIR)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Current pump morning CF: " + danaRPump.morningCF)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Current pump afternoon CIR: " + danaRPump.afternoonCIR)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Current pump afternoon CF: " + danaRPump.afternoonCF)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Current pump evening CIR: " + danaRPump.eveningCIR)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Current pump evening CF: " + danaRPump.eveningCF)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Current pump night CIR: " + danaRPump.nightCIR)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "Current pump night CF: " + danaRPump.nightCF)
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "cir02: $cir02")
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "cir04: $cir04")
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "cir06: $cir06")
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "cf02: $cf02")
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "cf04: $cf04")
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "cf06: $cf06")
|
||||
}
|
||||
|
||||
override fun getFriendlyName(): String {
|
||||
|
|
|
@ -21,6 +21,14 @@ open class DanaRSTestBase : TestBase() {
|
|||
return ret
|
||||
}
|
||||
|
||||
fun createArray(length: Int, fillWith: Double): Array<Double> {
|
||||
val ret = Array(length) {0.0}
|
||||
for (i in 0 until length) {
|
||||
ret[i] = fillWith
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
danaRPump = DanaRPump(aapsLogger, sp)
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Rumen on 01.08.2018
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class DanaRS_Packet_Basal_Set_Basal_RateTest {
|
||||
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
|
||||
// test message decoding
|
||||
DanaRS_Packet_Basal_Set_Basal_Rate packet = new DanaRS_Packet_Basal_Set_Basal_Rate(createArray(24, 5));
|
||||
byte[] requested = packet.getRequestParams();
|
||||
byte lookingFor = (byte) ((5 * 100) & 0xff);
|
||||
assertEquals(lookingFor, requested[24]);
|
||||
lookingFor = (byte) ((500 >>> 8) & 0xff);
|
||||
assertEquals(lookingFor, requested[25]);
|
||||
packet.handleMessage(createArray(3, (byte) 0));
|
||||
assertEquals(false, packet.failed);
|
||||
packet.handleMessage(createArray(3, (byte) 1));
|
||||
assertEquals(true, packet.failed);
|
||||
|
||||
assertEquals("BASAL__SET_BASAL_RATE", packet.getFriendlyName());
|
||||
}
|
||||
|
||||
double[] createArray(int length, double fillWith) {
|
||||
double[] ret = new double[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
ret[i] = fillWith;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
byte[] createArray(int length, byte fillWith) {
|
||||
byte[] ret = new byte[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
ret[i] = fillWith;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest()
|
||||
class DanaRS_Packet_Basal_Set_Basal_RateTest : DanaRSTestBase() {
|
||||
|
||||
@Test fun runTest() {
|
||||
// test message decoding
|
||||
val packet = DanaRS_Packet_Basal_Set_Basal_Rate(aapsLogger, createArray(24, 5.0))
|
||||
val requested = packet.requestParams
|
||||
var lookingFor = (5 * 100 and 0xff).toByte()
|
||||
Assert.assertEquals(lookingFor, requested[24])
|
||||
lookingFor = (500 ushr 8 and 0xff).toByte()
|
||||
Assert.assertEquals(lookingFor, requested[25])
|
||||
packet.handleMessage(createArray(3, 0.toByte()))
|
||||
Assert.assertEquals(false, packet.failed)
|
||||
packet.handleMessage(createArray(3, 1.toByte()))
|
||||
Assert.assertEquals(true, packet.failed)
|
||||
Assert.assertEquals("BASAL__SET_BASAL_RATE", packet.friendlyName)
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Rumen on 01.08.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest {
|
||||
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
|
||||
DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal packet = new DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal();
|
||||
|
||||
// test message decoding
|
||||
packet.handleMessage(createArray(3,(byte) 0));
|
||||
assertEquals(false, packet.failed);
|
||||
packet.handleMessage(createArray(3,(byte) 1));
|
||||
assertEquals(true, packet.failed);
|
||||
|
||||
assertEquals("BASAL__CANCEL_TEMPORARY_BASAL", packet.getFriendlyName());
|
||||
}
|
||||
|
||||
byte[] createArray(int length, byte fillWith) {
|
||||
byte[] ret = new byte[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
ret[i] = fillWith;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest()
|
||||
class DanaRS_Packet_Basal_Set_Cancel_Temporary_BasalTest : DanaRSTestBase() {
|
||||
|
||||
@Test fun runTest() {
|
||||
val packet = DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger)
|
||||
// test message decoding
|
||||
packet.handleMessage(createArray(3, 0.toByte()))
|
||||
Assert.assertEquals(false, packet.failed)
|
||||
packet.handleMessage(createArray(3, 1.toByte()))
|
||||
Assert.assertEquals(true, packet.failed)
|
||||
Assert.assertEquals("BASAL__CANCEL_TEMPORARY_BASAL", packet.friendlyName)
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Rumen on 06.08.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class DanaRS_Packet_Basal_Set_Profile_Basal_RateTest {
|
||||
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
DanaRS_Packet_Basal_Set_Profile_Basal_Rate packet = new DanaRS_Packet_Basal_Set_Profile_Basal_Rate(1, createArray(24,1));
|
||||
|
||||
// test params
|
||||
byte[] testparams =packet.getRequestParams();
|
||||
// is profile 1
|
||||
assertEquals((byte) 1, testparams[0]);
|
||||
// is value 100
|
||||
assertEquals((byte) 100, testparams[3]);
|
||||
|
||||
|
||||
// test message decoding
|
||||
packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0});
|
||||
assertEquals(false, packet.failed);
|
||||
packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 1});
|
||||
assertEquals(true, packet.failed);
|
||||
|
||||
assertEquals("BASAL__SET_PROFILE_BASAL_RATE", packet.getFriendlyName());
|
||||
}
|
||||
|
||||
byte[] createArray(int length, byte fillWith){
|
||||
byte[] ret = new byte[length];
|
||||
for(int i = 0; i<length; i++){
|
||||
ret[i] = fillWith;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
double[] createArray(int length, double fillWith){
|
||||
double[] ret = new double[length];
|
||||
for(int i = 0; i<length; i++){
|
||||
ret[i] = fillWith;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest()
|
||||
class DanaRS_Packet_Basal_Set_Profile_Basal_RateTest : DanaRSTestBase() {
|
||||
|
||||
@Test fun runTest() {
|
||||
val packet = DanaRS_Packet_Basal_Set_Profile_Basal_Rate(aapsLogger, 1, createArray(24, 1.0))
|
||||
// test params
|
||||
val testparams = packet.requestParams
|
||||
// is profile 1
|
||||
Assert.assertEquals(1.toByte(), testparams[0])
|
||||
// is value 100
|
||||
Assert.assertEquals(100.toByte(), testparams[3])
|
||||
// test message decoding
|
||||
packet.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte()))
|
||||
Assert.assertEquals(false, packet.failed)
|
||||
packet.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 1.toByte()))
|
||||
Assert.assertEquals(true, packet.failed)
|
||||
Assert.assertEquals("BASAL__SET_PROFILE_BASAL_RATE", packet.friendlyName)
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Rumen on 06.08.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class DanaRS_Packet_Basal_Set_Profile_NumberTest {
|
||||
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
DanaRS_Packet_Basal_Set_Profile_Number packet = new DanaRS_Packet_Basal_Set_Profile_Number(1);
|
||||
|
||||
// test params
|
||||
byte[] testparams = packet.getRequestParams();
|
||||
// is profile 1
|
||||
assertEquals((byte) 1, testparams[0]);
|
||||
|
||||
// test message decoding
|
||||
packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0});
|
||||
assertEquals(false, packet.failed);
|
||||
packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 1});
|
||||
assertEquals(true, packet.failed);
|
||||
|
||||
assertEquals("BASAL__SET_PROFILE_NUMBER", packet.getFriendlyName());
|
||||
}
|
||||
|
||||
byte[] createArray(int length, byte fillWith){
|
||||
byte[] ret = new byte[length];
|
||||
for(int i = 0; i<length; i++){
|
||||
ret[i] = fillWith;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
double[] createArray(int length, double fillWith){
|
||||
double[] ret = new double[length];
|
||||
for(int i = 0; i<length; i++){
|
||||
ret[i] = fillWith;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest()
|
||||
class DanaRS_Packet_Basal_Set_Profile_NumberTest : DanaRSTestBase() {
|
||||
|
||||
@Test fun runTest() {
|
||||
val packet = DanaRS_Packet_Basal_Set_Profile_Number(aapsLogger, 1)
|
||||
// test params
|
||||
val testparams = packet.requestParams
|
||||
// is profile 1
|
||||
Assert.assertEquals(1.toByte(), testparams[0])
|
||||
// test message decoding
|
||||
packet.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte()))
|
||||
Assert.assertEquals(false, packet.failed)
|
||||
packet.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 1.toByte()))
|
||||
Assert.assertEquals(true, packet.failed)
|
||||
Assert.assertEquals("BASAL__SET_PROFILE_NUMBER", packet.friendlyName)
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Rumen on 01.08.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class DanaRS_Packet_Basal_Set_Suspend_OffTest {
|
||||
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
|
||||
DanaRS_Packet_Basal_Set_Suspend_Off packet = new DanaRS_Packet_Basal_Set_Suspend_Off();
|
||||
|
||||
// test message decoding
|
||||
packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0});
|
||||
assertEquals(false, packet.failed);
|
||||
packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 1});
|
||||
assertEquals(true, packet.failed);
|
||||
|
||||
assertEquals("BASAL__SET_SUSPEND_OFF", packet.getFriendlyName());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest()
|
||||
class DanaRS_Packet_Basal_Set_Suspend_OffTest : DanaRSTestBase() {
|
||||
|
||||
@Test fun runTest() {
|
||||
val packet = DanaRS_Packet_Basal_Set_Suspend_Off(aapsLogger)
|
||||
// test message decoding
|
||||
packet.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte()))
|
||||
Assert.assertEquals(false, packet.failed)
|
||||
packet.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 1.toByte()))
|
||||
Assert.assertEquals(true, packet.failed)
|
||||
Assert.assertEquals("BASAL__SET_SUSPEND_OFF", packet.friendlyName)
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Rumen on 01.08.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class DanaRS_Packet_Basal_Set_Suspend_OnTest {
|
||||
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
|
||||
DanaRS_Packet_Basal_Set_Suspend_On packet = new DanaRS_Packet_Basal_Set_Suspend_On();
|
||||
|
||||
// test message decoding
|
||||
packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0});
|
||||
assertEquals(false, packet.failed);
|
||||
packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 1});
|
||||
assertEquals(true, packet.failed);
|
||||
|
||||
assertEquals("BASAL__SET_SUSPEND_ON", packet.getFriendlyName());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest()
|
||||
class DanaRS_Packet_Basal_Set_Suspend_OnTest : DanaRSTestBase() {
|
||||
|
||||
@Test fun runTest() {
|
||||
val packet = DanaRS_Packet_Basal_Set_Suspend_On(aapsLogger)
|
||||
// test message decoding
|
||||
packet.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte()))
|
||||
Assert.assertEquals(false, packet.failed)
|
||||
packet.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 1.toByte()))
|
||||
Assert.assertEquals(true, packet.failed)
|
||||
Assert.assertEquals("BASAL__SET_SUSPEND_ON", packet.friendlyName)
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Rumen on 02.08.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@SuppressStaticInitializationFor("info.nightscout.androidaps.logging.L")
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class DanaRS_Packet_Basal_Set_Temporary_BasalTest extends DanaRS_Packet_Basal_Set_Temporary_Basal {
|
||||
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
|
||||
DanaRS_Packet_Basal_Set_Temporary_Basal testPacket = new DanaRS_Packet_Basal_Set_Temporary_Basal(50, 20);
|
||||
// params
|
||||
byte[] params = testPacket.getRequestParams();
|
||||
// is ratio 50
|
||||
assertEquals(50, params[0]);
|
||||
// is duration 20
|
||||
assertEquals(20, params[1]);
|
||||
|
||||
// test message decoding
|
||||
handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0});
|
||||
assertEquals(false, failed);
|
||||
handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 1});
|
||||
assertEquals(true, failed);
|
||||
|
||||
assertEquals("BASAL__SET_TEMPORARY_BASAL", getFriendlyName());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest()
|
||||
class DanaRS_Packet_Basal_Set_Temporary_BasalTest : DanaRSTestBase() {
|
||||
|
||||
@Test fun runTest() {
|
||||
val testPacket = DanaRS_Packet_Basal_Set_Temporary_Basal(aapsLogger, 50, 20)
|
||||
// params
|
||||
val params = testPacket.requestParams
|
||||
// is ratio 50
|
||||
Assert.assertEquals(50.toByte(), params[0])
|
||||
// is duration 20
|
||||
Assert.assertEquals(20.toByte(), params[1])
|
||||
// test message decoding
|
||||
testPacket.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte()))
|
||||
Assert.assertEquals(false, testPacket.failed)
|
||||
testPacket.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 1.toByte()))
|
||||
Assert.assertEquals(true, testPacket.failed)
|
||||
Assert.assertEquals("BASAL__SET_TEMPORARY_BASAL", testPacket.friendlyName)
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Rumen on 01.08.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class DanaRS_Packet_Bolus_Get_Bolus_OptionTest {
|
||||
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
|
||||
DanaRS_Packet_Bolus_Get_Bolus_Option packet = new DanaRS_Packet_Bolus_Get_Bolus_Option();
|
||||
|
||||
// test message decoding
|
||||
DanaRPump pump = DanaRPump.getInstance();
|
||||
//if dataArray is 1 pump.isExtendedBolusEnabled should be true
|
||||
packet.handleMessage(createArray(21,(byte) 1));
|
||||
assertEquals(false, packet.failed);
|
||||
//Are options saved to pump
|
||||
assertEquals(false, !pump.isExtendedBolusEnabled);
|
||||
assertEquals(1, pump.bolusCalculationOption);
|
||||
assertEquals(1, pump.missedBolusConfig);
|
||||
|
||||
packet.handleMessage(createArray(21,(byte) 0));
|
||||
assertEquals(true, packet.failed);
|
||||
//Are options saved to pump
|
||||
assertEquals(true, !pump.isExtendedBolusEnabled);
|
||||
|
||||
assertEquals("BOLUS__GET_BOLUS_OPTION", packet.getFriendlyName());
|
||||
}
|
||||
|
||||
byte[] createArray(int length, byte fillWith) {
|
||||
byte[] ret = new byte[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
ret[i] = fillWith;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest(RxBusWrapper::class)
|
||||
class DanaRS_Packet_Bolus_Get_Bolus_OptionTest : DanaRSTestBase() {
|
||||
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var rxBus: RxBusWrapper
|
||||
|
||||
@Test fun runTest() {
|
||||
val packet = DanaRS_Packet_Bolus_Get_Bolus_Option(aapsLogger, rxBus, resourceHelper, danaRPump)
|
||||
// test message decoding
|
||||
//if dataArray is 1 pump.isExtendedBolusEnabled should be true
|
||||
packet.handleMessage(createArray(21, 1.toByte()))
|
||||
Assert.assertEquals(false, packet.failed)
|
||||
//Are options saved to pump
|
||||
Assert.assertEquals(false, !danaRPump.isExtendedBolusEnabled)
|
||||
Assert.assertEquals(1, danaRPump.bolusCalculationOption)
|
||||
Assert.assertEquals(1, danaRPump.missedBolusConfig)
|
||||
packet.handleMessage(createArray(21, 0.toByte()))
|
||||
Assert.assertEquals(true, packet.failed)
|
||||
//Are options saved to pump
|
||||
Assert.assertEquals(true, !danaRPump.isExtendedBolusEnabled)
|
||||
Assert.assertEquals("BOLUS__GET_BOLUS_OPTION", packet.friendlyName)
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Rumen on 06.08.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class DanaRS_Packet_Bolus_Get_CIR_CF_ArrayTest {
|
||||
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
DanaRS_Packet_Bolus_Get_CIR_CF_Array packet = new DanaRS_Packet_Bolus_Get_CIR_CF_Array();
|
||||
|
||||
// test params
|
||||
byte[] testparams = packet.getRequestParams();
|
||||
assertEquals(null, packet.getRequestParams());
|
||||
|
||||
|
||||
// test message decoding
|
||||
packet.handleMessage(createArray(34, (byte) 0));
|
||||
// are pump units MG/DL ???
|
||||
DanaRPump testPump = DanaRPump.getInstance();
|
||||
assertEquals(DanaRPump.UNITS_MGDL, testPump.units);
|
||||
assertEquals(false, packet.failed);
|
||||
packet.handleMessage(createArray(34, (byte) 3));
|
||||
assertEquals(true, packet.failed);
|
||||
|
||||
assertEquals("BOLUS__GET_CIR_CF_ARRAY", packet.getFriendlyName());
|
||||
}
|
||||
|
||||
byte[] createArray(int length, byte fillWith){
|
||||
byte[] ret = new byte[length];
|
||||
for(int i = 0; i<length; i++){
|
||||
ret[i] = fillWith;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
double[] createArray(int length, double fillWith){
|
||||
double[] ret = new double[length];
|
||||
for(int i = 0; i<length; i++){
|
||||
ret[i] = fillWith;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||
|
||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest()
|
||||
class DanaRS_Packet_Bolus_Get_CIR_CF_ArrayTest : DanaRSTestBase() {
|
||||
|
||||
@Test fun runTest() {
|
||||
val packet = DanaRS_Packet_Bolus_Get_CIR_CF_Array(aapsLogger, danaRPump)
|
||||
// test params
|
||||
Assert.assertEquals(null, packet.requestParams)
|
||||
// test message decoding
|
||||
packet.handleMessage(createArray(34, 0.toByte()))
|
||||
// are pump units MG/DL ???
|
||||
Assert.assertEquals(DanaRPump.UNITS_MGDL, danaRPump.units)
|
||||
Assert.assertEquals(false, packet.failed)
|
||||
packet.handleMessage(createArray(34, 3.toByte()))
|
||||
Assert.assertEquals(true, packet.failed)
|
||||
Assert.assertEquals("BOLUS__GET_CIR_CF_ARRAY", packet.friendlyName)
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Rumen on 06.08.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class DanaRS_Packet_Bolus_Get_Calculation_InformationTest {
|
||||
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
DanaRS_Packet_Bolus_Get_Calculation_Information packet = new DanaRS_Packet_Bolus_Get_Calculation_Information();
|
||||
|
||||
// test params
|
||||
byte[] testparams = packet.getRequestParams();
|
||||
assertEquals(null, packet.getRequestParams());
|
||||
|
||||
|
||||
// test message decoding
|
||||
packet.handleMessage(createArray(24, (byte) 0));
|
||||
assertEquals(false, packet.failed);
|
||||
packet.handleMessage(createArray(24, (byte) 1));
|
||||
assertEquals(true, packet.failed);
|
||||
|
||||
assertEquals("BOLUS__GET_CALCULATION_INFORMATION", packet.getFriendlyName());
|
||||
}
|
||||
|
||||
byte[] createArray(int length, byte fillWith){
|
||||
byte[] ret = new byte[length];
|
||||
for(int i = 0; i<length; i++){
|
||||
ret[i] = fillWith;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
double[] createArray(int length, double fillWith){
|
||||
double[] ret = new double[length];
|
||||
for(int i = 0; i<length; i++){
|
||||
ret[i] = fillWith;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest()
|
||||
class DanaRS_Packet_Bolus_Get_Calculation_InformationTest : DanaRSTestBase() {
|
||||
|
||||
@Test fun runTest() {
|
||||
val packet = DanaRS_Packet_Bolus_Get_Calculation_Information(aapsLogger, danaRPump)
|
||||
// test params
|
||||
val testparams = packet.requestParams
|
||||
Assert.assertEquals(null, packet.requestParams)
|
||||
// test message decoding
|
||||
packet.handleMessage(createArray(24, 0.toByte()))
|
||||
Assert.assertEquals(false, packet.failed)
|
||||
packet.handleMessage(createArray(24, 1.toByte()))
|
||||
Assert.assertEquals(true, packet.failed)
|
||||
Assert.assertEquals("BOLUS__GET_CALCULATION_INFORMATION", packet.friendlyName)
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Rumen on 06.08.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_InformationTest {
|
||||
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information packet = new DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information();
|
||||
|
||||
// test params
|
||||
byte[] testparams = packet.getRequestParams();
|
||||
assertEquals(null, packet.getRequestParams());
|
||||
|
||||
|
||||
// test message decoding
|
||||
packet.handleMessage(createArray(24, (byte) 0));
|
||||
assertEquals(false, packet.failed);
|
||||
packet.handleMessage(createArray(24, (byte) 1));
|
||||
assertEquals(true, packet.failed);
|
||||
|
||||
assertEquals("BOLUS__GET_CARBOHYDRATE_CALCULATION_INFORMATION", packet.getFriendlyName());
|
||||
}
|
||||
|
||||
byte[] createArray(int length, byte fillWith){
|
||||
byte[] ret = new byte[length];
|
||||
for(int i = 0; i<length; i++){
|
||||
ret[i] = fillWith;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
double[] createArray(int length, double fillWith){
|
||||
double[] ret = new double[length];
|
||||
for(int i = 0; i<length; i++){
|
||||
ret[i] = fillWith;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest()
|
||||
class DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_InformationTest : DanaRSTestBase() {
|
||||
|
||||
@Test fun runTest() {
|
||||
val packet = DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information(aapsLogger, danaRPump)
|
||||
// test params
|
||||
val testparams = packet.requestParams
|
||||
Assert.assertEquals(null, packet.requestParams)
|
||||
// test message decoding
|
||||
packet.handleMessage(createArray(24, 0.toByte()))
|
||||
Assert.assertEquals(false, packet.failed)
|
||||
packet.handleMessage(createArray(24, 1.toByte()))
|
||||
Assert.assertEquals(true, packet.failed)
|
||||
Assert.assertEquals("BOLUS__GET_CARBOHYDRATE_CALCULATION_INFORMATION", packet.friendlyName)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue