| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "base/file_version_info.h" | 8 #include "base/file_version_info.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 #if defined(OS_WIN) |
| 12 #include "base/file_version_info_win.h" |
| 13 #endif |
| 14 |
| 11 namespace { | 15 namespace { |
| 12 | 16 |
| 13 class FileVersionInfoTest : public testing::Test { | 17 class FileVersionInfoTest : public testing::Test { |
| 14 }; | 18 }; |
| 15 | 19 |
| 16 FilePath GetTestDataPath() { | 20 FilePath GetTestDataPath() { |
| 17 FilePath path; | 21 FilePath path; |
| 18 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 22 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 19 path = path.AppendASCII("base"); | 23 path = path.AppendASCII("base"); |
| 20 path = path.AppendASCII("data"); | 24 path = path.AppendASCII("data"); |
| 21 path = path.AppendASCII("file_version_info_unittest"); | 25 path = path.AppendASCII("file_version_info_unittest"); |
| 22 return path; | 26 return path; |
| 23 } | 27 } |
| 24 | 28 |
| 25 } | 29 } |
| 26 | 30 |
| 27 #ifdef OS_WIN | 31 #if defined(OS_WIN) |
| 28 TEST(FileVersionInfoTest, HardCodedProperties) { | 32 TEST(FileVersionInfoTest, HardCodedProperties) { |
| 29 const wchar_t* kDLLNames[] = { | 33 const wchar_t* kDLLNames[] = { |
| 30 L"FileVersionInfoTest1.dll" | 34 L"FileVersionInfoTest1.dll" |
| 31 }; | 35 }; |
| 32 | 36 |
| 33 const wchar_t* kExpectedValues[1][15] = { | 37 const wchar_t* kExpectedValues[1][15] = { |
| 34 // FileVersionInfoTest.dll | 38 // FileVersionInfoTest.dll |
| 35 L"Goooooogle", // company_name | 39 L"Goooooogle", // company_name |
| 36 L"Google", // company_short_name | 40 L"Google", // company_short_name |
| 37 L"This is the product name", // product_name | 41 L"This is the product name", // product_name |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 EXPECT_EQ(kExpectedValues[i][j++], version_info->original_filename()); | 73 EXPECT_EQ(kExpectedValues[i][j++], version_info->original_filename()); |
| 70 EXPECT_EQ(kExpectedValues[i][j++], version_info->file_description()); | 74 EXPECT_EQ(kExpectedValues[i][j++], version_info->file_description()); |
| 71 EXPECT_EQ(kExpectedValues[i][j++], version_info->file_version()); | 75 EXPECT_EQ(kExpectedValues[i][j++], version_info->file_version()); |
| 72 EXPECT_EQ(kExpectedValues[i][j++], version_info->legal_copyright()); | 76 EXPECT_EQ(kExpectedValues[i][j++], version_info->legal_copyright()); |
| 73 EXPECT_EQ(kExpectedValues[i][j++], version_info->legal_trademarks()); | 77 EXPECT_EQ(kExpectedValues[i][j++], version_info->legal_trademarks()); |
| 74 EXPECT_EQ(kExpectedValues[i][j++], version_info->last_change()); | 78 EXPECT_EQ(kExpectedValues[i][j++], version_info->last_change()); |
| 75 } | 79 } |
| 76 } | 80 } |
| 77 #endif | 81 #endif |
| 78 | 82 |
| 79 #ifdef OS_WIN | 83 #if defined(OS_WIN) |
| 80 TEST(FileVersionInfoTest, IsOfficialBuild) { | 84 TEST(FileVersionInfoTest, IsOfficialBuild) { |
| 81 const wchar_t* kDLLNames[] = { | 85 const wchar_t* kDLLNames[] = { |
| 82 L"FileVersionInfoTest1.dll", | 86 L"FileVersionInfoTest1.dll", |
| 83 L"FileVersionInfoTest2.dll" | 87 L"FileVersionInfoTest2.dll" |
| 84 }; | 88 }; |
| 85 | 89 |
| 86 const bool kExpected[] = { | 90 const bool kExpected[] = { |
| 87 true, | 91 true, |
| 88 false, | 92 false, |
| 89 }; | 93 }; |
| 90 | 94 |
| 91 // Test consistency check. | 95 // Test consistency check. |
| 92 ASSERT_EQ(arraysize(kDLLNames), arraysize(kExpected)); | 96 ASSERT_EQ(arraysize(kDLLNames), arraysize(kExpected)); |
| 93 | 97 |
| 94 for (int i = 0; i < arraysize(kDLLNames); ++i) { | 98 for (int i = 0; i < arraysize(kDLLNames); ++i) { |
| 95 FilePath dll_path = GetTestDataPath(); | 99 FilePath dll_path = GetTestDataPath(); |
| 96 dll_path = dll_path.Append(kDLLNames[i]); | 100 dll_path = dll_path.Append(kDLLNames[i]); |
| 97 | 101 |
| 98 scoped_ptr<FileVersionInfo> version_info( | 102 scoped_ptr<FileVersionInfo> version_info( |
| 99 FileVersionInfo::CreateFileVersionInfo(dll_path)); | 103 FileVersionInfo::CreateFileVersionInfo(dll_path)); |
| 100 | 104 |
| 101 EXPECT_EQ(kExpected[i], version_info->is_official_build()); | 105 EXPECT_EQ(kExpected[i], version_info->is_official_build()); |
| 102 } | 106 } |
| 103 } | 107 } |
| 104 #endif | 108 #endif |
| 105 | 109 |
| 110 #if defined(OS_WIN) |
| 106 TEST(FileVersionInfoTest, CustomProperties) { | 111 TEST(FileVersionInfoTest, CustomProperties) { |
| 107 FilePath dll_path = GetTestDataPath(); | 112 FilePath dll_path = GetTestDataPath(); |
| 108 dll_path = dll_path.AppendASCII("FileVersionInfoTest1.dll"); | 113 dll_path = dll_path.AppendASCII("FileVersionInfoTest1.dll"); |
| 109 | 114 |
| 110 scoped_ptr<FileVersionInfo> version_info( | 115 scoped_ptr<FileVersionInfo> version_info( |
| 111 FileVersionInfo::CreateFileVersionInfo(dll_path)); | 116 FileVersionInfo::CreateFileVersionInfo(dll_path)); |
| 112 | 117 |
| 113 // Test few existing properties. | 118 // Test few existing properties. |
| 114 std::wstring str; | 119 std::wstring str; |
| 115 #ifdef OS_WIN | 120 FileVersionInfoWin* version_info_win = |
| 116 EXPECT_TRUE(version_info->GetValue(L"Custom prop 1", &str)); | 121 static_cast<FileVersionInfoWin*>(version_info.get()); |
| 122 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 1", &str)); |
| 117 EXPECT_EQ(L"Un", str); | 123 EXPECT_EQ(L"Un", str); |
| 118 EXPECT_EQ(L"Un", version_info->GetStringValue(L"Custom prop 1")); | 124 EXPECT_EQ(L"Un", version_info_win->GetStringValue(L"Custom prop 1")); |
| 119 | 125 |
| 120 EXPECT_TRUE(version_info->GetValue(L"Custom prop 2", &str)); | 126 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 2", &str)); |
| 121 EXPECT_EQ(L"Deux", str); | 127 EXPECT_EQ(L"Deux", str); |
| 122 EXPECT_EQ(L"Deux", version_info->GetStringValue(L"Custom prop 2")); | 128 EXPECT_EQ(L"Deux", version_info_win->GetStringValue(L"Custom prop 2")); |
| 123 | 129 |
| 124 EXPECT_TRUE(version_info->GetValue(L"Custom prop 3", &str)); | 130 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 3", &str)); |
| 125 EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", str); | 131 EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", str); |
| 126 EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", | 132 EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", |
| 127 version_info->GetStringValue(L"Custom prop 3")); | 133 version_info_win->GetStringValue(L"Custom prop 3")); |
| 128 #endif | |
| 129 | 134 |
| 130 // Test an non-existing property. | 135 // Test an non-existing property. |
| 131 EXPECT_FALSE(version_info->GetValue(L"Unknown property", &str)); | 136 EXPECT_FALSE(version_info_win->GetValue(L"Unknown property", &str)); |
| 132 EXPECT_EQ(L"", version_info->GetStringValue(L"Unknown property")); | 137 EXPECT_EQ(L"", version_info_win->GetStringValue(L"Unknown property")); |
| 133 } | 138 } |
| 139 #endif |
| OLD | NEW |