diff options
author | kuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-05 19:44:07 +0000 |
---|---|---|
committer | kuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-05 19:44:07 +0000 |
commit | ec37d38793379facce6e10bafa9b4456efcdd12f (patch) | |
tree | ed1adb3bf1c29dc8a96a9fc8da3a1248908793ac /chrome | |
parent | 731980c04db87643c41d6f8d6f594de1cf7b725d (diff) | |
download | chromium_src-ec37d38793379facce6e10bafa9b4456efcdd12f.zip chromium_src-ec37d38793379facce6e10bafa9b4456efcdd12f.tar.gz chromium_src-ec37d38793379facce6e10bafa9b4456efcdd12f.tar.bz2 |
Renamed installer_unittests to util_unittests and added setup_unitests project with only one unit test for now.
BUG=12849
TEST=none
Review URL: http://codereview.chromium.org/118247
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17758 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/installer/installer.gyp | 26 | ||||
-rw-r--r-- | chrome/installer/setup/main.cc | 33 | ||||
-rw-r--r-- | chrome/installer/setup/run_all_unittests.cc | 9 | ||||
-rw-r--r-- | chrome/installer/setup/setup.vcproj | 8 | ||||
-rw-r--r-- | chrome/installer/setup/setup_util.cc | 36 | ||||
-rw-r--r-- | chrome/installer/setup/setup_util.h | 19 | ||||
-rw-r--r-- | chrome/installer/setup/setup_util_unittest.cc | 70 | ||||
-rw-r--r-- | chrome/installer/util/util_unittests.rc (renamed from chrome/installer/util/installer_unittests.rc) | 2 | ||||
-rw-r--r-- | chrome/installer/util/util_unittests.vcproj (renamed from chrome/installer/util/installer_unittests.vcproj) | 8 | ||||
-rw-r--r-- | chrome/installer/util/util_unittests_resource.h (renamed from chrome/installer/util/installer_unittests_resource.h) | 2 |
10 files changed, 172 insertions, 41 deletions
diff --git a/chrome/installer/installer.gyp b/chrome/installer/installer.gyp index 807fb47..3e45670 100644 --- a/chrome/installer/installer.gyp +++ b/chrome/installer/installer.gyp @@ -238,10 +238,10 @@ ], }, { - 'target_name': 'installer_unittests', + 'target_name': 'util_unittests', 'type': 'executable', 'msvs_guid': '903F8C1E-537A-4C9E-97BE-075147CBE769', - 'msvs_existing_vcproj': 'util/installer_unittests.vcproj', + 'msvs_existing_vcproj': 'util/util_unittests.vcproj', 'dependencies': [ 'installer_util', 'installer_util_strings', @@ -261,8 +261,8 @@ 'util/delete_tree_work_item_unittest.cc', 'util/google_chrome_distribution_unittest.cc', 'util/helper_unittest.cc', - 'util/installer_unittests.rc', - 'util/installer_unittests_resource.h', + 'util/util_unittests.rc', + 'util/util_unittests_resource.h', 'util/move_tree_work_item_unittest.cc', 'util/run_all_unittests.cc', 'util/set_reg_value_work_item_unittest.cc', @@ -546,6 +546,24 @@ }], ], }, + { + 'target_name': 'setup_unittests', + 'type': 'executable', + 'msvs_guid': 'C0AE4E06-F023-460F-BC14-6302CEAC51F8', + 'dependencies': [ + 'installer_util', + '../../base/base.gyp:base', + '../../testing/gtest.gyp:gtest', + ], + 'include_dirs': [ + '../..', + ], + 'sources': [ + 'setup/run_all_unittests.cc', + 'setup/setup_util.cc', + 'setup/setup_util_unittest.cc', + ], + }, ], }], [ 'branding == "Chrome"', { diff --git a/chrome/installer/setup/main.cc b/chrome/installer/setup/main.cc index f1e38ad..d840982 100644 --- a/chrome/installer/setup/main.cc +++ b/chrome/installer/setup/main.cc @@ -17,6 +17,7 @@ #include "base/win_util.h" #include "chrome/installer/setup/setup.h" #include "chrome/installer/setup/setup_constants.h" +#include "chrome/installer/setup/setup_util.h" #include "chrome/installer/setup/uninstall.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/delete_tree_work_item.h" @@ -154,36 +155,6 @@ DWORD UnPackArchive(const std::wstring& archive, bool system_install, } -// Find the version of Chrome from an install source directory. -// Chrome_path should contain a complete and unpacked install package (i.e. -// a Chrome directory under which there is a version folder). -// Returns the version or NULL if no version is found. -installer::Version* GetVersionFromDir(const std::wstring& chrome_path) { - LOG(INFO) << "Looking for Chrome version folder under " << chrome_path; - std::wstring root_path(chrome_path); - file_util::AppendToPath(&root_path, L"*"); - - WIN32_FIND_DATA find_file_data; - HANDLE file_handle = FindFirstFile(root_path.c_str(), &find_file_data); - BOOL ret = TRUE; - installer::Version *version = NULL; - // Here we are assuming that the installer we have is really valid so there - // can not be two version directories. We exit as soon as we find a valid - // version directory. - while (ret) { - if (find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - LOG(INFO) << "directory found: " << find_file_data.cFileName; - version = - installer::Version::GetVersionFromString(find_file_data.cFileName); - if (version) break; - } - ret = FindNextFile(file_handle, &find_file_data); - } - FindClose(file_handle); - - return version; -} - // This function is called when --rename-chrome-exe option is specified on // setup.exe command line. This function assumes an in-use update has happened // for Chrome so there should be a file called new_chrome.exe on the file @@ -385,7 +356,7 @@ installer_util::InstallStatus InstallChrome(const CommandLine& cmd_line, file_util::AppendToPath(&src_path, std::wstring(installer::kInstallSourceChromeDir)); scoped_ptr<installer::Version> - installer_version(GetVersionFromDir(src_path)); + installer_version(setup_util::GetVersionFromDir(src_path)); if (!installer_version.get()) { LOG(ERROR) << "Did not find any valid version in installer."; install_status = installer_util::INVALID_ARCHIVE; diff --git a/chrome/installer/setup/run_all_unittests.cc b/chrome/installer/setup/run_all_unittests.cc new file mode 100644 index 0000000..b5fc4a6 --- /dev/null +++ b/chrome/installer/setup/run_all_unittests.cc @@ -0,0 +1,9 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/test_suite.h" + +int main(int argc, char** argv) { + return TestSuite(argc, argv).Run(); +} diff --git a/chrome/installer/setup/setup.vcproj b/chrome/installer/setup/setup.vcproj index 4afb42f..00792ce 100644 --- a/chrome/installer/setup/setup.vcproj +++ b/chrome/installer/setup/setup.vcproj @@ -108,6 +108,14 @@ > </File> <File + RelativePath=".\setup_util.cc" + > + </File> + <File + RelativePath=".\setup_util.h" + > + </File> + <File RelativePath=".\setup_constants.cc" > </File> diff --git a/chrome/installer/setup/setup_util.cc b/chrome/installer/setup/setup_util.cc new file mode 100644 index 0000000..7356ecf --- /dev/null +++ b/chrome/installer/setup/setup_util.cc @@ -0,0 +1,36 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// This file declares util functions for setup project. + +#include "chrome/installer/setup/setup_util.h" + +#include "base/file_util.h" +#include "base/logging.h" + +installer::Version* setup_util::GetVersionFromDir( + const std::wstring& chrome_path) { + LOG(INFO) << "Looking for Chrome version folder under " << chrome_path; + std::wstring root_path(chrome_path); + file_util::AppendToPath(&root_path, L"*"); + + WIN32_FIND_DATA find_data; + HANDLE file_handle = FindFirstFile(root_path.c_str(), &find_data); + BOOL ret = TRUE; + installer::Version *version = NULL; + // Here we are assuming that the installer we have is really valid so there + // can not be two version directories. We exit as soon as we find a valid + // version directory. + while (ret) { + if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + LOG(INFO) << "directory found: " << find_data.cFileName; + version = installer::Version::GetVersionFromString(find_data.cFileName); + if (version) break; + } + ret = FindNextFile(file_handle, &find_data); + } + FindClose(file_handle); + + return version; +} diff --git a/chrome/installer/setup/setup_util.h b/chrome/installer/setup/setup_util.h new file mode 100644 index 0000000..c9e067f --- /dev/null +++ b/chrome/installer/setup/setup_util.h @@ -0,0 +1,19 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// This file declares util functions for setup project. + +#ifndef CHROME_INSTALLER_SETUP_SETUP_UTIL_H_ +#define CHROME_INSTALLER_SETUP_SETUP_UTIL_H_ + +#include "chrome/installer/util/version.h" + +namespace setup_util { + // Find the version of Chrome from an install source directory. + // Chrome_path should contain a version folder. + // Returns the first version found or NULL if no version is found. + installer::Version* GetVersionFromDir(const std::wstring& chrome_path); +} // namespace setup_util + +#endif // CHROME_INSTALLER_SETUP_SETUP_UTIL_H_ diff --git a/chrome/installer/setup/setup_util_unittest.cc b/chrome/installer/setup/setup_util_unittest.cc new file mode 100644 index 0000000..42cecdf --- /dev/null +++ b/chrome/installer/setup/setup_util_unittest.cc @@ -0,0 +1,70 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <windows.h> + +#include <fstream> +#include <iostream> + +#include "base/base_paths.h" +#include "base/file_util.h" +#include "base/path_service.h" +#include "base/process_util.h" +#include "base/string_util.h" +#include "chrome/installer/setup/setup_util.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + class SetupUtilTest : public testing::Test { + protected: + virtual void SetUp() { + // Name a subdirectory of the user temp directory. + ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); + test_dir_ = test_dir_.AppendASCII("SetupUtilTest"); + + // Create a fresh, empty copy of this test directory. + file_util::Delete(test_dir_, true); + file_util::CreateDirectory(test_dir_); + ASSERT_TRUE(file_util::PathExists(test_dir_)); + } + + virtual void TearDown() { + // Clean up test directory + ASSERT_TRUE(file_util::Delete(test_dir_, false)); + ASSERT_FALSE(file_util::PathExists(test_dir_)); + } + + // the path to temporary directory used to contain the test operations + FilePath test_dir_; + }; +}; + +// Test that we are parsing Chrome version correctly. +TEST_F(SetupUtilTest, GetVersionFromDirTest) { + // Create a version dir + std::wstring chrome_dir(test_dir_.value()); + file_util::AppendToPath(&chrome_dir, L"1.0.0.0"); + CreateDirectory(chrome_dir.c_str(), NULL); + ASSERT_TRUE(file_util::PathExists(chrome_dir)); + scoped_ptr<installer::Version> version( + setup_util::GetVersionFromDir(test_dir_.value())); + ASSERT_TRUE(version->GetString() == L"1.0.0.0"); + + file_util::Delete(chrome_dir, true); + ASSERT_FALSE(file_util::PathExists(chrome_dir)); + ASSERT_TRUE(setup_util::GetVersionFromDir(test_dir_.value()) == NULL); + + chrome_dir = test_dir_.value(); + file_util::AppendToPath(&chrome_dir, L"ABC"); + CreateDirectory(chrome_dir.c_str(), NULL); + ASSERT_TRUE(file_util::PathExists(chrome_dir)); + ASSERT_TRUE(setup_util::GetVersionFromDir(test_dir_.value()) == NULL); + + chrome_dir = test_dir_.value(); + file_util::AppendToPath(&chrome_dir, L"2.3.4.5"); + CreateDirectory(chrome_dir.c_str(), NULL); + ASSERT_TRUE(file_util::PathExists(chrome_dir)); + version.reset(setup_util::GetVersionFromDir(test_dir_.value())); + ASSERT_TRUE(version->GetString() == L"2.3.4.5"); +} diff --git a/chrome/installer/util/installer_unittests.rc b/chrome/installer/util/util_unittests.rc index 0df7619..7519c5c 100644 --- a/chrome/installer/util/installer_unittests.rc +++ b/chrome/installer/util/util_unittests.rc @@ -1,6 +1,6 @@ // Microsoft Visual C++ generated resource script.
//
-#include "installer_unittests_resource.h"
+#include "util_unittests_resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/installer/util/installer_unittests.vcproj b/chrome/installer/util/util_unittests.vcproj index 99aa3b1..4e95cf6 100644 --- a/chrome/installer/util/installer_unittests.vcproj +++ b/chrome/installer/util/util_unittests.vcproj @@ -2,9 +2,9 @@ <VisualStudioProject ProjectType="Visual C++" Version="8.00" - Name="installer_unittests" + Name="util_unittests" ProjectGUID="{903F8C1E-537A-4C9E-97BE-075147CBE769}" - RootNamespace="installer_unittests" + RootNamespace="util_unittests" > <Platforms> <Platform @@ -144,11 +144,11 @@ Name="resources" > <File - RelativePath="installer_unittests.rc" + RelativePath="util_unittests.rc" > </File> <File - RelativePath="installer_unittests_resource.h" + RelativePath="unit_unittests_resource.h" > </File> </Filter> diff --git a/chrome/installer/util/installer_unittests_resource.h b/chrome/installer/util/util_unittests_resource.h index c5979f7..97c58c3 100644 --- a/chrome/installer/util/installer_unittests_resource.h +++ b/chrome/installer/util/util_unittests_resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
-// Used by installer_unittests.rc
+// Used by util_unittests.rc
// Next default values for new objects
//
|