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 60% |
rename from base/file_version_info_unittest.cc |
rename to base/file_version_info_win_unittest.cc |
index ac5320f398b2dac51fabf6889ec7558668c79a13..6ca3f13bfbefa2061c3c6afb3dbf40fe5670f3cb 100644 |
--- a/base/file_version_info_unittest.cc |
+++ b/base/file_version_info_win_unittest.cc |
@@ -2,27 +2,25 @@ |
// 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 "base/scoped_native_library.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 +30,53 @@ 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) |
+ // Load the library with LOAD_LIBRARY_AS_IMAGE_RESOURCE since it shouldn't |
+ // be executed. |
+ : library_(::LoadLibraryEx(path.value().c_str(), |
+ NULL, |
grt (UTC plus 2)
2016/06/20 20:05:14
nullptr ALL the things!
fdoray
2016/06/21 19:31:11
Done.
|
+ LOAD_LIBRARY_AS_IMAGE_RESOURCE)) { |
+ EXPECT_TRUE(library_.is_valid()); |
+ } |
+ |
+ FileVersionInfo* Create() const { |
grt (UTC plus 2)
2016/06/20 20:05:14
nit: return std::unique_ptr so that the ownership
fdoray
2016/06/21 19:31:11
Done.
|
+ return FileVersionInfo::CreateFileVersionInfoForModule(library_.get()); |
+ } |
+ |
+ private: |
+ const base::ScopedNativeLibrary 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 +101,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,62 +122,57 @@ 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* const kDLLNames[] = {L"FileVersionInfoTest1.dll", |
+ L"FileVersionInfoTest2.dll"}; |
- const bool kExpected[] = { |
- true, |
- false, |
+ const bool kExpectedIsOfficialBuild[] = { |
+ true, false, |
}; |
- // Test consistency check. |
- ASSERT_EQ(arraysize(kDLLNames), arraysize(kExpected)); |
+ static_assert(arraysize(kDLLNames) == arraysize(kExpectedIsOfficialBuild), |
+ "kDLLNames should have the same number of elements as " |
+ "kExpectedIsOfficialBuild"); |
for (size_t i = 0; i < arraysize(kDLLNames); ++i) { |
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()); |
+ EXPECT_EQ(kExpectedIsOfficialBuild[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 |