Browse Source

Consolidate tests

Also, removed leftover in runbin.c (what did it do there??) that
could result in tests falsely passing.
pull/85/head
Virgil Dupras 4 years ago
parent
commit
e3c885085d
4 changed files with 202 additions and 237 deletions
  1. +0
    -1
      tools/emul/runbin/runbin.c
  2. +31
    -0
      tools/tests/unit/common.asm
  3. +171
    -61
      tools/tests/unit/test_lib_parse.asm
  4. +0
    -175
      tools/tests/unit/test_parse_z.asm

+ 0
- 1
tools/emul/runbin/runbin.c View File

@@ -28,7 +28,6 @@ int main()
return 1;
}
emul_loop();
if (m->cpu.R1.wr.HL)
return m->cpu.R1.br.A;
}


+ 31
- 0
tools/tests/unit/common.asm View File

@@ -37,6 +37,37 @@ assertNZ:
.msg:
.db "Z set", CR, LF, 0

assertC:
ret c
ld hl, .msg
call printstr
jp fail
.msg:
.db "C not set", CR, LF, 0

assertNC:
ret nc
ld hl, .msg
call printstr
jp fail
.msg:
.db "C set", CR, LF, 0

; Assert that A == B
assertEQB:
cp b
ret z
call printHex
call printcrlf
ld a, b
call printHex
call printcrlf
ld hl, .msg
call printstr
jp fail
.msg:
.db "A != B", CR, LF, 0

; Assert that HL == DE
assertEQW:
ld a, h


+ 171
- 61
tools/tests/unit/test_lib_parse.asm View File

@@ -1,85 +1,195 @@
jp test

.inc "ascii.h"
.inc "core.asm"
.equ STDIO_RAMSTART RAMSTART
.inc "stdio.asm"
.inc "common.asm"
.inc "lib/ari.asm"
.inc "lib/util.asm"
.inc "lib/fmt.asm"
.inc "lib/parse.asm"

zasmGetPC:
ret

testNum: .db 1

test:
ld sp, 0xffff

call testParseHex
call testParseHexadecimal
call testParseDecimal
call testParseLiteral

; success
xor a
halt

testParseHex:
ld a, '8'
ld hl, .allGood
ld ix, .testGood
call testList
ld hl, .allBad
ld ix, .testBad
jp testList

.testGood:
ld a, (hl)
call parseHex
jp c, fail
cp 8
jp nz, fail
call nexttest
call assertNC
inc hl
ld b, (hl)
jp assertEQB

ld a, 'e'
.testBad:
ld a, (hl)
call parseHex
jp c, fail
cp 0xe
jp nz, fail
call nexttest
jp assertC

ld a, 'x'
call parseHex
jp nc, fail
call nexttest
ret
.g1:
.db '8', 8
.g2:
.db 'e', 0xe

testParseHexadecimal:
ld hl, .s99
call parseHexadecimal
jp nz, fail
ld a, e
cp 0x99
jp nz, fail
call nexttest
.allGood:
.dw .g1, .g2, 0

ld hl, .saB
call parseHexadecimal
jp nz, fail
ld a, e
cp 0xab
jp nz, fail
call nexttest

; The string "Foo" will not cause a failure. We will parse up to "o"
; and then stop.
ld hl, .sFoo
call parseHexadecimal
jp nz, fail
ld a, e
cp 0xf
call nexttest
ret

.sFoo: .db "Foo", 0
.saB: .db "aB", 0
.s99: .db "99", 0

nexttest:
ld a, (testNum)
inc a
ld (testNum), a
ret

fail:
ld a, (testNum)
halt
.b1:
.db 'x'

.allBad:
.dw .b1, 0

; used as RAM
sandbox:
testParseHexadecimal:
ld hl, .allGood
ld ix, .testGood
jp testList

.testGood:
ld c, (hl)
inc hl
ld b, (hl)
inc hl
call parseHexadecimal
call assertZ
ld l, c
ld h, b
jp assertEQW

.g1:
.dw 0x99
.db "99", 0
.g2:
.dw 0xab
.db "aB", 0
; The string "Foo" will not cause a failure. We will parse up to "o" and then
; stop.
.g3:
.dw 0xf
.db "Foo", 0

.allGood:
.dw .g1, .g2, .g3, 0

testParseDecimal:
ld hl, .allGood
ld ix, .testGood
call testList
ld hl, .allBad
ld ix, .testBad
jp testList

.testGood:
ld c, (hl)
inc hl
ld b, (hl)
inc hl
call parseDecimalC
call assertZ
ld l, c
ld h, b
jp assertEQW

.testBad:
call parseDecimalC
jp assertNZ

.g1:
.dw 99
.db "99", 0
.g2:
.dw 65535
.db "65535", 0
; Space is also accepted as a number "ender"
.g3:
.dw 42
.db "42 x", 0
; Tab too
.g4:
.dw 42
.db "42", 0x09, 'x', 0
; A simple "0" works too!
.g5:
.dw 0
.db '0', 0

.allGood:
.dw .g1, .g2, .g3, .g4, .g5, 0

; null string is invalid
.b1:
.db 0
; too big, 5 chars
.b2:
.db "65536", 0
.b3:
.db "99999", 0
.b4:
; too big, 6 chars with rightmost chars being within bound
.db "111111", 0

.allBad:
.dw .b1, .b2, .b3, .b4, 0

testParseLiteral:
ld hl, .allGood
ld ix, .testGood
call testList
ld hl, .allBad
ld ix, .testBad
jp testList

.testGood:
ld c, (hl)
inc hl
ld b, (hl)
inc hl
call parseLiteral
call assertZ
ld l, c
ld h, b
jp assertEQW

.testBad:
call parseLiteral
jp assertNZ

.g1:
.dw 99
.db "99", 0
.g2:
.dw 0x100
.db "0x100", 0
.g3:
.dw 0b0101
.db "0b0101", 0
.g4:
.dw 0b01010101
.db "0b01010101", 0

.allGood:
.dw .g1, .g2, .g3, .g4, 0

.b1:
.db "Foo", 0
.allBad:
.dw .b1, 0

RAMSTART:

+ 0
- 175
tools/tests/unit/test_parse_z.asm View File

@@ -1,175 +0,0 @@
jp test

.inc "core.asm"
.inc "str.asm"
.inc "lib/util.asm"
.inc "zasm/util.asm"
.inc "lib/parse.asm"

; mocks. aren't used in tests
zasmGetPC:
zasmIsFirstPass:
symSelect:
symFindVal:
jp fail

testNum: .db 1

s99: .db "99", 0
s0x99: .db "0x99", 0
s0x100: .db "0x100", 0
s0b0101: .db "0b0101", 0
s0b01010101: .db "0b01010101", 0
sFoo: .db "Foo", 0

test:
ld sp, 0xffff

call testLiteral
call testDecimal

; success
xor a
halt

testLiteral:
ld hl, s99
call parseLiteral
jp nz, fail
ld a, d
or a
jp nz, fail
ld a, e
cp 99
jp nz, fail
call nexttest

ld hl, s0x100
call parseLiteral
jp nz, fail
ld a, d
cp 1
jp nz, fail
ld a, e
or a
jp nz, fail
call nexttest

ld hl, sFoo
call parseLiteral
jp z, fail
call nexttest

ld hl, s0b0101
call parseLiteral
jp nz, fail
ld a, d
or a
jp nz, fail
ld a, e
cp 0b0101
jp nz, fail
call nexttest

ld hl, s0b01010101
call parseLiteral
jp nz, fail
ld a, d
or a
jp nz, fail
ld a, e
cp 0b01010101
jp nz, fail
call nexttest

.equ FOO 0x42
.equ BAR @+1
ld a, BAR
cp 0x43
jp nz, fail
call nexttest
ret

testDecimal:

; test valid cases. We loop through tblDecimalValid for our cases
ld b, 5
ld hl, .valid

.loop1:
push hl ; --> lvl 1
; put expected number in IX
ld e, (hl)
inc hl
ld d, (hl)
inc hl
push de \ pop ix
call parseDecimalC ; --> DE
jp nz, fail
push ix \ pop hl ; push expected number in HL
ld a, h
cp d
jp nz, fail
ld a, l
cp e
jp nz, fail
pop hl ; <-- lvl 1
ld de, 8 ; row size
add hl, de
djnz .loop1
call nexttest

; test invalid cases. We loop through tblDecimalInvalid for our cases
ld b, 4
ld hl, .invalid

.loop2:
push hl
call parseDecimalC
pop hl
jp z, fail
ld de, 7 ; row size
add hl, de
djnz .loop2
call nexttest
ret

; 2b int, 6b str, null-padded
.valid:
.dw 99
.db "99", 0, 0, 0, 0
.dw 65535
.db "65535", 0
; Space is also accepted as a number "ender"
.dw 42
.db "42 x", 0, 0
; Tab too
.dw 42
.db "42", 0x09, 'x', 0, 0
; A simple "0" works too!
.dw 0
.db '0', 0, 0, 0, 0, 0


; 7b strings, null-padded
.invalid:
; null string is invalid
.db 0, 0, 0, 0, 0, 0, 0
; too big, 5 chars
.db "65536", 0, 0
.db "99999", 0, 0
; too big, 6 chars with rightmost chars being within bound
.db "111111", 0


nexttest:
ld a, (testNum)
inc a
ld (testNum), a
ret

fail:
ld a, (testNum)
halt



Loading…
Cancel
Save