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

Side by Side Diff: goopdate/resource_manager_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 | « goopdate/resource_manager.cc ('k') | goopdate/resources/build.scons » ('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 2007-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 // ResourceManager unit tests.
17
18 #include <map>
19 #include <vector>
20 #include "omaha/base/app_util.h"
21 #include "omaha/base/constants.h"
22 #include "omaha/base/debug.h"
23 #include "omaha/base/file.h"
24 #include "omaha/base/path.h"
25 #include "omaha/base/string.h"
26 #include "omaha/common/lang.h"
27 #include "omaha/goopdate/resource_manager.h"
28 #include "omaha/goopdate/resources/goopdateres/goopdate.grh"
29 #include "omaha/testing/unit_test.h"
30
31 namespace omaha {
32
33 namespace {
34
35 const int kNumberOfLanguageDlls = 55;
36
37 } // namespace
38
39 class ResourceManagerTest : public testing::Test {
40 protected:
41 virtual void SetUp() {
42 path_ = app_util::GetModuleDirectory(NULL);
43 EXPECT_HRESULT_SUCCEEDED(
44 ResourceManager::CreateForDefaultLanguage(false, path_));
45 }
46
47 virtual void TearDown() {
48 ResourceManager::Delete();
49 }
50
51 void SetMachine(bool is_machine) {
52 ResourceManager::instance_->is_machine_ = is_machine;
53 }
54
55 void SetResourceDir(const CString& resource_dir) {
56 ResourceManager::instance_->resource_dir_ = resource_dir;
57 }
58
59 CString GetResourceDir() const {
60 return ResourceManager::instance_->resource_dir_;
61 }
62
63 CString GetLang(LANGID langid) {
64 return lang::GetLanguageForLangID(langid);
65 }
66
67 void VerifyLoadingResourceDll(const CString& lang, bool is_success) {
68 ResourceManager::ResourceDllInfo dll_info;
69
70 HRESULT hr = ResourceManager::Instance().GetResourceDllInfo(lang,
71 &dll_info);
72 if (is_success) {
73 EXPECT_HRESULT_SUCCEEDED(hr);
74 EXPECT_TRUE(dll_info.dll_handle != NULL);
75 EXPECT_STREQ(lang, dll_info.language);
76
77 CString expected_file_name;
78 expected_file_name.Format(kOmahaResourceDllNameFormat, lang);
79 CString expected_path = ConcatenatePath(path_, expected_file_name);
80 EXPECT_STREQ(expected_path, dll_info.file_path);
81 } else {
82 EXPECT_HRESULT_FAILED(hr);
83 EXPECT_EQ(NULL, dll_info.dll_handle);
84 EXPECT_STREQ(_T(""), dll_info.language);
85 }
86 }
87
88 static CString GetResourceDllName(const CString& language) {
89 return ResourceManager::GetResourceDllName(language);
90 }
91
92 CString path_;
93 };
94
95 // Disables the default resources used for unit testing and restores them after
96 // the test.
97 // For some reason, the _AtlBaseModule.SetResourceInstance() call in
98 // ResourceManager does not replace the existing resources, so they must be
99 // unloaded first.
100 class ResourceManagerResourcesProtectedTest : public ResourceManagerTest {
101 protected:
102 // Assumes that the default resources are the first loaded at index 0.
103 virtual void SetUp() {
104 ResourceManagerTest::SetUp();
105
106 default_resources_ = _AtlBaseModule.GetHInstanceAt(0);
107 _AtlBaseModule.RemoveResourceInstance(default_resources_);
108 }
109
110 virtual void TearDown() {
111 _AtlBaseModule.AddResourceInstance(default_resources_);
112
113 ResourceManagerTest::TearDown();
114 }
115
116 private:
117 HINSTANCE default_resources_;
118 };
119
120 TEST_F(ResourceManagerTest, GetResourceDllName) {
121 const CString kLang(_T("en"));
122 CString ret = GetResourceDllName(kLang);
123
124 CString expected_filename;
125 expected_filename.Format(kOmahaResourceDllNameFormat, kLang);
126 EXPECT_STREQ(expected_filename, ret);
127 }
128
129 TEST_F(ResourceManagerTest, GetResourceDllName_SpecialCases) {
130 // zh-HK -> zh-TW
131 EXPECT_STREQ(_T("goopdateres_zh-TW.dll"), GetResourceDllName(_T("zh-TW")));
132 EXPECT_STREQ(_T("goopdateres_zh-TW.dll"), GetResourceDllName(_T("zh-HK")));
133
134 // he -> iw
135 EXPECT_STREQ(_T("goopdateres_iw.dll"), GetResourceDllName(_T("iw")));
136 EXPECT_STREQ(_T("goopdateres_iw.dll"), GetResourceDllName(_T("he")));
137 }
138
139 TEST_F(ResourceManagerTest, LoadResourceFail) {
140 SetMachine(false);
141
142 CString original_resoruce_dir = GetResourceDir();
143 SetResourceDir(_T("non_existing\\abcddir"));
144
145 // Loading resource from a non-existing directory should fail. The language
146 // being loaded here should not be loaded previously. Otherwise the resource
147 // manager will return the cached value instead of doing actual load.
148 VerifyLoadingResourceDll(_T("ca"), false);
149
150 SetResourceDir(original_resoruce_dir);
151 }
152
153 TEST_F(ResourceManagerTest, LoadResourceDllCmdLine) {
154 SetMachine(false);
155
156 CString lang = _T("ca");
157 VerifyLoadingResourceDll(lang, true);
158 }
159
160 TEST_F(ResourceManagerTest, LoadResourceDllCmdLineMachine) {
161 SetMachine(true);
162
163 CString lang = _T("ca");
164 VerifyLoadingResourceDll(lang, true);
165 }
166
167 TEST_F(ResourceManagerTest, TestCountLanguageDlls) {
168 std::vector<CString> filenames;
169 ResourceManager::GetSupportedLanguageDllNames(&filenames);
170 EXPECT_EQ(kNumberOfLanguageDlls, filenames.size());
171 }
172
173 TEST_F(ResourceManagerTest, TestAppropriateLanguageDlls) {
174 std::vector<CString> filenames;
175 ResourceManager::GetSupportedLanguageDllNames(&filenames);
176
177 std::vector<CString>::iterator iter = filenames.begin();
178
179 EXPECT_STREQ(_T("goopdateres_am.dll"), *iter++);
180 EXPECT_STREQ(_T("goopdateres_ar.dll"), *iter++);
181 EXPECT_STREQ(_T("goopdateres_bg.dll"), *iter++);
182 EXPECT_STREQ(_T("goopdateres_bn.dll"), *iter++);
183 EXPECT_STREQ(_T("goopdateres_ca.dll"), *iter++);
184 EXPECT_STREQ(_T("goopdateres_cs.dll"), *iter++);
185 EXPECT_STREQ(_T("goopdateres_da.dll"), *iter++);
186 EXPECT_STREQ(_T("goopdateres_de.dll"), *iter++);
187 EXPECT_STREQ(_T("goopdateres_el.dll"), *iter++);
188 EXPECT_STREQ(_T("goopdateres_en.dll"), *iter++);
189 EXPECT_STREQ(_T("goopdateres_en-GB.dll"), *iter++);
190 EXPECT_STREQ(_T("goopdateres_es.dll"), *iter++);
191 EXPECT_STREQ(_T("goopdateres_es-419.dll"), *iter++);
192 EXPECT_STREQ(_T("goopdateres_et.dll"), *iter++);
193 EXPECT_STREQ(_T("goopdateres_fa.dll"), *iter++);
194 EXPECT_STREQ(_T("goopdateres_fi.dll"), *iter++);
195 EXPECT_STREQ(_T("goopdateres_fil.dll"), *iter++);
196 EXPECT_STREQ(_T("goopdateres_fr.dll"), *iter++);
197 EXPECT_STREQ(_T("goopdateres_gu.dll"), *iter++);
198 EXPECT_STREQ(_T("goopdateres_hi.dll"), *iter++);
199 EXPECT_STREQ(_T("goopdateres_hr.dll"), *iter++);
200 EXPECT_STREQ(_T("goopdateres_hu.dll"), *iter++);
201 EXPECT_STREQ(_T("goopdateres_id.dll"), *iter++);
202 EXPECT_STREQ(_T("goopdateres_is.dll"), *iter++);
203 EXPECT_STREQ(_T("goopdateres_it.dll"), *iter++);
204 EXPECT_STREQ(_T("goopdateres_iw.dll"), *iter++);
205 EXPECT_STREQ(_T("goopdateres_ja.dll"), *iter++);
206 EXPECT_STREQ(_T("goopdateres_kn.dll"), *iter++);
207 EXPECT_STREQ(_T("goopdateres_ko.dll"), *iter++);
208 EXPECT_STREQ(_T("goopdateres_lt.dll"), *iter++);
209 EXPECT_STREQ(_T("goopdateres_lv.dll"), *iter++);
210 EXPECT_STREQ(_T("goopdateres_ml.dll"), *iter++);
211 EXPECT_STREQ(_T("goopdateres_mr.dll"), *iter++);
212 EXPECT_STREQ(_T("goopdateres_ms.dll"), *iter++);
213 EXPECT_STREQ(_T("goopdateres_nl.dll"), *iter++);
214 EXPECT_STREQ(_T("goopdateres_no.dll"), *iter++);
215 EXPECT_STREQ(_T("goopdateres_pl.dll"), *iter++);
216 EXPECT_STREQ(_T("goopdateres_pt-BR.dll"), *iter++);
217 EXPECT_STREQ(_T("goopdateres_pt-PT.dll"), *iter++);
218 EXPECT_STREQ(_T("goopdateres_ro.dll"), *iter++);
219 EXPECT_STREQ(_T("goopdateres_ru.dll"), *iter++);
220 EXPECT_STREQ(_T("goopdateres_sk.dll"), *iter++);
221 EXPECT_STREQ(_T("goopdateres_sl.dll"), *iter++);
222 EXPECT_STREQ(_T("goopdateres_sr.dll"), *iter++);
223 EXPECT_STREQ(_T("goopdateres_sv.dll"), *iter++);
224 EXPECT_STREQ(_T("goopdateres_sw.dll"), *iter++);
225 EXPECT_STREQ(_T("goopdateres_ta.dll"), *iter++);
226 EXPECT_STREQ(_T("goopdateres_te.dll"), *iter++);
227 EXPECT_STREQ(_T("goopdateres_th.dll"), *iter++);
228 EXPECT_STREQ(_T("goopdateres_tr.dll"), *iter++);
229 EXPECT_STREQ(_T("goopdateres_uk.dll"), *iter++);
230 EXPECT_STREQ(_T("goopdateres_ur.dll"), *iter++);
231 EXPECT_STREQ(_T("goopdateres_vi.dll"), *iter++);
232 EXPECT_STREQ(_T("goopdateres_zh-CN.dll"), *iter++);
233 // goopdateres_zh-HK.dll not present
234 EXPECT_STREQ(_T("goopdateres_zh-TW.dll"), *iter++);
235 }
236
237 TEST_F(ResourceManagerResourcesProtectedTest, RussianResourcesValid) {
238 ResourceManager::Delete();
239
240 CString lang(_T("ru"));
241 EXPECT_HRESULT_SUCCEEDED(ResourceManager::Create(false, path_, lang));
242
243 CString install_success(FormatResourceMessage(
244 IDS_BUNDLE_INSTALLED_SUCCESSFULLY, _T("Google Gears")));
245
246 EXPECT_STREQ("Благодарим за установку Google Gears.",
247 WideToUtf8(install_success));
248
249 CString install_fail(FormatResourceMessage(IDS_INSTALLER_FAILED_WITH_MESSAGE,
250 _T("12345"),
251 _T("Action failed.")));
252
253 EXPECT_STREQ("Ошибка установщика 12345: Action failed.",
254 WideToUtf8(install_fail));
255 }
256
257 } // namespace omaha
OLDNEW
« no previous file with comments | « goopdate/resource_manager.cc ('k') | goopdate/resources/build.scons » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698