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