diff --git a/src/tests.asm b/src/tests.asm index e0b0c9b..0f57d5f 100644 --- a/src/tests.asm +++ b/src/tests.asm @@ -197,6 +197,20 @@ section .rodata addTest(clampu2, "clampu(0, 1, 1000)") addTest(clampu3, "clampu(1337, 1, 1000)") addTest(clampu4, "clampu(MAX_UINT64, 0, MAX_UINT32)") + ;print() + addTestHeader(_print, "print") + addTest(print1, "print(''Hello, world!\n'')") + printStr db "Hello, world!",NL,EOS + ;puts() + addTestHeader(_puts, "puts") + addTest(puts1, "puts(''Howdy, environment!''") + putsStr db "Howdy, environment!",EOS + ;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%' => 20 (+1 for NL) (yes, aware of the fact that '%0' is printed as '0' at the time of writing) + 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])") + printfStr2 db "%x | %16x | %016x | %#16x | %#016x\n%X | %016X | %16X | %#016X | %#16X\n",EOS section .data @@ -521,6 +535,55 @@ _start: assert_u_eq(MAX_UINT32) %endif +;--- print() +%if TEST_print + printTestHeader(_print) + + lea rdi, [rel printStr] + call print + assert_eq(14) +%endif + +;--- puts() +%if TEST_puts + printTestHeader(_puts) + + lea rdi, [rel putsStr] + call puts + assert_eq(20) +%endif + +;--- printf() +%if TEST_printf + printTestHeader(_printf) + + ; TEST 1 (some invalid specifiers/characters) + printTest(printf_invalid) + lea rdi, [rel printfStr1] + xor rsi, rsi + xor rdx, rdx + xor rcx, rcx + call printf + assert_eq(21) + + ; TEST 2 (print hexadecimal numbers in multiple possible ways) + printTest(printf_hexpadd) + lea rdi, [rel printfStr2] + mov rsi, 80181775710 + mov rdx, rsi + mov rcx, rsi + mov r8, rsi + mov r9, rsi + push rsi + push rsi + push rsi + push rsi + push rsi + call printf + add rsp, SIZE_QWORD * 5 + assert_eq(174) ;8*16(%[#][0]16(x|X)) + (8*3( | ) + 20 (2x %x) + 2 (NL) => 174 +%endif + ;;; ;;; TEST RESULTS ;;;