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

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

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

Powered by Google App Engine
This is Rietveld 408576698