aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gyp/tests.gyp1
-rw-r--r--src/core/SkBitmap.cpp2
-rw-r--r--tests/BitmapTest.cpp30
3 files changed, 32 insertions, 1 deletions
diff --git a/gyp/tests.gyp b/gyp/tests.gyp
index 4c8053e6a6..d6a1a7c57b 100644
--- a/gyp/tests.gyp
+++ b/gyp/tests.gyp
@@ -32,6 +32,7 @@
'../tests/AnnotationTest.cpp',
'../tests/ARGBImageEncoderTest.cpp',
'../tests/AtomicTest.cpp',
+ '../tests/BitmapTest.cpp',
'../tests/BitmapCopyTest.cpp',
'../tests/BitmapGetColorTest.cpp',
'../tests/BitmapHasherTest.cpp',
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 25a6b1dba4..f2b56290ea 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -298,7 +298,7 @@ bool SkBitmap::setConfig(Config config, int width, int height, size_t rowBytes,
}
if (rowBytes == 0) {
rowBytes = SkBitmap::ComputeRowBytes(config, width);
- if (0 == rowBytes && kNo_Config != config) {
+ if (0 == rowBytes && kNo_Config != config && width > 0) {
goto BAD_CONFIG;
}
}
diff --git a/tests/BitmapTest.cpp b/tests/BitmapTest.cpp
new file mode 100644
index 0000000000..a6859fabf0
--- /dev/null
+++ b/tests/BitmapTest.cpp
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkBitmap.h"
+
+#include "Test.h"
+#include "TestClassDef.h"
+
+/**
+ * This test contains basic sanity checks concerning bitmaps.
+ */
+DEF_TEST(Bitmap, reporter) {
+ const SkBitmap::Config conf = SkBitmap::kARGB_8888_Config;
+ // Zero-sized bitmaps are allowed
+ for (int width = 0; width < 2; ++width) {
+ for (int height = 0; height < 2; ++height) {
+ SkBitmap bm;
+ bool setConf = bm.setConfig(conf, width, height);
+ REPORTER_ASSERT(reporter, setConf);
+ if (setConf) {
+ REPORTER_ASSERT(reporter, bm.allocPixels(NULL));
+ }
+ REPORTER_ASSERT(reporter, (width & height) != bm.empty());
+ }
+ }
+}