package com.nodka.zysjtest;
|
|
import android.text.InputType;
|
|
class TestItem {
|
final String chineseName;
|
final String methodName;
|
final String description;
|
final boolean hasInput;
|
final String inputHint;
|
final String defaultInput;
|
final String inputDescription;
|
final InputField[] inputFields;
|
final boolean hasSwitch;
|
final String switchLabel;
|
boolean switchChecked;
|
final boolean requiresConfirmation;
|
final String confirmationMessage;
|
final TestAction testAction;
|
String inputValue;
|
String result;
|
|
TestItem(String chineseName, String methodName, String description) {
|
this(chineseName, methodName, description, false, null, false, null, null, new InputField[0]);
|
}
|
|
TestItem(String chineseName, String methodName, String description, TestAction testAction) {
|
this(chineseName, methodName, description, false, null, false, null, testAction, new InputField[0]);
|
}
|
|
TestItem(
|
String chineseName,
|
String methodName,
|
String description,
|
boolean requiresConfirmation,
|
String confirmationMessage,
|
TestAction testAction) {
|
this(chineseName, methodName, description, requiresConfirmation, confirmationMessage, false, null, testAction, new InputField[0]);
|
}
|
|
TestItem(
|
String chineseName,
|
String methodName,
|
String description,
|
boolean hasSwitch,
|
String switchLabel,
|
boolean defaultSwitchChecked,
|
TestAction testAction) {
|
this(chineseName, methodName, description, false, null, hasSwitch, switchLabel, testAction, new InputField[0]);
|
this.switchChecked = defaultSwitchChecked;
|
}
|
|
TestItem(
|
String chineseName,
|
String methodName,
|
String description,
|
TestAction testAction,
|
InputField... inputFields) {
|
this(chineseName, methodName, description, false, null, false, null, testAction, inputFields);
|
}
|
|
TestItem(
|
String chineseName,
|
String methodName,
|
String description,
|
boolean requiresConfirmation,
|
String confirmationMessage,
|
TestAction testAction,
|
InputField... inputFields) {
|
this(chineseName, methodName, description, requiresConfirmation, confirmationMessage, false, null, testAction, inputFields);
|
}
|
|
private TestItem(
|
String chineseName,
|
String methodName,
|
String description,
|
boolean requiresConfirmation,
|
String confirmationMessage,
|
boolean hasSwitch,
|
String switchLabel,
|
TestAction testAction,
|
InputField... inputFields) {
|
this.chineseName = chineseName;
|
this.methodName = methodName;
|
this.description = description;
|
this.requiresConfirmation = requiresConfirmation;
|
this.confirmationMessage = confirmationMessage;
|
this.hasSwitch = hasSwitch;
|
this.switchLabel = switchLabel;
|
this.testAction = testAction;
|
this.inputFields = inputFields == null ? new InputField[0] : inputFields;
|
this.hasInput = this.inputFields.length > 0;
|
this.inputHint = this.hasInput ? this.inputFields[0].hint : "";
|
this.defaultInput = this.hasInput ? this.inputFields[0].defaultValue : "";
|
this.inputDescription = this.hasInput ? this.inputFields[0].description : "";
|
this.inputValue = this.defaultInput;
|
this.result = "等待测试";
|
}
|
|
String[] getInputValues() {
|
String[] values = new String[inputFields.length];
|
for (int i = 0; i < inputFields.length; i++) {
|
values[i] = inputFields[i].value;
|
}
|
return values;
|
}
|
|
void setInputValue(int index, String value) {
|
if (index < 0 || index >= inputFields.length) {
|
return;
|
}
|
inputFields[index].value = value;
|
if (index == 0) {
|
inputValue = value;
|
}
|
}
|
|
interface TestAction {
|
String run(TestItem item, String[] inputs) throws Exception;
|
}
|
|
static final class InputField {
|
final String hint;
|
final String defaultValue;
|
final String description;
|
final int inputType;
|
String value;
|
|
InputField(String hint, String defaultValue, String description, int inputType) {
|
this.hint = hint;
|
this.defaultValue = defaultValue;
|
this.description = description;
|
this.inputType = inputType;
|
this.value = defaultValue;
|
}
|
|
static InputField number(String hint, String defaultValue, String description) {
|
return new InputField(hint, defaultValue, description, InputType.TYPE_CLASS_NUMBER);
|
}
|
|
static InputField text(String hint, String defaultValue, String description) {
|
return new InputField(hint, defaultValue, description, InputType.TYPE_CLASS_TEXT);
|
}
|
}
|
}
|