android: add gyp rules for platform android_window
[chromium-blink-merge.git] / base / file_version_info_unittest.cc
blobc5e9859400316a31c651850c3defccc5c656f254
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("test");
25 path = path.AppendASCII("data");
26 path = path.AppendASCII("file_version_info_unittest");
27 return path;
29 #endif
31 } // namespace
33 #if defined(OS_WIN)
34 TEST(FileVersionInfoTest, HardCodedProperties) {
35 const wchar_t kDLLName[] = {L"FileVersionInfoTest1.dll"};
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
56 FilePath dll_path = GetTestDataPath();
57 dll_path = dll_path.Append(kDLLName);
59 scoped_ptr<FileVersionInfo> version_info(
60 FileVersionInfo::CreateFileVersionInfo(dll_path));
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());
79 #endif
81 #if defined(OS_WIN)
82 TEST(FileVersionInfoTest, IsOfficialBuild) {
83 const wchar_t* kDLLNames[] = {
84 L"FileVersionInfoTest1.dll",
85 L"FileVersionInfoTest2.dll"
88 const bool kExpected[] = {
89 true,
90 false,
93 // Test consistency check.
94 ASSERT_EQ(arraysize(kDLLNames), arraysize(kExpected));
96 for (int i = 0; i < arraysize(kDLLNames); ++i) {
97 FilePath dll_path = GetTestDataPath();
98 dll_path = dll_path.Append(kDLLNames[i]);
100 scoped_ptr<FileVersionInfo> version_info(
101 FileVersionInfo::CreateFileVersionInfo(dll_path));
103 EXPECT_EQ(kExpected[i], version_info->is_official_build());
106 #endif
108 #if defined(OS_WIN)
109 TEST(FileVersionInfoTest, CustomProperties) {
110 FilePath dll_path = GetTestDataPath();
111 dll_path = dll_path.AppendASCII("FileVersionInfoTest1.dll");
113 scoped_ptr<FileVersionInfo> version_info(
114 FileVersionInfo::CreateFileVersionInfo(dll_path));
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"));
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"));
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"));
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"));
137 #endif