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

Side by Side Diff: tests/DataRefTest.cpp

Issue 2206633004: Move off SK_SUPPORT_LEGACY_DATA_FACTORIES. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Gotta catch 'em all. Created 4 years, 4 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
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 "SkDataTable.h" 9 #include "SkDataTable.h"
10 #include "SkOSFile.h" 10 #include "SkOSFile.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 142 }
143 143
144 static void* gGlobal; 144 static void* gGlobal;
145 145
146 static void delete_int_proc(const void* ptr, void* context) { 146 static void delete_int_proc(const void* ptr, void* context) {
147 int* data = (int*)ptr; 147 int* data = (int*)ptr;
148 SkASSERT(context == gGlobal); 148 SkASSERT(context == gGlobal);
149 delete[] data; 149 delete[] data;
150 } 150 }
151 151
152 static void assert_len(skiatest::Reporter* reporter, SkData* ref, size_t len) { 152 static void assert_len(skiatest::Reporter* reporter, const sk_sp<SkData>& ref, s ize_t len) {
153 REPORTER_ASSERT(reporter, ref->size() == len); 153 REPORTER_ASSERT(reporter, ref->size() == len);
154 } 154 }
155 155
156 static void assert_data(skiatest::Reporter* reporter, SkData* ref, 156 static void assert_data(skiatest::Reporter* reporter, const sk_sp<SkData>& ref,
157 const void* data, size_t len) { 157 const void* data, size_t len) {
158 REPORTER_ASSERT(reporter, ref->size() == len); 158 REPORTER_ASSERT(reporter, ref->size() == len);
159 REPORTER_ASSERT(reporter, !memcmp(ref->data(), data, len)); 159 REPORTER_ASSERT(reporter, !memcmp(ref->data(), data, len));
160 } 160 }
161 161
162 static void test_cstring(skiatest::Reporter* reporter) { 162 static void test_cstring(skiatest::Reporter* reporter) {
163 const char str[] = "Hello world"; 163 const char str[] = "Hello world";
164 size_t len = strlen(str); 164 size_t len = strlen(str);
165 165
166 SkAutoTUnref<SkData> r0(SkData::NewWithCopy(str, len + 1)); 166 sk_sp<SkData> r0(SkData::MakeWithCopy(str, len + 1));
167 SkAutoTUnref<SkData> r1(SkData::NewWithCString(str)); 167 sk_sp<SkData> r1(SkData::MakeWithCString(str));
168 168
169 REPORTER_ASSERT(reporter, r0->equals(r1)); 169 REPORTER_ASSERT(reporter, r0->equals(r1.get()));
170 170
171 SkAutoTUnref<SkData> r2(SkData::NewWithCString(nullptr)); 171 sk_sp<SkData> r2(SkData::MakeWithCString(nullptr));
172 REPORTER_ASSERT(reporter, 1 == r2->size()); 172 REPORTER_ASSERT(reporter, 1 == r2->size());
173 REPORTER_ASSERT(reporter, 0 == *r2->bytes()); 173 REPORTER_ASSERT(reporter, 0 == *r2->bytes());
174 } 174 }
175 175
176 static void test_files(skiatest::Reporter* reporter) { 176 static void test_files(skiatest::Reporter* reporter) {
177 SkString tmpDir = skiatest::GetTmpDir(); 177 SkString tmpDir = skiatest::GetTmpDir();
178 if (tmpDir.isEmpty()) { 178 if (tmpDir.isEmpty()) {
179 return; 179 return;
180 } 180 }
181 181
182 SkString path = SkOSPath::Join(tmpDir.c_str(), "data_test"); 182 SkString path = SkOSPath::Join(tmpDir.c_str(), "data_test");
183 183
184 const char s[] = "abcdefghijklmnopqrstuvwxyz"; 184 const char s[] = "abcdefghijklmnopqrstuvwxyz";
185 { 185 {
186 SkFILEWStream writer(path.c_str()); 186 SkFILEWStream writer(path.c_str());
187 if (!writer.isValid()) { 187 if (!writer.isValid()) {
188 ERRORF(reporter, "Failed to create tmp file %s\n", path.c_str()); 188 ERRORF(reporter, "Failed to create tmp file %s\n", path.c_str());
189 return; 189 return;
190 } 190 }
191 writer.write(s, 26); 191 writer.write(s, 26);
192 } 192 }
193 193
194 FILE* file = sk_fopen(path.c_str(), kRead_SkFILE_Flag); 194 FILE* file = sk_fopen(path.c_str(), kRead_SkFILE_Flag);
195 SkAutoTUnref<SkData> r1(SkData::NewFromFILE(file)); 195 sk_sp<SkData> r1(SkData::MakeFromFILE(file));
196 REPORTER_ASSERT(reporter, r1.get() != nullptr); 196 REPORTER_ASSERT(reporter, r1.get() != nullptr);
197 REPORTER_ASSERT(reporter, r1->size() == 26); 197 REPORTER_ASSERT(reporter, r1->size() == 26);
198 REPORTER_ASSERT(reporter, strncmp(static_cast<const char*>(r1->data()), s, 2 6) == 0); 198 REPORTER_ASSERT(reporter, strncmp(static_cast<const char*>(r1->data()), s, 2 6) == 0);
199 199
200 int fd = sk_fileno(file); 200 int fd = sk_fileno(file);
201 SkAutoTUnref<SkData> r2(SkData::NewFromFD(fd)); 201 sk_sp<SkData> r2(SkData::MakeFromFD(fd));
202 REPORTER_ASSERT(reporter, r2.get() != nullptr); 202 REPORTER_ASSERT(reporter, r2.get() != nullptr);
203 REPORTER_ASSERT(reporter, r2->size() == 26); 203 REPORTER_ASSERT(reporter, r2->size() == 26);
204 REPORTER_ASSERT(reporter, strncmp(static_cast<const char*>(r2->data()), s, 2 6) == 0); 204 REPORTER_ASSERT(reporter, strncmp(static_cast<const char*>(r2->data()), s, 2 6) == 0);
205 } 205 }
206 206
207 DEF_TEST(Data, reporter) { 207 DEF_TEST(Data, reporter) {
208 const char* str = "We the people, in order to form a more perfect union."; 208 const char* str = "We the people, in order to form a more perfect union.";
209 const int N = 10; 209 const int N = 10;
210 210
211 SkAutoTUnref<SkData> r0(SkData::NewEmpty()); 211 sk_sp<SkData> r0(SkData::MakeEmpty());
212 SkAutoTUnref<SkData> r1(SkData::NewWithCopy(str, strlen(str))); 212 sk_sp<SkData> r1(SkData::MakeWithCopy(str, strlen(str)));
213 SkAutoTUnref<SkData> r2(SkData::NewWithProc(new int[N], N*sizeof(int), 213 sk_sp<SkData> r2(SkData::MakeWithProc(new int[N], N*sizeof(int), delete_int_ proc, gGlobal));
214 delete_int_proc, gGlobal)); 214 sk_sp<SkData> r3(SkData::MakeSubset(r1.get(), 7, 6));
215 SkAutoTUnref<SkData> r3(SkData::NewSubset(r1, 7, 6));
216 215
217 assert_len(reporter, r0, 0); 216 assert_len(reporter, r0, 0);
218 assert_len(reporter, r1, strlen(str)); 217 assert_len(reporter, r1, strlen(str));
219 assert_len(reporter, r2, N * sizeof(int)); 218 assert_len(reporter, r2, N * sizeof(int));
220 assert_len(reporter, r3, 6); 219 assert_len(reporter, r3, 6);
221 220
222 assert_data(reporter, r1, str, strlen(str)); 221 assert_data(reporter, r1, str, strlen(str));
223 assert_data(reporter, r3, "people", 6); 222 assert_data(reporter, r3, "people", 6);
224 223
225 SkData* tmp = SkData::NewSubset(r1, strlen(str), 10); 224 sk_sp<SkData> tmp(SkData::MakeSubset(r1.get(), strlen(str), 10));
226 assert_len(reporter, tmp, 0); 225 assert_len(reporter, tmp, 0);
227 tmp->unref(); 226 tmp = SkData::MakeSubset(r1.get(), 0, 0);
228 tmp = SkData::NewSubset(r1, 0, 0);
229 assert_len(reporter, tmp, 0); 227 assert_len(reporter, tmp, 0);
230 tmp->unref();
231 228
232 test_cstring(reporter); 229 test_cstring(reporter);
233 test_files(reporter); 230 test_files(reporter);
234 } 231 }
235 232
236 //////////////////////////////////////////////////////////////////////////////// /////////////////// 233 //////////////////////////////////////////////////////////////////////////////// ///////////////////
237 #include "SkRWBuffer.h" 234 #include "SkRWBuffer.h"
238 235
239 const char gABC[] = "abcdefghijklmnopqrstuvwxyz"; 236 const char gABC[] = "abcdefghijklmnopqrstuvwxyz";
240 237
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 } 371 }
375 372
376 SkAutoTDelete<SkStream> stream(buffer.newStreamSnapshot()); 373 SkAutoTDelete<SkStream> stream(buffer.newStreamSnapshot());
377 REPORTER_ASSERT(r, stream); 374 REPORTER_ASSERT(r, stream);
378 if (stream) { 375 if (stream) {
379 REPORTER_ASSERT(r, stream->hasLength()); 376 REPORTER_ASSERT(r, stream->hasLength());
380 REPORTER_ASSERT(r, stream->getLength() == 0); 377 REPORTER_ASSERT(r, stream->getLength() == 0);
381 REPORTER_ASSERT(r, stream->skip(10) == 0); 378 REPORTER_ASSERT(r, stream->skip(10) == 0);
382 } 379 }
383 } 380 }
OLDNEW
« include/core/SkData.h ('K') | « tests/CodecTest.cpp ('k') | tests/ImageGeneratorTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698