Open HTML files in Chrome by default.
[chromium-blink-merge.git] / base / file_version_info_unittest.cc
blob5c899ba3dde2c5a97e0ae61512b98d02e0345e84
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_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"
11 #if defined(OS_WIN)
12 #include "base/file_version_info_win.h"
13 #endif
15 using base::FilePath;
17 namespace {
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("data");
25 path = path.AppendASCII("file_version_info_unittest");
26 return path;
28 #endif
30 } // namespace
32 #if defined(OS_WIN)
33 TEST(FileVersionInfoTest, HardCodedProperties) {
34 const wchar_t* kDLLNames[] = {
35 L"FileVersionInfoTest1.dll"
38 const wchar_t* kExpectedValues[1][15] = {
39 // FileVersionInfoTest.dll
40 L"Goooooogle", // company_name
41 L"Google", // company_short_name
42 L"This is the product name", // product_name
43 L"This is the product short name", // product_short_name
44 L"The Internal Name", // internal_name
45 L"4.3.2.1", // product_version
46 L"Private build property", // private_build
47 L"Special build property", // special_build
48 L"This is a particularly interesting comment", // comments
49 L"This is the original filename", // original_filename
50 L"This is my file description", // file_description
51 L"1.2.3.4", // file_version
52 L"This is the legal copyright", // legal_copyright
53 L"This is the legal trademarks", // legal_trademarks
54 L"This is the last change", // last_change
57 for (int i = 0; i < arraysize(kDLLNames); ++i) {
58 FilePath dll_path = GetTestDataPath();
59 dll_path = dll_path.Append(kDLLNames[i]);
61 scoped_ptr<FileVersionInfo> version_info(
62 FileVersionInfo::CreateFileVersionInfo(dll_path));
64 int j = 0;
65 EXPECT_EQ(kExpectedValues[i][j++], version_info->company_name());
66 EXPECT_EQ(kExpectedValues[i][j++], version_info->company_short_name());
67 EXPECT_EQ(kExpectedValues[i][j++], version_info->product_name());
68 EXPECT_EQ(kExpectedValues[i][j++], version_info->product_short_name());
69 EXPECT_EQ(kExpectedValues[i][j++], version_info->internal_name());
70 EXPECT_EQ(kExpectedValues[i][j++], version_info->product_version());
71 EXPECT_EQ(kExpectedValues[i][j++], version_info->private_build());
72 EXPECT_EQ(kExpectedValues[i][j++], version_info->special_build());
73 EXPECT_EQ(kExpectedValues[i][j++], version_info->comments());
74 EXPECT_EQ(kExpectedValues[i][j++], version_info->original_filename());
75 EXPECT_EQ(kExpectedValues[i][j++], version_info->file_description());
76 EXPECT_EQ(kExpectedValues[i][j++], version_info->file_version());
77 EXPECT_EQ(kExpectedValues[i][j++], version_info->legal_copyright());
78 EXPECT_EQ(kExpectedValues[i][j++], version_info->legal_trademarks());
79 EXPECT_EQ(kExpectedValues[i][j++], version_info->last_change());
82 #endif
84 #if defined(OS_WIN)
85 TEST(FileVersionInfoTest, IsOfficialBuild) {
86 const wchar_t* kDLLNames[] = {
87 L"FileVersionInfoTest1.dll",
88 L"FileVersionInfoTest2.dll"
91 const bool kExpected[] = {
92 true,
93 false,
96 // Test consistency check.
97 ASSERT_EQ(arraysize(kDLLNames), arraysize(kExpected));
99 for (int i = 0; i < arraysize(kDLLNames); ++i) {
100 FilePath dll_path = GetTestDataPath();
101 dll_path = dll_path.Append(kDLLNames[i]);
103 scoped_ptr<FileVersionInfo> version_info(
104 FileVersionInfo::CreateFileVersionInfo(dll_path));
106 EXPECT_EQ(kExpected[i], version_info->is_official_build());
109 #endif
111 #if defined(OS_WIN)
112 TEST(FileVersionInfoTest, CustomProperties) {
113 FilePath dll_path = GetTestDataPath();
114 dll_path = dll_path.AppendASCII("FileVersionInfoTest1.dll");
116 scoped_ptr<FileVersionInfo> version_info(
117 FileVersionInfo::CreateFileVersionInfo(dll_path));
119 // Test few existing properties.
120 std::wstring str;
121 FileVersionInfoWin* version_info_win =
122 static_cast<FileVersionInfoWin*>(version_info.get());
123 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 1", &str));
124 EXPECT_EQ(L"Un", str);
125 EXPECT_EQ(L"Un", version_info_win->GetStringValue(L"Custom prop 1"));
127 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 2", &str));
128 EXPECT_EQ(L"Deux", str);
129 EXPECT_EQ(L"Deux", version_info_win->GetStringValue(L"Custom prop 2"));
131 EXPECT_TRUE(version_info_win->GetValue(L"Custom prop 3", &str));
132 EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", str);
133 EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043",
134 version_info_win->GetStringValue(L"Custom prop 3"));
136 // Test an non-existing property.
137 EXPECT_FALSE(version_info_win->GetValue(L"Unknown property", &str));
138 EXPECT_EQ(L"", version_info_win->GetStringValue(L"Unknown property"));
140 #endif