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

Side by Side Diff: base/localization_unittest.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@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
« no previous file with comments | « base/localization.cc ('k') | base/lock_ptr.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2004-2009 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 // ========================================================================
15 //
16 // localization_unittest.cpp
17 //
18 // Unit test functions for Localization
19
20 #include "omaha/base/localization.h"
21 #include "omaha/base/string.h"
22 #include "omaha/base/time.h"
23 #include "omaha/testing/unit_test.h"
24
25 using testing::Message;
26
27 namespace omaha {
28
29 // Test out the time display functions
30 void LocalizationTimeTest() {
31 CString time_str;
32
33 // Lets process this a bit to give ourselves a known time.
34 SYSTEMTIME temp_time;
35 temp_time.wYear = 2004;
36 temp_time.wMonth = 4;
37 temp_time.wDayOfWeek = 1;
38 temp_time.wDay = 19;
39 temp_time.wHour = 19;
40 temp_time.wMinute = 18;
41 temp_time.wSecond = 17;
42 temp_time.wMilliseconds = 16;
43
44 time64 override_time = SystemTimeToTime64(&temp_time);
45
46 // Useful when debugging to confirm that this worked
47 SYSTEMTIME confirm = Time64ToSystemTime(override_time);
48
49 // the need to check two different times below is because:
50
51 // FileTimeToLocalFileTime uses the current settings for the time
52 // zone and daylight saving time. Therefore, if it is daylight
53 // saving time, this function will take daylight saving time into
54 // account, even if the time you are converting is in standard
55 // time.
56 // TODO(omaha): we may want to fix this.
57
58 // Show just the time [ie -12:19pm]
59 time_str = ShowTimeForLocale(override_time, 1033 /* US english */);
60 ASSERT_TRUE(time_str == _T("12:18 PM") || time_str == _T("11:18 AM"))
61 << _T("Returned time string was ") << time_str.GetString();
62
63 // Show just the time [ie - 12:19:18pm]
64 time_str = ShowFormattedTimeForLocale(override_time, 1033,
65 _T("hh:mm:ss tt"));
66 ASSERT_TRUE(time_str == _T("12:18:17 PM") || time_str == _T("11:18:17 AM"))
67 << _T("Returned time string was ") << time_str.GetString();
68
69 // Try it out with a some different values to test out single digit
70 // minutes and such
71 temp_time.wHour = 15;
72 temp_time.wMinute = 4;
73 temp_time.wSecond = 3;
74 temp_time.wMilliseconds = 2;
75 override_time = SystemTimeToTime64(&temp_time);
76
77 time_str = ShowTimeForLocale(override_time, 1033);
78 ASSERT_TRUE(time_str == _T("8:04 AM") || time_str == _T("7:04 AM"))
79 << _T("Returned time string was ") << time_str.GetString();
80
81 time_str = ShowFormattedTimeForLocale(override_time, 1033,
82 _T("hh:mm:ss tt"));
83 ASSERT_TRUE(time_str == _T("08:04:03 AM") || time_str == _T("07:04:03 AM"))
84 << _T("Returned time string was ") << time_str.GetString();
85
86
87 //
88 // Check the date functionality
89 //
90
91 temp_time.wYear = 2004;
92 temp_time.wMonth = 4;
93 temp_time.wDayOfWeek = 1;
94 temp_time.wDay = 19;
95
96 // Show the short date
97 time_str = ShowDateForLocale(override_time, 1033);
98 // CHKM(time_str == _T("Monday, April 19, 2004"),
99 ASSERT_STREQ(time_str, _T("4/19/2004"));
100
101 // Show the customized date
102 time_str = ShowFormattedDateForLocale(override_time, 1033,
103 _T("MMM d, yyyy"));
104 ASSERT_STREQ(time_str, _T("Apr 19, 2004"));
105
106 // Try it out with a some different values to test out single dates and such
107 temp_time.wDay = 1;
108 override_time = SystemTimeToTime64(&temp_time);
109
110 time_str = ShowFormattedDateForLocale(override_time, 1033,
111 _T("ddd, MMM dd"));
112 ASSERT_STREQ(time_str, _T("Thu, Apr 01"));
113
114 time_str = ShowFormattedDateForLocale(override_time, 1033, _T("MM/dd/yyyy"));
115 ASSERT_STREQ(time_str, _T("04/01/2004"));
116 }
117
118 // Test out the numbers and display functions
119 void LocalizationNumberTest() {
120 // Make sure we are using the normal american version
121 SetLcidOverride(1033); // the codepage for american english
122
123 // Try some basics
124 ASSERT_STREQ(Show(1), _T("1"));
125 ASSERT_STREQ(Show(2), _T("2"));
126
127 // Try some extremes
128 ASSERT_STREQ(Show(0), _T("0"));
129 ASSERT_STREQ(Show(kint32max), _T("2,147,483,647"));
130 ASSERT_STREQ(Show(-kint32max), _T("-2,147,483,647"));
131 ASSERT_STREQ(Show(kuint32max), _T("4,294,967,295"));
132
133 // Try some doubles
134 ASSERT_STREQ(Show(0.3, 0), _T("0"));
135 ASSERT_STREQ(Show(0.3, 1), _T("0.3"));
136 ASSERT_STREQ(Show(0.3, 2), _T("0.30"));
137 ASSERT_STREQ(Show(0.3, 5), _T("0.30000"));
138
139 // Try some with interesting rounding
140 ASSERT_STREQ(Show(0.159, 0), _T("0"));
141 ASSERT_STREQ(Show(0.159, 1), _T("0.1"));
142 ASSERT_STREQ(Show(0.159, 2), _T("0.15"));
143 ASSERT_STREQ(Show(0.159, 5), _T("0.15900"));
144
145 // Try a nice whole number
146 ASSERT_STREQ(Show(12.0, 0), _T("12"));
147 ASSERT_STREQ(Show(12.0, 1), _T("12.0"));
148 ASSERT_STREQ(Show(12.0, 2), _T("12.00"));
149 ASSERT_STREQ(Show(12.0, 5), _T("12.00000"));
150 }
151
152 TEST(LocalizationTest, Localization) {
153 LocalizationTimeTest();
154 LocalizationNumberTest();
155 }
156
157 } // namespace omaha
158
OLDNEW
« no previous file with comments | « base/localization.cc ('k') | base/lock_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698