| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "Resources.h" | 8 #include "Resources.h" |
| 9 #include "SkData.h" | 9 #include "SkData.h" |
| 10 #include "SkFrontBufferedStream.h" | 10 #include "SkFrontBufferedStream.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 SkMemoryStream rstream(buffer, sizeof(buffer)); | 163 SkMemoryStream rstream(buffer, sizeof(buffer)); |
| 164 for (i = 0; i < SK_ARRAY_COUNT(sizes); ++i) { | 164 for (i = 0; i < SK_ARRAY_COUNT(sizes); ++i) { |
| 165 size_t n = rstream.readPackedUInt(); | 165 size_t n = rstream.readPackedUInt(); |
| 166 if (sizes[i] != n) { | 166 if (sizes[i] != n) { |
| 167 SkDebugf("-- %d: sizes:%x n:%x\n", i, sizes[i], n); | 167 SkDebugf("-- %d: sizes:%x n:%x\n", i, sizes[i], n); |
| 168 } | 168 } |
| 169 REPORTER_ASSERT(reporter, sizes[i] == n); | 169 REPORTER_ASSERT(reporter, sizes[i] == n); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 // Test that setting an SkMemoryStream to a NULL data does not result in a crash
when calling | 173 // Test that setting an SkMemoryStream to a nullptr data does not result in a cr
ash when calling |
| 174 // methods that access fData. | 174 // methods that access fData. |
| 175 static void TestDereferencingData(SkMemoryStream* memStream) { | 175 static void TestDereferencingData(SkMemoryStream* memStream) { |
| 176 memStream->read(NULL, 0); | 176 memStream->read(nullptr, 0); |
| 177 memStream->getMemoryBase(); | 177 memStream->getMemoryBase(); |
| 178 SkAutoDataUnref data(memStream->copyToData()); | 178 SkAutoDataUnref data(memStream->copyToData()); |
| 179 } | 179 } |
| 180 | 180 |
| 181 static void TestNullData() { | 181 static void TestNullData() { |
| 182 SkData* nullData = NULL; | 182 SkData* nullData = nullptr; |
| 183 SkMemoryStream memStream(nullData); | 183 SkMemoryStream memStream(nullData); |
| 184 TestDereferencingData(&memStream); | 184 TestDereferencingData(&memStream); |
| 185 | 185 |
| 186 memStream.setData(nullData); | 186 memStream.setData(nullData); |
| 187 TestDereferencingData(&memStream); | 187 TestDereferencingData(&memStream); |
| 188 | 188 |
| 189 } | 189 } |
| 190 | 190 |
| 191 DEF_TEST(Stream, reporter) { | 191 DEF_TEST(Stream, reporter) { |
| 192 TestWStream(reporter); | 192 TestWStream(reporter); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 break; | 234 break; |
| 235 } | 235 } |
| 236 peeked += i; | 236 peeked += i; |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 | 239 |
| 240 static void test_peeking_front_buffered_stream(skiatest::Reporter* r, | 240 static void test_peeking_front_buffered_stream(skiatest::Reporter* r, |
| 241 const SkStream& original, | 241 const SkStream& original, |
| 242 size_t bufferSize) { | 242 size_t bufferSize) { |
| 243 SkStream* dupe = original.duplicate(); | 243 SkStream* dupe = original.duplicate(); |
| 244 REPORTER_ASSERT(r, dupe != NULL); | 244 REPORTER_ASSERT(r, dupe != nullptr); |
| 245 SkAutoTDelete<SkStream> bufferedStream(SkFrontBufferedStream::Create(dupe, b
ufferSize)); | 245 SkAutoTDelete<SkStream> bufferedStream(SkFrontBufferedStream::Create(dupe, b
ufferSize)); |
| 246 REPORTER_ASSERT(r, bufferedStream != NULL); | 246 REPORTER_ASSERT(r, bufferedStream != nullptr); |
| 247 test_peeking_stream(r, bufferedStream, bufferSize); | 247 test_peeking_stream(r, bufferedStream, bufferSize); |
| 248 } | 248 } |
| 249 | 249 |
| 250 // This test uses file system operations that don't work out of the | 250 // This test uses file system operations that don't work out of the |
| 251 // box on iOS. It's likely that we don't need them on iOS. Ignoring for now. | 251 // box on iOS. It's likely that we don't need them on iOS. Ignoring for now. |
| 252 // TODO(stephana): Re-evaluate if we need this in the future. | 252 // TODO(stephana): Re-evaluate if we need this in the future. |
| 253 #ifndef SK_BUILD_FOR_IOS | 253 #ifndef SK_BUILD_FOR_IOS |
| 254 DEF_TEST(StreamPeek, reporter) { | 254 DEF_TEST(StreamPeek, reporter) { |
| 255 // Test a memory stream. | 255 // Test a memory stream. |
| 256 const char gAbcs[] = "abcdefghijklmnopqrstuvwxyz"; | 256 const char gAbcs[] = "abcdefghijklmnopqrstuvwxyz"; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 for (int j = 0; j < N; ++j) { | 386 for (int j = 0; j < N; ++j) { |
| 387 src[j] = random.nextU() & 0xff; | 387 src[j] = random.nextU() & 0xff; |
| 388 } | 388 } |
| 389 // SkStreamCopy had two code paths; this test both. | 389 // SkStreamCopy had two code paths; this test both. |
| 390 DumbStream dumbStream(src.get(), (size_t)N); | 390 DumbStream dumbStream(src.get(), (size_t)N); |
| 391 stream_copy_test(reporter, src, N, &dumbStream); | 391 stream_copy_test(reporter, src, N, &dumbStream); |
| 392 SkMemoryStream smartStream(src.get(), (size_t)N); | 392 SkMemoryStream smartStream(src.get(), (size_t)N); |
| 393 stream_copy_test(reporter, src, N, &smartStream); | 393 stream_copy_test(reporter, src, N, &smartStream); |
| 394 | 394 |
| 395 } | 395 } |
| OLD | NEW |