1 //===-- Unittests for atoll -----------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "src/stdlib/atoll.h" 10 11 #include "utils/UnitTest/Test.h" 12 13 #include <limits.h> 14 15 TEST(LlvmLibcAToLLTest, ValidNumbers) { 16 const char *zero = "0"; 17 ASSERT_EQ(__llvm_libc::atoll(zero), 0ll); 18 19 const char *ten = "10"; 20 ASSERT_EQ(__llvm_libc::atoll(ten), 10ll); 21 22 const char *negative_hundred = "-100"; 23 ASSERT_EQ(__llvm_libc::atoll(negative_hundred), -100ll); 24 25 const char *positive_thousand = "+1000"; 26 ASSERT_EQ(__llvm_libc::atoll(positive_thousand), 1000ll); 27 28 const char *spaces_before = " 12345"; 29 ASSERT_EQ(__llvm_libc::atoll(spaces_before), 12345ll); 30 31 const char *tabs_before = "\t\t\t\t67890"; 32 ASSERT_EQ(__llvm_libc::atoll(tabs_before), 67890ll); 33 34 const char *letters_after = "123abc"; 35 ASSERT_EQ(__llvm_libc::atoll(letters_after), 123ll); 36 37 const char *letters_between = "456def789"; 38 ASSERT_EQ(__llvm_libc::atoll(letters_between), 456ll); 39 40 const char *all_together = "\t 110 times 5 = 550"; 41 ASSERT_EQ(__llvm_libc::atoll(all_together), 110ll); 42 43 const char *biggest_long_long = "9223372036854775807"; 44 ASSERT_EQ(__llvm_libc::atoll(biggest_long_long), LLONG_MAX); 45 46 const char *smallest_long_long = "-9223372036854775808"; 47 ASSERT_EQ(__llvm_libc::atoll(smallest_long_long), LLONG_MIN); 48 } 49 50 TEST(LlvmLibcAToLLTest, NonBaseTenWholeNumbers) { 51 const char *hexadecimal = "0x10"; 52 ASSERT_EQ(__llvm_libc::atoll(hexadecimal), 0ll); 53 54 const char *octal = "010"; 55 ASSERT_EQ(__llvm_libc::atoll(octal), 10ll); 56 57 const char *decimal_point = "5.9"; 58 ASSERT_EQ(__llvm_libc::atoll(decimal_point), 5ll); 59 } 60 61 TEST(LlvmLibcAToLLTest, NotNumbers) { 62 const char *ten_as_word = "ten"; 63 ASSERT_EQ(__llvm_libc::atoll(ten_as_word), 0ll); 64 65 const char *lots_of_letters = 66 "wtragsdhfgjykutjdyfhgnchgmjhkyurktfgjhlu;po7urtdjyfhgklyk"; 67 ASSERT_EQ(__llvm_libc::atoll(lots_of_letters), 0ll); 68 } 69