lzh
3 days ago 9e3ee0fb3332f604000c20863cece6a09ad23f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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);
        }
    }
}