summary refs log tree commit diff stats
path: root/test/tc_ui.py
blob: 3c659459d4079cdafba1293ea94b705a214c03cc (plain) (blame)
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
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

if __name__ == '__main__': from __init__ import init; init()

import unittest
import curses

from ranger.gui import ui

from test import Fake, OK, raise_ok

ui.curses = Fake()

class Test(unittest.TestCase):
	def setUp(self):

		self.fm = Fake()
		self.ui = ui.UI(env=Fake(), fm=self.fm)

		def fakesetup():
			self.ui.widget = Fake()
			self.ui.add_child(self.ui.widget)
		self.ui.setup = fakesetup

		self.ui.initialize()

	def tearDown(self):
		self.ui.destroy()
	
	def test_passing(self):
		# Test whether certain method calls are passed to widgets
		widget = self.ui.widget

		widget.draw = raise_ok
		self.assertRaises(OK, self.ui.draw)
		widget.__clear__()

		widget.finalize = raise_ok
		self.assertRaises(OK, self.ui.finalize)
		widget.__clear__()

		widget.press = raise_ok
		random_key = 123
		self.assertRaises(OK, self.ui.handle_key, random_key)
		widget.__clear__()

		widget.destroy = raise_ok
		self.assertRaises(OK, self.ui.destroy)
		widget.__clear__()

if __name__ == '__main__':
	unittest.main()
09cb9690dc5a04'>1639687b ^
21cb677f ^

71ee78f2 ^
db268970 ^

21cb677f ^

db268970 ^

21cb677f ^
db268970 ^
21cb677f ^
71ee78f2 ^
21cb677f ^

51c311d5 ^
db268970 ^


21cb677f ^
db268970 ^
21cb677f ^
71ee78f2 ^
db268970 ^
3c420101 ^
db268970 ^
3c420101 ^
71ee78f2 ^

6030d7e2 ^
71ee78f2 ^

6030d7e2 ^
71ee78f2 ^
ee9a9237 ^
db268970 ^
6030d7e2 ^
6030d7e2 ^

ee9a9237 ^
6030d7e2 ^


d11372f6 ^
9d27e966 ^
d11372f6 ^
03d50cc8 ^
71ee78f2 ^
ee9a9237 ^
6030d7e2 ^

ee9a9237 ^
71ee78f2 ^
ee9a9237 ^
6030d7e2 ^
9d27e966 ^
ee9a9237 ^
6030d7e2 ^


ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^

d11372f6 ^
03d50cc8 ^
71ee78f2 ^
ee9a9237 ^
6030d7e2 ^

ee9a9237 ^
71ee78f2 ^
ee9a9237 ^
6030d7e2 ^
9d27e966 ^
ee9a9237 ^
6030d7e2 ^


ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^

d11372f6 ^
03d50cc8 ^
71ee78f2 ^
ee9a9237 ^
6030d7e2 ^

ee9a9237 ^
71ee78f2 ^
ee9a9237 ^
6030d7e2 ^
9d27e966 ^
ee9a9237 ^
6030d7e2 ^


ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^

d11372f6 ^
03d50cc8 ^
71ee78f2 ^
ee9a9237 ^
6030d7e2 ^

ee9a9237 ^
71ee78f2 ^
ee9a9237 ^
6030d7e2 ^
9d27e966 ^
ee9a9237 ^
6030d7e2 ^


ee9a9237 ^
6030d7e2 ^
ee9a9237 ^
6030d7e2 ^

ed0e64a9 ^
0b2d2d97 ^




















































ee9a9237 ^
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230


                                              


                                                                                                                                                 
 
                       
                                                
                                                                                                                                         
                                      
                                                                                                                                                                                      
                                
                         
 
                                                                                     
                 
                                                        

                               

                                  


                                    
                          
                   
     
                
                  
                 


                  
     





                                                                                                                                                                       
               




                                                                                                                                                                             

                                                                                                                                                                        
                       

                                                                                                                                                                            
                                                    

                                                                                                                                                                  

                                                                                                                                                                      

                                                                                                                                                                  
                         
                                                                                                                                                                 
                                                                                                                                                                 
                    

                                                                                                                                                                            
                                                                   


                                                                                                                                                                               
                                                                                                                                                                               
                                
                                                                                                                                                                           
                                                    
             
                    
             
                    

                                      
                           

                                     
                           
                   
                         
                 
                 

                 
              


                                                                                                                                                                       
 
         
 
                                     
                                 
                   

                     
              
                                 
                      
                                                                                                                                                                  
                                   
                   


                                                             
              
                                    
                      

                                                                                                                                                                  
 
                                                                                  
                                    
                   

                        
              
                                 
                      
                                                                                                                                                                  
                                   
                   


                                                                 
              
                                    
                      

                                                                                                                                                                  
 
                           
                                       
                   

                        
              
                                 
                      
                                                                                                                                                                  
                                   
                   


                                                   
              
                                    
                      

                                                                                                                                                                  
 
                                           
                                       
                   

                        
              
                                 
                      
                                                                                                                                                                  
                                   
                   


                                                                   
              
                                    
                      

                                                                                                                                                                  
 




















































                                                                                                                                                                       
                            
# Comparing 'regular' length-prefixed strings.

== code
#   instruction                     effective address                                                   register    displacement    immediate
# . op          subop               mod             rm32          base        index         scale       r32
# . 1-3 bytes   3 bits              2 bits          3 bits        3 bits      3 bits        2 bits      2 bits      0/1/2/4 bytes   0/1/2/4 bytes

Entry:  # run all tests
#?     e8/call test-compare-equal-strings/disp32
    e8/call  run-tests/disp32  # 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.
    # syscall(exit, Num-test-failures)
    8b/copy                         0/mod/indirect  5/rm32/.disp32            .             .           3/r32/EBX   Num-test-failures/disp32          # copy *Num-test-failures to EBX
    b8/copy-to-EAX  1/imm32/exit
    cd/syscall  0x80/imm8

string-equal?:  # s : (address string), benchmark : (address string) -> EAX : boolean
    # pseudocode:
    #   if (s->length != benchmark->length) return false
    #   currs = s->data
    #   currb = benchmark->data
    #   maxs = s->data + s->length
    #   while currs < maxs
    #     c1 = *currs
    #     c2 = *currb
    #     if (c1 != c2) return false
    #     ++currs, ++currb
    #   return true
    #
    # registers:
    #   currs: ESI
    #   maxs: ECX
    #   currb: EDI
    #   c1: EAX
    #   c2: EBX
    #
    # . prolog
    55/push-EBP
    89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
    # . save registers
    51/push-ECX
    52/push-EDX
    56/push-ESI
    57/push-EDI
    # ESI = s
    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           6/r32/ESI   8/disp8         .                 # copy *(EBP+8) to ESI
    # EDI = benchmark
    8b/copy                         1/mod/*+disp8   5/rm32/EBP    .           .             .           7/r32/EDI   0xc/disp8       .                 # copy *(EBP+12) to EDI
    # ECX = s->length
    8b/copy                         0/mod/indirect  6/rm32/ESI    .           .             .           1/r32/ECX   .               .                 # copy *ESI to ECX
$string-equal?:lengths:
    # if (ECX != benchmark->length) return false
    39/compare                      0/mod/indirect  7/rm32/EDI    .           .             .           1/r32/ECX   .               .                 # compare *EDI and ECX
    75/jump-if-not-equal  $string-equal?:false/disp8
    # currs/ESI = s->data
    81          0/subop/add         3/mod/direct    6/rm32/ESI    .           .             .           .           .               4/imm32           # add to ESI
    # maxs/ECX = s->data + s->length
    01/add                          3/mod/direct    1/rm32/ECX    .           .             .           6/r32/ESI   .               .                 # add ESI to ECX
    # currb/EDI = benchmark->data
    81          0/subop/add         3/mod/direct    7/rm32/EDI    .           .             .           .           .               4/imm32           # add to EDI
    # c1/EAX = c2/EDX = 0
    31/xor                          3/mod/direct    0/rm32/EAX    .           .             .           0/r32/EAX   .               .                 # clear EAX
    31/xor                          3/mod/direct    2/rm32/EDX    .           .             .           2/r32/EDX   .               .                 # clear EDX
$string-equal?:loop:
    # if (currs >= maxs) return true
    39/compare                      3/mod/direct    6/rm32/ESI    .           .             .           1/r32/ECX   .               .                 # compare ESI with ECX
    73/jump-if-greater-or-equal-unsigned  $string-equal?:true/disp8
    # c1 = *currs
    8a/copy-byte                    0/mod/indirect  6/rm32/ESI    .           .             .           0/r32/AL    .               .                 # copy byte at *ESI to AL
    # c2 = *currb
    8a/copy-byte                    0/mod/indirect  7/rm32/EDI    .           .             .           2/r32/DL    .               .                 # copy byte at *EDI to DL
    # if (c1 != c2) return false
    39/compare                      3/mod/direct    0/rm32/EAX    .           .             .           2/r32/EDX   .               .                 # compare EAX and EDX
    75/jump-if-not-equal  $string-equal?:false/disp8
    # ++currs
    46/increment-ESI
    # ++currb
    47/increment-EDI
    eb/jump  $string-equal?:loop/disp8
$string-equal?:true:
    b8/copy-to-EAX  1/imm32
    eb/jump  $string-equal?:end/disp8
$string-equal?:false:
    b8/copy-to-EAX  0/imm32
$string-equal?:end:
    # . restore registers
    5f/pop-to-EDI
    5e/pop-to-ESI
    5a/pop-to-EDX
    59/pop-to-ECX
    # . epilog
    89/copy                         3/mod/direct    4/rm32/ESP    .           .             .           5/r32/EBP   .               .                 # copy EBP to ESP
    5d/pop-to-EBP
    c3/return

# - tests

test-compare-empty-with-empty-string:
    # EAX = string-equal?("", "")
    # . . push args
    68/push  ""/imm32
    68/push  ""/imm32
    # . . call
    e8/call  string-equal?/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
    # check-ints-equal(EAX, 1, msg)
    # . . push args
    68/push  "F - test-compare-empty-with-empty-string"/imm32
    68/push  1/imm32/true
    50/push-EAX
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
    c3/return

test-compare-empty-with-non-empty-string:  # also checks length-mismatch code path
    # EAX = string-equal?("", "Abc")
    # . . push args
    68/push  "Abc"/imm32
    68/push  ""/imm32
    # . . call
    e8/call  string-equal?/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
    # check-ints-equal(EAX, 0, msg)
    # . . push args
    68/push  "F - test-compare-empty-with-non-empty-string"/imm32
    68/push  0/imm32/false
    50/push-EAX
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
    c3/return

test-compare-equal-strings:
    # EAX = string-equal?("Abc", "Abc")
    # . . push args
    68/push  "Abc"/imm32
    68/push  "Abc"/imm32
    # . . call
    e8/call  string-equal?/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
    # check-ints-equal(EAX, 1, msg)
    # . . push args
    68/push  "F - test-compare-equal-strings"/imm32
    68/push  1/imm32/true
    50/push-EAX
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
    c3/return

test-compare-inequal-strings-equal-lengths:
    # EAX = string-equal?("Abc", "Adc")
    # . . push args
    68/push  "Adc"/imm32
    68/push  "Abc"/imm32
    # . . call
    e8/call  string-equal?/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
    # check-ints-equal(EAX, 0, msg)
    # . . push args
    68/push  "F - test-compare-inequal-strings-equal-lengths"/imm32
    68/push  0/imm32/false
    50/push-EAX
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
    c3/return

# helper for later tests
check-string-equal:  # s : (address string), expected : (address string), msg : (address string)
    # . prolog
    55/push-EBP
    89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
    # . save registers
    50/push-EAX
    # EAX = string-equal?(s, expected)
    # . . push args
    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0xc/disp8       .                 # push *(EBP+12)
    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           8/disp8         .                 # push *(EBP+8)
    # . . call
    e8/call  string-equal?/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
    # check-ints-equal(EAX, 1, msg)
    # . . push args
    ff          6/subop/push        1/mod/*+disp8   5/rm32/EBP    .           .             .           .           0x10/disp8      .                 # push *(EBP+16)
    68/push  1/imm32
    50/push-EAX
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
$check-string-equal:end:
    # . restore registers
    58/pop-to-EAX
    # . epilog
    89/copy                         3/mod/direct    4/rm32/ESP    .           .             .           5/r32/EBP   .               .                 # copy EBP to ESP
    5d/pop-to-EBP
    c3/return

# test the helper
test-check-string-equal:
    # check-string-equal?("Abc", "Abc")
    # . . push args
    68/push  "Abc"/imm32
    68/push  "Abc"/imm32
    # . . call
    e8/call  check-string-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
    # check-ints-equal(EAX, 1, msg)
    # . . push args
    68/push  "F - test-check-string-equal"/imm32
    68/push  0/imm32/false
    50/push-EAX
    # . . call
    e8/call  check-ints-equal/disp32
    # . . discard args
    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
    c3/return

# . . vim:nowrap:textwidth=0