From 16ffdc51c3d43b06cc6d4e2f9fa44ed038ead859 Mon Sep 17 00:00:00 2001 From: "fbarchard@chromium.org" Date: Fri, 11 Jun 2010 20:17:21 +0000 Subject: BlockDifference function that returns 0 or 1 depending if block is same or different. BUG=none TEST=unittest updated and includes benchmarking. Review URL: http://codereview.chromium.org/2712006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49583 0039d316-1c4b-4281-b951-d872f2087c98 --- remoting/host/differ_block_unittest.cc | 77 ++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 18 deletions(-) (limited to 'remoting/host/differ_block_unittest.cc') diff --git a/remoting/host/differ_block_unittest.cc b/remoting/host/differ_block_unittest.cc index 02bd0b3..3bf6cb4 100644 --- a/remoting/host/differ_block_unittest.cc +++ b/remoting/host/differ_block_unittest.cc @@ -8,9 +8,9 @@ namespace remoting { -static const int kWidth = 32; -static const int kHeight = 32; -static const int kBytesPerPixel = 3; +// Run 900 times to mimic 1280x720. +// TODO(fbarchard): Remove benchmark once performance is non-issue. +static const int kTimesToRun = 900; static void GenerateData(uint8* data, int size) { for (int i = 0; i < size; ++i) { @@ -24,23 +24,64 @@ class EncodeDoneHandler MOCK_METHOD0(EncodeDone, void()); }; -TEST(BlockDifferenceTest, BlockDifference) { - // Prepare 2 blocks to compare. - uint8 block1[kHeight * kWidth * kBytesPerPixel]; - uint8 block2[kHeight * kWidth * kBytesPerPixel]; - GenerateData(block1, sizeof(block1)); - memcpy(block2, block1, sizeof(block2)); +// Memory buffer large enough for 2 blocks aligned to 16 bytes. +static const int kSizeOfBlock = kBlockHeight * kBlockWidth * kBytesPerPixel; +uint8 block_buffer[kSizeOfBlock * 2 + 16]; + +void PrepareBuffers(uint8* &block1, uint8* &block2) { + block1 = reinterpret_cast + ((reinterpret_cast(&block_buffer[0]) + 15) & ~15); + GenerateData(block1, kSizeOfBlock); + block2 = block1 + kSizeOfBlock; + memcpy(block2, block1, kSizeOfBlock); +} + +TEST(BlockDifferenceTestSame, BlockDifference) { + uint8* block1; + uint8* block2; + PrepareBuffers(block1, block2); // These blocks should match. - int same = BlockDifference(block1, block2, kWidth * kBytesPerPixel); - EXPECT_EQ(0, same); - - // Change block2 a little. - block2[7] += 3; - block2[sizeof(block2)-1] -= 5; - // These blocks should not match. The difference should be 8. - int not_same = BlockDifference(block1, block2, kWidth * kBytesPerPixel); - EXPECT_EQ(8, not_same); + for (int i = 0; i < kTimesToRun; ++i) { + int result = BlockDifference(block1, block2, kBlockWidth * kBytesPerPixel); + EXPECT_EQ(0, result); + } +} + +TEST(BlockDifferenceTestLast, BlockDifference) { + uint8* block1; + uint8* block2; + PrepareBuffers(block1, block2); + block2[kSizeOfBlock-2] += 1; + + for (int i = 0; i < kTimesToRun; ++i) { + int result = BlockDifference(block1, block2, kBlockWidth * kBytesPerPixel); + EXPECT_EQ(1, result); + } +} + +TEST(BlockDifferenceTestMid, BlockDifference) { + uint8* block1; + uint8* block2; + PrepareBuffers(block1, block2); + block2[kSizeOfBlock/2+1] += 1; + + for (int i = 0; i < kTimesToRun; ++i) { + int result = BlockDifference(block1, block2, kBlockWidth * kBytesPerPixel); + EXPECT_EQ(1, result); + } +} + +TEST(BlockDifferenceTestFirst, BlockDifference) { + uint8* block1; + uint8* block2; + PrepareBuffers(block1, block2); + block2[0] += 1; + + for (int i = 0; i < kTimesToRun; ++i) { + int result = BlockDifference(block1, block2, kBlockWidth * kBytesPerPixel); + EXPECT_EQ(1, result); + } } } // namespace remoting -- cgit v1.1