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/installer/setup/setup_util_unittest.cc | |
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/installer/setup/setup_util_unittest.cc')
-rw-r--r-- | chrome/installer/setup/setup_util_unittest.cc | 70 |
1 files changed, 70 insertions, 0 deletions
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"); +} |