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

Side by Side Diff: tests/StreamTest.cpp

Issue 12334131: Change random number generator for tests to SkMWCRandom (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Rebase to latest Created 7 years, 9 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 | « tests/SortTest.cpp ('k') | tests/UtilsTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "Test.h" 8 #include "Test.h"
9 #include "SkRandom.h" 9 #include "SkRandom.h"
10 #include "SkStream.h" 10 #include "SkStream.h"
11 #include "SkData.h" 11 #include "SkData.h"
12 12
13 #ifndef SK_BUILD_FOR_WIN 13 #ifndef SK_BUILD_FOR_WIN
14 #include <unistd.h> 14 #include <unistd.h>
15 #include <fcntl.h> 15 #include <fcntl.h>
16 #endif 16 #endif
17 17
18 #define MAX_SIZE (256 * 1024) 18 #define MAX_SIZE (256 * 1024)
19 19
20 static void random_fill(SkRandom& rand, void* buffer, size_t size) { 20 static void random_fill(SkMWCRandom& rand, void* buffer, size_t size) {
21 char* p = (char*)buffer; 21 char* p = (char*)buffer;
22 char* stop = p + size; 22 char* stop = p + size;
23 while (p < stop) { 23 while (p < stop) {
24 *p++ = (char)(rand.nextU() >> 8); 24 *p++ = (char)(rand.nextU() >> 8);
25 } 25 }
26 } 26 }
27 27
28 static void test_buffer(skiatest::Reporter* reporter) { 28 static void test_buffer(skiatest::Reporter* reporter) {
29 SkRandom rand; 29 SkMWCRandom rand;
30 SkAutoMalloc am(MAX_SIZE * 2); 30 SkAutoMalloc am(MAX_SIZE * 2);
31 char* storage = (char*)am.get(); 31 char* storage = (char*)am.get();
32 char* storage2 = storage + MAX_SIZE; 32 char* storage2 = storage + MAX_SIZE;
33 33
34 random_fill(rand, storage, MAX_SIZE); 34 random_fill(rand, storage, MAX_SIZE);
35 35
36 for (int sizeTimes = 0; sizeTimes < 100; sizeTimes++) { 36 for (int sizeTimes = 0; sizeTimes < 100; sizeTimes++) {
37 int size = rand.nextU() % MAX_SIZE; 37 int size = rand.nextU() % MAX_SIZE;
38 if (size == 0) { 38 if (size == 0) {
39 size = MAX_SIZE; 39 size = MAX_SIZE;
(...skipping 15 matching lines...) Expand all
55 } 55 }
56 REPORTER_ASSERT(reporter, bytesRead == size); 56 REPORTER_ASSERT(reporter, bytesRead == size);
57 } 57 }
58 } 58 }
59 } 59 }
60 60
61 static void TestRStream(skiatest::Reporter* reporter) { 61 static void TestRStream(skiatest::Reporter* reporter) {
62 static const char s[] = 62 static const char s[] =
63 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 63 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
64 char copy[sizeof(s)]; 64 char copy[sizeof(s)];
65 SkRandom rand; 65 SkMWCRandom rand;
66 66
67 for (int i = 0; i < 65; i++) { 67 for (int i = 0; i < 65; i++) {
68 char* copyPtr = copy; 68 char* copyPtr = copy;
69 SkMemoryStream mem(s, sizeof(s)); 69 SkMemoryStream mem(s, sizeof(s));
70 SkBufferStream buff(&mem, i); 70 SkBufferStream buff(&mem, i);
71 71
72 do { 72 do {
73 copyPtr += buff.read(copyPtr, rand.nextU() & 15); 73 copyPtr += buff.read(copyPtr, rand.nextU() & 15);
74 } while (copyPtr < copy + sizeof(s)); 74 } while (copyPtr < copy + sizeof(s));
75 REPORTER_ASSERT(reporter, copyPtr == copy + sizeof(s)); 75 REPORTER_ASSERT(reporter, copyPtr == copy + sizeof(s));
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 211
212 static void TestStreams(skiatest::Reporter* reporter) { 212 static void TestStreams(skiatest::Reporter* reporter) {
213 TestRStream(reporter); 213 TestRStream(reporter);
214 TestWStream(reporter); 214 TestWStream(reporter);
215 TestPackedUInt(reporter); 215 TestPackedUInt(reporter);
216 TestNullData(); 216 TestNullData();
217 } 217 }
218 218
219 #include "TestClassDef.h" 219 #include "TestClassDef.h"
220 DEFINE_TESTCLASS("Stream", StreamTestClass, TestStreams) 220 DEFINE_TESTCLASS("Stream", StreamTestClass, TestStreams)
OLDNEW
« no previous file with comments | « tests/SortTest.cpp ('k') | tests/UtilsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698