From c66931ce8606697a5c500b02dff1ef2e15fdbf75 Mon Sep 17 00:00:00 2001 From: "tommi@chromium.org" Date: Wed, 16 Mar 2011 20:43:26 +0000 Subject: Clean up temporary files and folders left over from previous installations. Installation failures due to out-of-disk-space seem to be getting more and more frequent and upon inspection, I found that we can in some cases do a terrible job and leave cruft behind. Worst of all we can do this if an installation fails due to low free disk space, thus only adding to the problem. I suspect there maybe users stuck on a specific revision of Chrome because of this. I'm also implementing Robert's idea of supporting for a --cleanup command line arg that can be passed to the mini installer to only do the cleanup and not the installation. BUG=74777 TEST=This should reduce the number of crashes we're getting due to out of disk space. Review URL: http://codereview.chromium.org/6670023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78424 0039d316-1c4b-4281-b951-d872f2087c98 --- .../installer/mini_installer/mini_string_test.cc | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 chrome/installer/mini_installer/mini_string_test.cc (limited to 'chrome/installer/mini_installer/mini_string_test.cc') diff --git a/chrome/installer/mini_installer/mini_string_test.cc b/chrome/installer/mini_installer/mini_string_test.cc new file mode 100644 index 0000000..67b11f9 --- /dev/null +++ b/chrome/installer/mini_installer/mini_string_test.cc @@ -0,0 +1,77 @@ +// Copyright (c) 2011 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 + +#include + +#include "base/basictypes.h" +#include "chrome/installer/mini_installer/mini_string.h" +#include "testing/gtest/include/gtest/gtest.h" + +using mini_installer::StackString; + +namespace { +class MiniInstallerStringTest : public testing::Test { + protected: + virtual void SetUp() { + } + virtual void TearDown() { + } +}; +} + +// Tests the strcat/strcpy/length support of the StackString class. +TEST_F(MiniInstallerStringTest, StackStringOverflow) { + static const wchar_t kTestString[] = L"1234567890"; + + StackString str; + EXPECT_EQ(MAX_PATH, str.capacity()); + + std::wstring compare_str; + + EXPECT_EQ(str.length(), compare_str.length()); + EXPECT_EQ(0, compare_str.compare(str.get())); + + size_t max_chars = str.capacity() - 1; + + while ((str.length() + (arraysize(kTestString) - 1)) <= max_chars) { + EXPECT_TRUE(str.append(kTestString)); + compare_str.append(kTestString); + EXPECT_EQ(str.length(), compare_str.length()); + EXPECT_EQ(0, compare_str.compare(str.get())); + } + + EXPECT_GT(static_cast(MAX_PATH), str.length()); + + // Now we've exhausted the space we allocated for the string, + // so append should fail. + EXPECT_FALSE(str.append(kTestString)); + + // ...and remain unchanged. + EXPECT_EQ(0, compare_str.compare(str.get())); + EXPECT_EQ(str.length(), compare_str.length()); + + // Last test for fun. + str.clear(); + compare_str.clear(); + EXPECT_EQ(0, compare_str.compare(str.get())); + EXPECT_EQ(str.length(), compare_str.length()); +} + +// Tests the case insensitive find support of the StackString class. +TEST_F(MiniInstallerStringTest, StackStringFind) { + static const wchar_t kTestStringSource[] = L"1234ABcD567890"; + static const wchar_t kTestStringFind[] = L"abcd"; + static const wchar_t kTestStringNotFound[] = L"80"; + + StackString str; + EXPECT_TRUE(str.assign(kTestStringSource)); + EXPECT_EQ(str.get(), str.findi(kTestStringSource)); + EXPECT_EQ(static_cast(NULL), str.findi(kTestStringNotFound)); + const wchar_t* found = str.findi(kTestStringFind); + EXPECT_NE(static_cast(NULL), found); + std::wstring check(found, arraysize(kTestStringFind) - 1); + EXPECT_EQ(0, lstrcmpi(check.c_str(), kTestStringFind)); +} -- cgit v1.1