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

[NPLB] Support SetTimeZone extension on win #4288

Open
wants to merge 4 commits into
base: 25.lts.1+
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions starboard/nplb/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ target(gtest_target_type, "nplb") {
[ "//starboard/nplb/compiler_compliance/cpp_compiler_version_check.cc" ]
}

if (is_win) {
sources +=
[ "//starboard/nplb/time_zone_with_expect_value_win.cc" ]
} else {
sources +=
[ "//starboard/nplb/time_zone_with_expect_value.cc" ]
}

configs += [ "//starboard/build/config:starboard_implementation" ]
if (sb_enable_cast_codec_tests) {
configs += [ ":cast_codec_tests" ]
Expand Down
101 changes: 42 additions & 59 deletions starboard/nplb/time_zone_get_current_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "starboard/nplb/time_zone_with_expect_value.h"

#include <gmock/gmock.h>
#include <array>

#include "starboard/extension/time_zone.h"
#include "starboard/nplb/time_constants.h"
#include "starboard/system.h"
#include "starboard/time_zone.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand All @@ -21,6 +27,32 @@ namespace starboard {
namespace nplb {
namespace {

class SbTimeZoneGetCurrentSetTimeZoneTest
MarekLuxoft marked this conversation as resolved.
Show resolved Hide resolved
: public testing::Test,
public testing::WithParamInterface<TimeZoneWithExpectValue> {
protected:
void SetUp() override {
time_zone_extension = static_cast<const StarboardExtensionTimeZoneApi*>(
SbSystemGetExtension(kStarboardExtensionTimeZoneName));
if (!time_zone_extension) {
GTEST_SKIP()
<< "Skipping test for platform with missing Time Zone Extension.";
}
ASSERT_STREQ(time_zone_extension->name, kStarboardExtensionTimeZoneName);
ASSERT_EQ(time_zone_extension->version, 1u);
savedTimeZone = SbTimeZoneGetName();
}

void TearDown() override {
if (time_zone_extension) {
time_zone_extension->SetTimeZone(savedTimeZone.c_str());
}
}

std::string savedTimeZone;
const StarboardExtensionTimeZoneApi* time_zone_extension;
};

TEST(SbTimeZoneGetCurrentTest, IsKindOfSane) {
SbTimeZone zone = SbTimeZoneGetCurrent();

Expand All @@ -34,68 +66,19 @@ TEST(SbTimeZoneGetCurrentTest, IsKindOfSane) {

// ... and +24 hours from the Prime Meridian, inclusive
EXPECT_LE(zone, 24 * 60);
}

static auto const* time_zone_extension =
static_cast<const StarboardExtensionTimeZoneApi*>(
SbSystemGetExtension(kStarboardExtensionTimeZoneName));
if (time_zone_extension) {
ASSERT_STREQ(time_zone_extension->name, kStarboardExtensionTimeZoneName);
ASSERT_EQ(time_zone_extension->version, 1u);
time_zone_extension->SetTimeZone("UTC");
zone = SbTimeZoneGetCurrent();
EXPECT_EQ(zone, 0);

// Atlantic time zone, UTC−04:00
time_zone_extension->SetTimeZone("America/Puerto_Rico");
zone = SbTimeZoneGetCurrent();
EXPECT_EQ(zone, 240);

// Eastern time zone, UTC−05:00
time_zone_extension->SetTimeZone("America/New_York");
zone = SbTimeZoneGetCurrent();
EXPECT_EQ(zone, 300);

time_zone_extension->SetTimeZone("US/Eastern");
zone = SbTimeZoneGetCurrent();
EXPECT_EQ(zone, 300);

// Central time zone, UTC−06:00
time_zone_extension->SetTimeZone("America/Chicago");
zone = SbTimeZoneGetCurrent();
EXPECT_EQ(zone, 360);

// Mountain time zone, UTC−07:00
time_zone_extension->SetTimeZone("US/Mountain");
zone = SbTimeZoneGetCurrent();
EXPECT_EQ(zone, 420);

// Pacific time zone, UTC-08:00
time_zone_extension->SetTimeZone("US/Pacific");
zone = SbTimeZoneGetCurrent();
EXPECT_EQ(zone, 480);

// Alaska time zone, UTC-09:00
time_zone_extension->SetTimeZone("US/Alaska");
zone = SbTimeZoneGetCurrent();
EXPECT_EQ(zone, 540);

// Hawaii-Aleutian time zone, UTC-10:00
time_zone_extension->SetTimeZone("Pacific/Honolulu");
zone = SbTimeZoneGetCurrent();
EXPECT_EQ(zone, 600);

// American Samoa time zone, UTC-11:00
time_zone_extension->SetTimeZone("US/Samoa");
zone = SbTimeZoneGetCurrent();
EXPECT_EQ(zone, 660);

// American Samoa time zone, UTC+10:00
time_zone_extension->SetTimeZone("Pacific/Guam");
zone = SbTimeZoneGetCurrent();
EXPECT_EQ(zone, -600);
}
TEST_P(SbTimeZoneGetCurrentSetTimeZoneTest, IsKindOfSane) {
EXPECT_TRUE(time_zone_extension->SetTimeZone(GetParam().timeZoneName.c_str()));
auto zone = SbTimeZoneGetCurrent();
EXPECT_THAT(zone, ::testing::AnyOf(GetParam().expectedStandardValue,
GetParam().expectedDaylightValue));
}

INSTANTIATE_TEST_SUITE_P(SbTimeZoneGetCurrentSetTimeZoneTest,
SbTimeZoneGetCurrentSetTimeZoneTest,
::testing::ValuesIn(timeZonesWithExpectedTimeValues));

} // namespace
} // namespace nplb
} // namespace starboard
4 changes: 4 additions & 0 deletions starboard/nplb/time_zone_get_name_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ TEST(SbTimeZoneGetNameTest, IsKindOfSane) {
// ":Pacific/Kiritimati" is the western-most timezone at UTC+14.
}

#if defined(_WIN32)
TEST(SbTimeZoneGetNameTest, DISABLED_IsIANAFormat) {
#else
TEST(SbTimeZoneGetNameTest, IsIANAFormat) {
#endif
const char* name = SbTimeZoneGetName();
SB_LOG(INFO) << "time zone name: " << name;
char cpy[100];
Expand Down
33 changes: 33 additions & 0 deletions starboard/nplb/time_zone_with_expect_value.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2024 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "starboard/nplb/time_zone_with_expect_value.h"

#if !defined(_WIN32)

const std::array<TimeZoneWithExpectValue, 12> timeZonesWithExpectedTimeValues{
TimeZoneWithExpectValue("UTC", 0, 0),
TimeZoneWithExpectValue("America/Puerto_Rico", 240, 240),
TimeZoneWithExpectValue("America/New_York", 300, 300),
TimeZoneWithExpectValue("US/Eastern", 300, 300),
TimeZoneWithExpectValue("America/Chicago", 360, 360),
TimeZoneWithExpectValue("US/Mountain", 420, 420),
TimeZoneWithExpectValue("US/Pacific", 480, 480),
TimeZoneWithExpectValue("US/Alaska", 540, 540),
TimeZoneWithExpectValue("Pacific/Honolulu", 600, 600),
TimeZoneWithExpectValue("US/Samoa", 660, 660),
TimeZoneWithExpectValue("Australia/South", -570, -570),
TimeZoneWithExpectValue("Pacific/Guam", -600, -600)};

#endif
40 changes: 40 additions & 0 deletions starboard/nplb/time_zone_with_expect_value.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2024 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef STARBOARD_NPLB_TIME_ZONE_WITH_EXPECT_VALUE_H_
#define STARBOARD_NPLB_TIME_ZONE_WITH_EXPECT_VALUE_H_

#include "starboard/time_zone.h"

#include <gmock/gmock.h>
#include <array>
#include <string>

struct TimeZoneWithExpectValue {
TimeZoneWithExpectValue(std::string timeZoneName_,
SbTimeZone expectedStandardValue_,
SbTimeZone expectedDaylightValue_)
: timeZoneName{timeZoneName_},
expectedStandardValue{expectedStandardValue_},
expectedDaylightValue{expectedDaylightValue_} {}

std::string timeZoneName;

SbTimeZone expectedStandardValue;
SbTimeZone expectedDaylightValue;
};

extern const std::array<TimeZoneWithExpectValue, 12> timeZonesWithExpectedTimeValues;

#endif // STARBOARD_NPLB_TIME_ZONE_WITH_EXPECT_VALUE_H_
33 changes: 33 additions & 0 deletions starboard/nplb/time_zone_with_expect_value_win.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2024 The Cobalt Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "starboard/nplb/time_zone_with_expect_value.h"

#if defined(_WIN32)

const std::array<TimeZoneWithExpectValue, 12> timeZonesWithExpectedTimeValues{
TimeZoneWithExpectValue("UTC", 0, 0),
TimeZoneWithExpectValue("Atlantic Standard Time", 240, 180),
TimeZoneWithExpectValue("Eastern Standard Time", 300, 240),
TimeZoneWithExpectValue("Central Standard Time", 360, 300),
TimeZoneWithExpectValue("Mountain Standard Time", 420, 360),
TimeZoneWithExpectValue("Pacific Standard Time", 480, 420),
TimeZoneWithExpectValue("Yukon Standard Time", 420, 420),
TimeZoneWithExpectValue("Samoa Standard Time", -840, -840),
TimeZoneWithExpectValue("China Standard Time", -480, -480),
TimeZoneWithExpectValue("Central European Standard Time", -60, -120),
TimeZoneWithExpectValue("Omsk Standard Time", -360, -360),
TimeZoneWithExpectValue("Cen. Australia Standard Time", -570, -630)};

#endif
5 changes: 5 additions & 0 deletions starboard/shared/win32/system_get_extensions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
#include "starboard/common/string.h"
#include "starboard/extension/configuration.h"
#include "starboard/extension/graphics.h"
#include "starboard/extension/time_zone.h"
#include "starboard/shared/win32/configuration.h"
#include "starboard/shared/win32/graphics.h"
#include "starboard/shared/win32/time_zone.h"

const void* SbSystemGetExtension(const char* name) {
if (strcmp(name, kCobaltExtensionGraphicsName) == 0) {
Expand All @@ -27,5 +29,8 @@ const void* SbSystemGetExtension(const char* name) {
if (strcmp(name, kCobaltExtensionConfigurationName) == 0) {
return starboard::shared::win32::GetConfigurationApi();
}
if (strcmp(name, kStarboardExtensionTimeZoneName) == 0) {
return starboard::shared::win32::GetTimeZoneApi();
}
return NULL;
}
Loading
Loading