2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "webrtc/modules/desktop_capture/differ_block.h"
13 #include "webrtc/system_wrappers/interface/ref_count.h"
17 // Run 900 times to mimic 1280x720.
18 // TODO(fbarchard): Remove benchmark once performance is non-issue.
19 static const int kTimesToRun = 900;
21 static void GenerateData(uint8_t* data, int size) {
22 for (int i = 0; i < size; ++i) {
27 // Memory buffer large enough for 2 blocks aligned to 16 bytes.
28 static const int kSizeOfBlock = kBlockSize * kBlockSize * kBytesPerPixel;
29 uint8_t block_buffer[kSizeOfBlock * 2 + 16];
31 void PrepareBuffers(uint8_t* &block1, uint8_t* &block2) {
32 block1 = reinterpret_cast<uint8_t*>
33 ((reinterpret_cast<uintptr_t>(&block_buffer[0]) + 15) & ~15);
34 GenerateData(block1, kSizeOfBlock);
35 block2 = block1 + kSizeOfBlock;
36 memcpy(block2, block1, kSizeOfBlock);
39 TEST(BlockDifferenceTestSame, BlockDifference) {
42 PrepareBuffers(block1, block2);
44 // These blocks should match.
45 for (int i = 0; i < kTimesToRun; ++i) {
46 int result = BlockDifference(block1, block2, kBlockSize * kBytesPerPixel);
51 TEST(BlockDifferenceTestLast, BlockDifference) {
54 PrepareBuffers(block1, block2);
55 block2[kSizeOfBlock-2] += 1;
57 for (int i = 0; i < kTimesToRun; ++i) {
58 int result = BlockDifference(block1, block2, kBlockSize * kBytesPerPixel);
63 TEST(BlockDifferenceTestMid, BlockDifference) {
66 PrepareBuffers(block1, block2);
67 block2[kSizeOfBlock/2+1] += 1;
69 for (int i = 0; i < kTimesToRun; ++i) {
70 int result = BlockDifference(block1, block2, kBlockSize * kBytesPerPixel);
75 TEST(BlockDifferenceTestFirst, BlockDifference) {
78 PrepareBuffers(block1, block2);
81 for (int i = 0; i < kTimesToRun; ++i) {
82 int result = BlockDifference(block1, block2, kBlockSize * kBytesPerPixel);