time_zone_test.cc
Go to the documentation of this file.
00001 // Copyright 2017 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 
00015 #include "absl/time/internal/cctz/include/cctz/time_zone.h"
00016 
00017 #include "gtest/gtest.h"
00018 #include "absl/time/internal/test_util.h"
00019 #include "absl/time/time.h"
00020 
00021 namespace cctz = absl::time_internal::cctz;
00022 
00023 namespace {
00024 
00025 TEST(TimeZone, ValueSemantics) {
00026   absl::TimeZone tz;
00027   absl::TimeZone tz2 = tz;  // Copy-construct
00028   EXPECT_EQ(tz, tz2);
00029   tz2 = tz;  // Copy-assign
00030   EXPECT_EQ(tz, tz2);
00031 }
00032 
00033 TEST(TimeZone, Equality) {
00034   absl::TimeZone a, b;
00035   EXPECT_EQ(a, b);
00036   EXPECT_EQ(a.name(), b.name());
00037 
00038   absl::TimeZone implicit_utc;
00039   absl::TimeZone explicit_utc = absl::UTCTimeZone();
00040   EXPECT_EQ(implicit_utc, explicit_utc);
00041   EXPECT_EQ(implicit_utc.name(), explicit_utc.name());
00042 
00043   absl::TimeZone la = absl::time_internal::LoadTimeZone("America/Los_Angeles");
00044   absl::TimeZone nyc = absl::time_internal::LoadTimeZone("America/New_York");
00045   EXPECT_NE(la, nyc);
00046 }
00047 
00048 TEST(TimeZone, CCTZConversion) {
00049   const cctz::time_zone cz = cctz::utc_time_zone();
00050   const absl::TimeZone tz(cz);
00051   EXPECT_EQ(cz, cctz::time_zone(tz));
00052 }
00053 
00054 TEST(TimeZone, DefaultTimeZones) {
00055   absl::TimeZone tz;
00056   EXPECT_EQ("UTC", absl::TimeZone().name());
00057   EXPECT_EQ("UTC", absl::UTCTimeZone().name());
00058 }
00059 
00060 TEST(TimeZone, FixedTimeZone) {
00061   const absl::TimeZone tz = absl::FixedTimeZone(123);
00062   const cctz::time_zone cz = cctz::fixed_time_zone(cctz::seconds(123));
00063   EXPECT_EQ(tz, absl::TimeZone(cz));
00064 }
00065 
00066 TEST(TimeZone, LocalTimeZone) {
00067   const absl::TimeZone local_tz = absl::LocalTimeZone();
00068   absl::TimeZone tz = absl::time_internal::LoadTimeZone("localtime");
00069   EXPECT_EQ(tz, local_tz);
00070 }
00071 
00072 TEST(TimeZone, NamedTimeZones) {
00073   absl::TimeZone nyc = absl::time_internal::LoadTimeZone("America/New_York");
00074   EXPECT_EQ("America/New_York", nyc.name());
00075   absl::TimeZone syd = absl::time_internal::LoadTimeZone("Australia/Sydney");
00076   EXPECT_EQ("Australia/Sydney", syd.name());
00077   absl::TimeZone fixed = absl::FixedTimeZone((((3 * 60) + 25) * 60) + 45);
00078   EXPECT_EQ("Fixed/UTC+03:25:45", fixed.name());
00079 }
00080 
00081 TEST(TimeZone, Failures) {
00082   absl::TimeZone tz = absl::time_internal::LoadTimeZone("America/Los_Angeles");
00083   EXPECT_FALSE(LoadTimeZone("Invalid/TimeZone", &tz));
00084   EXPECT_EQ(absl::UTCTimeZone(), tz);  // guaranteed fallback to UTC
00085 
00086   // Ensures that the load still fails on a subsequent attempt.
00087   tz = absl::time_internal::LoadTimeZone("America/Los_Angeles");
00088   EXPECT_FALSE(LoadTimeZone("Invalid/TimeZone", &tz));
00089   EXPECT_EQ(absl::UTCTimeZone(), tz);  // guaranteed fallback to UTC
00090 
00091   // Loading an empty std::string timezone should fail.
00092   tz = absl::time_internal::LoadTimeZone("America/Los_Angeles");
00093   EXPECT_FALSE(LoadTimeZone("", &tz));
00094   EXPECT_EQ(absl::UTCTimeZone(), tz);  // guaranteed fallback to UTC
00095 }
00096 
00097 }  // namespace


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:15