Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORC-1663: [C++] Enable TestTimezone.testMissingTZDB on Windows #1856

Closed
wants to merge 6 commits into from
Closed
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
28 changes: 23 additions & 5 deletions c++/test/TestTimezone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "wrap/gmock.h"
#include "wrap/gtest-wrapper.h"

#include <cstdlib>
#include <iostream>
#include <vector>

Expand Down Expand Up @@ -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
Loading