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

Unified Diff: tests/ImageGeneratorTest.cpp

Issue 1229933003: add runtime option to provide data->imagegenerator factory (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase 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 side-by-side diff with in-line comments
Download patch
Index: tests/ImageGeneratorTest.cpp
diff --git a/tests/ImageGeneratorTest.cpp b/tests/ImageGeneratorTest.cpp
index 94867bc945f446be34abfdd1fdd2641b633bcdfd..c856d8be604d020dc54243693fb86443692a5777 100644
--- a/tests/ImageGeneratorTest.cpp
+++ b/tests/ImageGeneratorTest.cpp
@@ -5,9 +5,39 @@
* found in the LICENSE file.
*/
+#include "SkData.h"
+#include "SkGraphics.h"
#include "SkImageGenerator.h"
#include "Test.h"
+static SkImageGenerator* my_factory(SkData* data) {
+ int* ptr = *(int**)data->data();
+ *ptr = 1; // signal that we were called
+ return NULL;
+}
+
+static void test_imagegenerator_factory(skiatest::Reporter* reporter) {
scroggo 2015/07/09 19:01:15 Why not make this its own test, with DEF_TEST?
reed1 2015/07/09 19:05:45 Just style difference. When I see the output from
+ int factoryHasBeenCalled = 0;
+ int* sentinelPtr = &factoryHasBeenCalled;
+ SkData* data = SkData::NewWithCopy(&sentinelPtr, sizeof(sentinelPtr));
+
+ SkImageGenerator* gen;
+ REPORTER_ASSERT(reporter, 0 == *sentinelPtr);
+
+ gen = SkImageGenerator::NewFromEncoded(data);
+ REPORTER_ASSERT(reporter, NULL == gen);
+ REPORTER_ASSERT(reporter, 0 == *sentinelPtr);
+
+ // Test is racy, in that it hopes no other thread is changing this global...
+ SkGraphics::ImageGeneratorFromEncodedFactory prev =
+ SkGraphics::GetImageGeneratorFromEncodedFactory();
+ SkGraphics::SetImageGeneratorFromEncodedFactory(my_factory);
+ gen = SkImageGenerator::NewFromEncoded(data);
+ REPORTER_ASSERT(reporter, NULL == gen);
+ REPORTER_ASSERT(reporter, 1 == *sentinelPtr);
+ SkGraphics::SetImageGeneratorFromEncodedFactory(prev);
+}
+
class MyImageGenerator : public SkImageGenerator {
public:
MyImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(0, 0)) {}
@@ -36,4 +66,6 @@ DEF_TEST(ImageGenerator, reporter) {
rowBytes[0] = rowBytes[1] = rowBytes[2] = 250;
ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace);
+
+ test_imagegenerator_factory(reporter);
}

Powered by Google App Engine
This is Rietveld 408576698