Fix subg_rfspy version check and add tests
This commit is contained in:
parent
9e51f35c41
commit
6ac449d684
|
@ -246,7 +246,7 @@ dependencies {
|
|||
|
||||
testImplementation "junit:junit:$junit_version"
|
||||
testImplementation 'org.json:json:20200518'
|
||||
testImplementation "org.mockito:mockito-core:2.8.47"
|
||||
testImplementation "org.mockito:mockito-core:${mockitoVersion}"
|
||||
testImplementation "org.powermock:powermock-api-mockito2:${powermockVersion}"
|
||||
testImplementation "org.powermock:powermock-module-junit4-rule-agent:${powermockVersion}"
|
||||
testImplementation "org.powermock:powermock-module-junit4-rule:${powermockVersion}"
|
||||
|
|
|
@ -23,6 +23,7 @@ buildscript {
|
|||
work_version = '2.4.0'
|
||||
|
||||
junit_version = '4.13.1'
|
||||
mockitoVersion = '2.8.47'
|
||||
powermockVersion = "1.7.3"
|
||||
dexmakerVersion = "1.2"
|
||||
retrofit2Version = '2.9.0'
|
||||
|
|
|
@ -59,7 +59,7 @@ dependencies {
|
|||
kapt "com.google.dagger:dagger-compiler:$dagger_version"
|
||||
|
||||
testImplementation "junit:junit:$junit_version"
|
||||
testImplementation "org.mockito:mockito-core:2.8.47"
|
||||
testImplementation "org.mockito:mockito-core:${mockitoVersion}"
|
||||
testImplementation "org.powermock:powermock-api-mockito2:$powermockVersion"
|
||||
testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}"
|
||||
testImplementation 'joda-time:joda-time:2.10.6'
|
||||
|
|
|
@ -50,6 +50,9 @@ dependencies {
|
|||
kapt "com.google.dagger:dagger-compiler:$dagger_version"
|
||||
|
||||
testImplementation "junit:junit:$junit_version"
|
||||
testImplementation "org.mockito:mockito-core:${mockitoVersion}"
|
||||
testImplementation "org.powermock:powermock-api-mockito2:${powermockVersion}"
|
||||
testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}"
|
||||
androidTestImplementation "androidx.test.ext:junit:$androidx_junit"
|
||||
androidTestImplementation "androidx.test:rules:$androidx_rules"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -10,15 +13,18 @@ public enum RileyLinkFirmwareVersion {
|
|||
Version_0_0(0, 0, "0.0"), // just for defaulting
|
||||
Version_0_9(0, 9, "0.9"), //
|
||||
Version_1_0(1, 0, "1.0"), //
|
||||
Version_1_x(1, null, "1.x"), //
|
||||
Version_2_0(2, 0, "2.0"), //
|
||||
Version_2_2(2, 2, "2.2"), //
|
||||
Version_2_x(2, null, "2.x"), //
|
||||
Version_3_x(3, null, "3.x"), //
|
||||
Version_4_x(4, null, "4.x"), //
|
||||
UnknownVersion(null, null, "???"), //
|
||||
Version1(Version_0_0, Version_0_9, Version_1_0), //
|
||||
Version1(Version_0_0, Version_0_9, Version_1_0, Version_1_x), //
|
||||
Version2(Version_2_0, Version_2_2, Version_2_x), //
|
||||
Version2AndHigher(Version2, Version_3_x, Version_4_x);
|
||||
Version3(Version_3_x), //
|
||||
Version4(Version_4_x), //
|
||||
Version2AndHigher(Version2, Version3, Version4);
|
||||
|
||||
private static final String FIRMWARE_IDENTIFICATION_PREFIX = "subg_rfspy ";
|
||||
private static final Pattern _version_pattern = Pattern.compile(FIRMWARE_IDENTIFICATION_PREFIX
|
||||
|
@ -34,12 +40,11 @@ public enum RileyLinkFirmwareVersion {
|
|||
}
|
||||
}
|
||||
|
||||
protected RileyLinkFirmwareVersion[] familyMembers;
|
||||
private List<RileyLinkFirmwareVersion> familyMembers;
|
||||
private Integer major;
|
||||
private Integer minor;
|
||||
private String versionKey = "";
|
||||
|
||||
|
||||
RileyLinkFirmwareVersion(Integer major, Integer minor, String versionKey) {
|
||||
this.major = major;
|
||||
this.minor = minor;
|
||||
|
@ -48,23 +53,40 @@ public enum RileyLinkFirmwareVersion {
|
|||
|
||||
|
||||
RileyLinkFirmwareVersion(RileyLinkFirmwareVersion... familyMembers) {
|
||||
this.familyMembers = familyMembers;
|
||||
this.familyMembers = Arrays.asList(familyMembers);
|
||||
}
|
||||
|
||||
public boolean hasFamilyMembers() {
|
||||
return familyMembers != null;
|
||||
}
|
||||
|
||||
private List<RileyLinkFirmwareVersion> getFamilyMembersRecursive() {
|
||||
List<RileyLinkFirmwareVersion> members = new ArrayList<>();
|
||||
if (hasFamilyMembers()) {
|
||||
for (RileyLinkFirmwareVersion version : familyMembers) {
|
||||
members.add(version);
|
||||
if (version.hasFamilyMembers()) {
|
||||
members.addAll(version.getFamilyMembersRecursive());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return members;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isSameVersion(RileyLinkFirmwareVersion versionWeCheck, RileyLinkFirmwareVersion versionSources) {
|
||||
if (versionSources.familyMembers != null) {
|
||||
for (RileyLinkFirmwareVersion vrs : versionSources.familyMembers) {
|
||||
if (vrs == versionWeCheck)
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return (versionWeCheck == versionSources);
|
||||
if (versionWeCheck == versionSources) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (versionSources.familyMembers != null) {
|
||||
return versionSources.getFamilyMembersRecursive().contains(versionWeCheck);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static RileyLinkFirmwareVersion getByVersionString(String versionString) {
|
||||
if (versionString != null) {
|
||||
Matcher m = _version_pattern.matcher(versionString);
|
||||
|
@ -100,6 +122,9 @@ public enum RileyLinkFirmwareVersion {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (hasFamilyMembers()) {
|
||||
return FIRMWARE_IDENTIFICATION_PREFIX + name();
|
||||
}
|
||||
return FIRMWARE_IDENTIFICATION_PREFIX + versionKey;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkFirmwareVersion;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
public class RFSpyTest {
|
||||
@Mock
|
||||
private AAPSLogger aapsLogger;
|
||||
|
||||
@Test
|
||||
public void testGetFirmwareVersion() {
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_1_0, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 1.0"));
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_1_x, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 1.1"));
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_1_x, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 1.1.13"));
|
||||
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_2_0, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 2.0"));
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_2_0, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 2.0.1"));
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_2_2, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 2.2"));
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_2_2, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 2.2.16"));
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_2_2, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 2.2.17"));
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_2_x, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 2.3"));
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_2_x, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 2.3.0"));
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_2_x, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 2.3.17"));
|
||||
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_3_x, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 3.0"));
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_3_x, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 3.0.1"));
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_3_x, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 3.1"));
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_3_x, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 3.1.13"));
|
||||
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_4_x, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 4.0"));
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_4_x, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 4.0.4"));
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_4_x, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 4.3"));
|
||||
assertEquals(RileyLinkFirmwareVersion.Version_4_x, RFSpy.getFirmwareVersion(aapsLogger, "", "subg_rfspy 4.5.7"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class RileyLinkFirmwareVersionTest {
|
||||
|
||||
@Test
|
||||
public void testIsSameVersion() {
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version1, RileyLinkFirmwareVersion.Version1));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_1_0, RileyLinkFirmwareVersion.Version1));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_0_0, RileyLinkFirmwareVersion.Version1));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_0_9, RileyLinkFirmwareVersion.Version1));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_1_x, RileyLinkFirmwareVersion.Version1));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version1, RileyLinkFirmwareVersion.Version_1_0));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_0_0, RileyLinkFirmwareVersion.Version2AndHigher));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_1_0, RileyLinkFirmwareVersion.Version2AndHigher));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_0_9, RileyLinkFirmwareVersion.Version2AndHigher));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_1_x, RileyLinkFirmwareVersion.Version2AndHigher));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version1, RileyLinkFirmwareVersion.Version2AndHigher));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version2, RileyLinkFirmwareVersion.Version1));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version2AndHigher, RileyLinkFirmwareVersion.Version1));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version3, RileyLinkFirmwareVersion.Version1));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version4, RileyLinkFirmwareVersion.Version1));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_2_0, RileyLinkFirmwareVersion.Version1));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_2_2, RileyLinkFirmwareVersion.Version1));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_2_x, RileyLinkFirmwareVersion.Version1));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_3_x, RileyLinkFirmwareVersion.Version1));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_4_x, RileyLinkFirmwareVersion.Version1));
|
||||
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version2, RileyLinkFirmwareVersion.Version2));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version2, RileyLinkFirmwareVersion.Version2AndHigher));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_2_0, RileyLinkFirmwareVersion.Version2));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_2_0, RileyLinkFirmwareVersion.Version2AndHigher));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_2_2, RileyLinkFirmwareVersion.Version2));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_2_2, RileyLinkFirmwareVersion.Version2AndHigher));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_2_x, RileyLinkFirmwareVersion.Version2));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_2_x, RileyLinkFirmwareVersion.Version2AndHigher));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version2, RileyLinkFirmwareVersion.Version_2_x));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version3, RileyLinkFirmwareVersion.Version2));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version4, RileyLinkFirmwareVersion.Version2));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_3_x, RileyLinkFirmwareVersion.Version2));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_4_x, RileyLinkFirmwareVersion.Version2));
|
||||
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version3, RileyLinkFirmwareVersion.Version3));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version3, RileyLinkFirmwareVersion.Version2AndHigher));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_3_x, RileyLinkFirmwareVersion.Version3));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_3_x, RileyLinkFirmwareVersion.Version2AndHigher));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version3, RileyLinkFirmwareVersion.Version_3_x));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version4, RileyLinkFirmwareVersion.Version3));
|
||||
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version4, RileyLinkFirmwareVersion.Version4));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version4, RileyLinkFirmwareVersion.Version2AndHigher));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_4_x, RileyLinkFirmwareVersion.Version4));
|
||||
assertTrue(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version_4_x, RileyLinkFirmwareVersion.Version2AndHigher));
|
||||
assertFalse(RileyLinkFirmwareVersion.isSameVersion(RileyLinkFirmwareVersion.Version4, RileyLinkFirmwareVersion.Version_4_x));
|
||||
}
|
||||
}
|
|
@ -127,7 +127,7 @@ dependencies {
|
|||
|
||||
testImplementation "junit:junit:$junit_version"
|
||||
testImplementation 'org.json:json:20200518'
|
||||
testImplementation("org.mockito:mockito-core:2.8.47") {
|
||||
testImplementation("org.mockito:mockito-core:${mockitoVersion}") {
|
||||
exclude group: 'net.bytebuddy', module: 'byte-buddy'
|
||||
exclude group: 'net.bytebuddy', module: 'byte-buddy-android'
|
||||
exclude group: 'net.bytebuddy', module: 'byte-buddy-agent'
|
||||
|
|
Loading…
Reference in a new issue