blob: c5e9859400316a31c651850c3defccc5c656f254 [file] [log] [blame]
levin@chromium.org5c528682011-03-28 10:54:15 +09001// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botf003cfe2008-08-24 09:55:55 +09002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit3f4a7322008-07-27 06:49:38 +09004
thestig@chromium.org1b6e1b72013-05-14 19:12:56 +09005#include "base/file_version_info.h"
6#include "base/files/file_path.h"
levin@chromium.org5c528682011-03-28 10:54:15 +09007#include "base/memory/scoped_ptr.h"
initial.commit3f4a7322008-07-27 06:49:38 +09008#include "base/path_service.h"
initial.commit3f4a7322008-07-27 06:49:38 +09009#include "testing/gtest/include/gtest/gtest.h"
10
tony@chromium.org9f7a86f2010-04-14 10:46:43 +090011#if defined(OS_WIN)
12#include "base/file_version_info_win.h"
13#endif
14
brettw@chromium.orgb64a5cb2013-02-18 15:14:59 +090015using base::FilePath;
16
initial.commit3f4a7322008-07-27 06:49:38 +090017namespace {
18
thakis@chromium.org5dab7482010-10-04 09:34:04 +090019#if defined(OS_WIN)
thestig@chromium.org8942e862009-09-10 05:00:13 +090020FilePath GetTestDataPath() {
21 FilePath path;
initial.commit3f4a7322008-07-27 06:49:38 +090022 PathService::Get(base::DIR_SOURCE_ROOT, &path);
thestig@chromium.org8942e862009-09-10 05:00:13 +090023 path = path.AppendASCII("base");
jam@chromium.org88d0d232014-07-29 04:45:21 +090024 path = path.AppendASCII("test");
thestig@chromium.org8942e862009-09-10 05:00:13 +090025 path = path.AppendASCII("data");
26 path = path.AppendASCII("file_version_info_unittest");
initial.commit3f4a7322008-07-27 06:49:38 +090027 return path;
28}
thakis@chromium.org5dab7482010-10-04 09:34:04 +090029#endif
initial.commit3f4a7322008-07-27 06:49:38 +090030
thestig@chromium.org1b6e1b72013-05-14 19:12:56 +090031} // namespace
initial.commit3f4a7322008-07-27 06:49:38 +090032
tony@chromium.org9f7a86f2010-04-14 10:46:43 +090033#if defined(OS_WIN)
initial.commit3f4a7322008-07-27 06:49:38 +090034TEST(FileVersionInfoTest, HardCodedProperties) {
dcheng116473a2015-07-02 09:07:41 +090035 const wchar_t kDLLName[] = {L"FileVersionInfoTest1.dll"};
initial.commit3f4a7322008-07-27 06:49:38 +090036
dcheng116473a2015-07-02 09:07:41 +090037 const wchar_t* const kExpectedValues[15] = {
initial.commit3f4a7322008-07-27 06:49:38 +090038 // FileVersionInfoTest.dll
dcheng116473a2015-07-02 09:07:41 +090039 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
initial.commit3f4a7322008-07-27 06:49:38 +090047 L"This is a particularly interesting comment", // comments
dcheng116473a2015-07-02 09:07:41 +090048 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
initial.commit3f4a7322008-07-27 06:49:38 +090054 };
55
dcheng116473a2015-07-02 09:07:41 +090056 FilePath dll_path = GetTestDataPath();
57 dll_path = dll_path.Append(kDLLName);
initial.commit3f4a7322008-07-27 06:49:38 +090058
dcheng116473a2015-07-02 09:07:41 +090059 scoped_ptr<FileVersionInfo> version_info(
60 FileVersionInfo::CreateFileVersionInfo(dll_path));
initial.commit3f4a7322008-07-27 06:49:38 +090061
dcheng116473a2015-07-02 09:07:41 +090062 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());
initial.commit3f4a7322008-07-27 06:49:38 +090078}
paulg@google.com9ea1e862008-08-06 05:00:26 +090079#endif
initial.commit3f4a7322008-07-27 06:49:38 +090080
tony@chromium.org9f7a86f2010-04-14 10:46:43 +090081#if defined(OS_WIN)
initial.commit3f4a7322008-07-27 06:49:38 +090082TEST(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) {
thestig@chromium.org8942e862009-09-10 05:00:13 +090097 FilePath dll_path = GetTestDataPath();
98 dll_path = dll_path.Append(kDLLNames[i]);
initial.commit3f4a7322008-07-27 06:49:38 +090099
100 scoped_ptr<FileVersionInfo> version_info(
101 FileVersionInfo::CreateFileVersionInfo(dll_path));
102
103 EXPECT_EQ(kExpected[i], version_info->is_official_build());
104 }
105}
paulg@google.com9ea1e862008-08-06 05:00:26 +0900106#endif
initial.commit3f4a7322008-07-27 06:49:38 +0900107
tony@chromium.org9f7a86f2010-04-14 10:46:43 +0900108#if defined(OS_WIN)
initial.commit3f4a7322008-07-27 06:49:38 +0900109TEST(FileVersionInfoTest, CustomProperties) {
thestig@chromium.org8942e862009-09-10 05:00:13 +0900110 FilePath dll_path = GetTestDataPath();
111 dll_path = dll_path.AppendASCII("FileVersionInfoTest1.dll");
initial.commit3f4a7322008-07-27 06:49:38 +0900112
113 scoped_ptr<FileVersionInfo> version_info(
114 FileVersionInfo::CreateFileVersionInfo(dll_path));
115
116 // Test few existing properties.
117 std::wstring str;
tony@chromium.org9f7a86f2010-04-14 10:46:43 +0900118 FileVersionInfoWin* version_info_win =
119 static_cast<FileVersionInfoWin*>(version_info.get());
120 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 1", &str));
initial.commit3f4a7322008-07-27 06:49:38 +0900121 EXPECT_EQ(L"Un", str);
tony@chromium.org9f7a86f2010-04-14 10:46:43 +0900122 EXPECT_EQ(L"Un", version_info_win->GetStringValue(L"Custom prop 1"));
initial.commit3f4a7322008-07-27 06:49:38 +0900123
tony@chromium.org9f7a86f2010-04-14 10:46:43 +0900124 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 2", &str));
initial.commit3f4a7322008-07-27 06:49:38 +0900125 EXPECT_EQ(L"Deux", str);
tony@chromium.org9f7a86f2010-04-14 10:46:43 +0900126 EXPECT_EQ(L"Deux", version_info_win->GetStringValue(L"Custom prop 2"));
initial.commit3f4a7322008-07-27 06:49:38 +0900127
tony@chromium.org9f7a86f2010-04-14 10:46:43 +0900128 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 3", &str));
initial.commit3f4a7322008-07-27 06:49:38 +0900129 EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", str);
130 EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043",
tony@chromium.org9f7a86f2010-04-14 10:46:43 +0900131 version_info_win->GetStringValue(L"Custom prop 3"));
initial.commit3f4a7322008-07-27 06:49:38 +0900132
133 // Test an non-existing property.
tony@chromium.org9f7a86f2010-04-14 10:46:43 +0900134 EXPECT_FALSE(version_info_win->GetValue(L"Unknown property", &str));
135 EXPECT_EQ(L"", version_info_win->GetStringValue(L"Unknown property"));
initial.commit3f4a7322008-07-27 06:49:38 +0900136}
tony@chromium.org9f7a86f2010-04-14 10:46:43 +0900137#endif