This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/main by this push:
new fa627ec6d ORC-1663: [C++] Enable TestTimezone.testMissingTZDB on
Windows
fa627ec6d is described below
commit fa627ec6d7c72289c8a83632e6a43ae48603fc4b
Author: Gang Wu <[email protected]>
AuthorDate: Fri Mar 22 08:09:02 2024 -0700
ORC-1663: [C++] Enable TestTimezone.testMissingTZDB on Windows
### What changes were proposed in this pull request?
Enable TestTimezone.testMissingTZDB unit test to run on Windows.
### Why are the changes needed?
When /usr/share/zoneinfo is unavailable and TZDIR env is unset, creating
C++ ORC reader will crash on Windows. We need to better deal with this case.
See context from the Apache Arrow community:
https://github.com/apache/arrow/issues/36026 and
https://github.com/apache/arrow/issues/40633
### How was this patch tested?
Make sure the test passes on Windows.
### Was this patch authored or co-authored using generative AI tooling?
No.
Closes #1856 from wgtmac/win_tz_test.
Authored-by: Gang Wu <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
---
c++/test/TestTimezone.cc | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc
index 69f3b854e..2330fcfb0 100644
--- a/c++/test/TestTimezone.cc
+++ b/c++/test/TestTimezone.cc
@@ -21,6 +21,7 @@
#include "wrap/gmock.h"
#include "wrap/gtest-wrapper.h"
+#include <cstdlib>
#include <iostream>
#include <vector>
@@ -403,20 +404,37 @@ namespace orc {
EXPECT_EQ(1699164000 + 8 * 3600, la->convertFromUTC(1699164000));
}
-#ifndef _MSC_VER
+ bool setEnv(const char* name, const char* value) {
+#ifdef _MSC_VER
+ return _putenv_s(name, value) == 0;
+#else
+ return setenv(name, value, 1) == 0;
+#endif
+ }
+
+ bool delEnv(const char* name) {
+#ifdef _MSC_VER
+ return _putenv_s(name, "") == 0;
+#else
+ return unsetenv(name) == 0;
+#endif
+ }
+
TEST(TestTimezone, testMissingTZDB) {
const char* tzDirBackup = std::getenv("TZDIR");
- setenv("TZDIR", "/path/to/wrong/tzdb", 1);
+ if (tzDirBackup != nullptr) {
+ ASSERT_TRUE(delEnv("TZDIR"));
+ }
+ ASSERT_TRUE(setEnv("TZDIR", "/path/to/wrong/tzdb"));
EXPECT_THAT([]() { getTimezoneByName("America/Los_Angeles"); },
testing::ThrowsMessage<TimezoneError>(testing::HasSubstr(
"Time zone file /path/to/wrong/tzdb/America/Los_Angeles
does not exist."
" Please install IANA time zone database and set TZDIR
env.")));
if (tzDirBackup != nullptr) {
- setenv("TZDIR", tzDirBackup, 1);
+ ASSERT_TRUE(setEnv("TZDIR", tzDirBackup));
} else {
- unsetenv("TZDIR");
+ ASSERT_TRUE(delEnv("TZDIR"));
}
}
-#endif
} // namespace orc