2020-02-11 17:06:30 +01:00
|
|
|
package info.nightscout.androidaps
|
|
|
|
|
|
|
|
import android.os.SystemClock
|
|
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
|
|
import androidx.test.filters.LargeTest
|
|
|
|
import androidx.test.rule.ActivityTestRule
|
|
|
|
import androidx.test.rule.GrantPermissionRule
|
|
|
|
import info.nightscout.androidaps.data.Profile
|
|
|
|
import info.nightscout.androidaps.interfaces.PluginBase
|
|
|
|
import info.nightscout.androidaps.interfaces.PluginType
|
|
|
|
import info.nightscout.androidaps.logging.L
|
|
|
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
|
2020-02-28 18:20:31 +01:00
|
|
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
2020-02-11 17:06:30 +01:00
|
|
|
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.general.actions.ActionsPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.insulin.InsulinOrefUltraRapidActingPlugin
|
|
|
|
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin
|
|
|
|
import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin
|
|
|
|
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin
|
|
|
|
import info.nightscout.androidaps.plugins.source.RandomBgPlugin
|
2020-02-28 18:20:31 +01:00
|
|
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
2020-02-11 17:06:30 +01:00
|
|
|
import info.nightscout.androidaps.utils.DateUtil
|
2020-02-28 18:20:31 +01:00
|
|
|
import info.nightscout.androidaps.utils.extensions.isRunningTest
|
|
|
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
2020-02-11 17:06:30 +01:00
|
|
|
import org.json.JSONObject
|
|
|
|
import org.junit.Assert
|
|
|
|
import org.junit.Before
|
|
|
|
import org.junit.Rule
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
import org.slf4j.LoggerFactory
|
2020-02-28 18:20:31 +01:00
|
|
|
import javax.inject.Inject
|
2020-02-11 17:06:30 +01:00
|
|
|
|
|
|
|
@LargeTest
|
|
|
|
@RunWith(AndroidJUnit4::class)
|
|
|
|
class RealPumpTest {
|
|
|
|
|
|
|
|
private val log = LoggerFactory.getLogger(L.CORE)
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
const val R_PASSWORD = 1234
|
|
|
|
const val R_SERIAL = "PBB00013LR_P"
|
|
|
|
}
|
|
|
|
|
|
|
|
private val validProfile = "{\"dia\":\"6\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"10\"},{\"time\":\"2:00\",\"value\":\"11\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"0.1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4\"}],\"target_high\":[{\"time\":\"00:00\",\"value\":\"5\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
|
|
|
|
2020-02-28 18:20:31 +01:00
|
|
|
@Inject lateinit var pump : DanaRv2Plugin
|
|
|
|
@Inject lateinit var randomBgPlugin :RandomBgPlugin
|
|
|
|
@Inject lateinit var localProfilePlugin: LocalProfilePlugin
|
|
|
|
@Inject lateinit var profileFunction: ProfileFunction
|
|
|
|
@Inject lateinit var insulinOrefUltraRapidActingPlugin: InsulinOrefUltraRapidActingPlugin
|
|
|
|
@Inject lateinit var sensitivityOref1Plugin: SensitivityOref1Plugin
|
|
|
|
@Inject lateinit var openAPSSMBPlugin: OpenAPSSMBPlugin
|
|
|
|
@Inject lateinit var loopPlugin: LoopPlugin
|
|
|
|
@Inject lateinit var actionsPlugin: ActionsPlugin
|
|
|
|
@Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
|
|
|
@Inject lateinit var objectivesPlugin: ObjectivesPlugin
|
|
|
|
@Inject lateinit var treatmentsPlugin: TreatmentsPlugin
|
|
|
|
@Inject lateinit var sp: SP
|
|
|
|
|
2020-02-11 17:06:30 +01:00
|
|
|
@Rule
|
|
|
|
@JvmField
|
|
|
|
var mActivityTestRule = ActivityTestRule(MainActivity::class.java)
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
@JvmField
|
|
|
|
var mGrantPermissionRule: GrantPermissionRule =
|
|
|
|
GrantPermissionRule.grant(
|
|
|
|
android.Manifest.permission.ACCESS_FINE_LOCATION,
|
|
|
|
android.Manifest.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
|
|
|
|
android.Manifest.permission.WRITE_EXTERNAL_STORAGE
|
|
|
|
)
|
|
|
|
|
|
|
|
@Before
|
|
|
|
fun clear() {
|
2020-02-28 18:20:31 +01:00
|
|
|
sp.clear()
|
|
|
|
sp.putBoolean(R.string.key_setupwizard_processed, true)
|
|
|
|
sp.putString(R.string.key_aps_mode, "closed")
|
2020-02-11 17:06:30 +01:00
|
|
|
MainApp.getDbHelper().resetDatabases()
|
|
|
|
MainApp.devBranch = false
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun preparePlugins() {
|
|
|
|
// Source
|
2020-02-28 18:20:31 +01:00
|
|
|
configBuilderPlugin.performPluginSwitch(randomBgPlugin,true, PluginType.BGSOURCE)
|
2020-02-11 17:06:30 +01:00
|
|
|
// Profile
|
2020-02-28 18:20:31 +01:00
|
|
|
configBuilderPlugin.performPluginSwitch(localProfilePlugin, true, PluginType.PROFILE)
|
2020-02-11 17:06:30 +01:00
|
|
|
val profile = Profile(JSONObject(validProfile), Constants.MGDL)
|
|
|
|
Assert.assertTrue(profile.isValid("Test"))
|
2020-02-28 18:20:31 +01:00
|
|
|
localProfilePlugin.profiles.clear()
|
|
|
|
localProfilePlugin.numOfProfiles = 0
|
|
|
|
val singleProfile = LocalProfilePlugin.SingleProfile().copyFrom(localProfilePlugin.rawProfile, profile, "TestProfile")
|
|
|
|
localProfilePlugin.addProfile(singleProfile)
|
|
|
|
val profileSwitch = profileFunction.prepareProfileSwitch(localProfilePlugin.createProfileStore(), "TestProfile", 0, 100, 0, DateUtil.now())
|
|
|
|
treatmentsPlugin.addToHistoryProfileSwitch(profileSwitch)
|
2020-02-11 17:06:30 +01:00
|
|
|
// Insulin
|
2020-02-28 18:20:31 +01:00
|
|
|
configBuilderPlugin.performPluginSwitch(insulinOrefUltraRapidActingPlugin, true, PluginType.INSULIN)
|
2020-02-11 17:06:30 +01:00
|
|
|
// Pump
|
2020-02-28 18:20:31 +01:00
|
|
|
sp.putInt(R.string.key_danar_password, R_PASSWORD)
|
|
|
|
sp.putString(R.string.key_danar_bt_name, R_SERIAL)
|
|
|
|
configBuilderPlugin.performPluginSwitch((pump as PluginBase), true, PluginType.PUMP)
|
2020-02-11 17:06:30 +01:00
|
|
|
// Sensitivity
|
2020-02-28 18:20:31 +01:00
|
|
|
configBuilderPlugin.performPluginSwitch(sensitivityOref1Plugin, true, PluginType.SENSITIVITY)
|
2020-02-11 17:06:30 +01:00
|
|
|
// APS
|
2020-02-28 18:20:31 +01:00
|
|
|
configBuilderPlugin.performPluginSwitch(openAPSSMBPlugin, true, PluginType.APS)
|
|
|
|
configBuilderPlugin.performPluginSwitch(loopPlugin, true, PluginType.LOOP)
|
2020-02-11 17:06:30 +01:00
|
|
|
|
|
|
|
// Enable common
|
2020-02-28 18:20:31 +01:00
|
|
|
configBuilderPlugin.performPluginSwitch(actionsPlugin, true, PluginType.GENERAL)
|
2020-02-11 17:06:30 +01:00
|
|
|
|
|
|
|
// Disable unneeded
|
2020-02-28 18:20:31 +01:00
|
|
|
MainApp.getPluginsList().remove(objectivesPlugin)
|
2020-02-11 17:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun doTest() {
|
|
|
|
Assert.assertTrue(isRunningTest())
|
|
|
|
preparePlugins()
|
|
|
|
|
|
|
|
while (!pump.isInitialized) {
|
|
|
|
log.debug("Waiting for initialization")
|
|
|
|
SystemClock.sleep(1000)
|
|
|
|
}
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
log.debug("Tick")
|
|
|
|
SystemClock.sleep(1000)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|