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

Side by Side Diff: tests/StreamTest.cpp

Issue 849103004: Make SkStream *not* ref counted. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase, just in case. Created 5 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/SerializationTest.cpp ('k') | tools/dump_record.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 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 "SkData.h" 8 #include "SkData.h"
9 #include "SkOSFile.h" 9 #include "SkOSFile.h"
10 #include "SkRandom.h" 10 #include "SkRandom.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 for (int i = 0; i < 100; ++i) { 51 for (int i = 0; i < 100; ++i) {
52 writer.write(s, 26); 52 writer.write(s, 26);
53 } 53 }
54 } 54 }
55 55
56 { 56 {
57 SkFILEStream stream(path.c_str()); 57 SkFILEStream stream(path.c_str());
58 REPORTER_ASSERT(reporter, stream.isValid()); 58 REPORTER_ASSERT(reporter, stream.isValid());
59 test_loop_stream(reporter, &stream, s, 26, 100); 59 test_loop_stream(reporter, &stream, s, 26, 100);
60 60
61 SkAutoTUnref<SkStreamAsset> stream2(stream.duplicate()); 61 SkAutoTDelete<SkStreamAsset> stream2(stream.duplicate());
62 test_loop_stream(reporter, stream2.get(), s, 26, 100); 62 test_loop_stream(reporter, stream2.get(), s, 26, 100);
63 } 63 }
64 64
65 { 65 {
66 FILE* file = ::fopen(path.c_str(), "rb"); 66 FILE* file = ::fopen(path.c_str(), "rb");
67 SkFILEStream stream(file, SkFILEStream::kCallerPasses_Ownership); 67 SkFILEStream stream(file, SkFILEStream::kCallerPasses_Ownership);
68 REPORTER_ASSERT(reporter, stream.isValid()); 68 REPORTER_ASSERT(reporter, stream.isValid());
69 test_loop_stream(reporter, &stream, s, 26, 100); 69 test_loop_stream(reporter, &stream, s, 26, 100);
70 70
71 SkAutoTUnref<SkStreamAsset> stream2(stream.duplicate()); 71 SkAutoTDelete<SkStreamAsset> stream2(stream.duplicate());
72 test_loop_stream(reporter, stream2.get(), s, 26, 100); 72 test_loop_stream(reporter, stream2.get(), s, 26, 100);
73 } 73 }
74 } 74 }
75 75
76 static void TestWStream(skiatest::Reporter* reporter) { 76 static void TestWStream(skiatest::Reporter* reporter) {
77 SkDynamicMemoryWStream ds; 77 SkDynamicMemoryWStream ds;
78 const char s[] = "abcdefghijklmnopqrstuvwxyz"; 78 const char s[] = "abcdefghijklmnopqrstuvwxyz";
79 int i; 79 int i;
80 for (i = 0; i < 100; i++) { 80 for (i = 0; i < 100; i++) {
81 REPORTER_ASSERT(reporter, ds.write(s, 26)); 81 REPORTER_ASSERT(reporter, ds.write(s, 26));
82 } 82 }
83 REPORTER_ASSERT(reporter, ds.getOffset() == 100 * 26); 83 REPORTER_ASSERT(reporter, ds.getOffset() == 100 * 26);
84 84
85 char* dst = new char[100 * 26 + 1]; 85 char* dst = new char[100 * 26 + 1];
86 dst[100*26] = '*'; 86 dst[100*26] = '*';
87 ds.copyTo(dst); 87 ds.copyTo(dst);
88 REPORTER_ASSERT(reporter, dst[100*26] == '*'); 88 REPORTER_ASSERT(reporter, dst[100*26] == '*');
89 for (i = 0; i < 100; i++) { 89 for (i = 0; i < 100; i++) {
90 REPORTER_ASSERT(reporter, memcmp(&dst[i * 26], s, 26) == 0); 90 REPORTER_ASSERT(reporter, memcmp(&dst[i * 26], s, 26) == 0);
91 } 91 }
92 92
93 { 93 {
94 SkAutoTUnref<SkStreamAsset> stream(ds.detachAsStream()); 94 SkAutoTDelete<SkStreamAsset> stream(ds.detachAsStream());
95 REPORTER_ASSERT(reporter, 100 * 26 == stream->getLength()); 95 REPORTER_ASSERT(reporter, 100 * 26 == stream->getLength());
96 REPORTER_ASSERT(reporter, ds.getOffset() == 0); 96 REPORTER_ASSERT(reporter, ds.getOffset() == 0);
97 test_loop_stream(reporter, stream.get(), s, 26, 100); 97 test_loop_stream(reporter, stream.get(), s, 26, 100);
98 98
99 SkAutoTUnref<SkStreamAsset> stream2(stream->duplicate()); 99 SkAutoTDelete<SkStreamAsset> stream2(stream->duplicate());
100 test_loop_stream(reporter, stream2.get(), s, 26, 100); 100 test_loop_stream(reporter, stream2.get(), s, 26, 100);
101 101
102 SkAutoTUnref<SkStreamAsset> stream3(stream->fork()); 102 SkAutoTDelete<SkStreamAsset> stream3(stream->fork());
103 REPORTER_ASSERT(reporter, stream3->isAtEnd()); 103 REPORTER_ASSERT(reporter, stream3->isAtEnd());
104 char tmp; 104 char tmp;
105 size_t bytes = stream->read(&tmp, 1); 105 size_t bytes = stream->read(&tmp, 1);
106 REPORTER_ASSERT(reporter, 0 == bytes); 106 REPORTER_ASSERT(reporter, 0 == bytes);
107 stream3->rewind(); 107 stream3->rewind();
108 test_loop_stream(reporter, stream3.get(), s, 26, 100); 108 test_loop_stream(reporter, stream3.get(), s, 26, 100);
109 } 109 }
110 110
111 for (i = 0; i < 100; i++) { 111 for (i = 0; i < 100; i++) {
112 REPORTER_ASSERT(reporter, ds.write(s, 26)); 112 REPORTER_ASSERT(reporter, ds.write(s, 26));
113 } 113 }
114 REPORTER_ASSERT(reporter, ds.getOffset() == 100 * 26); 114 REPORTER_ASSERT(reporter, ds.getOffset() == 100 * 26);
115 115
116 { 116 {
117 SkAutoTUnref<SkData> data(ds.copyToData()); 117 SkAutoTUnref<SkData> data(ds.copyToData());
118 REPORTER_ASSERT(reporter, 100 * 26 == data->size()); 118 REPORTER_ASSERT(reporter, 100 * 26 == data->size());
119 REPORTER_ASSERT(reporter, memcmp(dst, data->data(), data->size()) == 0); 119 REPORTER_ASSERT(reporter, memcmp(dst, data->data(), data->size()) == 0);
120 } 120 }
121 121
122 { 122 {
123 // Test that this works after a copyToData. 123 // Test that this works after a copyToData.
124 SkAutoTUnref<SkStreamAsset> stream(ds.detachAsStream()); 124 SkAutoTDelete<SkStreamAsset> stream(ds.detachAsStream());
125 REPORTER_ASSERT(reporter, ds.getOffset() == 0); 125 REPORTER_ASSERT(reporter, ds.getOffset() == 0);
126 test_loop_stream(reporter, stream.get(), s, 26, 100); 126 test_loop_stream(reporter, stream.get(), s, 26, 100);
127 127
128 SkAutoTUnref<SkStreamAsset> stream2(stream->duplicate()); 128 SkAutoTDelete<SkStreamAsset> stream2(stream->duplicate());
129 test_loop_stream(reporter, stream2.get(), s, 26, 100); 129 test_loop_stream(reporter, stream2.get(), s, 26, 100);
130 } 130 }
131 delete[] dst; 131 delete[] dst;
132 132
133 SkString tmpDir = skiatest::GetTmpDir(); 133 SkString tmpDir = skiatest::GetTmpDir();
134 if (!tmpDir.isEmpty()) { 134 if (!tmpDir.isEmpty()) {
135 test_filestreams(reporter, tmpDir.c_str()); 135 test_filestreams(reporter, tmpDir.c_str());
136 } 136 }
137 } 137 }
138 138
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 memStream.setData(nullData); 183 memStream.setData(nullData);
184 TestDereferencingData(&memStream); 184 TestDereferencingData(&memStream);
185 185
186 } 186 }
187 187
188 DEF_TEST(Stream, reporter) { 188 DEF_TEST(Stream, reporter) {
189 TestWStream(reporter); 189 TestWStream(reporter);
190 TestPackedUInt(reporter); 190 TestPackedUInt(reporter);
191 TestNullData(); 191 TestNullData();
192 } 192 }
OLDNEW
« no previous file with comments | « tests/SerializationTest.cpp ('k') | tools/dump_record.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698