Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions libc/test/src/time/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ add_libc_unittest(
CXX_STANDARD
20
DEPENDS
libc.hdr.errno_macros
libc.src.time.asctime
libc.hdr.types.struct_tm
libc.src.time.time_constants
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_unittest(
Expand All @@ -29,9 +31,11 @@ add_libc_unittest(
CXX_STANDARD
20
DEPENDS
libc.hdr.errno_macros
libc.src.time.asctime_r
libc.hdr.types.struct_tm
libc.src.time.time_constants
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_unittest(
Expand All @@ -51,6 +55,7 @@ add_libc_unittest(
libc.src.time.ctime
libc.src.time.time_constants
libc.hdr.types.struct_tm
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_unittest(
Expand All @@ -70,6 +75,7 @@ add_libc_unittest(
libc.src.time.ctime_r
libc.src.time.time_constants
libc.hdr.types.struct_tm
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_unittest(
Expand Down Expand Up @@ -151,10 +157,12 @@ add_libc_unittest(
HDRS
TmMatcher.h
DEPENDS
libc.hdr.errno_macros
libc.src.time.gmtime
libc.src.__support.CPP.limits
libc.hdr.types.struct_tm
libc.src.time.time_constants
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_unittest(
Expand All @@ -169,6 +177,7 @@ add_libc_unittest(
libc.src.time.gmtime_r
libc.hdr.types.struct_tm
libc.src.time.time_constants
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_test(
Expand Down Expand Up @@ -197,9 +206,9 @@ add_libc_test(
nanosleep_test.cpp
DEPENDS
libc.include.time
libc.src.time.nanosleep
libc.src.errno.errno
libc.hdr.types.struct_timespec
libc.src.time.nanosleep
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_test(
Expand Down
9 changes: 6 additions & 3 deletions libc/test/src/time/asctime_r_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/libc_errno.h"
#include "hdr/errno_macros.h"
#include "src/time/asctime_r.h"
#include "src/time/time_constants.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"
#include "test/src/time/TmHelper.h"

using LlvmLibcAsctimeR = LIBC_NAMESPACE::testing::ErrnoCheckingTest;

static inline char *call_asctime_r(struct tm *tm_data, int year, int month,
int mday, int hour, int min, int sec,
int wday, int yday, char *buffer) {
Expand All @@ -22,7 +25,7 @@ static inline char *call_asctime_r(struct tm *tm_data, int year, int month,

// asctime and asctime_r share the same code and thus didn't repeat all the
// tests from asctime. Added couple of validation tests.
TEST(LlvmLibcAsctimeR, Nullptr) {
TEST_F(LlvmLibcAsctimeR, Nullptr) {
char *result;
result = LIBC_NAMESPACE::asctime_r(nullptr, nullptr);
ASSERT_ERRNO_EQ(EINVAL);
Expand All @@ -39,7 +42,7 @@ TEST(LlvmLibcAsctimeR, Nullptr) {
ASSERT_STREQ(nullptr, result);
}

TEST(LlvmLibcAsctimeR, ValidDate) {
TEST_F(LlvmLibcAsctimeR, ValidDate) {
char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE];
struct tm tm_data;
char *result;
Expand Down
19 changes: 11 additions & 8 deletions libc/test/src/time/asctime_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/libc_errno.h"
#include "hdr/errno_macros.h"
#include "src/time/asctime.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"
#include "test/src/time/TmHelper.h"

using LlvmLibcAsctime = LIBC_NAMESPACE::testing::ErrnoCheckingTest;

static inline char *call_asctime(struct tm *tm_data, int year, int month,
int mday, int hour, int min, int sec, int wday,
int yday) {
Expand All @@ -19,15 +22,15 @@ static inline char *call_asctime(struct tm *tm_data, int year, int month,
return LIBC_NAMESPACE::asctime(tm_data);
}

TEST(LlvmLibcAsctime, Nullptr) {
TEST_F(LlvmLibcAsctime, Nullptr) {
char *result;
result = LIBC_NAMESPACE::asctime(nullptr);
ASSERT_ERRNO_EQ(EINVAL);
ASSERT_STREQ(nullptr, result);
}

// Weekdays are in the range 0 to 6. Test passing invalid value in wday.
TEST(LlvmLibcAsctime, InvalidWday) {
TEST_F(LlvmLibcAsctime, InvalidWday) {
struct tm tm_data;

// Test with wday = -1.
Expand Down Expand Up @@ -56,7 +59,7 @@ TEST(LlvmLibcAsctime, InvalidWday) {
}

// Months are from January to December. Test passing invalid value in month.
TEST(LlvmLibcAsctime, InvalidMonth) {
TEST_F(LlvmLibcAsctime, InvalidMonth) {
struct tm tm_data;

// Test with month = 0.
Expand Down Expand Up @@ -84,7 +87,7 @@ TEST(LlvmLibcAsctime, InvalidMonth) {
ASSERT_ERRNO_EQ(EINVAL);
}

TEST(LlvmLibcAsctime, ValidWeekdays) {
TEST_F(LlvmLibcAsctime, ValidWeekdays) {
struct tm tm_data;
char *result;
// 1970-01-01 00:00:00.
Expand Down Expand Up @@ -124,7 +127,7 @@ TEST(LlvmLibcAsctime, ValidWeekdays) {
ASSERT_STREQ("Sun Jan 4 00:00:00 1970\n", result);
}

TEST(LlvmLibcAsctime, ValidMonths) {
TEST_F(LlvmLibcAsctime, ValidMonths) {
struct tm tm_data;
char *result;
// 1970-01-01 00:00:00.
Expand Down Expand Up @@ -164,7 +167,7 @@ TEST(LlvmLibcAsctime, ValidMonths) {
ASSERT_STREQ("Thu Dec 31 23:59:59 1970\n", result);
}

TEST(LlvmLibcAsctime, EndOf32BitEpochYear) {
TEST_F(LlvmLibcAsctime, EndOf32BitEpochYear) {
struct tm tm_data;
char *result;
// Test for maximum value of a signed 32-bit integer.
Expand All @@ -181,7 +184,7 @@ TEST(LlvmLibcAsctime, EndOf32BitEpochYear) {
ASSERT_STREQ("Tue Jan 19 03:14:07 2038\n", result);
}

TEST(LlvmLibcAsctime, Max64BitYear) {
TEST_F(LlvmLibcAsctime, Max64BitYear) {
if (sizeof(time_t) == 4)
return;
// Mon Jan 1 12:50:50 2170 (200 years from 1970),
Expand Down
12 changes: 7 additions & 5 deletions libc/test/src/time/ctime_r_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/libc_errno.h"
#include "src/time/ctime_r.h"
#include "src/time/time_constants.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"
#include "test/src/time/TmHelper.h"

TEST(LlvmLibcCtimeR, Nullptr) {
using LlvmLibcCtimeR = LIBC_NAMESPACE::testing::ErrnoCheckingTest;

TEST_F(LlvmLibcCtimeR, Nullptr) {
char *result;
result = LIBC_NAMESPACE::ctime_r(nullptr, nullptr);
ASSERT_STREQ(nullptr, result);
Expand All @@ -26,7 +28,7 @@ TEST(LlvmLibcCtimeR, Nullptr) {
ASSERT_STREQ(nullptr, result);
}

TEST(LlvmLibcCtimeR, ValidUnixTimestamp0) {
TEST_F(LlvmLibcCtimeR, ValidUnixTimestamp0) {
char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE];
time_t t;
char *result;
Expand All @@ -36,7 +38,7 @@ TEST(LlvmLibcCtimeR, ValidUnixTimestamp0) {
ASSERT_STREQ("Thu Jan 1 00:00:00 1970\n", result);
}

TEST(LlvmLibcCtime, ValidUnixTimestamp32Int) {
TEST_F(LlvmLibcCtimeR, ValidUnixTimestamp32Int) {
char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE];
time_t t;
char *result;
Expand All @@ -46,7 +48,7 @@ TEST(LlvmLibcCtime, ValidUnixTimestamp32Int) {
ASSERT_STREQ("Tue Jan 19 03:14:07 2038\n", result);
}

TEST(LlvmLibcCtimeR, InvalidArgument) {
TEST_F(LlvmLibcCtimeR, InvalidArgument) {
char buffer[LIBC_NAMESPACE::time_constants::ASCTIME_BUFFER_SIZE];
time_t t;
char *result;
Expand Down
12 changes: 7 additions & 5 deletions libc/test/src/time/ctime_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,36 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/libc_errno.h"
#include "src/time/ctime.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"
#include "test/src/time/TmHelper.h"

TEST(LlvmLibcCtime, nullptr) {
using LlvmLibcCtime = LIBC_NAMESPACE::testing::ErrnoCheckingTest;

TEST_F(LlvmLibcCtime, nullptr) {
char *result;
result = LIBC_NAMESPACE::ctime(nullptr);
ASSERT_STREQ(nullptr, result);
}

TEST(LlvmLibcCtime, ValidUnixTimestamp0) {
TEST_F(LlvmLibcCtime, ValidUnixTimestamp0) {
time_t t;
char *result;
t = 0;
result = LIBC_NAMESPACE::ctime(&t);
ASSERT_STREQ("Thu Jan 1 00:00:00 1970\n", result);
}

TEST(LlvmLibcCtime, ValidUnixTimestamp32Int) {
TEST_F(LlvmLibcCtime, ValidUnixTimestamp32Int) {
time_t t;
char *result;
t = 2147483647;
result = LIBC_NAMESPACE::ctime(&t);
ASSERT_STREQ("Tue Jan 19 03:14:07 2038\n", result);
}

TEST(LlvmLibcCtime, InvalidArgument) {
TEST_F(LlvmLibcCtime, InvalidArgument) {
time_t t;
char *result;
t = 2147483648;
Expand Down
7 changes: 5 additions & 2 deletions libc/test/src/time/gmtime_r_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@

#include "src/time/gmtime_r.h"
#include "src/time/time_constants.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"
#include "test/src/time/TmMatcher.h"

using LlvmLibcGmTimeR = LIBC_NAMESPACE::testing::ErrnoCheckingTest;

// gmtime and gmtime_r share the same code and thus didn't repeat all the tests
// from gmtime. Added couple of validation tests.
TEST(LlvmLibcGmTimeR, EndOf32BitEpochYear) {
TEST_F(LlvmLibcGmTimeR, EndOf32BitEpochYear) {
// Test for maximum value of a signed 32-bit integer.
// Test implementation can encode time for Tue 19 January 2038 03:14:07 UTC.
time_t seconds = 0x7FFFFFFF;
Expand All @@ -34,7 +37,7 @@ TEST(LlvmLibcGmTimeR, EndOf32BitEpochYear) {
EXPECT_TM_EQ(*tm_data_ptr, tm_data);
}

TEST(LlvmLibcGmTimeR, Max64BitYear) {
TEST_F(LlvmLibcGmTimeR, Max64BitYear) {
if (sizeof(time_t) == 4)
return;
// Test for Tue Jan 1 12:50:50 in 2,147,483,647th year.
Expand Down
Loading
Loading