commit
0a545dc92b
17 changed files with 540 additions and 20 deletions
|
@ -397,7 +397,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
QueryBuilder<BgReading, Long> queryBuilder = daoBgReadings.queryBuilder();
|
||||
queryBuilder.orderBy("date", false);
|
||||
queryBuilder.limit(1L);
|
||||
queryBuilder.where().gt("value", 38).and().eq("isValid", true);
|
||||
queryBuilder.where().ge("value", 39).and().eq("isValid", true);
|
||||
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
|
||||
bgList = daoBgReadings.query(preparedQuery);
|
||||
|
||||
|
@ -435,7 +435,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
QueryBuilder<BgReading, Long> queryBuilder = daoBgreadings.queryBuilder();
|
||||
queryBuilder.orderBy("date", ascending);
|
||||
Where where = queryBuilder.where();
|
||||
where.ge("date", mills).and().gt("value", 38).and().eq("isValid", true);
|
||||
where.ge("date", mills).and().ge("value", 39).and().eq("isValid", true);
|
||||
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
|
||||
bgReadings = daoBgreadings.query(preparedQuery);
|
||||
return bgReadings;
|
||||
|
@ -452,7 +452,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
QueryBuilder<BgReading, Long> queryBuilder = daoBgreadings.queryBuilder();
|
||||
queryBuilder.orderBy("date", ascending);
|
||||
Where where = queryBuilder.where();
|
||||
where.between("date", start, end).and().gt("value", 38).and().eq("isValid", true);
|
||||
where.between("date", start, end).and().ge("value", 39).and().eq("isValid", true);
|
||||
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
|
||||
bgReadings = daoBgreadings.query(preparedQuery);
|
||||
return bgReadings;
|
||||
|
|
|
@ -270,7 +270,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
if (profile == null) {
|
||||
editBg.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false, bgTextWatcher);
|
||||
editTemptarget.setParams(bg, 0d, 500d, 0.1d, new DecimalFormat("0.0"), false);
|
||||
} else if (profile.getUnits().equals(Constants.MMOL)) {
|
||||
} else if (units.equals(Constants.MMOL)) {
|
||||
editBg.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false, bgTextWatcher);
|
||||
editTemptarget.setParams(bg, 0d, 30d, 0.1d, new DecimalFormat("0.0"), false);
|
||||
} else {
|
||||
|
@ -279,7 +279,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
}
|
||||
|
||||
sensorRadioButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
Double bg1 = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, profile.getUnits());
|
||||
Double bg1 = Profile.fromMgdlToUnits(GlucoseStatus.getGlucoseStatusData() != null ? GlucoseStatus.getGlucoseStatusData().glucose : 0d, units);
|
||||
if (savedInstanceState != null && savedInstanceState.getDouble("editBg") != bg1) {
|
||||
editBg.setValue(savedInstanceState.getDouble("editBg"));
|
||||
} else {
|
||||
|
@ -459,7 +459,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
if ((data.size() > 0) &&
|
||||
(data.get(0).date > millis - 7 * 60 * 1000L) &&
|
||||
(data.get(0).date < millis + 7 * 60 * 1000L)) {
|
||||
editBg.setValue(Profile.fromMgdlToUnits(data.get(0).value, profile != null ? profile.getUnits() : Constants.MGDL));
|
||||
editBg.setValue(Profile.fromMgdlToUnits(data.get(0).value, units));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -736,8 +736,8 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
.reason(reason)
|
||||
.source(Source.USER);
|
||||
if (tempTarget.durationInMinutes != 0) {
|
||||
tempTarget.low(Profile.toMgdl(targetBottom, profile.getUnits()))
|
||||
.high(Profile.toMgdl(targetTop, profile.getUnits()));
|
||||
tempTarget.low(Profile.toMgdl(targetBottom, units))
|
||||
.high(Profile.toMgdl(targetTop, units));
|
||||
} else {
|
||||
tempTarget.low(0).high(0);
|
||||
}
|
||||
|
|
|
@ -307,6 +307,11 @@ public class APSResult {
|
|||
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
||||
|
||||
if (profile == null) {
|
||||
log.error("FALSE: No Profile");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (usePercent) {
|
||||
if (activeTemp == null && percent == 100) {
|
||||
if (L.isEnabled(L.APS))
|
||||
|
|
|
@ -144,9 +144,9 @@ public class BLEComm {
|
|||
|
||||
if (L.isEnabled(L.PUMPBTCOMM))
|
||||
log.debug("Trying to create a new connection from: " + from);
|
||||
mBluetoothDeviceName = device.getName();
|
||||
mBluetoothGatt = device.connectGatt(service.getApplicationContext(), false, mGattCallback);
|
||||
setCharacteristicNotification(getUARTReadBTGattChar(), true);
|
||||
mBluetoothDeviceName = device.getName();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -663,7 +663,7 @@ public class BLEComm {
|
|||
private void SendPumpCheck() {
|
||||
// 1st message sent to pump after connect
|
||||
String devicename = getConnectDeviceName();
|
||||
if(devicename == null || devicename == ""){
|
||||
if(devicename == null || devicename.equals("")){
|
||||
Notification n = new Notification(Notification.DEVICENOTPAIRED, MainApp.gs(R.string.pairfirst), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(n));
|
||||
return;
|
||||
|
|
|
@ -22,7 +22,7 @@ public class JsonHelper {
|
|||
public static Object safeGetObject(JSONObject json, String fieldName, Object defaultValue) {
|
||||
Object result = defaultValue;
|
||||
|
||||
if (json.has(fieldName)) {
|
||||
if (json != null && json.has(fieldName)) {
|
||||
try {
|
||||
result = json.get(fieldName);
|
||||
} catch (JSONException ignored) {
|
||||
|
@ -36,7 +36,7 @@ public class JsonHelper {
|
|||
public static String safeGetString(JSONObject json, String fieldName) {
|
||||
String result = null;
|
||||
|
||||
if (json.has(fieldName)) {
|
||||
if (json != null && json.has(fieldName)) {
|
||||
try {
|
||||
result = json.getString(fieldName);
|
||||
} catch (JSONException ignored) {
|
||||
|
@ -49,7 +49,7 @@ public class JsonHelper {
|
|||
public static String safeGetString(JSONObject json, String fieldName, String defaultValue) {
|
||||
String result = defaultValue;
|
||||
|
||||
if (json.has(fieldName)) {
|
||||
if (json != null && json.has(fieldName)) {
|
||||
try {
|
||||
result = json.getString(fieldName);
|
||||
} catch (JSONException ignored) {
|
||||
|
@ -62,7 +62,7 @@ public class JsonHelper {
|
|||
public static double safeGetDouble(JSONObject json, String fieldName) {
|
||||
double result = 0d;
|
||||
|
||||
if (json.has(fieldName)) {
|
||||
if (json != null && json.has(fieldName)) {
|
||||
try {
|
||||
result = json.getDouble(fieldName);
|
||||
} catch (JSONException ignored) {
|
||||
|
@ -75,7 +75,7 @@ public class JsonHelper {
|
|||
public static int safeGetInt(JSONObject json, String fieldName) {
|
||||
int result = 0;
|
||||
|
||||
if (json.has(fieldName)) {
|
||||
if (json != null && json.has(fieldName)) {
|
||||
try {
|
||||
result = json.getInt(fieldName);
|
||||
} catch (JSONException ignored) {
|
||||
|
@ -88,7 +88,7 @@ public class JsonHelper {
|
|||
public static long safeGetLong(JSONObject json, String fieldName) {
|
||||
long result = 0;
|
||||
|
||||
if (json.has(fieldName)) {
|
||||
if (json != null && json.has(fieldName)) {
|
||||
try {
|
||||
result = json.getLong(fieldName);
|
||||
} catch (JSONException e) {
|
||||
|
@ -101,7 +101,7 @@ public class JsonHelper {
|
|||
public static boolean safeGetBoolean(JSONObject json, String fieldName) {
|
||||
boolean result = false;
|
||||
|
||||
if (json.has(fieldName)) {
|
||||
if (json != null && json.has(fieldName)) {
|
||||
try {
|
||||
result = json.getBoolean(fieldName);
|
||||
} catch (JSONException e) {
|
||||
|
|
|
@ -1054,4 +1054,5 @@ Context | Edit Context</string>
|
|||
<string name="insulinlimitviolation">Нарушение ограничения инсулина</string>
|
||||
<string name="loop_openmode_min_change">Минимальный запрос на изменения [%]</string>
|
||||
<string name="loop_openmode_min_change_summary">Алгоритм Ипж выдаст всплывающее окно с запросом на новые изменения, только если изменение больше, чем это значение. Значение по умолчанию — 20%</string>
|
||||
<string name="pairfirst">Выполните сопряжение помпы с телефоном!</string>
|
||||
</resources>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--Generated by crowdin.com-->
|
||||
<resources>
|
||||
<string name="treatmentssafety_maxbolus_title">Max izin verilen bolus [U]</string>
|
||||
<string name="treatmentssafety_maxcarbs_title">Max izin verilen karbonhidrat [g]</string>
|
||||
<string name="treatmentssafety_maxbolus_title">Max izin verilen bolus [U]</string>
|
||||
<string name="treatmentssafety_maxcarbs_title">Max izin verilen karbonhidrat [g]</string>
|
||||
</resources>
|
||||
|
|
|
@ -24,6 +24,7 @@ import info.nightscout.androidaps.logging.L;
|
|||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentService;
|
||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||
|
@ -176,8 +177,10 @@ public class AAPSMocker {
|
|||
public static DanaRPlugin mockDanaRPlugin() {
|
||||
PowerMockito.mockStatic(DanaRPlugin.class);
|
||||
DanaRPlugin danaRPlugin = mock(DanaRPlugin.class);
|
||||
DanaRv2Plugin danaRv2Plugin = mock(DanaRv2Plugin.class);
|
||||
DanaRKoreanPlugin danaRKoreanPlugin = mock(DanaRKoreanPlugin.class);
|
||||
when(MainApp.getSpecificPlugin(DanaRPlugin.class)).thenReturn(danaRPlugin);
|
||||
when(MainApp.getSpecificPlugin(DanaRv2Plugin.class)).thenReturn(danaRv2Plugin);
|
||||
when(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).thenReturn(danaRKoreanPlugin);
|
||||
return danaRPlugin;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
package info.nightscout.androidaps.plugins.PumpdanaRv2;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Before;
|
||||
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.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.interfaces.Constraint;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||
import info.nightscout.utils.SP;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Created by Rumen on 01.08.2018
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, ToastUtils.class, Context.class, SP.class})
|
||||
public class DanaRv2PluginTest {
|
||||
DanaRv2Plugin danaRv2Plugin;
|
||||
|
||||
@Test
|
||||
public void getPlugin() {
|
||||
danaRv2Plugin.getPlugin();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basalRateShouldBeLimited() throws Exception {
|
||||
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true);
|
||||
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true);
|
||||
DanaRPump.getInstance().maxBasal = 0.8d;
|
||||
|
||||
Constraint<Double> c = new Constraint<>(Constants.REALLYHIGHBASALRATE);
|
||||
danaRv2Plugin.applyBasalConstraints(c, AAPSMocker.getValidProfile());
|
||||
Assert.assertEquals(0.8d, c.value());
|
||||
Assert.assertEquals("DanaRv2: Limiting basal rate to 0.80 U/h because of pump limit", c.getReasons());
|
||||
Assert.assertEquals("DanaRv2: Limiting basal rate to 0.80 U/h because of pump limit", c.getMostLimitedReasons());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void percentBasalRateShouldBeLimited() throws Exception {
|
||||
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true);
|
||||
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true);
|
||||
DanaRPump.getInstance().maxBasal = 0.8d;
|
||||
|
||||
Constraint<Integer> c = new Constraint<>(Constants.REALLYHIGHPERCENTBASALRATE);
|
||||
danaRv2Plugin.applyBasalPercentConstraints(c, AAPSMocker.getValidProfile());
|
||||
Assert.assertEquals((Integer) 200, c.value());
|
||||
Assert.assertEquals("DanaRv2: Limiting percent rate to 200% because of pump limit", c.getReasons());
|
||||
Assert.assertEquals("DanaRv2: Limiting percent rate to 200% because of pump limit", c.getMostLimitedReasons());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepareMocks() throws Exception {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockConfigBuilder();
|
||||
AAPSMocker.mockBus();
|
||||
AAPSMocker.mockStrings();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockCommandQueue();
|
||||
|
||||
// when(SP.getString(R.string.key_danars_address, "")).thenReturn("");
|
||||
|
||||
danaRv2Plugin = DanaRv2Plugin.getPlugin();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package info.nightscout.androidaps.plugins.PumpdanaRv2.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.PumpDanaR.comm.MessageBase;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MessageHashTable_v2;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusAPS_v2;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
/**
|
||||
* Created by Rumen Georgiev on 30.10.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class MessageHashTable_v2Test {
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
AAPSMocker.mockBus();
|
||||
|
||||
MessageHashTable_v2 packet = new MessageHashTable_v2();
|
||||
|
||||
MessageBase forTesting = new MsgStatusAPS_v2();
|
||||
MessageBase testPacket = MessageHashTable_v2.findMessage(forTesting.getCommand());
|
||||
assertEquals(0xE001, testPacket.getCommand());
|
||||
// try putting another command
|
||||
MessageBase testMessage = new MessageBase();
|
||||
testMessage.SetCommand(0xE005);
|
||||
packet.put(testMessage);
|
||||
assertEquals(0xE005, packet.findMessage(0xE005).getCommand());
|
||||
}
|
||||
|
||||
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,61 @@
|
|||
package info.nightscout.androidaps.plugins.PumpdanaRv2.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.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgCheckValue;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgCheckValue_v2;
|
||||
import info.nightscout.androidaps.plugins.Treatments.Treatment;
|
||||
import info.nightscout.androidaps.queue.CommandQueue;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class, DanaRv2Plugin.class, DanaRPlugin.class, ConfigBuilderPlugin.class, CommandQueue.class})
|
||||
public class MsgCheckValue_v2Test {
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
AAPSMocker.mockBus();
|
||||
AAPSMocker.mockDanaRPlugin();
|
||||
AAPSMocker.mockConfigBuilder();
|
||||
AAPSMocker.mockCommandQueue();
|
||||
Treatment t = new Treatment();
|
||||
MsgCheckValue_v2 packet = new MsgCheckValue_v2();
|
||||
// test message decoding
|
||||
packet.handleMessage(createArray(34, (byte) 3));
|
||||
DanaRPump pump = DanaRPump.getInstance();
|
||||
assertEquals(DanaRPump.EXPORT_MODEL, pump.model);
|
||||
}
|
||||
|
||||
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,67 @@
|
|||
package info.nightscout.androidaps.plugins.PumpdanaRv2.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.NSClientInternal.NSUpload;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgHistoryEvents_v2;
|
||||
import info.nightscout.androidaps.plugins.Treatments.Treatment;
|
||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentService;
|
||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by Rumen Georgiev on 30.10.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class, TreatmentsPlugin.class, TreatmentService.class})
|
||||
public class MsgHistoryEvents_v2Test {
|
||||
@Test
|
||||
public void runTest() throws Exception {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
AAPSMocker.mockBus();
|
||||
AAPSMocker.mockDatabaseHelper();
|
||||
AAPSMocker.mockTreatmentPlugin();
|
||||
AAPSMocker.mockTreatmentService();
|
||||
MsgHistoryEvents_v2 packet = new MsgHistoryEvents_v2();
|
||||
|
||||
// test message decoding
|
||||
//last message in history
|
||||
packet.handleMessage(createArray(34, (byte) 0xFF));
|
||||
assertEquals(true, packet.done);
|
||||
// passing an bigger number
|
||||
packet = new MsgHistoryEvents_v2();
|
||||
packet.handleMessage(createArray(34, (byte) 17));
|
||||
assertEquals(false, packet.done);
|
||||
|
||||
}
|
||||
|
||||
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,61 @@
|
|||
package info.nightscout.androidaps.plugins.PumpdanaRv2.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.PumpDanaR.DanaRPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetHistoryEntry_v2;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
/**
|
||||
* Created by Rumen Georgiev on 30.10.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class, DanaRv2Plugin.class, DanaRPlugin.class})
|
||||
public class MsgSetHistoryEntry_v2Test {
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
AAPSMocker.mockBus();
|
||||
AAPSMocker.mockDanaRPlugin();
|
||||
|
||||
MsgSetHistoryEntry_v2 initializerTest = new MsgSetHistoryEntry_v2((byte) 1, System.currentTimeMillis(), 1, 0);
|
||||
MsgSetHistoryEntry_v2 packet = new MsgSetHistoryEntry_v2();
|
||||
// test message decoding
|
||||
// != 1 fails
|
||||
packet.handleMessage(createArray(34, (byte) 2));
|
||||
assertEquals(true, packet.failed);
|
||||
// passing an bigger number
|
||||
packet = new MsgSetHistoryEntry_v2();
|
||||
packet.handleMessage(createArray(34, (byte) 1));
|
||||
assertEquals(false, packet.failed);
|
||||
}
|
||||
|
||||
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,58 @@
|
|||
package info.nightscout.androidaps.plugins.PumpdanaRv2.comm;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
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;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusAPS_v2;
|
||||
import info.nightscout.utils.SP;
|
||||
import static org.junit.Assert.*;
|
||||
/**
|
||||
* Created by Rumen Georgiev on 30.10.2018
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class MsgStatusAPS_v2Test {
|
||||
@Mock
|
||||
Context context;
|
||||
@Test
|
||||
public void runTest() throws Exception{
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
|
||||
try {
|
||||
AAPSMocker.mockTreatmentService();
|
||||
} catch (Exception e){
|
||||
|
||||
}
|
||||
MsgStatusAPS_v2 packet = new MsgStatusAPS_v2();
|
||||
// test iob
|
||||
//TODO Find a way to mock treatments plugin
|
||||
byte[] testArray = createArray(34, (byte) 7);
|
||||
double iob = MessageBase.intFromBuff(testArray, 0, 2) / 100d;
|
||||
packet.handleMessage(testArray);
|
||||
DanaRPump pump = DanaRPump.getInstance();
|
||||
assertEquals(iob, pump.iob, 0);
|
||||
|
||||
}
|
||||
|
||||
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,60 @@
|
|||
package info.nightscout.androidaps.plugins.PumpdanaRv2.comm;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
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;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusBolusExtended_v2;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||
import info.nightscout.androidaps.plugins.Treatments.Treatment;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by Rumen Georgiev on 30.10.2018
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class MsgStatusBolusExtended_v2Test {
|
||||
@Mock
|
||||
Context context;
|
||||
@Test
|
||||
public void runTest() throws Exception{
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
try {
|
||||
AAPSMocker.mockTreatmentService();
|
||||
} catch (Exception e){
|
||||
|
||||
}
|
||||
MsgStatusBolusExtended_v2 packet = new MsgStatusBolusExtended_v2();
|
||||
// test message decoding
|
||||
//TODO Find a way to mock treatments plugin
|
||||
packet.handleMessage(createArray(34, (byte) 7));
|
||||
DanaRPump pump = DanaRPump.getInstance();
|
||||
assertEquals((double) MessageBase.intFromBuff(createArray(10, (byte) 7), 2, 2)/100d, pump.extendedBolusAmount,0);
|
||||
|
||||
}
|
||||
|
||||
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,62 @@
|
|||
package info.nightscout.androidaps.plugins.PumpdanaRv2.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.PumpDanaR.DanaRPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusTempBasal_v2;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
/**
|
||||
* Created by Rumen Georgiev on 30.10.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class, DanaRv2Plugin.class, DanaRPlugin.class})
|
||||
public class MsgStatusTempBasal_v2Test {
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
AAPSMocker.mockBus();
|
||||
AAPSMocker.mockDanaRPlugin();
|
||||
|
||||
MsgStatusTempBasal_v2 packet = new MsgStatusTempBasal_v2();
|
||||
DanaRPump pump = DanaRPump.getInstance();
|
||||
// test message decoding
|
||||
packet.handleMessage(createArray(34, (byte) 1));
|
||||
assertEquals(true, pump.isTempBasalInProgress);
|
||||
// passing an bigger number
|
||||
packet = new MsgStatusTempBasal_v2();
|
||||
|
||||
packet.handleMessage(createArray(34, (byte) 2));
|
||||
assertEquals(false, pump.isTempBasalInProgress);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
google()
|
||||
jcenter()
|
||||
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||
}
|
||||
dependencies {
|
||||
|
|
Loading…
Reference in a new issue