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

Side by Side Diff: tests/SerializationTest.cpp

Issue 137433003: Convert SkWriter32 to use an SkTDArray for its internal storage. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: of course 0's fine too... Created 6 years, 11 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
« no previous file with comments | « tests/PathTest.cpp ('k') | tests/Writer32Test.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 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Test.h" 8 #include "Test.h"
9 #include "TestClassDef.h" 9 #include "TestClassDef.h"
10 #include "SkBitmapDevice.h" 10 #include "SkBitmapDevice.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 static void Write(SkOrderedWriteBuffer& writer, SkScalar* data, uint32_t arr aySize) { 104 static void Write(SkOrderedWriteBuffer& writer, SkScalar* data, uint32_t arr aySize) {
105 writer.writeScalarArray(data, arraySize); 105 writer.writeScalarArray(data, arraySize);
106 } 106 }
107 static bool Read(SkValidatingReadBuffer& reader, SkScalar* data, uint32_t ar raySize) { 107 static bool Read(SkValidatingReadBuffer& reader, SkScalar* data, uint32_t ar raySize) {
108 return reader.readScalarArray(data, arraySize); 108 return reader.readScalarArray(data, arraySize);
109 } 109 }
110 }; 110 };
111 111
112 template<typename T> 112 template<typename T>
113 static void TestObjectSerialization(T* testObj, skiatest::Reporter* reporter) { 113 static void TestObjectSerialization(T* testObj, skiatest::Reporter* reporter) {
114 SkOrderedWriteBuffer writer(1024); 114 SkOrderedWriteBuffer writer;
115 writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag); 115 writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag);
116 SerializationUtils<T>::Write(writer, testObj); 116 SerializationUtils<T>::Write(writer, testObj);
117 size_t bytesWritten = writer.bytesWritten(); 117 size_t bytesWritten = writer.bytesWritten();
118 REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten); 118 REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten);
119 119
120 unsigned char dataWritten[1024]; 120 unsigned char dataWritten[1024];
121 writer.writeToMemory(dataWritten); 121 writer.writeToMemory(dataWritten);
122 122
123 // Make sure this fails when it should (test with smaller size, but still mu ltiple of 4) 123 // Make sure this fails when it should (test with smaller size, but still mu ltiple of 4)
124 SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4); 124 SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4);
(...skipping 10 matching lines...) Expand all
135 // This should have succeeded, since there are enough bytes to read this 135 // This should have succeeded, since there are enough bytes to read this
136 REPORTER_ASSERT(reporter, buffer2.isValid()); 136 REPORTER_ASSERT(reporter, buffer2.isValid());
137 REPORTER_ASSERT(reporter, static_cast<size_t>(peekAfter - peekBefore) == byt esWritten); 137 REPORTER_ASSERT(reporter, static_cast<size_t>(peekAfter - peekBefore) == byt esWritten);
138 138
139 TestAlignment(testObj, reporter); 139 TestAlignment(testObj, reporter);
140 } 140 }
141 141
142 template<typename T> 142 template<typename T>
143 static T* TestFlattenableSerialization(T* testObj, bool shouldSucceed, 143 static T* TestFlattenableSerialization(T* testObj, bool shouldSucceed,
144 skiatest::Reporter* reporter) { 144 skiatest::Reporter* reporter) {
145 SkOrderedWriteBuffer writer(1024); 145 SkOrderedWriteBuffer writer;
146 writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag); 146 writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag);
147 SerializationUtils<T>::Write(writer, testObj); 147 SerializationUtils<T>::Write(writer, testObj);
148 size_t bytesWritten = writer.bytesWritten(); 148 size_t bytesWritten = writer.bytesWritten();
149 REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten); 149 REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten);
150 150
151 unsigned char dataWritten[1024]; 151 unsigned char dataWritten[1024];
152 SkASSERT(bytesWritten <= sizeof(dataWritten)); 152 SkASSERT(bytesWritten <= sizeof(dataWritten));
153 writer.writeToMemory(dataWritten); 153 writer.writeToMemory(dataWritten);
154 154
155 // Make sure this fails when it should (test with smaller size, but still mu ltiple of 4) 155 // Make sure this fails when it should (test with smaller size, but still mu ltiple of 4)
(...skipping 18 matching lines...) Expand all
174 // If the deserialization was supposed to fail, make sure it did 174 // If the deserialization was supposed to fail, make sure it did
175 REPORTER_ASSERT(reporter, !buffer.isValid()); 175 REPORTER_ASSERT(reporter, !buffer.isValid());
176 REPORTER_ASSERT(reporter, NULL == obj2); 176 REPORTER_ASSERT(reporter, NULL == obj2);
177 } 177 }
178 178
179 return obj2; // Return object to perform further validity tests on it 179 return obj2; // Return object to perform further validity tests on it
180 } 180 }
181 181
182 template<typename T> 182 template<typename T>
183 static void TestArraySerialization(T* data, skiatest::Reporter* reporter) { 183 static void TestArraySerialization(T* data, skiatest::Reporter* reporter) {
184 SkOrderedWriteBuffer writer(1024); 184 SkOrderedWriteBuffer writer;
185 writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag); 185 writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag);
186 SerializationUtils<T>::Write(writer, data, kArraySize); 186 SerializationUtils<T>::Write(writer, data, kArraySize);
187 size_t bytesWritten = writer.bytesWritten(); 187 size_t bytesWritten = writer.bytesWritten();
188 // This should write the length (in 4 bytes) and the array 188 // This should write the length (in 4 bytes) and the array
189 REPORTER_ASSERT(reporter, (4 + kArraySize * sizeof(T)) == bytesWritten); 189 REPORTER_ASSERT(reporter, (4 + kArraySize * sizeof(T)) == bytesWritten);
190 190
191 unsigned char dataWritten[1024]; 191 unsigned char dataWritten[1024];
192 writer.writeToMemory(dataWritten); 192 writer.writeToMemory(dataWritten);
193 193
194 // Make sure this fails when it should 194 // Make sure this fails when it should
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 info.fHeight = 1; 327 info.fHeight = 1;
328 328
329 invalidBitmap2.setPixelRef(SkMallocPixelRef::NewAllocate( 329 invalidBitmap2.setPixelRef(SkMallocPixelRef::NewAllocate(
330 info, invalidBitmap2.rowBytes(), NULL))->unref(); 330 info, invalidBitmap2.rowBytes(), NULL))->unref();
331 331
332 // The deserialization should detect the pixel ref being too small and f ail 332 // The deserialization should detect the pixel ref being too small and f ail
333 TestBitmapSerialization(validBitmap, invalidBitmap2, false, reporter); 333 TestBitmapSerialization(validBitmap, invalidBitmap2, false, reporter);
334 #endif 334 #endif
335 } 335 }
336 } 336 }
OLDNEW
« no previous file with comments | « tests/PathTest.cpp ('k') | tests/Writer32Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698