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