| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_version_info.h" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 6 | 8 |
| 7 #include "base/file_version_info.h" | 9 #include <memory> |
| 10 |
| 8 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 9 #include "base/macros.h" | 12 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 12 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 16 |
| 15 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
| 16 #include "base/file_version_info_win.h" | 18 #include "base/file_version_info_win.h" |
| 17 #endif | 19 #endif |
| 18 | 20 |
| 19 using base::FilePath; | 21 using base::FilePath; |
| 20 | 22 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 L"This is my file description", // file_description | 55 L"This is my file description", // file_description |
| 54 L"1.2.3.4", // file_version | 56 L"1.2.3.4", // file_version |
| 55 L"This is the legal copyright", // legal_copyright | 57 L"This is the legal copyright", // legal_copyright |
| 56 L"This is the legal trademarks", // legal_trademarks | 58 L"This is the legal trademarks", // legal_trademarks |
| 57 L"This is the last change", // last_change | 59 L"This is the last change", // last_change |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 FilePath dll_path = GetTestDataPath(); | 62 FilePath dll_path = GetTestDataPath(); |
| 61 dll_path = dll_path.Append(kDLLName); | 63 dll_path = dll_path.Append(kDLLName); |
| 62 | 64 |
| 63 scoped_ptr<FileVersionInfo> version_info( | 65 std::unique_ptr<FileVersionInfo> version_info( |
| 64 FileVersionInfo::CreateFileVersionInfo(dll_path)); | 66 FileVersionInfo::CreateFileVersionInfo(dll_path)); |
| 65 | 67 |
| 66 int j = 0; | 68 int j = 0; |
| 67 EXPECT_EQ(kExpectedValues[j++], version_info->company_name()); | 69 EXPECT_EQ(kExpectedValues[j++], version_info->company_name()); |
| 68 EXPECT_EQ(kExpectedValues[j++], version_info->company_short_name()); | 70 EXPECT_EQ(kExpectedValues[j++], version_info->company_short_name()); |
| 69 EXPECT_EQ(kExpectedValues[j++], version_info->product_name()); | 71 EXPECT_EQ(kExpectedValues[j++], version_info->product_name()); |
| 70 EXPECT_EQ(kExpectedValues[j++], version_info->product_short_name()); | 72 EXPECT_EQ(kExpectedValues[j++], version_info->product_short_name()); |
| 71 EXPECT_EQ(kExpectedValues[j++], version_info->internal_name()); | 73 EXPECT_EQ(kExpectedValues[j++], version_info->internal_name()); |
| 72 EXPECT_EQ(kExpectedValues[j++], version_info->product_version()); | 74 EXPECT_EQ(kExpectedValues[j++], version_info->product_version()); |
| 73 EXPECT_EQ(kExpectedValues[j++], version_info->private_build()); | 75 EXPECT_EQ(kExpectedValues[j++], version_info->private_build()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 94 false, | 96 false, |
| 95 }; | 97 }; |
| 96 | 98 |
| 97 // Test consistency check. | 99 // Test consistency check. |
| 98 ASSERT_EQ(arraysize(kDLLNames), arraysize(kExpected)); | 100 ASSERT_EQ(arraysize(kDLLNames), arraysize(kExpected)); |
| 99 | 101 |
| 100 for (size_t i = 0; i < arraysize(kDLLNames); ++i) { | 102 for (size_t i = 0; i < arraysize(kDLLNames); ++i) { |
| 101 FilePath dll_path = GetTestDataPath(); | 103 FilePath dll_path = GetTestDataPath(); |
| 102 dll_path = dll_path.Append(kDLLNames[i]); | 104 dll_path = dll_path.Append(kDLLNames[i]); |
| 103 | 105 |
| 104 scoped_ptr<FileVersionInfo> version_info( | 106 std::unique_ptr<FileVersionInfo> version_info( |
| 105 FileVersionInfo::CreateFileVersionInfo(dll_path)); | 107 FileVersionInfo::CreateFileVersionInfo(dll_path)); |
| 106 | 108 |
| 107 EXPECT_EQ(kExpected[i], version_info->is_official_build()); | 109 EXPECT_EQ(kExpected[i], version_info->is_official_build()); |
| 108 } | 110 } |
| 109 } | 111 } |
| 110 #endif | 112 #endif |
| 111 | 113 |
| 112 #if defined(OS_WIN) | 114 #if defined(OS_WIN) |
| 113 TEST(FileVersionInfoTest, CustomProperties) { | 115 TEST(FileVersionInfoTest, CustomProperties) { |
| 114 FilePath dll_path = GetTestDataPath(); | 116 FilePath dll_path = GetTestDataPath(); |
| 115 dll_path = dll_path.AppendASCII("FileVersionInfoTest1.dll"); | 117 dll_path = dll_path.AppendASCII("FileVersionInfoTest1.dll"); |
| 116 | 118 |
| 117 scoped_ptr<FileVersionInfo> version_info( | 119 std::unique_ptr<FileVersionInfo> version_info( |
| 118 FileVersionInfo::CreateFileVersionInfo(dll_path)); | 120 FileVersionInfo::CreateFileVersionInfo(dll_path)); |
| 119 | 121 |
| 120 // Test few existing properties. | 122 // Test few existing properties. |
| 121 std::wstring str; | 123 std::wstring str; |
| 122 FileVersionInfoWin* version_info_win = | 124 FileVersionInfoWin* version_info_win = |
| 123 static_cast<FileVersionInfoWin*>(version_info.get()); | 125 static_cast<FileVersionInfoWin*>(version_info.get()); |
| 124 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 1", &str)); | 126 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 1", &str)); |
| 125 EXPECT_EQ(L"Un", str); | 127 EXPECT_EQ(L"Un", str); |
| 126 EXPECT_EQ(L"Un", version_info_win->GetStringValue(L"Custom prop 1")); | 128 EXPECT_EQ(L"Un", version_info_win->GetStringValue(L"Custom prop 1")); |
| 127 | 129 |
| 128 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 2", &str)); | 130 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 2", &str)); |
| 129 EXPECT_EQ(L"Deux", str); | 131 EXPECT_EQ(L"Deux", str); |
| 130 EXPECT_EQ(L"Deux", version_info_win->GetStringValue(L"Custom prop 2")); | 132 EXPECT_EQ(L"Deux", version_info_win->GetStringValue(L"Custom prop 2")); |
| 131 | 133 |
| 132 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 3", &str)); | 134 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 3", &str)); |
| 133 EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", str); | 135 EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", str); |
| 134 EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", | 136 EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", |
| 135 version_info_win->GetStringValue(L"Custom prop 3")); | 137 version_info_win->GetStringValue(L"Custom prop 3")); |
| 136 | 138 |
| 137 // Test an non-existing property. | 139 // Test an non-existing property. |
| 138 EXPECT_FALSE(version_info_win->GetValue(L"Unknown property", &str)); | 140 EXPECT_FALSE(version_info_win->GetValue(L"Unknown property", &str)); |
| 139 EXPECT_EQ(L"", version_info_win->GetStringValue(L"Unknown property")); | 141 EXPECT_EQ(L"", version_info_win->GetStringValue(L"Unknown property")); |
| 140 } | 142 } |
| 141 #endif | 143 #endif |
| OLD | NEW |