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