Add tests for strlen
This commit is contained in:
@@ -228,14 +228,26 @@ section .rodata
|
|||||||
putsStr db "Howdy, environment!",EOS
|
putsStr db "Howdy, environment!",EOS
|
||||||
;printf()
|
;printf()
|
||||||
addTestHeader(_printf, "printf")
|
addTestHeader(_printf, "printf")
|
||||||
addTest(printf_invalid, "printf(''H%ell%0 T\\%t\he%%%re%\n'')") ;=> Should be 'H%ell%0 T\\%t\he%%re%' => 21 (+1 for NL) (yes, aware of the fact that '%0' is printed as '0' at the time of writing)
|
addTest(printf_invalid, "printf(''H%ell%0 T\\%t\he%%%re%\n'')") ;'H%ell%0 T\\%t\he%%re%' => 21 (+1 for NL)
|
||||||
printfStr1 db "H%ell%0 T\\%t\he%%%re%\n",EOS
|
printfStr1 db "H%ell%0 T\\%t\he%%%re%\n",EOS
|
||||||
addTest(printf_hexpadd, "printf(''%x | %16x | %016x | %#16x | %#016x\n%X | %016X | %16X | %#016X | %#16X\n'', 80181775710, [... same arg 9 more times])")
|
addTest(printf_hexpadd, "printf(''%x | %16x | %016x | %#16x | %#016x\n%X | %016X | %16X | %#016X | %#16X\n'', 80181775710, [... same arg 9 more times])")
|
||||||
printfStr2 db "%x | %16x | %016x | %#16x | %#016x\n%X | %016X | %16X | %#016X | %#16X\n",EOS
|
printfStr2 db "%x | %16x | %016x | %#16x | %#016x\n%X | %016X | %16X | %#016X | %#16X\n",EOS
|
||||||
addTest(printf_ppadd, "printf(''%p | %16p | %016p | %#16p | %#016p\n%p | %016p | %16p | %#016p | %#16p\n'', 80181775710, [... same arg 9 more times])")
|
addTest(printf_ppadd, "printf(''%p | %16p | %016p | %#16p | %#016p\n%p | %016p | %16p | %#016p | %#16p\n'', 80181775710, [... same arg 9 more times])")
|
||||||
printfStr3 db "%p | %16p | %016p | %#16p | %#016p\n%p | %016p | %16p | %#016p | %#16p\n",EOS
|
printfStr3 db "%p | %16p | %016p | %#16p | %#016p\n%p | %016p | %16p | %#016p | %#16p\n",EOS
|
||||||
|
; STRINGS FOR USE IN STRING FUNCTIOns
|
||||||
section .data
|
str1 db "Hello, World!",EOS;13
|
||||||
|
str2 db "Hello, world!",EOS;13
|
||||||
|
str3 db "Hello World!",EOS;12
|
||||||
|
str4 db "Howdy environment!",EOS;18
|
||||||
|
str5 db "The quick brown fox jumps over the lazy dog",EOS;23
|
||||||
|
printStrs db "\n### Strings for string functions ###\nstr1: %s\nstr2: %s\nstr3: %s\nstr4: %s\nstr5: %s\n",EOS
|
||||||
|
;strlen()
|
||||||
|
addTestHeader(_strlen, "strlen")
|
||||||
|
addTest(strlen1, "strlen(str1)")
|
||||||
|
addTest(strlen2, "strlen(str2)")
|
||||||
|
addTest(strlen3, "strlen(str3)")
|
||||||
|
addTest(strlen4, "strlen(str4)")
|
||||||
|
addTest(strlen5, "strlen(str5)")
|
||||||
|
|
||||||
section .bss
|
section .bss
|
||||||
|
|
||||||
@@ -678,6 +690,52 @@ _start:
|
|||||||
assert_eq(178) ;Len of TEST 2 + 4 (since %p always uses prefix 0x, this test has that two times extra => 4 chars)
|
assert_eq(178) ;Len of TEST 2 + 4 (since %p always uses prefix 0x, this test has that two times extra => 4 chars)
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
|
;;;
|
||||||
|
;;; STRINGS FOR STRING FUNCTIONS
|
||||||
|
;;;
|
||||||
|
lea rdi, [rel printStrs]
|
||||||
|
lea rsi, [rel str1]
|
||||||
|
lea rdx, [rel str2]
|
||||||
|
lea rcx, [rel str3]
|
||||||
|
lea r8, [rel str4]
|
||||||
|
lea r9, [rel str5]
|
||||||
|
call printf
|
||||||
|
|
||||||
|
;--- strlen()
|
||||||
|
%if TEST_strlen
|
||||||
|
printTestHeader(_strlen)
|
||||||
|
|
||||||
|
; TEST 1: strlen(str1)
|
||||||
|
printTest(strlen1)
|
||||||
|
lea rdi, [rel str1]
|
||||||
|
call strlen
|
||||||
|
assert_eq(13)
|
||||||
|
|
||||||
|
; TEST 2: strlen(str2)
|
||||||
|
printTest(strlen2)
|
||||||
|
lea rdi, [rel str2]
|
||||||
|
call strlen
|
||||||
|
assert_eq(13)
|
||||||
|
|
||||||
|
; TEST 3: strlen(str3)
|
||||||
|
printTest(strlen3)
|
||||||
|
lea rdi, [rel str3]
|
||||||
|
call strlen
|
||||||
|
assert_eq(12)
|
||||||
|
|
||||||
|
; TEST 4: strlen(str4)
|
||||||
|
printTest(strlen4)
|
||||||
|
lea rdi, [rel str4]
|
||||||
|
call strlen
|
||||||
|
assert_eq(18)
|
||||||
|
|
||||||
|
; TEST 5: strlen(str5)
|
||||||
|
printTest(strlen5)
|
||||||
|
lea rdi, [rel str5]
|
||||||
|
call strlen
|
||||||
|
assert_eq(43)
|
||||||
|
%endif
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
;;; TEST RESULTS
|
;;; TEST RESULTS
|
||||||
;;;
|
;;;
|
||||||
|
Reference in New Issue
Block a user