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.
5 #include "base/file_util.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/path_service.h"
8 #include "base/file_version_info.h"
9 #include "testing/gtest/include/gtest/gtest.h"
12 #include "base/file_version_info_win.h"
18 FilePath
GetTestDataPath() {
20 PathService::Get(base::DIR_SOURCE_ROOT
, &path
);
21 path
= path
.AppendASCII("base");
22 path
= path
.AppendASCII("data");
23 path
= path
.AppendASCII("file_version_info_unittest");
31 TEST(FileVersionInfoTest
, HardCodedProperties
) {
32 const wchar_t* kDLLNames
[] = {
33 L
"FileVersionInfoTest1.dll"
36 const wchar_t* kExpectedValues
[1][15] = {
37 // FileVersionInfoTest.dll
38 L
"Goooooogle", // company_name
39 L
"Google", // company_short_name
40 L
"This is the product name", // product_name
41 L
"This is the product short name", // product_short_name
42 L
"The Internal Name", // internal_name
43 L
"4.3.2.1", // product_version
44 L
"Private build property", // private_build
45 L
"Special build property", // special_build
46 L
"This is a particularly interesting comment", // comments
47 L
"This is the original filename", // original_filename
48 L
"This is my file description", // file_description
49 L
"1.2.3.4", // file_version
50 L
"This is the legal copyright", // legal_copyright
51 L
"This is the legal trademarks", // legal_trademarks
52 L
"This is the last change", // last_change
55 for (int i
= 0; i
< arraysize(kDLLNames
); ++i
) {
56 FilePath dll_path
= GetTestDataPath();
57 dll_path
= dll_path
.Append(kDLLNames
[i
]);
59 scoped_ptr
<FileVersionInfo
> version_info(
60 FileVersionInfo::CreateFileVersionInfo(dll_path
));
63 EXPECT_EQ(kExpectedValues
[i
][j
++], version_info
->company_name());
64 EXPECT_EQ(kExpectedValues
[i
][j
++], version_info
->company_short_name());
65 EXPECT_EQ(kExpectedValues
[i
][j
++], version_info
->product_name());
66 EXPECT_EQ(kExpectedValues
[i
][j
++], version_info
->product_short_name());
67 EXPECT_EQ(kExpectedValues
[i
][j
++], version_info
->internal_name());
68 EXPECT_EQ(kExpectedValues
[i
][j
++], version_info
->product_version());
69 EXPECT_EQ(kExpectedValues
[i
][j
++], version_info
->private_build());
70 EXPECT_EQ(kExpectedValues
[i
][j
++], version_info
->special_build());
71 EXPECT_EQ(kExpectedValues
[i
][j
++], version_info
->comments());
72 EXPECT_EQ(kExpectedValues
[i
][j
++], version_info
->original_filename());
73 EXPECT_EQ(kExpectedValues
[i
][j
++], version_info
->file_description());
74 EXPECT_EQ(kExpectedValues
[i
][j
++], version_info
->file_version());
75 EXPECT_EQ(kExpectedValues
[i
][j
++], version_info
->legal_copyright());
76 EXPECT_EQ(kExpectedValues
[i
][j
++], version_info
->legal_trademarks());
77 EXPECT_EQ(kExpectedValues
[i
][j
++], version_info
->last_change());
83 TEST(FileVersionInfoTest
, IsOfficialBuild
) {
84 const wchar_t* kDLLNames
[] = {
85 L
"FileVersionInfoTest1.dll",
86 L
"FileVersionInfoTest2.dll"
89 const bool kExpected
[] = {
94 // Test consistency check.
95 ASSERT_EQ(arraysize(kDLLNames
), arraysize(kExpected
));
97 for (int i
= 0; i
< arraysize(kDLLNames
); ++i
) {
98 FilePath dll_path
= GetTestDataPath();
99 dll_path
= dll_path
.Append(kDLLNames
[i
]);
101 scoped_ptr
<FileVersionInfo
> version_info(
102 FileVersionInfo::CreateFileVersionInfo(dll_path
));
104 EXPECT_EQ(kExpected
[i
], version_info
->is_official_build());
110 TEST(FileVersionInfoTest
, CustomProperties
) {
111 FilePath dll_path
= GetTestDataPath();
112 dll_path
= dll_path
.AppendASCII("FileVersionInfoTest1.dll");
114 scoped_ptr
<FileVersionInfo
> version_info(
115 FileVersionInfo::CreateFileVersionInfo(dll_path
));
117 // Test few existing properties.
119 FileVersionInfoWin
* version_info_win
=
120 static_cast<FileVersionInfoWin
*>(version_info
.get());
121 EXPECT_TRUE(version_info_win
->GetValue(L
"Custom prop 1", &str
));
122 EXPECT_EQ(L
"Un", str
);
123 EXPECT_EQ(L
"Un", version_info_win
->GetStringValue(L
"Custom prop 1"));
125 EXPECT_TRUE(version_info_win
->GetValue(L
"Custom prop 2", &str
));
126 EXPECT_EQ(L
"Deux", str
);
127 EXPECT_EQ(L
"Deux", version_info_win
->GetStringValue(L
"Custom prop 2"));
129 EXPECT_TRUE(version_info_win
->GetValue(L
"Custom prop 3", &str
));
130 EXPECT_EQ(L
"1600 Amphitheatre Parkway Mountain View, CA 94043", str
);
131 EXPECT_EQ(L
"1600 Amphitheatre Parkway Mountain View, CA 94043",
132 version_info_win
->GetStringValue(L
"Custom prop 3"));
134 // Test an non-existing property.
135 EXPECT_FALSE(version_info_win
->GetValue(L
"Unknown property", &str
));
136 EXPECT_EQ(L
"", version_info_win
->GetStringValue(L
"Unknown property"));