| OLD | NEW |
| (Empty) |
| 1 // Copyright 2010 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 #include "base/scoped_ptr.h" | |
| 17 #include "omaha/base/app_util.h" | |
| 18 #include "omaha/base/string.h" | |
| 19 #include "omaha/common/lang.h" | |
| 20 #include "omaha/goopdate/resource_manager.h" | |
| 21 #include "omaha/goopdate/server_resource.h" | |
| 22 #include "omaha/goopdate/string_formatter.h" | |
| 23 #include "omaha/testing/unit_test.h" | |
| 24 | |
| 25 using ::testing::_; | |
| 26 | |
| 27 namespace omaha { | |
| 28 | |
| 29 class StringFormatterTest : public testing::Test { | |
| 30 protected: | |
| 31 StringFormatterTest() {} | |
| 32 | |
| 33 static void SetUpTestCase() { | |
| 34 CString resource_dir = app_util::GetModuleDirectory(NULL); | |
| 35 EXPECT_HRESULT_SUCCEEDED( | |
| 36 ResourceManager::CreateForDefaultLanguage(false, resource_dir)); | |
| 37 } | |
| 38 static void TearDownTestCase() { | |
| 39 ResourceManager::Delete(); | |
| 40 } | |
| 41 | |
| 42 virtual void SetUp() {} | |
| 43 | |
| 44 virtual void TearDown() {} | |
| 45 }; | |
| 46 | |
| 47 TEST_F(StringFormatterTest, LoadStringTest) { | |
| 48 CString loaded_string; | |
| 49 StringFormatter formatter_en(_T("en")); | |
| 50 EXPECT_HRESULT_SUCCEEDED(formatter_en.LoadString(IDS_CLOSE, &loaded_string)); | |
| 51 EXPECT_STREQ(_T("Close"), loaded_string); | |
| 52 | |
| 53 StringFormatter formatter_de(_T("de")); | |
| 54 EXPECT_HRESULT_SUCCEEDED( | |
| 55 formatter_de.LoadString(IDS_DOWNLOADING, &loaded_string)); | |
| 56 // The loaded string should keep the raw format ('%1!s!') untouched. | |
| 57 EXPECT_STREQ(_T("%1!s! wird heruntergeladen..."), loaded_string); | |
| 58 | |
| 59 // Test that loading non-existing language resource returns error. | |
| 60 { | |
| 61 StringFormatter formatter_unknown(_T("non-existing")); | |
| 62 ExpectAsserts expect_asserts; | |
| 63 EXPECT_HRESULT_FAILED( | |
| 64 formatter_unknown.LoadString(IDS_CLOSE, &loaded_string)); | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 TEST_F(StringFormatterTest, FormatMessageTest) { | |
| 69 CString format_result; | |
| 70 | |
| 71 // Test FormatMessage loads string from correct language resource file. | |
| 72 StringFormatter formatter_en(_T("en")); | |
| 73 EXPECT_HRESULT_SUCCEEDED( | |
| 74 formatter_en.FormatMessage(&format_result, IDS_CLOSE)); | |
| 75 EXPECT_STREQ(_T("Close"), format_result); | |
| 76 | |
| 77 StringFormatter formatter_de(_T("de")); | |
| 78 EXPECT_HRESULT_SUCCEEDED( | |
| 79 formatter_de.FormatMessage(&format_result, IDS_CLOSE)); | |
| 80 EXPECT_STREQ(_T("Schließen"), format_result); // NOLINT | |
| 81 | |
| 82 StringFormatter formatter_fr(_T("fr")); | |
| 83 EXPECT_HRESULT_SUCCEEDED( | |
| 84 formatter_fr.FormatMessage(&format_result, IDS_CLOSE)); | |
| 85 EXPECT_STREQ(_T("Fermer"), format_result); | |
| 86 | |
| 87 // Test FormatMessage with additional argument(s). | |
| 88 EXPECT_HRESULT_SUCCEEDED(formatter_en.FormatMessage(&format_result, | |
| 89 IDS_DOWNLOADING, | |
| 90 _T("English"))); | |
| 91 EXPECT_STREQ(_T("Downloading English..."), format_result); | |
| 92 | |
| 93 EXPECT_HRESULT_SUCCEEDED(formatter_de.FormatMessage(&format_result, | |
| 94 IDS_DOWNLOADING, | |
| 95 _T("German"))); | |
| 96 EXPECT_STREQ(_T("German wird heruntergeladen..."), format_result); | |
| 97 | |
| 98 EXPECT_HRESULT_SUCCEEDED(formatter_fr.FormatMessage(&format_result, | |
| 99 IDS_DOWNLOADING, | |
| 100 _T("French"))); | |
| 101 EXPECT_STREQ(_T("Téléchargement de French..."), format_result); // NOLINT | |
| 102 } | |
| 103 | |
| 104 } // namespace omaha | |
| 105 | |
| OLD | NEW |