-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathunit_tests.asm
200 lines (152 loc) · 4.96 KB
/
unit_tests.asm
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
;========================================================
; unit_tests.asm
;
; Collects and executes all unit tests.
;========================================================
include "unit_tests.inc"
; Initialization routine called before all unit tests are
; started.
UNITTEST_INITIALIZE
; Do your initialization here ...
; ...
; ...
; For this simple example we don't need any special initialization.
; So we simply return.
; Please note: the stack pointer does not need to be setup explicitly
; for the unit tests.
ret
MODULE TestSuite_ClearScreen
; A unit testcase needs to start with "UT_" (upper case letters).
; DeZog will collect all these labels and offer them for execution.
; Tests that the screen is cleared/filled with 0's.
UT_clear_screen:
; Write some bytes to the screen area
ld a,0xFF
ld (SCREEN),a
ld (SCREEN+SCREEN_SIZE/2),a
ld (SCREEN+SCREEN_SIZE-1),a
ld (SCREEN+SCREEN_SIZE),a
; Now clear the screen
call clear_screen
; Test that all values inside the screen area are cleared
TEST_MEMORY_BYTE SCREEN, 0
TEST_MEMORY_BYTE SCREEN+SCREEN_SIZE/2, 0
TEST_MEMORY_BYTE SCREEN+SCREEN_SIZE-1, 0
TEST_MEMORY_BYTE SCREEN+SCREEN_SIZE, 0xFF
nop
TC_END
; Tests filling the background.
UT_fill_backg:
; Write some bytes to the screen area
ld a,0xFF
ld (COLOR_SCREEN),a
ld (COLOR_SCREEN+COLOR_SCREEN_SIZE/2),a
ld (COLOR_SCREEN+COLOR_SCREEN_SIZE-1),a
ld (COLOR_SCREEN+COLOR_SCREEN_SIZE),a
; Now fill the background with 128
ld a,128
call fill_backg
; Test that all values inside the screen area are cleared
TEST_MEMORY_BYTE COLOR_SCREEN, 128
TEST_MEMORY_BYTE COLOR_SCREEN+COLOR_SCREEN_SIZE/2, 128
TEST_MEMORY_BYTE COLOR_SCREEN+COLOR_SCREEN_SIZE-1, 128
TEST_MEMORY_BYTE COLOR_SCREEN+COLOR_SCREEN_SIZE, 0xFF
TC_END
; Tests clearing the background.
UT_clear_backg:
; Write some bytes to the screen area
ld a,0xFF
ld (COLOR_SCREEN),a
ld (COLOR_SCREEN+COLOR_SCREEN_SIZE/2),a
ld (COLOR_SCREEN+COLOR_SCREEN_SIZE-1),a
ld (COLOR_SCREEN+COLOR_SCREEN_SIZE),a
; Now clear the background
call clear_backg
; Test that all values inside the screen area are cleared
TEST_MEMORY_BYTE COLOR_SCREEN, 0
TEST_MEMORY_BYTE COLOR_SCREEN+COLOR_SCREEN_SIZE/2, 0
TEST_MEMORY_BYTE COLOR_SCREEN+COLOR_SCREEN_SIZE-1, 0
TEST_MEMORY_BYTE COLOR_SCREEN+COLOR_SCREEN_SIZE, 0xFF
TC_END
ENDMODULE
MODULE TestSuite_Fill
; Tests filling a memory area
UT_fill_memory:
; Write some bytes
ld a,0xFF
ld (fill_memory_data-1),a
ld (fill_memory_data),a
ld (fill_memory_data+FILL_MEMORY_SIZE/2),a
ld (fill_memory_data+FILL_MEMORY_SIZE-1),a
ld (fill_memory_data+FILL_MEMORY_SIZE),a
; Now fill the memory area
ld a,22
ld hl,fill_memory_data
ld bc,FILL_MEMORY_SIZE
call fill_memory
; Test that all values inside the screen area are cleared
TEST_MEMORY_BYTE fill_memory_data-1, 0xFF
TEST_MEMORY_BYTE fill_memory_data, 22
TEST_MEMORY_BYTE fill_memory_data+FILL_MEMORY_SIZE/2, 22
TEST_MEMORY_BYTE fill_memory_data+FILL_MEMORY_SIZE-1, 22
TEST_MEMORY_BYTE fill_memory_data+FILL_MEMORY_SIZE, 0xFF
TC_END
FILL_MEMORY_SIZE: equ 10
defb 0
fill_memory_data:
defs 10
defb 0
; Tests filling a line in the background color screen.
UT_fill_bckg_line_normal:
; Initialize background
call clear_backg
; Fill line with color
ld a,MAGENTA
ld de,COLOR_SCREEN
call fill_bckg_line
; Test that line is filled
TEST_MEMORY_BYTE COLOR_SCREEN, MAGENTA
TEST_MEMORY_BYTE COLOR_SCREEN+16, MAGENTA
TEST_MEMORY_BYTE COLOR_SCREEN+31, MAGENTA
TEST_MEMORY_BYTE COLOR_SCREEN+32, 0
; Test that de points to the next line
nop ; ASSERTION DE == COLOR_SCREEN+32
TC_END
; Test wrap around.
UT_fill_bckg_line_wrap_around:
; Initialize background
call clear_backg
; Fill line with color
ld a,MAGENTA
ld de,COLOR_SCREEN+23*32
call fill_bckg_line
; Test that line is filled
TEST_MEMORY_BYTE COLOR_SCREEN+23*32, MAGENTA
TEST_MEMORY_BYTE COLOR_SCREEN+23*32+16, MAGENTA
TEST_MEMORY_BYTE COLOR_SCREEN+23*32+31, MAGENTA
TEST_MEMORY_BYTE COLOR_SCREEN+23*32-1, 0
; Test that de points to the first line (wrap around)
nop ; ASSERTION DE == COLOR_SCREEN
TC_END
; Test wrap around.
UT_fill_colors_ptr:
; Start value
ld hl,fill_colors
ld (fill_colors_ptr),hl
; Test increment
call inc_fill_colors_ptr
; Test that pointer is moved to next line
TEST_MEMORY_WORD fill_colors_ptr, fill_colors+1
; Test increment
call inc_fill_colors_ptr
; Test that pointer is moved to next line
TEST_MEMORY_WORD fill_colors_ptr, fill_colors+2
; Last value
ld hl,fill_colors_end-1
ld (fill_colors_ptr),hl
; Test increment
call inc_fill_colors_ptr
; Test that pointer wraps around and points to first line
TEST_MEMORY_WORD fill_colors_ptr, fill_colors
TC_END
ENDMODULE