-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller_test.go
208 lines (183 loc) · 5.62 KB
/
controller_test.go
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package maa
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func createDbgController(t *testing.T, notify Notification) Controller {
testingPath := "./test/data_set/PipelineSmoking/Screenshot"
resultPath := "./test/data_set/debug"
ctrl := NewDbgController(testingPath, resultPath, DbgControllerTypeCarouselImage, "{}", notify)
require.NotNil(t, ctrl)
return ctrl
}
func TestNewDbgController(t *testing.T) {
ctrl := createDbgController(t, nil)
ctrl.Destroy()
}
func TestController_Handle(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
require.NotNil(t, ctrl)
}
func TestController_SetScreenshotTargetLongSide(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
got := ctrl.SetScreenshotTargetLongSide(1280)
require.True(t, got)
}
func TestController_SetScreenshotTargetShortSide(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
got := ctrl.SetScreenshotTargetShortSide(720)
require.True(t, got)
}
func TestController_SetScreenshotUseRawSize(t *testing.T) {
testCases := []struct {
name string
enabled bool
expected bool
}{
{
name: "enabled true",
enabled: true,
},
{
name: "enabled false",
enabled: false,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
got := ctrl.SetScreenshotUseRawSize(tc.enabled)
require.True(t, got)
})
}
}
func TestController_SetRecording(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
got := ctrl.SetRecording(true)
require.True(t, got)
}
func TestController_PostConnect(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
isConnected := ctrl.PostConnect().Wait().Success()
require.True(t, isConnected)
}
func TestController_Connected(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
isConnected := ctrl.PostConnect().Wait().Success()
require.True(t, isConnected)
connected := ctrl.Connected()
require.True(t, connected)
}
func TestController_PostClick(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
isConnected := ctrl.PostConnect().Wait().Success()
require.True(t, isConnected)
clicked := ctrl.PostClick(100, 200).Wait().Success()
require.True(t, clicked)
}
func TestController_PostSwipe(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
isConnected := ctrl.PostConnect().Wait().Success()
require.True(t, isConnected)
swiped := ctrl.PostSwipe(100, 200, 400, 300, 2*time.Second).Wait().Success()
require.True(t, swiped)
}
func TestController_PostPressKey(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
isConnected := ctrl.PostConnect().Wait().Success()
require.True(t, isConnected)
pressed := ctrl.PostPressKey(4).Wait().Success()
require.True(t, pressed)
}
func TestController_PostInputText(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
isConnected := ctrl.PostConnect().Wait().Success()
require.True(t, isConnected)
inputted := ctrl.PostInputText("Hello World").Wait().Success()
require.True(t, inputted)
}
func TestController_PostStartApp(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
isConnected := ctrl.PostConnect().Wait().Success()
require.True(t, isConnected)
started := ctrl.PostStartApp("com.android.settings").Wait().Success()
require.True(t, started)
}
func TestController_PostStopApp(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
isConnected := ctrl.PostConnect().Wait().Success()
require.True(t, isConnected)
stopped := ctrl.PostStopApp("com.android.settings").Wait().Success()
require.True(t, stopped)
}
func TestController_PostTouchDown(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
isConnected := ctrl.PostConnect().Wait().Success()
require.True(t, isConnected)
downed := ctrl.PostTouchDown(0, 100, 200, 1000).Wait().Success()
require.True(t, downed)
}
func TestController_PostTouchMove(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
isConnected := ctrl.PostConnect().Wait().Success()
require.True(t, isConnected)
downed := ctrl.PostTouchDown(0, 100, 200, 1000).Wait().Success()
require.True(t, downed)
moved := ctrl.PostTouchMove(0, 200, 300, 1000).Wait().Success()
require.True(t, moved)
}
func TestController_PostTouchUp(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
isConnected := ctrl.PostConnect().Wait().Success()
require.True(t, isConnected)
downed := ctrl.PostTouchDown(0, 100, 200, 1000).Wait().Success()
require.True(t, downed)
moved := ctrl.PostTouchMove(0, 200, 300, 1000).Wait().Success()
require.True(t, moved)
upped := ctrl.PostTouchUp(0).Wait().Success()
require.True(t, upped)
}
func TestController_PostScreencap(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
isConnected := ctrl.PostConnect().Wait().Success()
require.True(t, isConnected)
screencaped := ctrl.PostScreencap().Wait().Success()
require.True(t, screencaped)
}
func TestController_CacheImage(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
isConnected := ctrl.PostConnect().Wait().Success()
require.True(t, isConnected)
screencaped := ctrl.PostScreencap().Wait().Success()
require.True(t, screencaped)
img := ctrl.CacheImage()
require.NotNil(t, img)
}
func TestController_GetUUID(t *testing.T) {
ctrl := createDbgController(t, nil)
defer ctrl.Destroy()
isConnected := ctrl.PostConnect().Wait().Success()
require.True(t, isConnected)
uuid, oK := ctrl.GetUUID()
require.True(t, oK)
require.NotEmpty(t, uuid)
}