Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(543)

Side by Side Diff: snapshot/system_snapshot_mac_test.cc

Issue 626093005: Improve SystemSnapshotMac::TimeZone()’s computation of UTC offsets (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "snapshot/system_snapshot_mac.h" 15 #include "snapshot/system_snapshot_mac.h"
16 16
17 #include <sys/time.h> 17 #include <sys/time.h>
18 #include <time.h>
18 19
19 #include <string> 20 #include <string>
20 21
21 #include "build/build_config.h" 22 #include "build/build_config.h"
22 #include "gtest/gtest.h" 23 #include "gtest/gtest.h"
23 #include "util/mac/mac_util.h" 24 #include "util/mac/mac_util.h"
24 #include "util/mac/process_reader.h" 25 #include "util/mac/process_reader.h"
25 #include "util/test/errors.h" 26 #include "util/test/errors.h"
26 27
27 namespace { 28 namespace {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 EXPECT_GE(system_snapshot().CPUCount(), 1); 80 EXPECT_GE(system_snapshot().CPUCount(), 1);
80 } 81 }
81 82
82 TEST_F(SystemSnapshotMacTest, CPUVendor) { 83 TEST_F(SystemSnapshotMacTest, CPUVendor) {
83 std::string cpu_vendor = system_snapshot().CPUVendor(); 84 std::string cpu_vendor = system_snapshot().CPUVendor();
84 85
85 #if defined(ARCH_CPU_X86_FAMILY) 86 #if defined(ARCH_CPU_X86_FAMILY)
86 // Apple has only shipped Intel x86-family CPUs, but here’s a small nod to the 87 // Apple has only shipped Intel x86-family CPUs, but here’s a small nod to the
87 // “Hackintosh” crowd. 88 // “Hackintosh” crowd.
88 if (cpu_vendor != "GenuineIntel" && cpu_vendor != "AuthenticAMD") { 89 if (cpu_vendor != "GenuineIntel" && cpu_vendor != "AuthenticAMD") {
89 FAIL() << cpu_vendor; 90 FAIL() << "cpu_vendor " << cpu_vendor;
90 } 91 }
91 #else 92 #else
92 #error port to your architecture 93 #error port to your architecture
93 #endif 94 #endif
94 } 95 }
95 96
96 #if defined(ARCH_CPU_X86_FAMILY) 97 #if defined(ARCH_CPU_X86_FAMILY)
97 98
98 TEST_F(SystemSnapshotMacTest, CPUX86SupportsDAZ) { 99 TEST_F(SystemSnapshotMacTest, CPUX86SupportsDAZ) {
99 // All x86-family CPUs that Apple is known to have shipped should support DAZ. 100 // All x86-family CPUs that Apple is known to have shipped should support DAZ.
(...skipping 20 matching lines...) Expand all
120 } 121 }
121 122
122 TEST_F(SystemSnapshotMacTest, OSVersionFull) { 123 TEST_F(SystemSnapshotMacTest, OSVersionFull) {
123 EXPECT_FALSE(system_snapshot().OSVersionFull().empty()); 124 EXPECT_FALSE(system_snapshot().OSVersionFull().empty());
124 } 125 }
125 126
126 TEST_F(SystemSnapshotMacTest, MachineDescription) { 127 TEST_F(SystemSnapshotMacTest, MachineDescription) {
127 EXPECT_FALSE(system_snapshot().MachineDescription().empty()); 128 EXPECT_FALSE(system_snapshot().MachineDescription().empty());
128 } 129 }
129 130
131 TEST_F(SystemSnapshotMacTest, TimeZone) {
132 SystemSnapshot::DaylightSavingTimeStatus dst_status;
133 int standard_offset_seconds;
134 int daylight_offset_seconds;
135 std::string standard_name;
136 std::string daylight_name;
137
138 system_snapshot().TimeZone(&dst_status,
139 &standard_offset_seconds,
140 &daylight_offset_seconds,
141 &standard_name,
142 &daylight_name);
143
144 // |standard_offset_seconds| gives seconds east of UTC, and |timezone| gives
145 // seconds west of UTC.
146 EXPECT_EQ(-timezone, standard_offset_seconds);
147
148 // In contemporary usage, most time zones have an integer hour offset from
149 // UTC, although several are at a half-hour offset, and two are at 15-minute
150 // offsets. Throughout history, other variations existed. See
151 // http://www.timeanddate.com/time/time-zones-interesting.html.
152 EXPECT_EQ(0, standard_offset_seconds % (15 * 60))
153 << "standard_offset_seconds " << standard_offset_seconds;
154
155 if (dst_status == SystemSnapshot::kDoesNotObserveDaylightSavingTime) {
156 EXPECT_EQ(standard_offset_seconds, daylight_offset_seconds);
157 EXPECT_EQ(standard_name, daylight_name);
158 } else {
159 EXPECT_EQ(0, daylight_offset_seconds % (15 * 60))
160 << "daylight_offset_seconds " << daylight_offset_seconds;
161
162 // In contemporary usage, dst_delta_seconds will almost always be one hour,
163 // except for Lord Howe Island, Australia, which uses a 30-minute
164 // delta. Throughout history, other variations existed. See
165 // http://www.timeanddate.com/time/dst/#brief.
166 int dst_delta_seconds = daylight_offset_seconds - standard_offset_seconds;
167 if (dst_delta_seconds != 60 * 60 && dst_delta_seconds != 30 * 60) {
168 FAIL() << "dst_delta_seconds " << dst_delta_seconds;
169 }
170
171 EXPECT_NE(standard_name, daylight_name);
172 }
173 }
174
130 } // namespace 175 } // namespace
OLDNEW
« snapshot/system_snapshot_mac.cc ('K') | « snapshot/system_snapshot_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698