OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/file_version_info.h" |
| 6 |
| 7 #include <stddef.h> |
| 8 |
| 9 #include <memory> |
| 10 |
| 11 #include "base/files/file_path.h" |
| 12 #include "base/macros.h" |
| 13 #include "base/path_service.h" |
| 14 #include "build/build_config.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 #if defined(OS_WIN) |
| 18 #include "base/file_version_info_win.h" |
| 19 #endif |
| 20 |
| 21 using base::FilePath; |
| 22 |
| 23 namespace { |
| 24 |
| 25 #if defined(OS_WIN) |
| 26 FilePath GetTestDataPath() { |
| 27 FilePath path; |
| 28 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 29 path = path.AppendASCII("base"); |
| 30 path = path.AppendASCII("test"); |
| 31 path = path.AppendASCII("data"); |
| 32 path = path.AppendASCII("file_version_info_unittest"); |
| 33 return path; |
| 34 } |
| 35 #endif |
| 36 |
| 37 } // namespace |
| 38 |
| 39 #if defined(OS_WIN) |
| 40 TEST(FileVersionInfoTest, HardCodedProperties) { |
| 41 const wchar_t kDLLName[] = {L"FileVersionInfoTest1.dll"}; |
| 42 |
| 43 const wchar_t* const kExpectedValues[15] = { |
| 44 // FileVersionInfoTest.dll |
| 45 L"Goooooogle", // company_name |
| 46 L"Google", // company_short_name |
| 47 L"This is the product name", // product_name |
| 48 L"This is the product short name", // product_short_name |
| 49 L"The Internal Name", // internal_name |
| 50 L"4.3.2.1", // product_version |
| 51 L"Private build property", // private_build |
| 52 L"Special build property", // special_build |
| 53 L"This is a particularly interesting comment", // comments |
| 54 L"This is the original filename", // original_filename |
| 55 L"This is my file description", // file_description |
| 56 L"1.2.3.4", // file_version |
| 57 L"This is the legal copyright", // legal_copyright |
| 58 L"This is the legal trademarks", // legal_trademarks |
| 59 L"This is the last change", // last_change |
| 60 }; |
| 61 |
| 62 FilePath dll_path = GetTestDataPath(); |
| 63 dll_path = dll_path.Append(kDLLName); |
| 64 |
| 65 std::unique_ptr<FileVersionInfo> version_info( |
| 66 FileVersionInfo::CreateFileVersionInfo(dll_path)); |
| 67 |
| 68 int j = 0; |
| 69 EXPECT_EQ(kExpectedValues[j++], version_info->company_name()); |
| 70 EXPECT_EQ(kExpectedValues[j++], version_info->company_short_name()); |
| 71 EXPECT_EQ(kExpectedValues[j++], version_info->product_name()); |
| 72 EXPECT_EQ(kExpectedValues[j++], version_info->product_short_name()); |
| 73 EXPECT_EQ(kExpectedValues[j++], version_info->internal_name()); |
| 74 EXPECT_EQ(kExpectedValues[j++], version_info->product_version()); |
| 75 EXPECT_EQ(kExpectedValues[j++], version_info->private_build()); |
| 76 EXPECT_EQ(kExpectedValues[j++], version_info->special_build()); |
| 77 EXPECT_EQ(kExpectedValues[j++], version_info->comments()); |
| 78 EXPECT_EQ(kExpectedValues[j++], version_info->original_filename()); |
| 79 EXPECT_EQ(kExpectedValues[j++], version_info->file_description()); |
| 80 EXPECT_EQ(kExpectedValues[j++], version_info->file_version()); |
| 81 EXPECT_EQ(kExpectedValues[j++], version_info->legal_copyright()); |
| 82 EXPECT_EQ(kExpectedValues[j++], version_info->legal_trademarks()); |
| 83 EXPECT_EQ(kExpectedValues[j++], version_info->last_change()); |
| 84 } |
| 85 #endif |
| 86 |
| 87 #if defined(OS_WIN) |
| 88 TEST(FileVersionInfoTest, IsOfficialBuild) { |
| 89 const wchar_t* kDLLNames[] = { |
| 90 L"FileVersionInfoTest1.dll", |
| 91 L"FileVersionInfoTest2.dll" |
| 92 }; |
| 93 |
| 94 const bool kExpected[] = { |
| 95 true, |
| 96 false, |
| 97 }; |
| 98 |
| 99 // Test consistency check. |
| 100 ASSERT_EQ(arraysize(kDLLNames), arraysize(kExpected)); |
| 101 |
| 102 for (size_t i = 0; i < arraysize(kDLLNames); ++i) { |
| 103 FilePath dll_path = GetTestDataPath(); |
| 104 dll_path = dll_path.Append(kDLLNames[i]); |
| 105 |
| 106 std::unique_ptr<FileVersionInfo> version_info( |
| 107 FileVersionInfo::CreateFileVersionInfo(dll_path)); |
| 108 |
| 109 EXPECT_EQ(kExpected[i], version_info->is_official_build()); |
| 110 } |
| 111 } |
| 112 #endif |
| 113 |
| 114 #if defined(OS_WIN) |
| 115 TEST(FileVersionInfoTest, CustomProperties) { |
| 116 FilePath dll_path = GetTestDataPath(); |
| 117 dll_path = dll_path.AppendASCII("FileVersionInfoTest1.dll"); |
| 118 |
| 119 std::unique_ptr<FileVersionInfo> version_info( |
| 120 FileVersionInfo::CreateFileVersionInfo(dll_path)); |
| 121 |
| 122 // Test few existing properties. |
| 123 std::wstring str; |
| 124 FileVersionInfoWin* version_info_win = |
| 125 static_cast<FileVersionInfoWin*>(version_info.get()); |
| 126 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 1", &str)); |
| 127 EXPECT_EQ(L"Un", str); |
| 128 EXPECT_EQ(L"Un", version_info_win->GetStringValue(L"Custom prop 1")); |
| 129 |
| 130 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 2", &str)); |
| 131 EXPECT_EQ(L"Deux", str); |
| 132 EXPECT_EQ(L"Deux", version_info_win->GetStringValue(L"Custom prop 2")); |
| 133 |
| 134 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 3", &str)); |
| 135 EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", str); |
| 136 EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", |
| 137 version_info_win->GetStringValue(L"Custom prop 3")); |
| 138 |
| 139 // Test an non-existing property. |
| 140 EXPECT_FALSE(version_info_win->GetValue(L"Unknown property", &str)); |
| 141 EXPECT_EQ(L"", version_info_win->GetStringValue(L"Unknown property")); |
| 142 } |
| 143 #endif |
OLD | NEW |