blob: 8b909a441c73fb43d277a9a1c6d68c3792bc6ee3 [file] [log] [blame]
license.botf003cfe2008-08-24 09:55:55 +09001// Copyright (c) 2006-2008 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.
initial.commit3f4a7322008-07-27 06:49:38 +09004
5#include "base/file_util.h"
6#include "base/path_service.h"
7#include "base/scoped_ptr.h"
8#include "base/file_version_info.h"
9#include "testing/gtest/include/gtest/gtest.h"
10
11namespace {
12
13class FileVersionInfoTest : public testing::Test {
14};
15
16std::wstring GetTestDataPath() {
17 std::wstring path;
18 PathService::Get(base::DIR_SOURCE_ROOT, &path);
19 file_util::AppendToPath(&path, L"base");
20 file_util::AppendToPath(&path, L"data");
21 file_util::AppendToPath(&path, L"file_version_info_unittest");
22 return path;
23}
24
25}
26
paulg@google.com9ea1e862008-08-06 05:00:26 +090027#ifdef OS_WIN
initial.commit3f4a7322008-07-27 06:49:38 +090028TEST(FileVersionInfoTest, HardCodedProperties) {
29 const wchar_t* kDLLNames[] = {
30 L"FileVersionInfoTest1.dll"
31 };
32
33 const wchar_t* kExpectedValues[1][15] = {
34 // FileVersionInfoTest.dll
35 L"Goooooogle", // company_name
36 L"Google", // company_short_name
37 L"This is the product name", // product_name
38 L"This is the product short name", // product_short_name
39 L"The Internal Name", // internal_name
40 L"4.3.2.1", // product_version
41 L"Private build property", // private_build
42 L"Special build property", // special_build
43 L"This is a particularly interesting comment", // comments
44 L"This is the original filename", // original_filename
45 L"This is my file description", // file_description
46 L"1.2.3.4", // file_version
47 L"This is the legal copyright", // legal_copyright
48 L"This is the legal trademarks", // legal_trademarks
49 L"This is the last change", // last_change
50
51 };
52
53 for (int i = 0; i < arraysize(kDLLNames); ++i) {
54 std::wstring dll_path = GetTestDataPath();
55 file_util::AppendToPath(&dll_path, kDLLNames[i]);
56
57 scoped_ptr<FileVersionInfo> version_info(
58 FileVersionInfo::CreateFileVersionInfo(dll_path));
59
60 int j = 0;
61 EXPECT_EQ(kExpectedValues[i][j++], version_info->company_name());
62 EXPECT_EQ(kExpectedValues[i][j++], version_info->company_short_name());
63 EXPECT_EQ(kExpectedValues[i][j++], version_info->product_name());
64 EXPECT_EQ(kExpectedValues[i][j++], version_info->product_short_name());
65 EXPECT_EQ(kExpectedValues[i][j++], version_info->internal_name());
66 EXPECT_EQ(kExpectedValues[i][j++], version_info->product_version());
67 EXPECT_EQ(kExpectedValues[i][j++], version_info->private_build());
68 EXPECT_EQ(kExpectedValues[i][j++], version_info->special_build());
69 EXPECT_EQ(kExpectedValues[i][j++], version_info->comments());
70 EXPECT_EQ(kExpectedValues[i][j++], version_info->original_filename());
71 EXPECT_EQ(kExpectedValues[i][j++], version_info->file_description());
72 EXPECT_EQ(kExpectedValues[i][j++], version_info->file_version());
73 EXPECT_EQ(kExpectedValues[i][j++], version_info->legal_copyright());
74 EXPECT_EQ(kExpectedValues[i][j++], version_info->legal_trademarks());
75 EXPECT_EQ(kExpectedValues[i][j++], version_info->last_change());
76 }
77}
paulg@google.com9ea1e862008-08-06 05:00:26 +090078#endif
initial.commit3f4a7322008-07-27 06:49:38 +090079
paulg@google.com9ea1e862008-08-06 05:00:26 +090080#ifdef OS_WIN
initial.commit3f4a7322008-07-27 06:49:38 +090081TEST(FileVersionInfoTest, IsOfficialBuild) {
82 const wchar_t* kDLLNames[] = {
83 L"FileVersionInfoTest1.dll",
84 L"FileVersionInfoTest2.dll"
85 };
86
87 const bool kExpected[] = {
88 true,
89 false,
90 };
91
92 // Test consistency check.
93 ASSERT_EQ(arraysize(kDLLNames), arraysize(kExpected));
94
95 for (int i = 0; i < arraysize(kDLLNames); ++i) {
96 std::wstring dll_path = GetTestDataPath();
97 file_util::AppendToPath(&dll_path, kDLLNames[i]);
98
99 scoped_ptr<FileVersionInfo> version_info(
100 FileVersionInfo::CreateFileVersionInfo(dll_path));
101
102 EXPECT_EQ(kExpected[i], version_info->is_official_build());
103 }
104}
paulg@google.com9ea1e862008-08-06 05:00:26 +0900105#endif
initial.commit3f4a7322008-07-27 06:49:38 +0900106
107TEST(FileVersionInfoTest, CustomProperties) {
108 std::wstring dll_path = GetTestDataPath();
109 file_util::AppendToPath(&dll_path, L"FileVersionInfoTest1.dll");
110
111 scoped_ptr<FileVersionInfo> version_info(
112 FileVersionInfo::CreateFileVersionInfo(dll_path));
113
114 // Test few existing properties.
115 std::wstring str;
paulg@google.com9ea1e862008-08-06 05:00:26 +0900116#ifdef OS_WIN
initial.commit3f4a7322008-07-27 06:49:38 +0900117 EXPECT_TRUE(version_info->GetValue(L"Custom prop 1", &str));
118 EXPECT_EQ(L"Un", str);
119 EXPECT_EQ(L"Un", version_info->GetStringValue(L"Custom prop 1"));
120
121 EXPECT_TRUE(version_info->GetValue(L"Custom prop 2", &str));
122 EXPECT_EQ(L"Deux", str);
123 EXPECT_EQ(L"Deux", version_info->GetStringValue(L"Custom prop 2"));
124
125 EXPECT_TRUE(version_info->GetValue(L"Custom prop 3", &str));
126 EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043", str);
127 EXPECT_EQ(L"1600 Amphitheatre Parkway Mountain View, CA 94043",
128 version_info->GetStringValue(L"Custom prop 3"));
paulg@google.com9ea1e862008-08-06 05:00:26 +0900129#endif
initial.commit3f4a7322008-07-27 06:49:38 +0900130
131 // Test an non-existing property.
132 EXPECT_FALSE(version_info->GetValue(L"Unknown property", &str));
133 EXPECT_EQ(L"", version_info->GetStringValue(L"Unknown property"));
134}
license.botf003cfe2008-08-24 09:55:55 +0900135