Add tests for atoi()

This commit is contained in:
2025-07-20 11:41:20 +02:00
parent 4ed0ae373c
commit 3510139c25

View File

@@ -25,6 +25,7 @@ extern strcmp
; convert.asm
extern itoa
extern utoa
extern atoi
section .rodata
TEST_print equ 1
@@ -40,9 +41,10 @@ section .rodata
TEST_tolower equ 1
TEST_toupper equ 1
TEST_strcmp equ 1
TEST_min equ 0 ;includes minu
TEST_max equ 0 ;includes maxu
TEST_min equ 1 ;includes minu
TEST_max equ 1 ;includes maxu
TEST_clamp equ 1 ;includes clampu
TEST_atoi equ 1
str1 db "Hello, world!",EOS
str2 db "Hello, World!",EOS
@@ -202,6 +204,20 @@ section .rodata
clampuArg2 equ MAX_UINT32
clampu1 db TAB,"clampu(MAX_UINT64, clampArg1, clampArg2): %d",NL,EOS
clampu2 db TAB,"clampu(MAX_UINT16, clampArg1, clampArg2): %d",NL,EOS
; atoi()
msgAtoi db NL,"TEST atoi()",NL,EOS
atoiOutput db TAB,"%s = %d",NL,EOS
atoi1 db "1234567890",EOS
atoi2 db "0xFFFFFFFF",EOS ;4 294 967 295
atoi3 db "0o776655",EOS ;261 549
atoi4 db "0b11001001",EOS ;201
atoi5 db "-0000001",EOS ;-1
atoi6 db "-1690000000004",EOS
atoi7 db "0x0962ABCDEF",EOS ;40 310 132 207
atoi8 db "0x0962GBCDEF",EOS ;0
atoi9 db "0o77865",EOS ;0
atoi10 db "0b102001",EOS;0
section .data
section .bss
@@ -1064,6 +1080,33 @@ _start:
call printf
%endif
;---
;--- atoi()
;---
%if TEST_atoi
lea rdi, [rel msgAtoi]
call print
%macro testatoi 1
lea rdi, [rel %1]
call atoi
lea rdi, [rel atoiOutput]
lea rsi, [rel %1]
mov rdx, rax
call printf
%endmacro
testatoi atoi1
testatoi atoi2
testatoi atoi3
testatoi atoi4
testatoi atoi5
testatoi atoi6
testatoi atoi7
testatoi atoi8
testatoi atoi9
testatoi atoi10
%endif
;---
;--- exit()
;---