summaryrefslogtreecommitdiffstats
path: root/chrome/installer/util
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/installer/util')
-rw-r--r--chrome/installer/util/browser_distribution.cc4
-rw-r--r--chrome/installer/util/browser_distribution.h7
-rw-r--r--chrome/installer/util/google_chrome_distribution.cc9
-rw-r--r--chrome/installer/util/google_chrome_distribution.h4
-rw-r--r--chrome/installer/util/google_chrome_distribution_dummy.cc4
-rw-r--r--chrome/installer/util/helper_unittest.cc3
-rw-r--r--chrome/installer/util/install_util.cc6
-rw-r--r--chrome/installer/util/install_util.h6
-rw-r--r--chrome/installer/util/package.cc71
-rw-r--r--chrome/installer/util/package.h2
-rw-r--r--chrome/installer/util/package_unittest.cc13
-rw-r--r--chrome/installer/util/product.h2
-rw-r--r--chrome/installer/util/product_unittest.cc6
-rw-r--r--chrome/installer/util/version.cc56
-rw-r--r--chrome/installer/util/version.h51
-rw-r--r--chrome/installer/util/version_unittest.cc82
16 files changed, 61 insertions, 265 deletions
diff --git a/chrome/installer/util/browser_distribution.cc b/chrome/installer/util/browser_distribution.cc
index 98b2e64..2aa80b8 100644
--- a/chrome/installer/util/browser_distribution.cc
+++ b/chrome/installer/util/browser_distribution.cc
@@ -113,7 +113,7 @@ BrowserDistribution* BrowserDistribution::GetSpecificDistribution(
}
void BrowserDistribution::DoPostUninstallOperations(
- const installer::Version& version, const FilePath& local_data_path,
+ const Version& version, const FilePath& local_data_path,
const std::wstring& distribution_data) {
}
@@ -218,7 +218,7 @@ void BrowserDistribution::UpdateDiffInstallStatus(bool system_install,
}
void BrowserDistribution::LaunchUserExperiment(
- installer::InstallStatus status, const installer::Version& version,
+ installer::InstallStatus status, const Version& version,
const installer::Product& installation, bool system_level) {
}
diff --git a/chrome/installer/util/browser_distribution.h b/chrome/installer/util/browser_distribution.h
index 2b23169..1edc73d 100644
--- a/chrome/installer/util/browser_distribution.h
+++ b/chrome/installer/util/browser_distribution.h
@@ -13,8 +13,8 @@
#include "base/basictypes.h"
#include "base/file_path.h"
+#include "base/version.h"
#include "chrome/installer/util/util_constants.h"
-#include "chrome/installer/util/version.h"
#if defined(OS_WIN)
#include <windows.h> // NOLINT
@@ -47,7 +47,7 @@ class BrowserDistribution {
static int GetInstallReturnCode(installer::InstallStatus install_status);
- virtual void DoPostUninstallOperations(const installer::Version& version,
+ virtual void DoPostUninstallOperations(const Version& version,
const FilePath& local_data_path,
const std::wstring& distribution_data);
@@ -100,8 +100,7 @@ class BrowserDistribution {
// experiment. This function determines if the user qualifies and if so it
// sets the wheels in motion or in simple cases does the experiment itself.
virtual void LaunchUserExperiment(installer::InstallStatus status,
- const installer::Version& version,
- const installer::Product& installation,
+ const Version& version, const installer::Product& installation,
bool system_level);
// The user has qualified for the inactive user toast experiment and this
diff --git a/chrome/installer/util/google_chrome_distribution.cc b/chrome/installer/util/google_chrome_distribution.cc
index ef8e8b0..364f14b 100644
--- a/chrome/installer/util/google_chrome_distribution.cc
+++ b/chrome/installer/util/google_chrome_distribution.cc
@@ -326,7 +326,7 @@ bool GoogleChromeDistribution::ExtractUninstallMetrics(
#endif
void GoogleChromeDistribution::DoPostUninstallOperations(
- const installer::Version& version, const FilePath& local_data_path,
+ const Version& version, const FilePath& local_data_path,
const std::wstring& distribution_data) {
// Send the Chrome version and OS version as params to the form.
// It would be nice to send the locale, too, but I don't see an
@@ -336,7 +336,6 @@ void GoogleChromeDistribution::DoPostUninstallOperations(
// characters that need escaping: 0.2.13.4. Should that change, we will
// need to escape the string before using it in a URL.
const std::wstring kVersionParam = L"crversion";
- const std::wstring kVersion = version.GetString();
const std::wstring kOSParam = L"os";
std::wstring os_version = L"na";
OSVERSIONINFO version_info;
@@ -355,8 +354,8 @@ void GoogleChromeDistribution::DoPostUninstallOperations(
iexplore = iexplore.AppendASCII("iexplore.exe");
std::wstring command = iexplore.value() + L" " + GetUninstallSurveyUrl() +
- L"&" + kVersionParam + L"=" + kVersion + L"&" + kOSParam + L"=" +
- os_version;
+ L"&" + kVersionParam + L"=" + UTF8ToWide(version.GetString()) + L"&" +
+ kOSParam + L"=" + os_version;
std::wstring uninstall_metrics;
if (ExtractUninstallMetricsFromFile(local_data_path.value(),
@@ -553,7 +552,7 @@ void SetClient(std::wstring experiment_group, bool last_write) {
// 3- It has been re-launched from the #2 case. In this case we enter
// this function with |system_install| true and a REENTRY_SYS_UPDATE status.
void GoogleChromeDistribution::LaunchUserExperiment(
- installer::InstallStatus status, const installer::Version& version,
+ installer::InstallStatus status, const Version& version,
const installer::Product& installation, bool system_level) {
if (system_level) {
if (installer::NEW_VERSION_UPDATED == status) {
diff --git a/chrome/installer/util/google_chrome_distribution.h b/chrome/installer/util/google_chrome_distribution.h
index 5ac4835..006ed13 100644
--- a/chrome/installer/util/google_chrome_distribution.h
+++ b/chrome/installer/util/google_chrome_distribution.h
@@ -28,7 +28,7 @@ class GoogleChromeDistribution : public BrowserDistribution {
// distribution_data contains Google Update related data that will be
// concatenated to the survey url if the file in local_data_path indicates
// the user has opted in to providing anonymous usage data.
- virtual void DoPostUninstallOperations(const installer::Version& version,
+ virtual void DoPostUninstallOperations(const Version& version,
const FilePath& local_data_path,
const std::wstring& distribution_data);
@@ -69,7 +69,7 @@ class GoogleChromeDistribution : public BrowserDistribution {
bool incremental_install, installer::InstallStatus install_status);
virtual void LaunchUserExperiment(installer::InstallStatus status,
- const installer::Version& version,
+ const Version& version,
const installer::Product& installation,
bool system_level);
diff --git a/chrome/installer/util/google_chrome_distribution_dummy.cc b/chrome/installer/util/google_chrome_distribution_dummy.cc
index 648bfbf..370fec8 100644
--- a/chrome/installer/util/google_chrome_distribution_dummy.cc
+++ b/chrome/installer/util/google_chrome_distribution_dummy.cc
@@ -20,7 +20,7 @@ GoogleChromeDistribution::GoogleChromeDistribution(
}
void GoogleChromeDistribution::DoPostUninstallOperations(
- const installer::Version& version,
+ const Version& version,
const FilePath& local_data_path,
const std::wstring& distribution_data) {
}
@@ -106,7 +106,7 @@ void GoogleChromeDistribution::UpdateDiffInstallStatus(bool system_install,
}
void GoogleChromeDistribution::LaunchUserExperiment(
- installer::InstallStatus status, const installer::Version& version,
+ installer::InstallStatus status, const Version& version,
const installer::Product& installation, bool system_level) {
NOTREACHED();
}
diff --git a/chrome/installer/util/helper_unittest.cc b/chrome/installer/util/helper_unittest.cc
index 64139cf..7c1e955 100644
--- a/chrome/installer/util/helper_unittest.cc
+++ b/chrome/installer/util/helper_unittest.cc
@@ -11,16 +11,15 @@
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/string_util.h"
+#include "base/version.h"
#include "chrome/installer/util/helper.h"
#include "chrome/installer/util/package.h"
#include "chrome/installer/util/package_properties.h"
-#include "chrome/installer/util/version.h"
#include "chrome/installer/util/work_item.h"
#include "testing/gtest/include/gtest/gtest.h"
using installer::ChromePackageProperties;
using installer::Package;
-using installer::Version;
namespace {
class SetupHelperTest : public testing::Test {
diff --git a/chrome/installer/util/install_util.cc b/chrome/installer/util/install_util.cc
index 7d0d978..c5384b3 100644
--- a/chrome/installer/util/install_util.cc
+++ b/chrome/installer/util/install_util.cc
@@ -78,8 +78,8 @@ std::wstring InstallUtil::GetChromeUninstallCmd(bool system_install,
return uninstall_cmd;
}
-installer::Version* InstallUtil::GetChromeVersion(BrowserDistribution* dist,
- bool system_install) {
+Version* InstallUtil::GetChromeVersion(BrowserDistribution* dist,
+ bool system_install) {
DCHECK(dist);
RegKey key;
std::wstring version_str;
@@ -93,7 +93,7 @@ installer::Version* InstallUtil::GetChromeVersion(BrowserDistribution* dist,
}
key.Close();
VLOG(1) << "Existing Chrome version found " << version_str;
- return installer::Version::GetVersionFromString(version_str);
+ return Version::GetVersionFromString(version_str);
}
bool InstallUtil::IsOSSupported() {
diff --git a/chrome/installer/util/install_util.h b/chrome/installer/util/install_util.h
index fd21b29..59a4fb5 100644
--- a/chrome/installer/util/install_util.h
+++ b/chrome/installer/util/install_util.h
@@ -16,9 +16,9 @@
#include "base/basictypes.h"
#include "base/command_line.h"
+#include "base/version.h"
#include "chrome/installer/util/master_preferences.h"
#include "chrome/installer/util/util_constants.h"
-#include "chrome/installer/util/version.h"
class WorkItemList;
class BrowserDistribution;
@@ -48,8 +48,8 @@ class InstallUtil {
// found.
// system_install: if true, looks for version number under the HKLM root,
// otherwise looks under the HKCU.
- static installer::Version* GetChromeVersion(BrowserDistribution* dist,
- bool system_install);
+ static Version* GetChromeVersion(BrowserDistribution* dist,
+ bool system_install);
// This function checks if the current OS is supported for Chromium.
static bool IsOSSupported();
diff --git a/chrome/installer/util/package.cc b/chrome/installer/util/package.cc
index 998dbc6d..68e1a33 100644
--- a/chrome/installer/util/package.cc
+++ b/chrome/installer/util/package.cc
@@ -6,6 +6,7 @@
#include "base/file_util.h"
#include "base/logging.h"
+#include "base/utf_string_conversions.h"
#include "base/win/registry.h"
#include "chrome/installer/util/delete_tree_work_item.h"
#include "chrome/installer/util/google_update_constants.h"
@@ -57,7 +58,7 @@ bool Package::system_level() const {
FilePath Package::GetInstallerDirectory(
const Version& version) const {
- return path_.Append(version.GetString())
+ return path_.Append(UTF8ToWide(version.GetString()))
.Append(installer::kInstallerDir);
}
@@ -85,7 +86,7 @@ Version* Package::GetCurrentVersion() const {
scoped_ptr<Version> this_version(Version::GetVersionFromString(version));
if (this_version.get()) {
if (!current_version.get() ||
- current_version->IsHigherThan(this_version.get())) {
+ (current_version->CompareTo(*this_version) > 0)) {
current_version.reset(this_version.release());
} else if (current_version.get()) {
DCHECK_EQ(current_version->GetString(), this_version->GetString())
@@ -101,55 +102,41 @@ Version* Package::GetCurrentVersion() const {
void Package::RemoveOldVersionDirectories(
const Version& latest_version) const {
- std::wstring search_path(path_.value());
- file_util::AppendToPath(&search_path, L"*");
-
- // TODO(tommi): use file_util::FileEnumerator.
- WIN32_FIND_DATA find_file_data;
- HANDLE file_handle = FindFirstFile(search_path.c_str(), &find_file_data);
- if (file_handle == INVALID_HANDLE_VALUE) {
- VLOG(1) << "No directories found under: " << search_path;
- return;
- }
-
- BOOL ret = TRUE;
+ file_util::FileEnumerator version_enum(path_, false,
+ file_util::FileEnumerator::DIRECTORIES);
scoped_ptr<Version> version;
// We try to delete all directories whose versions are lower than
// latest_version.
- while (ret) {
- if (find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
- lstrcmpW(find_file_data.cFileName, L"..") != 0 &&
- lstrcmpW(find_file_data.cFileName, L".") != 0) {
- VLOG(1) << "directory found: " << find_file_data.cFileName;
- version.reset(Version::GetVersionFromString(find_file_data.cFileName));
- if (version.get() && latest_version.IsHigherThan(version.get())) {
- FilePath remove_dir(path_.Append(find_file_data.cFileName));
- std::vector<FilePath> key_files;
-
- Products::const_iterator it = products_.begin();
- for (; it != products_.end(); ++it) {
- BrowserDistribution* dist = it->get()->distribution();
- std::vector<FilePath> dist_key_files(dist->GetKeyFiles());
- std::vector<FilePath>::const_iterator key_file_iter(
- dist_key_files.begin());
- for (; key_file_iter != dist_key_files.end(); ++key_file_iter) {
- key_files.push_back(remove_dir.Append(*key_file_iter));
- }
+ FilePath next_version = version_enum.Next();
+ while (!next_version.empty()) {
+ file_util::FileEnumerator::FindInfo find_data = {0};
+ version_enum.GetFindInfo(&find_data);
+ VLOG(1) << "directory found: " << find_data.cFileName;
+ version.reset(Version::GetVersionFromString(find_data.cFileName));
+ if (version.get() && (latest_version.CompareTo(*version) > 0)) {
+ std::vector<FilePath> key_files;
+ for (Products::const_iterator it = products_.begin();
+ it != products_.end(); ++it) {
+ BrowserDistribution* dist = it->get()->distribution();
+ std::vector<FilePath> dist_key_files(dist->GetKeyFiles());
+ std::vector<FilePath>::const_iterator key_file_iter(
+ dist_key_files.begin());
+ for (; key_file_iter != dist_key_files.end(); ++key_file_iter) {
+ key_files.push_back(next_version.Append(*key_file_iter));
}
+ }
- VLOG(1) << "Deleting directory: " << remove_dir.value();
+ VLOG(1) << "Deleting directory: " << next_version.value();
- scoped_ptr<DeleteTreeWorkItem> item(
- WorkItem::CreateDeleteTreeWorkItem(remove_dir, key_files));
- if (!item->Do())
- item->Rollback();
- }
+ scoped_ptr<DeleteTreeWorkItem> item(
+ WorkItem::CreateDeleteTreeWorkItem(next_version, key_files));
+ if (!item->Do())
+ item->Rollback();
}
- ret = FindNextFile(file_handle, &find_file_data);
- }
- FindClose(file_handle);
+ next_version = version_enum.Next();
+ }
}
} // namespace installer
diff --git a/chrome/installer/util/package.h b/chrome/installer/util/package.h
index 8d2af0c..d89baa6 100644
--- a/chrome/installer/util/package.h
+++ b/chrome/installer/util/package.h
@@ -12,11 +12,11 @@
#include "base/ref_counted.h"
class CommandLine;
+class Version;
namespace installer {
class Product;
-class Version;
class PackageProperties;
typedef std::vector<scoped_refptr<const Product> > Products;
diff --git a/chrome/installer/util/package_unittest.cc b/chrome/installer/util/package_unittest.cc
index c328f9b..b553a46 100644
--- a/chrome/installer/util/package_unittest.cc
+++ b/chrome/installer/util/package_unittest.cc
@@ -4,6 +4,7 @@
#include "base/logging.h"
#include "base/scoped_handle.h"
+#include "base/utf_string_conversions.h"
#include "chrome/installer/util/browser_distribution.h"
#include "chrome/installer/util/google_update_constants.h"
#include "chrome/installer/util/master_preferences.h"
@@ -12,7 +13,6 @@
#include "chrome/installer/util/product.h"
#include "chrome/installer/util/product_unittest.h"
#include "chrome/installer/util/util_constants.h"
-#include "chrome/installer/util/version.h"
using base::win::RegKey;
using base::win::ScopedHandle;
@@ -20,7 +20,6 @@ using installer::ChromePackageProperties;
using installer::ChromiumPackageProperties;
using installer::Package;
using installer::Product;
-using installer::Version;
class PackageTest : public TestWithTempDirAndDeleteTempOverrideKeys {
protected:
@@ -48,8 +47,10 @@ TEST_F(PackageTest, Basic) {
FilePath installer_dir(package->GetInstallerDirectory(*new_version.get()));
EXPECT_FALSE(installer_dir.empty());
- FilePath new_version_dir(package->path().Append(new_version->GetString()));
- FilePath old_version_dir(package->path().Append(old_version->GetString()));
+ FilePath new_version_dir(package->path().Append(
+ UTF8ToWide(new_version->GetString())));
+ FilePath old_version_dir(package->path().Append(
+ UTF8ToWide(old_version->GetString())));
EXPECT_FALSE(file_util::PathExists(new_version_dir));
EXPECT_FALSE(file_util::PathExists(old_version_dir));
@@ -120,12 +121,12 @@ TEST_F(PackageTest, WithProduct) {
EXPECT_TRUE(chrome_key.Valid());
if (chrome_key.Valid()) {
chrome_key.WriteValue(google_update::kRegVersionField,
- current_version->GetString().c_str());
+ UTF8ToWide(current_version->GetString()).c_str());
// TODO(tommi): Also test for when there exists a new_chrome.exe.
scoped_ptr<Version> found_version(package->GetCurrentVersion());
EXPECT_TRUE(found_version.get() != NULL);
if (found_version.get()) {
- EXPECT_TRUE(current_version->IsEqual(*found_version.get()));
+ EXPECT_TRUE(current_version->Equals(*found_version));
}
}
}
diff --git a/chrome/installer/util/product.h b/chrome/installer/util/product.h
index aa1f1e5..cfd1736 100644
--- a/chrome/installer/util/product.h
+++ b/chrome/installer/util/product.h
@@ -14,6 +14,7 @@
#include "chrome/installer/util/package.h"
class CommandLine;
+class Version;
namespace installer {
class MasterPreferences;
@@ -24,7 +25,6 @@ namespace installer {
class Product;
class Package;
class PackageProperties;
-class Version;
typedef std::vector<scoped_refptr<Package> > Packages;
typedef std::vector<scoped_refptr<const Product> > Products;
diff --git a/chrome/installer/util/product_unittest.cc b/chrome/installer/util/product_unittest.cc
index 992bd4d..64cc1da 100644
--- a/chrome/installer/util/product_unittest.cc
+++ b/chrome/installer/util/product_unittest.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/scoped_handle.h"
+#include "base/utf_string_conversions.h"
#include "chrome/installer/util/chrome_frame_distribution.h"
#include "chrome/installer/util/google_update_constants.h"
#include "chrome/installer/util/package.h"
@@ -20,7 +21,6 @@ using installer::ChromiumPackageProperties;
using installer::Package;
using installer::Product;
using installer::ProductPackageMapping;
-using installer::Version;
using installer::MasterPreferences;
void TestWithTempDir::SetUp() {
@@ -144,12 +144,12 @@ TEST_F(ProductTest, ProductInstallBasic) {
scoped_ptr<Version> current_version(
Version::GetVersionFromString(kCurrentVersion));
version_key.WriteValue(google_update::kRegVersionField,
- current_version->GetString().c_str());
+ UTF8ToWide(current_version->GetString()).c_str());
scoped_ptr<Version> installed(product->GetInstalledVersion());
EXPECT_TRUE(installed.get() != NULL);
if (installed.get()) {
- EXPECT_TRUE(installed->IsEqual(*current_version.get()));
+ EXPECT_TRUE(installed->Equals(*current_version.get()));
}
}
}
diff --git a/chrome/installer/util/version.cc b/chrome/installer/util/version.cc
deleted file mode 100644
index 7618e7d..0000000
--- a/chrome/installer/util/version.cc
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright (c) 2010 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 "chrome/installer/util/version.h"
-
-#include <vector>
-
-#include "base/format_macros.h"
-#include "base/string_number_conversions.h"
-#include "base/string_split.h"
-#include "base/string_util.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/installer/util/version.h"
-
-installer::Version::Version(int64 major, int64 minor, int64 build,
- int64 patch)
- : major_(major),
- minor_(minor),
- build_(build),
- patch_(patch) {
- version_str_ = ASCIIToUTF16(
- StringPrintf("%" PRId64 ".%" PRId64 ".%" PRId64 ".%" PRId64,
- major_, minor_, build_, patch_));
-}
-
-installer::Version::~Version() {
-}
-
-bool installer::Version::IsHigherThan(const installer::Version* other) const {
- return ((major_ > other->major_) ||
- ((major_ == other->major_) && (minor_ > other->minor_)) ||
- ((major_ == other->major_) && (minor_ == other->minor_)
- && (build_ > other->build_)) ||
- ((major_ == other->major_) && (minor_ == other->minor_)
- && (build_ == other->build_)
- && (patch_ > other->patch_)));
-}
-
-installer::Version* installer::Version::GetVersionFromString(
- const string16& version_str) {
- std::vector<string16> numbers;
- base::SplitString(version_str, '.', &numbers);
-
- if (numbers.size() != 4) {
- LOG(ERROR) << "Invalid version string: " << version_str;
- return NULL;
- }
-
- int64 v0, v1, v2, v3;
- base::StringToInt64(numbers[0], &v0);
- base::StringToInt64(numbers[1], &v1);
- base::StringToInt64(numbers[2], &v2);
- base::StringToInt64(numbers[3], &v3);
- return new Version(v0, v1, v2, v3);
-}
diff --git a/chrome/installer/util/version.h b/chrome/installer/util/version.h
deleted file mode 100644
index e237260..0000000
--- a/chrome/installer/util/version.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// 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.
-
-#ifndef CHROME_INSTALLER_UTIL_VERSION_H_
-#define CHROME_INSTALLER_UTIL_VERSION_H_
-#pragma once
-
-#include "base/basictypes.h"
-#include "base/string16.h"
-
-namespace installer {
-
-// TODO(tommi): We should be using the Version class from base.
-class Version {
- public:
- virtual ~Version();
-
- // Check if the current version is higher than the version object passed
- // as parameter
- bool IsHigherThan(const Version* other) const;
-
- // Return the string representation of this version
- const string16& GetString() const {
- return version_str_;
- }
-
- bool IsEqual(const Version& other) const {
- return version_str_ == other.GetString();
- }
-
- // Assume that the version string is specified by four integers separated
- // by character '.'. Return NULL if string is not of this format.
- // Caller is responsible for freeing the Version object once done.
- static Version* GetVersionFromString(const string16& version_str);
-
- private:
- int64 major_;
- int64 minor_;
- int64 build_;
- int64 patch_;
- string16 version_str_;
-
- // Classes outside this file do not have any need to create objects of
- // this type so declare constructor as private.
- Version(int64 major, int64 minor, int64 build, int64 patch);
-};
-
-} // namespace installer
-
-#endif // CHROME_INSTALLER_UTIL_VERSION_H_
diff --git a/chrome/installer/util/version_unittest.cc b/chrome/installer/util/version_unittest.cc
deleted file mode 100644
index 6a3e12c..0000000
--- a/chrome/installer/util/version_unittest.cc
+++ /dev/null
@@ -1,82 +0,0 @@
-// 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 "chrome/installer/util/version.h"
-
-#include <string>
-#include <vector>
-
-#include "base/scoped_ptr.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-static const installer::Version* kNoVersion = NULL;
-
-TEST(VersionTest, Parse) {
- EXPECT_EQ(installer::Version::GetVersionFromString(L"1"), kNoVersion);
- EXPECT_EQ(installer::Version::GetVersionFromString(L"1.2"), kNoVersion);
- EXPECT_EQ(installer::Version::GetVersionFromString(L"1.2.3"), kNoVersion);
- EXPECT_EQ(installer::Version::GetVersionFromString(L"1.2.3.4.5"), kNoVersion);
- EXPECT_EQ(installer::Version::GetVersionFromString(L"hokum"), kNoVersion);
-
- scoped_ptr<installer::Version> v1(
- installer::Version::GetVersionFromString(L"1.22.333.4444"));
- EXPECT_EQ(v1->GetString(), L"1.22.333.4444");
-}
-
-bool Implies(bool p, bool q) { return !p | q; }
-
-TEST(VersionTest, Comparison) {
- static const wchar_t* version_strings[] = {
- L"0.0.0.0",
- L"1.0.0.0",
- L"0.1.0.0",
- L"0.0.1.0",
- L"0.0.0.1",
- L"2.0.193.1",
- L"3.0.183.1",
- L"3.0.187.1",
- L"3.0.189.0",
- };
-
- std::vector<const installer::Version*> versions;
-
- for (size_t i = 0; i < _countof(version_strings); ++i) {
- std::wstring version_string(version_strings[i]);
- const installer::Version* version =
- installer::Version::GetVersionFromString(version_string);
- EXPECT_NE(version, kNoVersion);
- EXPECT_EQ(version_string, version->GetString());
- versions.push_back(version);
- }
-
- // Compare all N*N pairs and check that IsHigherThan is antireflexive.
- for (size_t i = 0; i < versions.size(); ++i) {
- const installer::Version* v1 = versions[i];
- for (size_t j = 0; j < versions.size(); ++j) {
- const installer::Version* v2 = versions[j];
- // Check exactly one of '>', '<', or '=' is true.
- bool higher = v1->IsHigherThan(v2);
- bool lower = v2->IsHigherThan(v1);
- bool equal = v1->GetString() == v2->GetString();
- EXPECT_EQ(1, higher + lower + equal);
- }
- }
-
- // Compare all N*N*N triples and check that IsHigherThan is a total order.
- for (size_t i = 0; i < versions.size(); ++i) {
- const installer::Version* v1 = versions[i];
- for (size_t j = 0; j < versions.size(); ++j) {
- const installer::Version* v2 = versions[j];
- for (size_t k = 0; k < versions.size(); ++k) {
- const installer::Version* v3 = versions[j];
- EXPECT_TRUE(Implies(v2->IsHigherThan(v1) && v3->IsHigherThan(v2),
- v3->IsHigherThan(v1)));
- }
- }
- }
-
- for (size_t i = 0; i < versions.size(); ++i) {
- delete versions[i];
- }
-}