forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a basic backwards compatibility unittest.
This verifies we can still apply old patches, but does not verify that old clients can apply new patches. That seems important, but I'm not sure how to do it without storing old client binaries in version control. Also refactors a number of unit tests to allow code sharing for reading files into memory. This is done via a new base class. Uses test binaries submitted seperatly because of build tools problems. BUG=None TEST=New Unittest Review URL: http://codereview.chromium.org/8252011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105982 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
dgarrett@chromium.org
committed
Oct 18, 2011
1 parent
ec817ab
commit bf0ece4
Showing
8 changed files
with
126 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// 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 "courgette/base_test_unittest.h" | ||
|
||
#include "base/path_service.h" | ||
|
||
void BaseTest::SetUp() { | ||
PathService::Get(base::DIR_SOURCE_ROOT, &test_dir_); | ||
test_dir_ = test_dir_.AppendASCII("courgette"); | ||
test_dir_ = test_dir_.AppendASCII("testdata"); | ||
} | ||
|
||
void BaseTest::TearDown() { | ||
} | ||
|
||
// Reads a test file into a string. | ||
std::string BaseTest::FileContents(const char* file_name) const { | ||
FilePath file_path = test_dir_; | ||
file_path = file_path.AppendASCII(file_name); | ||
std::string file_bytes; | ||
|
||
EXPECT_TRUE(file_util::ReadFileToString(file_path, &file_bytes)); | ||
|
||
return file_bytes; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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 <string> | ||
|
||
#ifndef COURGETTE_BASE_TEST_UNITTEST_H_ | ||
#define COURGETTE_BASE_TEST_UNITTEST_H_ | ||
|
||
#include <string> | ||
|
||
#include "base/file_util.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
class BaseTest : public testing::Test { | ||
public: | ||
std::string FileContents(const char* file_name) const; | ||
|
||
private: | ||
virtual void SetUp(); | ||
virtual void TearDown(); | ||
|
||
FilePath test_dir_; | ||
}; | ||
|
||
#endif // COURGETTE_BASE_TEST_UNITTEST_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// 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 "courgette/base_test_unittest.h" | ||
|
||
#include <string> | ||
|
||
#include "base/basictypes.h" | ||
#include "courgette/courgette.h" | ||
#include "courgette/streams.h" | ||
|
||
class VersioningTest : public BaseTest { | ||
public: | ||
void TestApplyingOldPatch(const char* src_file, | ||
const char* patch_file, | ||
const char* expected_file) const; | ||
}; | ||
|
||
void VersioningTest::TestApplyingOldPatch(const char* src_file, | ||
const char* patch_file, | ||
const char* expected_file) const { | ||
|
||
std::string old_buffer = FileContents(src_file); | ||
std::string new_buffer = FileContents(patch_file); | ||
std::string expected_buffer = FileContents(expected_file); | ||
|
||
courgette::SourceStream old_stream; | ||
courgette::SourceStream patch_stream; | ||
old_stream.Init(old_buffer); | ||
patch_stream.Init(new_buffer); | ||
|
||
courgette::SinkStream generated_stream; | ||
|
||
courgette::Status status = | ||
courgette::ApplyEnsemblePatch(&old_stream, | ||
&patch_stream, | ||
&generated_stream); | ||
|
||
EXPECT_EQ(status, courgette::C_OK); | ||
|
||
size_t expected_length = expected_buffer.size(); | ||
size_t generated_length = generated_stream.Length(); | ||
|
||
EXPECT_EQ(generated_length, expected_length); | ||
EXPECT_EQ(0, memcmp(generated_stream.Buffer(), | ||
expected_buffer.c_str(), | ||
expected_length)); | ||
} | ||
|
||
|
||
TEST_F(VersioningTest, All) { | ||
TestApplyingOldPatch("setup1.exe", "setup1-setup2.v1.patch", "setup2.exe"); | ||
|
||
// We also need a way to test that newly generated patches are appropriately | ||
// applicable by older clients... not sure of the best way to do that. | ||
} |