OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/memory/ref_counted.h" | |
6 #include "remoting/host/differ_block.h" | |
7 #include "testing/gmock/include/gmock/gmock.h" | |
8 | |
9 namespace remoting { | |
10 | |
11 // Run 900 times to mimic 1280x720. | |
12 // TODO(fbarchard): Remove benchmark once performance is non-issue. | |
13 static const int kTimesToRun = 900; | |
14 | |
15 static void GenerateData(uint8* data, int size) { | |
16 for (int i = 0; i < size; ++i) { | |
17 data[i] = i; | |
18 } | |
19 } | |
20 | |
21 // Memory buffer large enough for 2 blocks aligned to 16 bytes. | |
22 static const int kSizeOfBlock = kBlockSize * kBlockSize * kBytesPerPixel; | |
23 uint8 block_buffer[kSizeOfBlock * 2 + 16]; | |
24 | |
25 void PrepareBuffers(uint8* &block1, uint8* &block2) { | |
26 block1 = reinterpret_cast<uint8*> | |
27 ((reinterpret_cast<uintptr_t>(&block_buffer[0]) + 15) & ~15); | |
28 GenerateData(block1, kSizeOfBlock); | |
29 block2 = block1 + kSizeOfBlock; | |
30 memcpy(block2, block1, kSizeOfBlock); | |
31 } | |
32 | |
33 TEST(BlockDifferenceTestSame, BlockDifference) { | |
34 uint8* block1; | |
35 uint8* block2; | |
36 PrepareBuffers(block1, block2); | |
37 | |
38 // These blocks should match. | |
39 for (int i = 0; i < kTimesToRun; ++i) { | |
40 int result = BlockDifference(block1, block2, kBlockSize * kBytesPerPixel); | |
41 EXPECT_EQ(0, result); | |
42 } | |
43 } | |
44 | |
45 TEST(BlockDifferenceTestLast, BlockDifference) { | |
46 uint8* block1; | |
47 uint8* block2; | |
48 PrepareBuffers(block1, block2); | |
49 block2[kSizeOfBlock-2] += 1; | |
50 | |
51 for (int i = 0; i < kTimesToRun; ++i) { | |
52 int result = BlockDifference(block1, block2, kBlockSize * kBytesPerPixel); | |
53 EXPECT_EQ(1, result); | |
54 } | |
55 } | |
56 | |
57 TEST(BlockDifferenceTestMid, BlockDifference) { | |
58 uint8* block1; | |
59 uint8* block2; | |
60 PrepareBuffers(block1, block2); | |
61 block2[kSizeOfBlock/2+1] += 1; | |
62 | |
63 for (int i = 0; i < kTimesToRun; ++i) { | |
64 int result = BlockDifference(block1, block2, kBlockSize * kBytesPerPixel); | |
65 EXPECT_EQ(1, result); | |
66 } | |
67 } | |
68 | |
69 TEST(BlockDifferenceTestFirst, BlockDifference) { | |
70 uint8* block1; | |
71 uint8* block2; | |
72 PrepareBuffers(block1, block2); | |
73 block2[0] += 1; | |
74 | |
75 for (int i = 0; i < kTimesToRun; ++i) { | |
76 int result = BlockDifference(block1, block2, kBlockSize * kBytesPerPixel); | |
77 EXPECT_EQ(1, result); | |
78 } | |
79 } | |
80 | |
81 } // namespace remoting | |
OLD | NEW |