1 //===-- Unittests for strerror --------------------------------------------===// 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/__support/StringUtil/platform_errors.h" 10 #include "src/__support/macros/properties/architectures.h" 11 #include "src/string/strerror.h" 12 #include "test/UnitTest/Test.h" 13 14 TEST(LlvmLibcStrErrorTest, KnownErrors) { 15 ASSERT_STREQ(LIBC_NAMESPACE::strerror(0), "Success"); 16 17 for (auto [i, msg] : LIBC_NAMESPACE::PLATFORM_ERRORS) 18 EXPECT_STREQ(LIBC_NAMESPACE::strerror(static_cast<int>(i)), msg.begin()); 19 } 20 21 TEST(LlvmLibcStrErrorTest, UnknownErrors) { 22 ASSERT_STREQ(LIBC_NAMESPACE::strerror(-1), "Unknown error -1"); 23 ASSERT_STREQ(LIBC_NAMESPACE::strerror(134), "Unknown error 134"); 24 ASSERT_STREQ(LIBC_NAMESPACE::strerror(2147483647), 25 "Unknown error 2147483647"); 26 ASSERT_STREQ(LIBC_NAMESPACE::strerror(-2147483648), 27 "Unknown error -2147483648"); 28 } 29