Skip to content

Commit 221846e

Browse files
author
Sriya Pratipati
committed
fixed errno check in tests
1 parent bbbc1f5 commit 221846e

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

libc/test/src/wchar/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ add_libc_test(
4747
libc.src.__support.libc_errno
4848
libc.src.wchar.mbtowc
4949
libc.hdr.types.wchar_t
50+
libc.test.UnitTest.ErrnoCheckingTest
5051
)
5152

5253
add_libc_test(

libc/test/src/wchar/mbtowc_test.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "hdr/types/wchar_t.h"
1010
#include "src/__support/libc_errno.h"
1111
#include "src/wchar/mbtowc.h"
12+
#include "test/UnitTest/ErrnoCheckingTest.h"
1213
#include "test/UnitTest/Test.h"
1314

1415
TEST(LlvmLibcMBToWC, OneByte) {
@@ -21,7 +22,7 @@ TEST(LlvmLibcMBToWC, OneByte) {
2122
// Should fail since we have not read enough
2223
n = LIBC_NAMESPACE::mbtowc(dest, ch, 0);
2324
ASSERT_EQ(n, -1);
24-
ASSERT_EQ(static_cast<int>(libc_errno), EILSEQ);
25+
ASSERT_ERRNO_EQ(EILSEQ);
2526
}
2627

2728
TEST(LlvmLibcMBToWC, TwoByte) {
@@ -38,7 +39,7 @@ TEST(LlvmLibcMBToWC, TwoByte) {
3839
// Should fail after trying to read next byte too
3940
n = LIBC_NAMESPACE::mbtowc(dest, ch + 1, 1);
4041
ASSERT_EQ(n, -1);
41-
ASSERT_EQ(static_cast<int>(libc_errno), EILSEQ);
42+
ASSERT_ERRNO_EQ(EILSEQ);
4243
}
4344

4445
TEST(LlvmLibcMBToWC, ThreeByte) {
@@ -52,7 +53,7 @@ TEST(LlvmLibcMBToWC, ThreeByte) {
5253
// Should fail since we have not read enough
5354
n = LIBC_NAMESPACE::mbtowc(dest, ch, 2);
5455
ASSERT_EQ(n, -1);
55-
ASSERT_EQ(static_cast<int>(libc_errno), EILSEQ);
56+
ASSERT_ERRNO_EQ(EILSEQ);
5657
}
5758

5859
TEST(LlvmLibcMBToWC, FourByte) {
@@ -67,15 +68,15 @@ TEST(LlvmLibcMBToWC, FourByte) {
6768
// Should fail since we have not read enough
6869
n = LIBC_NAMESPACE::mbtowc(dest, ch, 2);
6970
ASSERT_EQ(n, -1);
70-
ASSERT_EQ(static_cast<int>(libc_errno), EILSEQ);
71+
ASSERT_ERRNO_EQ(EILSEQ);
7172
}
7273

7374
TEST(LlvmLibcMBToWC, InvalidByte) {
7475
const char ch[1] = {static_cast<char>(0x80)};
7576
wchar_t dest[2];
7677
int n = LIBC_NAMESPACE::mbtowc(dest, ch, 1);
7778
ASSERT_EQ(n, -1);
78-
ASSERT_EQ(static_cast<int>(libc_errno), EILSEQ);
79+
ASSERT_ERRNO_EQ(EILSEQ);
7980
}
8081

8182
TEST(LlvmLibcMBToWC, InvalidMultiByte) {
@@ -86,7 +87,7 @@ TEST(LlvmLibcMBToWC, InvalidMultiByte) {
8687
// Trying to push all 4 should error
8788
int n = LIBC_NAMESPACE::mbtowc(dest, ch, 4);
8889
ASSERT_EQ(n, -1);
89-
ASSERT_EQ(static_cast<int>(libc_errno), EILSEQ);
90+
ASSERT_ERRNO_EQ(EILSEQ);
9091

9192
// Trying to push the second and third should correspond to null wc
9293
n = LIBC_NAMESPACE::mbtowc(dest, ch + 1, 2);
@@ -103,7 +104,7 @@ TEST(LlvmLibcMBToWC, InvalidLastByte) {
103104
// Trying to push all 4 should error
104105
int n = LIBC_NAMESPACE::mbtowc(dest, ch, 4);
105106
ASSERT_EQ(n, -1);
106-
ASSERT_EQ(static_cast<int>(libc_errno), EILSEQ);
107+
ASSERT_ERRNO_EQ(EILSEQ);
107108
}
108109

109110
TEST(LlvmLibcMBToWC, ValidTwoByteWithExtraRead) {

0 commit comments

Comments
 (0)