[libc-commits] [libc] [libc] implement localtime (PR #110363)
via libc-commits
libc-commits at lists.llvm.org
Sun Oct 6 08:59:29 PDT 2024
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?=,
=?utf-8?b?0JfQuNGI0LDQvSDQnNC40YDQtw=?Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/110363 at github.com>
================
@@ -0,0 +1,52 @@
+//===-- Unittests for localtime_s -----------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/time/localtime_s.h"
+#include "src/time/mktime.h"
+#include "src/time/time_utils.h"
+#include "test/UnitTest/Test.h"
+#include "test/src/time/TmHelper.h"
+
+using LIBC_NAMESPACE::time_utils::TimeConstants;
+
+TEST(LlvmLibcLocaltimeS, ValidUnixTimestamp0) {
+ struct tm input;
+ const time_t t_ptr = 0;
+ int result = LIBC_NAMESPACE::localtime_s(&t_ptr, &input);
+ ASSERT_EQ(-1, result);
----------------
graphite-app[bot] wrote:
The test assertion is incorrect. `localtime_s` should return 0 for success and non-zero for failure. For a valid timestamp of 0, the expected return value should be 0. Please update the test to:
```cpp
int result = LIBC_NAMESPACE::localtime_s(&t_ptr, &input);
ASSERT_EQ(0, result);
```
Additionally, consider adding assertions to verify the contents of the `input` struct after the call to ensure the time was correctly converted.
*Spotted by [Graphite Reviewer](https://app.graphite.dev/graphite-reviewer/?org=llvm&ref=ai-review-comment)*<i class='graphite__hidden'><br /><br />Is this helpful? React 👍 or 👎 to let us know.</i>
https://github.com/llvm/llvm-project/pull/110363
More information about the libc-commits
mailing list