1 //===-- Unittests for strerror --------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "src/string/strerror.h"
10 #include "test/UnitTest/Test.h"
12 TEST(LlvmLibcStrErrorTest
, KnownErrors
) {
13 ASSERT_STREQ(LIBC_NAMESPACE::strerror(0), "Success");
15 const char *message_array
[] = {
17 "Operation not permitted",
18 "No such file or directory",
20 "Interrupted system call",
22 "No such device or address",
23 "Argument list too long",
25 "Bad file descriptor",
27 "Resource temporarily unavailable",
28 "Cannot allocate memory",
31 "Block device required",
32 "Device or resource busy",
34 "Invalid cross-device link",
39 "Too many open files in system",
40 "Too many open files",
41 "Inappropriate ioctl for device",
44 "No space left on device",
46 "Read-only file system",
49 "Numerical argument out of domain",
50 "Numerical result out of range",
51 "Resource deadlock avoided",
54 "Function not implemented",
55 "Directory not empty",
56 "Too many levels of symbolic links",
57 "Unknown error 41", // Unknown
58 "No message of desired type",
60 "Channel number out of range",
61 "Level 2 not synchronized",
64 "Link number out of range",
65 "Protocol driver not attached",
66 "No CSI structure available",
69 "Invalid request descriptor",
72 "Invalid request code",
74 "Unknown error 58", // Unknown
75 "Bad font file format",
76 "Device not a stream",
79 "Out of streams resources",
80 "Machine is not on the network",
81 "Package not installed",
83 "Link has been severed",
86 "Communication error on send",
91 "Value too large for defined data type",
92 "Name not unique on network",
93 "File descriptor in bad state",
94 "Remote address changed",
95 "Can not access a needed shared library",
96 "Accessing a corrupted shared library",
97 ".lib section in a.out corrupted",
98 "Attempting to link in too many shared libraries",
99 "Cannot exec a shared library directly",
100 "Invalid or incomplete multibyte or wide character",
101 "Interrupted system call should be restarted",
102 "Streams pipe error",
104 "Socket operation on non-socket",
105 "Destination address required",
107 "Protocol wrong type for socket",
108 "Protocol not available",
109 "Protocol not supported",
110 "Socket type not supported",
111 "Operation not supported",
112 "Protocol family not supported",
113 "Address family not supported by protocol",
114 "Address already in use",
115 "Cannot assign requested address",
117 "Network is unreachable",
118 "Network dropped connection on reset",
119 "Software caused connection abort",
120 "Connection reset by peer",
121 "No buffer space available",
122 "Transport endpoint is already connected",
123 "Transport endpoint is not connected",
124 "Cannot send after transport endpoint shutdown",
125 "Too many references: cannot splice",
126 "Connection timed out",
127 "Connection refused",
130 "Operation already in progress",
131 "Operation now in progress",
133 "Structure needs cleaning",
134 "Not a XENIX named type file",
135 "No XENIX semaphores available",
136 "Is a named type file",
138 "Disk quota exceeded",
141 "Operation canceled",
142 "Required key not available",
144 "Key has been revoked",
145 "Key was rejected by service",
147 "State not recoverable",
148 "Operation not possible due to RF-kill",
149 "Memory page has hardware error",
152 for (size_t i
= 0; i
< (sizeof(message_array
) / sizeof(char *)); ++i
) {
153 EXPECT_STREQ(LIBC_NAMESPACE::strerror(static_cast<int>(i
)),
158 TEST(LlvmLibcStrErrorTest
, UnknownErrors
) {
159 ASSERT_STREQ(LIBC_NAMESPACE::strerror(-1), "Unknown error -1");
160 ASSERT_STREQ(LIBC_NAMESPACE::strerror(134), "Unknown error 134");
161 ASSERT_STREQ(LIBC_NAMESPACE::strerror(2147483647),
162 "Unknown error 2147483647");
163 ASSERT_STREQ(LIBC_NAMESPACE::strerror(-2147483648),
164 "Unknown error -2147483648");