| OLD | NEW |
| 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 "SkOSFile.h" | 10 #include "SkOSFile.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 char* dst = new char[100 * 26 + 1]; | 87 char* dst = new char[100 * 26 + 1]; |
| 88 dst[100*26] = '*'; | 88 dst[100*26] = '*'; |
| 89 ds.copyTo(dst); | 89 ds.copyTo(dst); |
| 90 REPORTER_ASSERT(reporter, dst[100*26] == '*'); | 90 REPORTER_ASSERT(reporter, dst[100*26] == '*'); |
| 91 for (i = 0; i < 100; i++) { | 91 for (i = 0; i < 100; i++) { |
| 92 REPORTER_ASSERT(reporter, memcmp(&dst[i * 26], s, 26) == 0); | 92 REPORTER_ASSERT(reporter, memcmp(&dst[i * 26], s, 26) == 0); |
| 93 } | 93 } |
| 94 | 94 |
| 95 { | 95 { |
| 96 SkAutoTUnref<SkStreamAsset> stream(ds.detatchAsStream()); | 96 SkAutoTUnref<SkStreamAsset> stream(ds.detachAsStream()); |
| 97 REPORTER_ASSERT(reporter, 100 * 26 == stream->getLength()); | 97 REPORTER_ASSERT(reporter, 100 * 26 == stream->getLength()); |
| 98 REPORTER_ASSERT(reporter, ds.getOffset() == 0); | 98 REPORTER_ASSERT(reporter, ds.getOffset() == 0); |
| 99 test_loop_stream(reporter, stream.get(), s, 26, 100); | 99 test_loop_stream(reporter, stream.get(), s, 26, 100); |
| 100 | 100 |
| 101 SkAutoTUnref<SkStreamAsset> stream2(stream->duplicate()); | 101 SkAutoTUnref<SkStreamAsset> stream2(stream->duplicate()); |
| 102 test_loop_stream(reporter, stream2.get(), s, 26, 100); | 102 test_loop_stream(reporter, stream2.get(), s, 26, 100); |
| 103 | 103 |
| 104 SkAutoTUnref<SkStreamAsset> stream3(stream->fork()); | 104 SkAutoTUnref<SkStreamAsset> stream3(stream->fork()); |
| 105 REPORTER_ASSERT(reporter, stream3->isAtEnd()); | 105 REPORTER_ASSERT(reporter, stream3->isAtEnd()); |
| 106 char tmp; | 106 char tmp; |
| 107 size_t bytes = stream->read(&tmp, 1); | 107 size_t bytes = stream->read(&tmp, 1); |
| 108 REPORTER_ASSERT(reporter, 0 == bytes); | 108 REPORTER_ASSERT(reporter, 0 == bytes); |
| 109 stream3->rewind(); | 109 stream3->rewind(); |
| 110 test_loop_stream(reporter, stream3.get(), s, 26, 100); | 110 test_loop_stream(reporter, stream3.get(), s, 26, 100); |
| 111 } | 111 } |
| 112 | 112 |
| 113 for (i = 0; i < 100; i++) { | 113 for (i = 0; i < 100; i++) { |
| 114 REPORTER_ASSERT(reporter, ds.write(s, 26)); | 114 REPORTER_ASSERT(reporter, ds.write(s, 26)); |
| 115 } | 115 } |
| 116 REPORTER_ASSERT(reporter, ds.getOffset() == 100 * 26); | 116 REPORTER_ASSERT(reporter, ds.getOffset() == 100 * 26); |
| 117 | 117 |
| 118 { | 118 { |
| 119 SkAutoTUnref<SkData> data(ds.copyToData()); | 119 SkAutoTUnref<SkData> data(ds.copyToData()); |
| 120 REPORTER_ASSERT(reporter, 100 * 26 == data->size()); | 120 REPORTER_ASSERT(reporter, 100 * 26 == data->size()); |
| 121 REPORTER_ASSERT(reporter, memcmp(dst, data->data(), data->size()) == 0); | 121 REPORTER_ASSERT(reporter, memcmp(dst, data->data(), data->size()) == 0); |
| 122 } | 122 } |
| 123 | 123 |
| 124 { | 124 { |
| 125 // Test that this works after a copyToData. | 125 // Test that this works after a copyToData. |
| 126 SkAutoTUnref<SkStreamAsset> stream(ds.detatchAsStream()); | 126 SkAutoTUnref<SkStreamAsset> stream(ds.detachAsStream()); |
| 127 REPORTER_ASSERT(reporter, ds.getOffset() == 0); | 127 REPORTER_ASSERT(reporter, ds.getOffset() == 0); |
| 128 test_loop_stream(reporter, stream.get(), s, 26, 100); | 128 test_loop_stream(reporter, stream.get(), s, 26, 100); |
| 129 | 129 |
| 130 SkAutoTUnref<SkStreamAsset> stream2(stream->duplicate()); | 130 SkAutoTUnref<SkStreamAsset> stream2(stream->duplicate()); |
| 131 test_loop_stream(reporter, stream2.get(), s, 26, 100); | 131 test_loop_stream(reporter, stream2.get(), s, 26, 100); |
| 132 } | 132 } |
| 133 delete[] dst; | 133 delete[] dst; |
| 134 | 134 |
| 135 SkString tmpDir = skiatest::Test::GetTmpDir(); | 135 SkString tmpDir = skiatest::Test::GetTmpDir(); |
| 136 if (!tmpDir.isEmpty()) { | 136 if (!tmpDir.isEmpty()) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } | 188 } |
| 189 | 189 |
| 190 static void TestStreams(skiatest::Reporter* reporter) { | 190 static void TestStreams(skiatest::Reporter* reporter) { |
| 191 TestWStream(reporter); | 191 TestWStream(reporter); |
| 192 TestPackedUInt(reporter); | 192 TestPackedUInt(reporter); |
| 193 TestNullData(); | 193 TestNullData(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 #include "TestClassDef.h" | 196 #include "TestClassDef.h" |
| 197 DEFINE_TESTCLASS("Stream", StreamTestClass, TestStreams) | 197 DEFINE_TESTCLASS("Stream", StreamTestClass, TestStreams) |
| OLD | NEW |