Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: trunk/src/remoting/base/util_unittest.cc

Issue 24217003: Revert 224101 "Remove dependency on Skia from chromoting client." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/src/remoting/base/util.cc ('k') | trunk/src/remoting/client/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 6
7 #include "remoting/base/util.h" 7 #include "remoting/base/util.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" 9 #include "third_party/skia/include/core/SkRect.h"
10 #include "third_party/skia/include/core/SkSize.h"
10 11
11 static const int kWidth = 32 ; 12 static const int kWidth = 32 ;
12 static const int kHeight = 24 ; 13 static const int kHeight = 24 ;
13 static const int kBytesPerPixel = 4; 14 static const int kBytesPerPixel = 4;
14 static const int kYStride = kWidth; 15 static const int kYStride = kWidth;
15 static const int kUvStride = kWidth / 2; 16 static const int kUvStride = kWidth / 2;
16 static const int kRgbStride = kWidth * kBytesPerPixel; 17 static const int kRgbStride = kWidth * kBytesPerPixel;
17 static const uint32 kFillColor = 0xffffff; 18 static const uint32 kFillColor = 0xffffff;
18 19
19 namespace remoting { 20 namespace remoting {
(...skipping 17 matching lines...) Expand all
37 ~YuvToRgbTester() {} 38 ~YuvToRgbTester() {}
38 39
39 void ResetYuvBuffer() { 40 void ResetYuvBuffer() {
40 memset(yuv_buffer_.get(), 0, yuv_buffer_size_); 41 memset(yuv_buffer_.get(), 0, yuv_buffer_size_);
41 } 42 }
42 43
43 void ResetRgbBuffer() { 44 void ResetRgbBuffer() {
44 memset(rgb_buffer_.get(), 0, rgb_buffer_size_); 45 memset(rgb_buffer_.get(), 0, rgb_buffer_size_);
45 } 46 }
46 47
47 void FillRgbBuffer(const webrtc::DesktopRect& rect) { 48 void FillRgbBuffer(const SkIRect& rect) {
48 uint32* ptr = reinterpret_cast<uint32*>( 49 uint32* ptr = reinterpret_cast<uint32*>(
49 rgb_buffer_.get() + (rect.top() * kRgbStride) + 50 rgb_buffer_.get() + (rect.top() * kRgbStride) +
50 (rect.left() * kBytesPerPixel)); 51 (rect.left() * kBytesPerPixel));
51 int width = rect.width(); 52 int width = rect.width();
52 for (int height = rect.height(); height > 0; --height) { 53 for (int height = rect.height(); height > 0; --height) {
53 std::fill(ptr, ptr + width, kFillColor); 54 std::fill(ptr, ptr + width, kFillColor);
54 ptr += kRgbStride / kBytesPerPixel; 55 ptr += kRgbStride / kBytesPerPixel;
55 } 56 }
56 } 57 }
57 58
58 // Check the the desination buffer is filled within expected bounds. 59 // Check the the desination buffer is filled within expected bounds.
59 void CheckRgbBuffer(const webrtc::DesktopRect& rect) { 60 void CheckRgbBuffer(const SkIRect& rect) {
60 uint32* ptr = reinterpret_cast<uint32*>(rgb_buffer_.get()); 61 uint32* ptr = reinterpret_cast<uint32*>(rgb_buffer_.get());
61 for (int y = 0; y < kHeight; ++y) { 62 for (int y = 0; y < kHeight; ++y) {
62 if (y < rect.top() || rect.bottom() <= y) { 63 if (y < rect.top() || rect.bottom() <= y) {
63 // The whole line should be intact. 64 // The whole line should be intact.
64 EXPECT_EQ((ptrdiff_t)kWidth, 65 EXPECT_EQ((ptrdiff_t)kWidth,
65 std::count(ptr, ptr + kWidth, 0u)); 66 std::count(ptr, ptr + kWidth, 0u));
66 } else { 67 } else {
67 // The space before the painted rectangle should be intact. 68 // The space before the painted rectangle should be intact.
68 EXPECT_EQ((ptrdiff_t)rect.left(), 69 EXPECT_EQ((ptrdiff_t)rect.left(),
69 std::count(ptr, ptr + rect.left(), 0u)); 70 std::count(ptr, ptr + rect.left(), 0u));
70 71
71 // All pixels of the target rectangle should be touched. 72 // All pixels of the target rectangle should be touched.
72 EXPECT_EQ(ptr + rect.right(), 73 EXPECT_EQ(ptr + rect.right(),
73 std::find(ptr + rect.left(), ptr + rect.right(), 0u)); 74 std::find(ptr + rect.left(), ptr + rect.right(), 0u));
74 75
75 // The space after the painted rectangle should be intact. 76 // The space after the painted rectangle should be intact.
76 EXPECT_EQ((ptrdiff_t)kWidth - rect.right(), 77 EXPECT_EQ((ptrdiff_t)kWidth - rect.right(),
77 std::count(ptr + rect.right(), ptr + kWidth, 0u)); 78 std::count(ptr + rect.right(), ptr + kWidth, 0u));
78 } 79 }
79 ptr += kRgbStride / kBytesPerPixel; 80 ptr += kRgbStride / kBytesPerPixel;
80 } 81 }
81 } 82 }
82 83
83 void RunTest(const webrtc::DesktopSize dest_size, 84 void RunTest(const SkISize dest_size, const SkIRect& rect) {
84 const webrtc::DesktopRect& rect) { 85 ASSERT_TRUE(SkIRect::MakeSize(dest_size).contains(rect));
85 ASSERT_TRUE(
86 DoesRectContain(webrtc::DesktopRect::MakeSize(dest_size), rect));
87 86
88 // Reset buffers. 87 // Reset buffers.
89 ResetYuvBuffer(); 88 ResetYuvBuffer();
90 ResetRgbBuffer(); 89 ResetRgbBuffer();
91 FillRgbBuffer(rect); 90 FillRgbBuffer(rect);
92 91
93 // RGB -> YUV 92 // RGB -> YUV
94 ConvertRGB32ToYUVWithRect(rgb_buffer_.get(), 93 ConvertRGB32ToYUVWithRect(rgb_buffer_.get(),
95 yplane_, 94 yplane_,
96 uplane_, 95 uplane_,
97 vplane_, 96 vplane_,
98 0, 97 0,
99 0, 98 0,
100 kWidth, 99 kWidth,
101 kHeight, 100 kHeight,
102 kRgbStride, 101 kRgbStride,
103 kYStride, 102 kYStride,
104 kUvStride); 103 kUvStride);
105 104
106 // Reset RGB buffer and do opposite conversion. 105 // Reset RGB buffer and do opposite conversion.
107 ResetRgbBuffer(); 106 ResetRgbBuffer();
108 ConvertAndScaleYUVToRGB32Rect(yplane_, 107 ConvertAndScaleYUVToRGB32Rect(yplane_,
109 uplane_, 108 uplane_,
110 vplane_, 109 vplane_,
111 kYStride, 110 kYStride,
112 kUvStride, 111 kUvStride,
113 webrtc::DesktopSize(kWidth, kHeight), 112 SkISize::Make(kWidth, kHeight),
114 webrtc::DesktopRect::MakeWH(kWidth, kHeight), 113 SkIRect::MakeWH(kWidth, kHeight),
115 rgb_buffer_.get(), 114 rgb_buffer_.get(),
116 kRgbStride, 115 kRgbStride,
117 dest_size, 116 dest_size,
118 webrtc::DesktopRect::MakeSize(dest_size), 117 SkIRect::MakeSize(dest_size),
119 rect); 118 rect);
120 119
121 // Check if it worked out. 120 // Check if it worked out.
122 CheckRgbBuffer(rect); 121 CheckRgbBuffer(rect);
123 } 122 }
124 123
125 void TestBasicConversion() { 124 void TestBasicConversion() {
126 // Whole buffer. 125 // Whole buffer.
127 RunTest(webrtc::DesktopSize(kWidth, kHeight), 126 RunTest(SkISize::Make(kWidth, kHeight), SkIRect::MakeWH(kWidth, kHeight));
128 webrtc::DesktopRect::MakeWH(kWidth, kHeight));
129 } 127 }
130 128
131 private: 129 private:
132 size_t yuv_buffer_size_; 130 size_t yuv_buffer_size_;
133 scoped_ptr<uint8[]> yuv_buffer_; 131 scoped_ptr<uint8[]> yuv_buffer_;
134 uint8* yplane_; 132 uint8* yplane_;
135 uint8* uplane_; 133 uint8* uplane_;
136 uint8* vplane_; 134 uint8* vplane_;
137 135
138 size_t rgb_buffer_size_; 136 size_t rgb_buffer_size_;
139 scoped_ptr<uint8[]> rgb_buffer_; 137 scoped_ptr<uint8[]> rgb_buffer_;
140 138
141 DISALLOW_COPY_AND_ASSIGN(YuvToRgbTester); 139 DISALLOW_COPY_AND_ASSIGN(YuvToRgbTester);
142 }; 140 };
143 141
144 TEST(YuvToRgbTest, BasicConversion) { 142 TEST(YuvToRgbTest, BasicConversion) {
145 YuvToRgbTester tester; 143 YuvToRgbTester tester;
146 tester.TestBasicConversion(); 144 tester.TestBasicConversion();
147 } 145 }
148 146
149 TEST(YuvToRgbTest, Clipping) { 147 TEST(YuvToRgbTest, Clipping) {
150 YuvToRgbTester tester; 148 YuvToRgbTester tester;
151 149
152 webrtc::DesktopSize dest_size = webrtc::DesktopSize(kWidth, kHeight); 150 SkISize dest_size = SkISize::Make(kWidth, kHeight);
153 webrtc::DesktopRect rect = 151 SkIRect rect = SkIRect::MakeLTRB(0, 0, kWidth - 1, kHeight - 1);
154 webrtc::DesktopRect::MakeLTRB(0, 0, kWidth - 1, kHeight - 1);
155 for (int i = 0; i < 16; ++i) { 152 for (int i = 0; i < 16; ++i) {
156 webrtc::DesktopRect dest_rect = webrtc::DesktopRect::MakeLTRB( 153 SkIRect dest_rect = rect;
157 rect.left() + ((i & 1) ? 1 : 0), 154 if ((i & 1) != 0)
158 rect.top() + ((i & 2) ? 1 : 0), 155 dest_rect.fLeft += 1;
159 rect.right() + ((i & 4) ? 1 : 0), 156 if ((i & 2) != 0)
160 rect.bottom() + ((i & 8) ? 1 : 0)); 157 dest_rect.fTop += 1;
158 if ((i & 4) != 0)
159 dest_rect.fRight += 1;
160 if ((i & 8) != 0)
161 dest_rect.fBottom += 1;
161 162
162 tester.RunTest(dest_size, dest_rect); 163 tester.RunTest(dest_size, dest_rect);
163 } 164 }
164 } 165 }
165 166
166 TEST(YuvToRgbTest, ClippingAndScaling) { 167 TEST(YuvToRgbTest, ClippingAndScaling) {
167 YuvToRgbTester tester; 168 YuvToRgbTester tester;
168 169
169 webrtc::DesktopSize dest_size = 170 SkISize dest_size = SkISize::Make(kWidth - 10, kHeight - 10);
170 webrtc::DesktopSize(kWidth - 10, kHeight - 10); 171 SkIRect rect = SkIRect::MakeLTRB(5, 5, kWidth - 11, kHeight - 11);
171 webrtc::DesktopRect rect =
172 webrtc::DesktopRect::MakeLTRB(5, 5, kWidth - 11, kHeight - 11);
173 for (int i = 0; i < 16; ++i) { 172 for (int i = 0; i < 16; ++i) {
174 webrtc::DesktopRect dest_rect = webrtc::DesktopRect::MakeLTRB( 173 SkIRect dest_rect = rect;
175 rect.left() + ((i & 1) ? 1 : 0), 174 if ((i & 1) != 0)
176 rect.top() + ((i & 2) ? 1 : 0), 175 dest_rect.fLeft += 1;
177 rect.right() + ((i & 4) ? 1 : 0), 176 if ((i & 2) != 0)
178 rect.bottom() + ((i & 8) ? 1 : 0)); 177 dest_rect.fTop += 1;
178 if ((i & 4) != 0)
179 dest_rect.fRight += 1;
180 if ((i & 8) != 0)
181 dest_rect.fBottom += 1;
179 182
180 tester.RunTest(dest_size, dest_rect); 183 tester.RunTest(dest_size, dest_rect);
181 } 184 }
182 } 185 }
183 186
184 TEST(ReplaceLfByCrLfTest, Basic) { 187 TEST(ReplaceLfByCrLfTest, Basic) {
185 EXPECT_EQ("ab", ReplaceLfByCrLf("ab")); 188 EXPECT_EQ("ab", ReplaceLfByCrLf("ab"));
186 EXPECT_EQ("\r\nab", ReplaceLfByCrLf("\nab")); 189 EXPECT_EQ("\r\nab", ReplaceLfByCrLf("\nab"));
187 EXPECT_EQ("\r\nab\r\n", ReplaceLfByCrLf("\nab\n")); 190 EXPECT_EQ("\r\nab\r\n", ReplaceLfByCrLf("\nab\n"));
188 EXPECT_EQ("\r\nab\r\ncd", ReplaceLfByCrLf("\nab\ncd")); 191 EXPECT_EQ("\r\nab\r\ncd", ReplaceLfByCrLf("\nab\ncd"));
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 EXPECT_FALSE(StringIsUtf8("\xfe\x80\x80\x80\x80\x80\x80", 7)); 281 EXPECT_FALSE(StringIsUtf8("\xfe\x80\x80\x80\x80\x80\x80", 7));
279 EXPECT_FALSE(StringIsUtf8("\xff\x80\x80\x80\x80\x80\x80", 7)); 282 EXPECT_FALSE(StringIsUtf8("\xff\x80\x80\x80\x80\x80\x80", 7));
280 283
281 // Invalid continuation byte 284 // Invalid continuation byte
282 EXPECT_FALSE(StringIsUtf8("\xc0\x00", 2)); 285 EXPECT_FALSE(StringIsUtf8("\xc0\x00", 2));
283 EXPECT_FALSE(StringIsUtf8("\xc0\x40", 2)); 286 EXPECT_FALSE(StringIsUtf8("\xc0\x40", 2));
284 EXPECT_FALSE(StringIsUtf8("\xc0\xc0", 2)); 287 EXPECT_FALSE(StringIsUtf8("\xc0\xc0", 2));
285 } 288 }
286 289
287 } // namespace remoting 290 } // namespace remoting
OLDNEW
« no previous file with comments | « trunk/src/remoting/base/util.cc ('k') | trunk/src/remoting/client/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698