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

Side by Side Diff: tests/ImageGeneratorTest.cpp

Issue 1223413002: remove getter for imagegenerator factory, update test (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: document that SkData will never be null Created 5 years, 5 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 | « src/core/SkImageGenerator.cpp ('k') | no next file » | 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 2014 Google Inc. 2 * Copyright 2014 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 "SkGraphics.h" 9 #include "SkGraphics.h"
10 #include "SkImageGenerator.h" 10 #include "SkImageGenerator.h"
11 #include "Test.h" 11 #include "Test.h"
12 12
13 static SkImageGenerator* my_factory(SkData* data) { 13 static bool gMyFactoryWasCalled;
14 int* ptr = *(int**)data->data(); 14
15 *ptr = 1; // signal that we were called 15 static SkImageGenerator* my_factory(SkData*) {
16 gMyFactoryWasCalled = true;
16 return NULL; 17 return NULL;
17 } 18 }
18 19
19 static void test_imagegenerator_factory(skiatest::Reporter* reporter) { 20 static void test_imagegenerator_factory(skiatest::Reporter* reporter) {
20 int factoryHasBeenCalled = 0; 21 // just need a non-empty data to test things
21 int* sentinelPtr = &factoryHasBeenCalled; 22 SkData* data = SkData::NewWithCString("test_imagegenerator_factory");
22 SkData* data = SkData::NewWithCopy(&sentinelPtr, sizeof(sentinelPtr)); 23
24 gMyFactoryWasCalled = false;
23 25
24 SkImageGenerator* gen; 26 SkImageGenerator* gen;
25 REPORTER_ASSERT(reporter, 0 == *sentinelPtr); 27 REPORTER_ASSERT(reporter, !gMyFactoryWasCalled);
26 28
27 gen = SkImageGenerator::NewFromEncoded(data); 29 gen = SkImageGenerator::NewFromEncoded(data);
28 REPORTER_ASSERT(reporter, NULL == gen); 30 REPORTER_ASSERT(reporter, NULL == gen);
29 REPORTER_ASSERT(reporter, 0 == *sentinelPtr); 31 REPORTER_ASSERT(reporter, !gMyFactoryWasCalled);
30 32
31 // Test is racy, in that it hopes no other thread is changing this global... 33 // Test is racy, in that it hopes no other thread is changing this global...
32 SkGraphics::ImageGeneratorFromEncodedFactory prev = 34 SkGraphics::ImageGeneratorFromEncodedFactory prev =
33 SkGraphics::GetImageGeneratorFro mEncodedFactory(); 35 SkGraphics::SetImageGeneratorFromEncodedFact ory(my_factory);
34 SkGraphics::SetImageGeneratorFromEncodedFactory(my_factory);
35 gen = SkImageGenerator::NewFromEncoded(data); 36 gen = SkImageGenerator::NewFromEncoded(data);
36 REPORTER_ASSERT(reporter, NULL == gen); 37 REPORTER_ASSERT(reporter, NULL == gen);
37 REPORTER_ASSERT(reporter, 1 == *sentinelPtr); 38 REPORTER_ASSERT(reporter, gMyFactoryWasCalled);
38 SkGraphics::SetImageGeneratorFromEncodedFactory(prev); 39 SkGraphics::SetImageGeneratorFromEncodedFactory(prev);
39 } 40 }
40 41
41 class MyImageGenerator : public SkImageGenerator { 42 class MyImageGenerator : public SkImageGenerator {
42 public: 43 public:
43 MyImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(0, 0)) {} 44 MyImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(0, 0)) {}
44 }; 45 };
45 46
46 DEF_TEST(ImageGenerator, reporter) { 47 DEF_TEST(ImageGenerator, reporter) {
47 MyImageGenerator ig; 48 MyImageGenerator ig;
(...skipping 14 matching lines...) Expand all
62 ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace); 63 ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace);
63 64
64 int dummy; 65 int dummy;
65 planes[0] = planes[1] = planes[2] = &dummy; 66 planes[0] = planes[1] = planes[2] = &dummy;
66 rowBytes[0] = rowBytes[1] = rowBytes[2] = 250; 67 rowBytes[0] = rowBytes[1] = rowBytes[2] = 250;
67 68
68 ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace); 69 ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace);
69 70
70 test_imagegenerator_factory(reporter); 71 test_imagegenerator_factory(reporter);
71 } 72 }
OLDNEW
« no previous file with comments | « src/core/SkImageGenerator.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698