aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-11-25 03:35:06 +0100
committerCharles <sircharlesaze@gmail.com>2019-11-25 03:35:06 +0100
commit5d6aa79961c10b56c6f59adf77ba00ddf296cdbe (patch)
tree32a2791b405ce82484de058414897168e3cf5101
parent6b8ffc0a55562b553698fd062ce046255c8ce04d (diff)
downloadlibasm_test-5d6aa79961c10b56c6f59adf77ba00ddf296cdbe.tar.gz
libasm_test-5d6aa79961c10b56c6f59adf77ba00ddf296cdbe.tar.bz2
libasm_test-5d6aa79961c10b56c6f59adf77ba00ddf296cdbe.zip
More atoi_base test
-rw-r--r--ft_atoi_base_test.c28
-rw-r--r--libasm_test.h2
2 files changed, 29 insertions, 1 deletions
diff --git a/ft_atoi_base_test.c b/ft_atoi_base_test.c
index ece1ce7..653d6b1 100644
--- a/ft_atoi_base_test.c
+++ b/ft_atoi_base_test.c
@@ -4,8 +4,9 @@ static int expected_ret;
static int actual_ret;
#define FT_ATOI_BASE_EXPECT(str, base) do { \
- expected_ret = ref_ft_atoi_base(str, base); \
+ asm("movq $0xffffffffffffffff, %rax"); \
actual_ret = ft_atoi_base(str, base); \
+ expected_ret = ref_ft_atoi_base(str, base); \
if (actual_ret != expected_ret) \
printf("KO: [COMPARE]: %s: expected: %d got: %d with: "#str", "#base"\n", \
test_name, expected_ret, actual_ret); \
@@ -45,6 +46,29 @@ ft_atoi_base_segfault(void)
TEST_ASM_FUNCTION(ft_atoi_base("ff", "abcc"));
TEST_ASM_FUNCTION(ft_atoi_base("ff", ""));
TEST_ASM_FUNCTION(ft_atoi_base("ff", "a"));
+ TEST_ASM_FUNCTION(ft_atoi_base("-ff", "0123456789abcdef"));
+ TEST_ASM_FUNCTION(ft_atoi_base("--ff", "0123456789abcdef"));
+ TEST_ASM_FUNCTION(ft_atoi_base("+--ff", "0123456789abcdef"));
+ TEST_ASM_FUNCTION(ft_atoi_base("-++++++-+--ff", "0123456789abcdef"));
+ TEST_ASM_FUNCTION(ft_atoi_base("-++++++-+--ff\xff", "0123456789abcdef"));
+ TEST_ASM_FUNCTION(ft_atoi_base("-+\r++-+--ff\xff", "0123456789abcdef"));
+ TEST_ASM_FUNCTION(ft_atoi_base("-01", "01"));
+ TEST_ASM_FUNCTION(ft_atoi_base("--11101", "01"));
+ TEST_ASM_FUNCTION(ft_atoi_base("+-123", "01"));
+ TEST_ASM_FUNCTION(ft_atoi_base("-++++01++-+--ff", "01"));
+ TEST_ASM_FUNCTION(ft_atoi_base("-++10101\xff", "01"));
+ TEST_ASM_FUNCTION(ft_atoi_base("-+\r++-+--01\x01", "01"));
+ TEST_ASM_FUNCTION(ft_atoi_base("a\0bb", "ab"));
+ TEST_ASM_FUNCTION(ft_atoi_base("-b\0bb", "ab"));
+ TEST_ASM_FUNCTION(ft_atoi_base(" \t\n\r-++++++-+--ff\xff", "0123456789abcdef"));
+ TEST_ASM_FUNCTION(ft_atoi_base(" -+\r++-+--ff\xff", "0123456789abcdef"));
+ TEST_ASM_FUNCTION(ft_atoi_base("\n-01", "01"));
+ TEST_ASM_FUNCTION(ft_atoi_base("\x0b--11101", "01"));
+ TEST_ASM_FUNCTION(ft_atoi_base(" 755x+", "01234567"));
+ TEST_ASM_FUNCTION(ft_atoi_base(" 700chmod", "01234567"));
+ TEST_ASM_FUNCTION(ft_atoi_base(" 644yo", "01234567"));
+ TEST_ASM_FUNCTION(ft_atoi_base(TO_STRING(INT_MAX), "0123456789"));
+ TEST_ASM_FUNCTION(ft_atoi_base(TO_STRING(INT_MIN), "0123456789"));
}
static void
@@ -100,6 +124,8 @@ ft_atoi_base_compare(void)
FT_ATOI_BASE_EXPECT(" 755x+", "01234567");
FT_ATOI_BASE_EXPECT(" 700chmod", "01234567");
FT_ATOI_BASE_EXPECT(" 644yo", "01234567");
+ FT_ATOI_BASE_EXPECT(TO_STRING(INT_MAX), "0123456789");
+ FT_ATOI_BASE_EXPECT(TO_STRING(INT_MIN), "0123456789");
}
void
diff --git a/libasm_test.h b/libasm_test.h
index d31f699..675c5ad 100644
--- a/libasm_test.h
+++ b/libasm_test.h
@@ -11,6 +11,8 @@
# include <limits.h>
# include <stddef.h>
+# define TO_STRING(x) #x
+
/*
* mandatory
*/