Chromium Code Reviews| Index: base/file_version_info_win_unittest.cc |
| diff --git a/base/file_version_info_unittest.cc b/base/file_version_info_win_unittest.cc |
| similarity index 66% |
| rename from base/file_version_info_unittest.cc |
| rename to base/file_version_info_win_unittest.cc |
| index ac5320f398b2dac51fabf6889ec7558668c79a13..0603aa34f0d0f073c959069bdf0d750b8164175e 100644 |
| --- a/base/file_version_info_unittest.cc |
| +++ b/base/file_version_info_win_unittest.cc |
| @@ -2,27 +2,24 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "base/file_version_info.h" |
| +#include "base/file_version_info_win.h" |
| + |
| +#include <windows.h> |
| #include <stddef.h> |
| #include <memory> |
| +#include "base/file_version_info.h" |
| #include "base/files/file_path.h" |
| #include "base/macros.h" |
| #include "base/path_service.h" |
| -#include "build/build_config.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| -#if defined(OS_WIN) |
| -#include "base/file_version_info_win.h" |
| -#endif |
| - |
| using base::FilePath; |
| namespace { |
| -#if defined(OS_WIN) |
| FilePath GetTestDataPath() { |
| FilePath path; |
| PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| @@ -32,12 +29,52 @@ FilePath GetTestDataPath() { |
| path = path.AppendASCII("file_version_info_unittest"); |
| return path; |
| } |
| -#endif |
| + |
| +class FileVersionInfoFactory { |
| + public: |
| + FileVersionInfoFactory(const FilePath& path) : path_(path) {} |
| + |
| + FileVersionInfo* Create() const { |
| + return FileVersionInfo::CreateFileVersionInfo(path_); |
| + } |
| + |
| + private: |
| + const FilePath path_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(FileVersionInfoFactory); |
| +}; |
| + |
| +class FileVersionInfoForModuleFactory { |
| + public: |
| + FileVersionInfoForModuleFactory(const FilePath& path) |
| + : library_(::LoadLibraryEx(path.value().c_str(), |
|
grt (UTC plus 2)
2016/06/17 20:35:00
please add a brief comment explaining why base::Sc
fdoray
2016/06/20 14:06:41
ScopedNativeLibrary can be used for this. We just
|
| + NULL, |
| + LOAD_LIBRARY_AS_IMAGE_RESOURCE)) { |
| + EXPECT_TRUE(library_); |
| + } |
| + ~FileVersionInfoForModuleFactory() { ::FreeLibrary(library_); } |
| + |
| + FileVersionInfo* Create() const { |
| + return FileVersionInfo::CreateFileVersionInfoForModule(library_); |
| + } |
| + |
| + private: |
| + const HMODULE library_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(FileVersionInfoForModuleFactory); |
| +}; |
| + |
| +template <typename T> |
| +class FileVersionInfoTest : public testing::Test {}; |
| + |
| +using FileVersionInfoFactories = |
| + ::testing::Types<FileVersionInfoFactory, FileVersionInfoForModuleFactory>; |
| } // namespace |
| -#if defined(OS_WIN) |
| -TEST(FileVersionInfoTest, HardCodedProperties) { |
| +TYPED_TEST_CASE(FileVersionInfoTest, FileVersionInfoFactories); |
| + |
| +TYPED_TEST(FileVersionInfoTest, HardCodedProperties) { |
| const wchar_t kDLLName[] = {L"FileVersionInfoTest1.dll"}; |
| const wchar_t* const kExpectedValues[15] = { |
| @@ -62,8 +99,9 @@ TEST(FileVersionInfoTest, HardCodedProperties) { |
| FilePath dll_path = GetTestDataPath(); |
| dll_path = dll_path.Append(kDLLName); |
| - std::unique_ptr<FileVersionInfo> version_info( |
| - FileVersionInfo::CreateFileVersionInfo(dll_path)); |
| + typename TypeParam factory(dll_path); |
| + std::unique_ptr<FileVersionInfo> version_info(factory.Create()); |
| + ASSERT_TRUE(version_info); |
| int j = 0; |
| EXPECT_EQ(kExpectedValues[j++], version_info->company_name()); |
| @@ -82,18 +120,13 @@ TEST(FileVersionInfoTest, HardCodedProperties) { |
| EXPECT_EQ(kExpectedValues[j++], version_info->legal_trademarks()); |
| EXPECT_EQ(kExpectedValues[j++], version_info->last_change()); |
| } |
| -#endif |
| -#if defined(OS_WIN) |
| -TEST(FileVersionInfoTest, IsOfficialBuild) { |
| - const wchar_t* kDLLNames[] = { |
| - L"FileVersionInfoTest1.dll", |
| - L"FileVersionInfoTest2.dll" |
| - }; |
| +TYPED_TEST(FileVersionInfoTest, IsOfficialBuild) { |
| + const wchar_t* kDLLNames[] = {L"FileVersionInfoTest1.dll", |
|
grt (UTC plus 2)
2016/06/17 20:34:59
nit: const wchar_t* const
fdoray
2016/06/20 14:06:41
Done.
|
| + L"FileVersionInfoTest2.dll"}; |
| const bool kExpected[] = { |
| - true, |
| - false, |
| + true, false, |
| }; |
| // Test consistency check. |
| @@ -103,41 +136,40 @@ TEST(FileVersionInfoTest, IsOfficialBuild) { |
| FilePath dll_path = GetTestDataPath(); |
| dll_path = dll_path.Append(kDLLNames[i]); |
| - std::unique_ptr<FileVersionInfo> version_info( |
| - FileVersionInfo::CreateFileVersionInfo(dll_path)); |
| + typename TypeParam factory(dll_path); |
| + std::unique_ptr<FileVersionInfo> version_info(factory.Create()); |
| + ASSERT_TRUE(version_info); |
| EXPECT_EQ(kExpected[i], version_info->is_official_build()); |
| } |
| } |
| -#endif |
| -#if defined(OS_WIN) |
| -TEST(FileVersionInfoTest, CustomProperties) { |
| +TYPED_TEST(FileVersionInfoTest, CustomProperties) { |
| FilePath dll_path = GetTestDataPath(); |
| dll_path = dll_path.AppendASCII("FileVersionInfoTest1.dll"); |
| - std::unique_ptr<FileVersionInfo> version_info( |
| - FileVersionInfo::CreateFileVersionInfo(dll_path)); |
| + typename TypeParam factory(dll_path); |
| + std::unique_ptr<FileVersionInfo> version_info(factory.Create()); |
| + ASSERT_TRUE(version_info); |
| // Test few existing properties. |
| std::wstring str; |
| FileVersionInfoWin* version_info_win = |
| static_cast<FileVersionInfoWin*>(version_info.get()); |
| - EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 1", &str)); |
| + EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 1", &str)); |
| EXPECT_EQ(L"Un", str); |
| EXPECT_EQ(L"Un", version_info_win->GetStringValue(L"Custom prop 1")); |
| - EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 2", &str)); |
| + EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 2", &str)); |
| EXPECT_EQ(L"Deux", str); |
| EXPECT_EQ(L"Deux", version_info_win->GetStringValue(L"Custom prop 2")); |
| - EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 3", &str)); |
| + EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 3", &str)); |
| EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", str); |
| EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", |
| version_info_win->GetStringValue(L"Custom prop 3")); |
| // Test an non-existing property. |
| - EXPECT_FALSE(version_info_win->GetValue(L"Unknown property", &str)); |
| + EXPECT_FALSE(version_info_win->GetValue(L"Unknown property", &str)); |
| EXPECT_EQ(L"", version_info_win->GetStringValue(L"Unknown property")); |
| } |
| -#endif |